From 28f65f13a5f5fdbefae6a8e4154365eafeb9e0d1 Mon Sep 17 00:00:00 2001 From: mezz Date: Tue, 5 Jul 2016 21:56:46 -0700 Subject: [PATCH] Fix worktable bug that could delete container items --- gradle.properties | 2 +- .../forestry/core/utils/InventoryUtil.java | 9 ---- .../forestry/core/utils/ItemStackUtil.java | 8 ++-- .../forestry/factory/tiles/TileWorktable.java | 44 ++++++------------- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/gradle.properties b/gradle.properties index a0ed8fcd5..f22eb6aca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,4 +8,4 @@ ic2_version=2.6.5-ex110 version_major=5 version_minor=1 -version_patch=9 +version_patch=10 diff --git a/src/main/java/forestry/core/utils/InventoryUtil.java b/src/main/java/forestry/core/utils/InventoryUtil.java index eb3ccd133..f40edc98f 100644 --- a/src/main/java/forestry/core/utils/InventoryUtil.java +++ b/src/main/java/forestry/core/utils/InventoryUtil.java @@ -36,15 +36,6 @@ import forestry.plugins.ForestryPluginUids; public abstract class InventoryUtil { - public static ItemStack depleteItem(ItemStack stack) { - if (stack.stackSize == 1) { - return stack.getItem().getContainerItem(stack); - } else { - stack.splitStack(1); - return stack; - } - } - public static boolean isWildcard(ItemStack stack) { return stack.getItemDamage() == OreDictionary.WILDCARD_VALUE; } diff --git a/src/main/java/forestry/core/utils/ItemStackUtil.java b/src/main/java/forestry/core/utils/ItemStackUtil.java index f57866d04..52d3eb5af 100644 --- a/src/main/java/forestry/core/utils/ItemStackUtil.java +++ b/src/main/java/forestry/core/utils/ItemStackUtil.java @@ -335,10 +335,6 @@ public abstract class ItemStackUtil { * Compare two item stacks for crafting equivalency. */ public static boolean isCraftingEquivalent(ItemStack base, ItemStack comparison, boolean oreDictionary, boolean craftingTools) { - if (isCraftingEquivalent(base, comparison)) { - return true; - } - if (base == null || comparison == null) { return false; } @@ -347,6 +343,10 @@ public abstract class ItemStackUtil { return true; } + if (isCraftingEquivalent(base, comparison)) { + return true; + } + if (base.hasTagCompound() && !base.getTagCompound().hasNoTags()) { if (!ItemStack.areItemStacksEqual(base, comparison)) { return false; diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index cf278c169..2462adb1c 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -14,13 +14,6 @@ import javax.annotation.Nonnull; import java.io.IOException; import java.util.List; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -import net.minecraftforge.common.ForgeHooks; - import forestry.core.inventory.InventoryAdapterTile; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.DataInputStreamForestry; @@ -36,6 +29,12 @@ import forestry.factory.inventory.InventoryGhostCrafting; import forestry.factory.inventory.InventoryWorktable; import forestry.factory.recipes.MemorizedRecipe; import forestry.factory.recipes.RecipeMemory; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.ForgeHooks; public class TileWorktable extends TileBase implements ICrafterWorktable { private RecipeMemory recipeMemory; @@ -157,30 +156,15 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { @Override public void onCraftingComplete(EntityPlayer player) { - IInventory craftingInventory = getCraftingDisplay(); - for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) { - ItemStack itemStack = craftingInventory.getStackInSlot(i); - if (itemStack == null) { - continue; - } + ForgeHooks.setCraftingPlayer(player); + ItemStack[] remainingItems = CraftingManager.getInstance().getRemainingItems(currentRecipe.getCraftMatrix(), player.worldObj); + ForgeHooks.setCraftingPlayer(null); - ItemStack container = null; - - if (itemStack.getItem().hasContainerItem(itemStack)) { - container = ForgeHooks.getContainerItem(itemStack); - } else if (itemStack.stackSize > 1) { - // TerraFirmaCraft's crafting event handler does some tricky stuff with its tools. - // It sets the tool's stack size to 2 instead of using a container. - container = ItemStackUtil.createSplitStack(itemStack, itemStack.stackSize - 1); - itemStack.stackSize = 1; - } - - if (container == null) { - continue; - } - - if (!InventoryUtil.tryAddStack(this, container, true)) { - player.dropItem(container, false); + for (ItemStack remainingItem : remainingItems) { + if (remainingItem != null) { + if (!InventoryUtil.tryAddStack(this, remainingItem, true)) { + player.dropItem(remainingItem, false); + } } }