diff --git a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java index 4a641eb15..b5fa1960b 100755 --- a/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java +++ b/src/main/java/forestry/apiculture/gadgets/TileAlvearySieve.java @@ -136,7 +136,7 @@ public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListe } @Override - public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { + public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { IInventoryAdapter inventory = getInternalInventory(); if (slotIndex == SLOT_SIEVE) { destroyPollen(); diff --git a/src/main/java/forestry/core/gadgets/TileEscritoire.java b/src/main/java/forestry/core/gadgets/TileEscritoire.java index ea5989959..b96bb5406 100755 --- a/src/main/java/forestry/core/gadgets/TileEscritoire.java +++ b/src/main/java/forestry/core/gadgets/TileEscritoire.java @@ -191,7 +191,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender } @Override - public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { + public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { if (slotIndex == SLOT_ANALYZE) { game.reset(); } diff --git a/src/main/java/forestry/core/gui/slots/SlotCrafter.java b/src/main/java/forestry/core/gui/slots/SlotCrafter.java index c00ce1cc0..dbab9854a 100755 --- a/src/main/java/forestry/core/gui/slots/SlotCrafter.java +++ b/src/main/java/forestry/core/gui/slots/SlotCrafter.java @@ -63,6 +63,6 @@ public class SlotCrafter extends SlotCrafting { public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) { FMLCommonHandler.instance().firePlayerCraftingEvent(player, itemStack, craftMatrix); this.onCrafting(itemStack, itemStack.stackSize); // handles crafting achievements, maps, and statistics - crafter.takenFromSlot(getSlotIndex(), true, player); + crafter.takenFromSlot(getSlotIndex(), player); } } diff --git a/src/main/java/forestry/core/gui/slots/SlotWatched.java b/src/main/java/forestry/core/gui/slots/SlotWatched.java index 376edf6ca..087d4a607 100644 --- a/src/main/java/forestry/core/gui/slots/SlotWatched.java +++ b/src/main/java/forestry/core/gui/slots/SlotWatched.java @@ -48,7 +48,7 @@ public abstract class SlotWatched extends SlotForestry { @Override public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack) { if (crafter != null) { - crafter.takenFromSlot(getSlotIndex(), true, player); + crafter.takenFromSlot(getSlotIndex(), player); } } diff --git a/src/main/java/forestry/core/interfaces/ICrafter.java b/src/main/java/forestry/core/interfaces/ICrafter.java index f53fdee44..62828d1e9 100755 --- a/src/main/java/forestry/core/interfaces/ICrafter.java +++ b/src/main/java/forestry/core/interfaces/ICrafter.java @@ -15,7 +15,7 @@ import net.minecraft.item.ItemStack; public interface ICrafter { - ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player); + ItemStack takenFromSlot(int slotIndex, EntityPlayer player); ItemStack getResult(); diff --git a/src/main/java/forestry/factory/gadgets/MachineFabricator.java b/src/main/java/forestry/factory/gadgets/MachineFabricator.java index bac9f85e6..6ded637a8 100755 --- a/src/main/java/forestry/factory/gadgets/MachineFabricator.java +++ b/src/main/java/forestry/factory/gadgets/MachineFabricator.java @@ -46,8 +46,6 @@ import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InvTools; import forestry.core.inventory.InventoryAdapter; import forestry.core.inventory.TileInventoryAdapter; -import forestry.core.inventory.wrappers.IInvSlot; -import forestry.core.inventory.wrappers.InventoryIterator; import forestry.core.network.GuiId; import forestry.core.utils.GuiUtil; import forestry.core.utils.ShapedRecipeCustom; @@ -81,11 +79,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT return molten == null; } - if (!resource.isFluidEqual(molten)) { - return false; - } - - return molten.amount <= resource.amount; + return resource.containsFluid(molten); } public ItemStack getPlan() { @@ -182,16 +176,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT return false; } - public static boolean isResourceLiquid(FluidStack liquid) { - for (Recipe recipe : recipes) { - if (recipe.hasLiquid(liquid)) { - return true; - } - } - - return false; - } - public static Smelting findMatchingSmelting(ItemStack resource) { if (resource == null) { return null; @@ -256,8 +240,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT private int heat = 0; private int guiMeltingPoint = 0; - private FluidStack pendingSmelt; - public MachineFabricator() { super(1100, 50, 3300); craftingInventory = new TileInventoryAdapter(this, SLOT_CRAFTING_COUNT, "CraftItems"); @@ -297,13 +279,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT // Tank tankManager.writeTanksToNBT(nbttagcompound); - // Pending Smelt - if (pendingSmelt != null) { - NBTTagCompound smelt = new NBTTagCompound(); - pendingSmelt.writeToNBT(smelt); - nbttagcompound.setTag("PendingSmelt", smelt); - } - craftingInventory.writeToNBT(nbttagcompound); } @@ -316,12 +291,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT // Tank tankManager.readTanksFromNBT(nbttagcompound); - // Pending Smelt - if (nbttagcompound.hasKey("PendingSmelt")) { - NBTTagCompound smelt = nbttagcompound.getCompoundTag("PendingSmelt"); - pendingSmelt = FluidStack.loadFluidStackFromNBT(smelt); - } - craftingInventory.readFromNBT(nbttagcompound); // FIXME 1.8: wont need this @@ -341,25 +310,12 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT /* UPDATING */ @Override public void updateServerSide() { - IInventoryAdapter inventory = getInternalInventory(); - // Add pending smelt - if (pendingSmelt != null) { - int filled = moltenTank.fill(pendingSmelt, true); - pendingSmelt.amount -= filled; + if (!moltenTank.isFull()) { + trySmelting(); + } - if (pendingSmelt.amount <= 0) { - pendingSmelt = null; - } - // Smelt if necessary and possible - } else if (moltenTank.getFluidAmount() < moltenTank.getCapacity() && inventory.getStackInSlot(SLOT_METAL) != null) { - Smelting smelt = RecipeManager.findMatchingSmelting(inventory.getStackInSlot(SLOT_METAL)); - if (smelt != null && smelt.meltingPoint <= heat) { - - this.decrStackSize(SLOT_METAL, 1); - pendingSmelt = smelt.product.copy(); - } - } else if (moltenTank.getFluidAmount() > 0) { + if (!moltenTank.isEmpty()) { // Remove smelt if we have gone below melting point Smelting smelt = RecipeManager.findMatchingSmelting(moltenTank.getFluid()); if (smelt != null && heat < smelt.meltingPoint) { @@ -376,9 +332,29 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT } } + private void trySmelting() { + IInventoryAdapter inventory = getInternalInventory(); + + ItemStack smeltResource = inventory.getStackInSlot(SLOT_METAL); + if (smeltResource == null) { + return; + } + + Smelting smelt = RecipeManager.findMatchingSmelting(smeltResource); + if (smelt == null || smelt.meltingPoint > heat) { + return; + } + + FluidStack smeltFluid = smelt.getProduct(); + if (moltenTank.fill(smeltFluid, false) == smeltFluid.amount) { + this.decrStackSize(SLOT_METAL, 1); + moltenTank.fill(smeltFluid, true); + } + } + @Override public boolean workCycle() { - craftResult(false, null); + craftResult(null); return addHeat(25); } @@ -428,25 +404,25 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT } @Override - public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { + public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { if (slotIndex != SLOT_RESULT) { return null; } - craftResult(consumeRecipe, player); - - IInventoryAdapter inventory = getInternalInventory(); - - // Return result - return inventory.decrStackSize(SLOT_RESULT, 1); + return getInternalInventory().decrStackSize(SLOT_RESULT, 1); } - private void craftResult(boolean consumeRecipe, EntityPlayer player) { + private void craftResult(EntityPlayer player) { Recipe myRecipe = getRecipe(); if (myRecipe == null) { return; } + ItemStack result = getResult(); + if (result == null) { + return; + } + IInventoryAdapter inventory = getInternalInventory(); if (inventory.getStackInSlot(SLOT_RESULT) != null) { @@ -457,17 +433,18 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT // Remove resources ItemStack[] crafting = InvTools.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT); - if (removeFromInventory(1, crafting, player, false)) { - removeFromInventory(1, crafting, player, true); - moltenTank.drain(liquid.amount, true); - } else if (consumeRecipe) { - removeFromCraftMatrix(myRecipe); - moltenTank.drain(liquid.amount, true); - } else { + if (!removeFromInventory(crafting, player, false)) { return; } - ItemStack result = getResult(); + FluidStack canDrain = moltenTank.drain(liquid.amount, false); + if (canDrain == null || !canDrain.isFluidStackIdentical(liquid)) { + return; + } + + removeFromInventory(crafting, player, true); + moltenTank.drain(liquid.amount, true); + // Damage plan if (inventory.getStackInSlot(SLOT_PLAN) != null) { Item planItem = inventory.getStackInSlot(SLOT_PLAN).getItem(); @@ -479,23 +456,13 @@ public class MachineFabricator extends TilePowered implements ICrafter, ILiquidT inventory.setInventorySlotContents(SLOT_RESULT, result); } - private void removeFromCraftMatrix(Recipe recipe) { - for (IInvSlot slot : InventoryIterator.getIterable(craftingInventory)) { - if (slot.getStackInSlot() == null) { - continue; - } - slot.decreaseStackInSlot(); - } - - } - - private boolean removeFromInventory(int count, ItemStack[] set, EntityPlayer player, boolean doRemove) { + private boolean removeFromInventory(ItemStack[] set, EntityPlayer player, boolean doRemove) { IInventoryAdapter inventory = getInternalInventory(); if (doRemove) { - return InvTools.removeSets(inventory, count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); + return InvTools.removeSets(inventory, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true); } else { ItemStack[] stock = InvTools.getStacks(inventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - return StackUtils.containsSets(set, stock) >= count; + return StackUtils.containsSets(set, stock) >= 1; } } diff --git a/src/main/java/forestry/factory/gadgets/TileWorktable.java b/src/main/java/forestry/factory/gadgets/TileWorktable.java index 5c12ba434..d6d6e5740 100755 --- a/src/main/java/forestry/factory/gadgets/TileWorktable.java +++ b/src/main/java/forestry/factory/gadgets/TileWorktable.java @@ -181,7 +181,7 @@ public class TileWorktable extends TileBase implements ICrafter { } @Override - public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) { + public ItemStack takenFromSlot(int slotIndex, EntityPlayer player) { if (!removeResources(player)) { return null; }