From 564f586c581030a45e0959348d212bd95fee782a Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Wed, 21 Jun 2017 20:27:04 +0200 Subject: [PATCH] Fix #137 [1.11.2] Lumbermill keeps working when bark and sawdust slots full. --- .../machines/lumbermill/LumbermillLogic.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/binnie/extratrees/machines/lumbermill/LumbermillLogic.java b/src/main/java/binnie/extratrees/machines/lumbermill/LumbermillLogic.java index 0ca6c364..27083806 100644 --- a/src/main/java/binnie/extratrees/machines/lumbermill/LumbermillLogic.java +++ b/src/main/java/binnie/extratrees/machines/lumbermill/LumbermillLogic.java @@ -3,6 +3,7 @@ package binnie.extratrees.machines.lumbermill; import net.minecraft.item.ItemStack; import binnie.core.machines.Machine; +import binnie.core.machines.MachineUtil; import binnie.core.machines.power.ComponentProcessSetCost; import binnie.core.machines.power.ErrorState; import binnie.core.machines.power.IProcess; @@ -19,17 +20,30 @@ public class LumbermillLogic extends ComponentProcessSetCost implements IProcess @Override public ErrorState canWork() { - ItemStack logStack = this.getUtil().getStack(LumbermillMachine.SLOT_LOG); + MachineUtil util = getUtil(); + ItemStack logStack = util.getStack(LumbermillMachine.SLOT_LOG); if (logStack.isEmpty()) { return new ErrorState.NoItem("No Wood", LumbermillMachine.SLOT_LOG); } final ItemStack plankResult = LumbermillRecipes.getPlankProduct(logStack); - if (!this.getUtil().isSlotEmpty(LumbermillMachine.SLOT_PLANKS) && plankResult != null) { - final ItemStack currentPlank = this.getUtil().getStack(LumbermillMachine.SLOT_PLANKS); + if (!util.isSlotEmpty(LumbermillMachine.SLOT_PLANKS) && !plankResult.isEmpty()) { + final ItemStack currentPlank = util.getStack(LumbermillMachine.SLOT_PLANKS); if (!plankResult.isItemEqual(currentPlank) || plankResult.getCount() + currentPlank.getCount() > currentPlank.getMaxStackSize()) { return new ErrorState.NoSpace("No room for new planks", new int[]{LumbermillMachine.SLOT_PLANKS}); } } + if(!util.isSlotEmpty(LumbermillMachine.SLOT_BARK)){ + ItemStack itemStack = util.getStack(LumbermillMachine.SLOT_BARK); + if (itemStack.getCount() + 1 > itemStack.getMaxStackSize()) { + return new ErrorState.NoSpace("No room for new bark", new int[]{LumbermillMachine.SLOT_BARK}); + } + } + if(!util.isSlotEmpty(LumbermillMachine.SLOT_SAWDUST)){ + ItemStack itemStack = util.getStack(LumbermillMachine.SLOT_SAWDUST); + if (itemStack.getCount() + 1 > itemStack.getMaxStackSize()) { + return new ErrorState.NoSpace("No room for new sawdust", new int[]{LumbermillMachine.SLOT_SAWDUST}); + } + } return super.canWork(); } @@ -43,15 +57,16 @@ public class LumbermillLogic extends ComponentProcessSetCost implements IProcess @Override protected void onFinishTask() { - final ItemStack logStack = this.getUtil().getStack(LumbermillMachine.SLOT_LOG); + MachineUtil util = getUtil(); + final ItemStack logStack = util.getStack(LumbermillMachine.SLOT_LOG); final ItemStack result = LumbermillRecipes.getPlankProduct(logStack); if (result == null) { return; } - this.getUtil().addStack(LumbermillMachine.SLOT_PLANKS, result); - this.getUtil().addStack(LumbermillMachine.SLOT_SAWDUST, ExtraTreeItems.Sawdust.get(1)); - this.getUtil().addStack(LumbermillMachine.SLOT_BARK, ExtraTreeItems.Bark.get(1)); - this.getUtil().decreaseStack(LumbermillMachine.SLOT_LOG, 1); + util.addStack(LumbermillMachine.SLOT_PLANKS, result); + util.addStack(LumbermillMachine.SLOT_SAWDUST, ExtraTreeItems.Sawdust.get(1)); + util.addStack(LumbermillMachine.SLOT_BARK, ExtraTreeItems.Bark.get(1)); + util.decreaseStack(LumbermillMachine.SLOT_LOG, 1); } @Override