Fix #1768 fix serious issues with the worktable

This commit is contained in:
mezz committed 2017-07-27 22:39:49 -07:00
1 parent b897056824
commit a1bc9144bd
8 files changed
+141 -130

No files matched your search

@@ -12,14 +12,31 @@ package forestry.factory.inventory;
import forestry.core.gui.ContainerDummy;
import forestry.factory.gui.ContainerWorktable;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
public class InventoryCraftingForestry extends InventoryCrafting {
private final Container eventHandlerIn;
public InventoryCraftingForestry(ContainerWorktable containerWorktable) {
super(containerWorktable, 3, 3);
this(containerWorktable, 3, 3);
}
public InventoryCraftingForestry() {
super(ContainerDummy.instance, 3, 3);
this(ContainerDummy.instance, 3, 3);
}
private InventoryCraftingForestry(Container eventHandlerIn, int width, int height) {
super(eventHandlerIn, width, height);
this.eventHandlerIn = eventHandlerIn;
}
public InventoryCraftingForestry copy() {
InventoryCraftingForestry copy = new InventoryCraftingForestry(this.eventHandlerIn, getWidth(), getHeight());
for (int slot = 0; slot < getSizeInventory(); slot++) {
copy.setInventorySlotContents(slot, getStackInSlot(slot).copy());
}
return copy;
}
}
@@ -23,7 +23,6 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
@@ -150,14 +149,13 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
return false;
}
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix());
NonNullList<ItemStack> inventoryStacks = InventoryUtil.getStacks(this);
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventoryStacks, world, selectedRecipe);
InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(currentRecipe.getCraftMatrix(), inventoryStacks, world, selectedRecipe);
if (crafting == null) {
return false;
}
recipeItems = InventoryUtil.getStacks(crafting);
NonNullList<ItemStack> recipeItems = InventoryUtil.getStacks(crafting);
IInventory inventory;
if (simulate) {
@@ -167,13 +165,11 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
inventory = this;
}
// craft recipe should exactly match ingredients here, so no oreDict or tool matching
NonNullList<ItemStack> removed = InventoryUtil.removeSets(inventory, 1, recipeItems, null, false, false, false);
if (removed == null) {
if (!InventoryUtil.deleteExactSet(inventory, recipeItems)) {
return false;
}
if (!simulate) {
if (!simulate && !world.isRemote) {
// update crafting display to match the ingredients that were actually used
setCraftingDisplay(crafting);
}
@@ -184,13 +180,16 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
@Override
public void onCraftingComplete(EntityPlayer player) {
Preconditions.checkState(currentRecipe != null);
IRecipe selectedRecipe = currentRecipe.getSelectedRecipe();
Preconditions.checkState(selectedRecipe != null);
ForgeHooks.setCraftingPlayer(player);
NonNullList<ItemStack> remainingItems = CraftingManager.getRemainingItems(currentRecipe.getCraftMatrix(), player.world);
InventoryCraftingForestry craftMatrix = currentRecipe.getCraftMatrix();
NonNullList<ItemStack> remainingItems = selectedRecipe.getRemainingItems(craftMatrix.copy());
ForgeHooks.setCraftingPlayer(null);
for (ItemStack remainingItem : remainingItems) {
if (remainingItem != null) {
if (remainingItem != null && !remainingItem.isEmpty()) {
if (!InventoryUtil.tryAddStack(this, remainingItem, true)) {
player.dropItem(remainingItem, false);
}