Rewrite of Solderer code, made it 2 times faster with upgrades
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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) {
|
|
||||||
stop();
|
|
||||||
} else if (newRecipe != recipe) {
|
|
||||||
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()))) {
|
|
||||||
recipe = newRecipe;
|
|
||||||
progress = 0;
|
|
||||||
working = true;
|
|
||||||
|
|
||||||
markDirty();
|
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 (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 (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,14 +141,12 @@ public class NetworkNodeSolderer extends NetworkNode {
|
|||||||
super.onConnectedStateChange(network, state);
|
super.onConnectedStateChange(network, state);
|
||||||
|
|
||||||
if (!state) {
|
if (!state) {
|
||||||
stop();
|
recipe = null;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stop() {
|
|
||||||
progress = 0;
|
progress = 0;
|
||||||
working = false;
|
working = false;
|
||||||
recipe = null;
|
} else {
|
||||||
|
recipe = API.instance().getSoldererRegistry().getRecipe(ingredients);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user