Rewrite of Solderer code, made it 2 times faster with upgrades

This commit is contained in:
raoulvdberge
2017-07-23 22:21:58 +02:00
parent ec8a82dd56
commit 0b5604fc09
2 changed files with 41 additions and 35 deletions

View File

@@ -2,6 +2,7 @@
### 1.5.14 ### 1.5.14
- Fixed more crashes relating to scrollbar in GUIs (raoulvdberge) - Fixed more crashes relating to scrollbar in GUIs (raoulvdberge)
- A Solderer with Speed Upgrades is now 2 times faster (raoulvdberge)
### 1.5.13 ### 1.5.13
- Fixed Wireless Fluid Grid not using up energy (raoulvdberge) - Fixed Wireless Fluid Grid not using up energy (raoulvdberge)

View File

@@ -41,6 +41,14 @@ public class NetworkNodeSolderer extends NetworkNode {
return stack; 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)) { 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 ItemHandlerProxy items = new ItemHandlerProxy(ingredients, result);
private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED); private ItemHandlerUpgrade upgrades = new ItemHandlerUpgrade(4, new ItemHandlerListenerNetworkNode(this), ItemUpgrade.TYPE_SPEED);
private boolean wasWorking;
private boolean working;
private ISoldererRecipe recipe; private ISoldererRecipe recipe;
private int progress;
private boolean working = false;
private boolean wasWorking = false;
private int progress = 0;
public NetworkNodeSolderer(World world, BlockPos pos) { public NetworkNodeSolderer(World world, BlockPos pos) {
super(world, pos); super(world, pos);
@@ -86,46 +92,47 @@ public class NetworkNodeSolderer extends NetworkNode {
return; return;
} }
if (ingredients.getStackInSlot(1).isEmpty() && ingredients.getStackInSlot(2).isEmpty() && result.getStackInSlot(0).isEmpty()) { if (working) {
stop(); if (recipe == null) {
} else { working = false;
ISoldererRecipe newRecipe = API.instance().getSoldererRegistry().getRecipe(ingredients);
if (newRecipe == null) { markDirty();
stop(); } 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()) {
} else if (newRecipe != recipe) { int increase = 1 + (upgrades.getUpgradeCount(ItemUpgrade.TYPE_SPEED) * 2);
boolean sameItem = !result.getStackInSlot(0).isEmpty() && API.instance().getComparer().isEqualNoQuantity(result.getStackInSlot(0), newRecipe.getResult());
if (result.getStackInSlot(0).isEmpty() || (sameItem && ((result.getStackInSlot(0).getCount() + newRecipe.getResult().getCount()) <= result.getStackInSlot(0).getMaxStackSize()))) { if (progress + increase > recipe.getDuration()) {
recipe = newRecipe; progress = recipe.getDuration();
progress = 0; } else {
working = true; progress += increase;
markDirty();
} }
} else if (working) {
progress += 1 + upgrades.getUpgradeCount(ItemUpgrade.TYPE_SPEED);
if (progress >= recipe.getDuration()) { if (progress >= recipe.getDuration()) {
if (!result.getStackInSlot(0).isEmpty()) { ItemStack resultSlot = result.getStackInSlot(0);
result.getStackInSlot(0).grow(recipe.getResult().getCount());
} else { if (resultSlot.isEmpty()) {
result.setStackInSlot(0, recipe.getResult().copy()); result.setStackInSlot(0, recipe.getResult().copy());
} else {
resultSlot.grow(recipe.getResult().getCount());
} }
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (!recipe.getRow(i).isEmpty()) { ItemStack ingredientSlot = ingredients.getStackInSlot(i);
ingredients.extractItem(i, recipe.getRow(i).get(0).getCount(), false);
if (!ingredientSlot.isEmpty()) {
ingredientSlot.shrink(recipe.getRow(i).get(0).getCount());
} }
} }
recipe = null; recipe = API.instance().getSoldererRegistry().getRecipe(ingredients);
progress = 0; progress = 0;
// Don't set working to false yet, wait till the next update because we may have another stack waiting.
} }
markDirty(); markDirty();
} }
} else if (recipe != null) {
working = true;
markDirty();
} }
} }
@@ -134,16 +141,14 @@ public class NetworkNodeSolderer extends NetworkNode {
super.onConnectedStateChange(network, state); super.onConnectedStateChange(network, state);
if (!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 @Override
public void read(NBTTagCompound tag) { public void read(NBTTagCompound tag) {
super.read(tag); super.read(tag);