Fixed crafting patterns crashing when item of an input or output no longer exists

This commit is contained in:
Raoul Van den Berge
2016-05-21 21:25:09 +02:00
parent e397f0b8ff
commit 2073a94fcf
7 changed files with 50 additions and 19 deletions

View File

@@ -1,5 +1,9 @@
# Refined Storage Changelog
### 0.6.11
**Bugfixes**
- Fixed crafting patterns crashing when item of an input or output no longer exists
### 0.6.10
**Bugfixes**
- Fixed Processing Patterns not working

View File

@@ -49,7 +49,7 @@ public class GuiCrafter extends GuiBase {
int x = 27;
int y = 19 + (i * 18);
if (crafter.getStackInSlot(i) != null) {
if (crafter.getStackInSlot(i) != null && ItemPattern.isValid(crafter.getStackInSlot(i))) {
ItemStack pattern = crafter.getStackInSlot(i);
String text = t("gui.refinedstorage:crafter.processing");

View File

@@ -65,7 +65,7 @@ public class ItemPattern extends ItemBase {
}
private static ItemStack[] get(ItemStack pattern, String type) {
if (!isValid(pattern)) {
if (!pattern.hasTagCompound() || !pattern.getTagCompound().hasKey(type)) {
return null;
}
@@ -81,10 +81,23 @@ public class ItemPattern extends ItemBase {
}
public static boolean isValid(ItemStack pattern) {
return pattern.getTagCompound() != null &&
pattern.getTagCompound().hasKey(NBT_INPUTS) &&
pattern.getTagCompound().hasKey(NBT_OUTPUTS) &&
pattern.getTagCompound().hasKey(NBT_PROCESSING);
if (pattern.getTagCompound() == null || (!pattern.getTagCompound().hasKey(NBT_INPUTS) || !pattern.getTagCompound().hasKey(NBT_OUTPUTS) || !pattern.getTagCompound().hasKey(NBT_PROCESSING))) {
return false;
}
for (ItemStack input : getInputs(pattern)) {
if (input == null) {
return false;
}
}
for (ItemStack output : getOutputs(pattern)) {
if (output == null) {
return false;
}
}
return true;
}
public static void setProcessing(ItemStack pattern, boolean processing) {
@@ -96,7 +109,7 @@ public class ItemPattern extends ItemBase {
}
public static boolean isProcessing(ItemStack pattern) {
if (pattern.getTagCompound() == null) {
if (!pattern.hasTagCompound() || !pattern.getTagCompound().hasKey(NBT_PROCESSING)) {
return false;
}

View File

@@ -226,7 +226,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
TileCrafter crafter = (TileCrafter) machine;
for (int i = 0; i < TileCrafter.PATTERN_SLOTS; ++i) {
if (crafter.getStackInSlot(i) != null) {
if (crafter.getStackInSlot(i) != null && ItemPattern.isValid(crafter.getStackInSlot(i))) {
ItemStack pattern = crafter.getStackInSlot(i);
patterns.add(new CraftingPattern(crafter.getPos().getX(), crafter.getPos().getY(), crafter.getPos().getZ(), ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
@@ -502,13 +502,17 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
for (int i = 0; i < taskList.tagCount(); ++i) {
NBTTagCompound taskTag = taskList.getCompoundTagAt(i);
switch (taskTag.getInteger("Type")) {
case BasicCraftingTask.ID:
addCraftingTask(new BasicCraftingTask(taskTag));
break;
case ProcessingCraftingTask.ID:
addCraftingTask(new ProcessingCraftingTask(taskTag));
break;
CraftingPattern pattern = CraftingPattern.readFromNBT(taskTag.getCompoundTag(CraftingPattern.NBT));
if (pattern != null) {
switch (taskTag.getInteger("Type")) {
case BasicCraftingTask.ID:
addCraftingTask(new BasicCraftingTask(taskTag, pattern));
break;
case ProcessingCraftingTask.ID:
addCraftingTask(new ProcessingCraftingTask(taskTag, pattern));
break;
}
}
}
}

View File

@@ -80,14 +80,24 @@ public class CraftingPattern {
NBTTagList inputsTag = tag.getTagList(ItemPattern.NBT_INPUTS, Constants.NBT.TAG_COMPOUND);
ItemStack inputs[] = new ItemStack[inputsTag.tagCount()];
for (int i = 0; i < inputsTag.tagCount(); ++i) {
inputs[i] = ItemStack.loadItemStackFromNBT(inputsTag.getCompoundTagAt(i));
if (inputs[i] == null) {
return null;
}
}
NBTTagList outputsTag = tag.getTagList(ItemPattern.NBT_OUTPUTS, Constants.NBT.TAG_COMPOUND);
ItemStack outputs[] = new ItemStack[outputsTag.tagCount()];
for (int i = 0; i < outputsTag.tagCount(); ++i) {
outputs[i] = ItemStack.loadItemStackFromNBT(outputsTag.getCompoundTagAt(i));
if (outputs[i] == null) {
return null;
}
}
return new CraftingPattern(cx, cy, cz, processing, inputs, outputs);

View File

@@ -33,8 +33,8 @@ public class BasicCraftingTask implements ICraftingTask {
this.childTasks = new boolean[pattern.getInputs().length];
}
public BasicCraftingTask(NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
public BasicCraftingTask(NBTTagCompound tag, CraftingPattern pattern) {
this.pattern = pattern;
this.satisfied = RefinedStorageUtils.readBooleanArray(tag, NBT_SATISFIED);
this.checked = RefinedStorageUtils.readBooleanArray(tag, NBT_CHECKED);
this.childTasks = RefinedStorageUtils.readBooleanArray(tag, NBT_CHILD_TASKS);

View File

@@ -30,8 +30,8 @@ public class ProcessingCraftingTask implements ICraftingTask {
this.satisfied = new boolean[pattern.getOutputs().length];
}
public ProcessingCraftingTask(NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
public ProcessingCraftingTask(NBTTagCompound tag, CraftingPattern pattern) {
this.pattern = pattern;
this.inserted = RefinedStorageUtils.readBooleanArray(tag, NBT_INSERTED);
this.childTasks = RefinedStorageUtils.readBooleanArray(tag, NBT_CHILD_TASKS);
this.satisfied = RefinedStorageUtils.readBooleanArray(tag, NBT_SATISFIED);