From 0b5604fc095c9da060665a10f0ae20019c4e8675 Mon Sep 17 00:00:00 2001 From: raoulvdberge Date: Sun, 23 Jul 2017 22:21:58 +0200 Subject: [PATCH] Rewrite of Solderer code, made it 2 times faster with upgrades --- CHANGELOG.md | 1 + .../network/node/NetworkNodeSolderer.java | 75 ++++++++++--------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 234909cae..1e37364e1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### 1.5.14 - Fixed more crashes relating to scrollbar in GUIs (raoulvdberge) +- A Solderer with Speed Upgrades is now 2 times faster (raoulvdberge) ### 1.5.13 - Fixed Wireless Fluid Grid not using up energy (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeSolderer.java b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeSolderer.java index 250b52d56..d848c4f01 100755 --- a/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeSolderer.java +++ b/src/main/java/com/raoulvdberge/refinedstorage/apiimpl/network/node/NetworkNodeSolderer.java @@ -41,6 +41,14 @@ public class NetworkNodeSolderer extends NetworkNode { return stack; } + + @Override + protected void onContentsChanged(int slot) { + super.onContentsChanged(slot); + + recipe = API.instance().getSoldererRegistry().getRecipe(this); + progress = 0; + } }; private ItemHandlerBase result = new ItemHandlerBase(1, new ItemHandlerListenerNetworkNode(this)) { @@ -52,14 +60,12 @@ public class NetworkNodeSolderer extends NetworkNode { }; private ItemHandlerProxy items = new ItemHandlerProxy(ingredients, result); - private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED); + private boolean wasWorking; + private boolean working; private ISoldererRecipe recipe; - - private boolean working = false; - private boolean wasWorking = false; - private int progress = 0; + private int progress; public NetworkNodeSolderer(World world, BlockPos pos) { super(world, pos); @@ -86,46 +92,47 @@ public class NetworkNodeSolderer extends NetworkNode { return; } - if (ingredients.getStackInSlot(1).isEmpty() && ingredients.getStackInSlot(2).isEmpty() && result.getStackInSlot(0).isEmpty()) { - stop(); - } else { - ISoldererRecipe newRecipe = API.instance().getSoldererRegistry().getRecipe(ingredients); + if (working) { + if (recipe == null) { + working = false; - if (newRecipe == null) { - stop(); - } else if (newRecipe != recipe) { - boolean sameItem = !result.getStackInSlot(0).isEmpty() && API.instance().getComparer().isEqualNoQuantity(result.getStackInSlot(0), newRecipe.getResult()); + markDirty(); + } else if ((result.getStackInSlot(0).isEmpty() || API.instance().getComparer().isEqualNoQuantity(recipe.getResult(), result.getStackInSlot(0))) && result.getStackInSlot(0).getCount() + recipe.getResult().getCount() <= result.getStackInSlot(0).getMaxStackSize()) { + int increase = 1 + (upgrades.getUpgradeCount(ItemUpgrade.TYPE_SPEED) * 2); - if (result.getStackInSlot(0).isEmpty() || (sameItem && ((result.getStackInSlot(0).getCount() + newRecipe.getResult().getCount()) <= result.getStackInSlot(0).getMaxStackSize()))) { - recipe = newRecipe; - progress = 0; - working = true; - - markDirty(); + if (progress + increase > recipe.getDuration()) { + progress = recipe.getDuration(); + } else { + progress += increase; } - } else if (working) { - progress += 1 + upgrades.getUpgradeCount(ItemUpgrade.TYPE_SPEED); if (progress >= recipe.getDuration()) { - if (!result.getStackInSlot(0).isEmpty()) { - result.getStackInSlot(0).grow(recipe.getResult().getCount()); - } else { + ItemStack resultSlot = result.getStackInSlot(0); + + if (resultSlot.isEmpty()) { result.setStackInSlot(0, recipe.getResult().copy()); + } else { + resultSlot.grow(recipe.getResult().getCount()); } for (int i = 0; i < 3; ++i) { - if (!recipe.getRow(i).isEmpty()) { - ingredients.extractItem(i, recipe.getRow(i).get(0).getCount(), false); + ItemStack ingredientSlot = ingredients.getStackInSlot(i); + + if (!ingredientSlot.isEmpty()) { + ingredientSlot.shrink(recipe.getRow(i).get(0).getCount()); } } - recipe = null; + recipe = API.instance().getSoldererRegistry().getRecipe(ingredients); progress = 0; - // Don't set working to false yet, wait till the next update because we may have another stack waiting. } markDirty(); } + } else if (recipe != null) { + working = true; + + markDirty(); } } @@ -134,16 +141,14 @@ public class NetworkNodeSolderer extends NetworkNode { super.onConnectedStateChange(network, state); if (!state) { - stop(); + recipe = null; + progress = 0; + working = false; + } else { + recipe = API.instance().getSoldererRegistry().getRecipe(ingredients); } } - private void stop() { - progress = 0; - working = false; - recipe = null; - } - @Override public void read(NBTTagCompound tag) { super.read(tag);