Make solderer more efficient

This commit is contained in:
Raoul Van den Berge
2016-06-04 01:37:13 +02:00
parent 214742e08c
commit dbf8ee3615

View File

@@ -22,7 +22,14 @@ public class TileSolderer extends TileMachine {
public static final String NBT_WORKING = "Working";
public static final String NBT_PROGRESS = "Progress";
private BasicItemHandler items = new BasicItemHandler(4, this);
private BasicItemHandler items = new BasicItemHandler(4, this) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
refresh();
}
};
private BasicItemHandler upgrades = new BasicItemHandler(4, this, new BasicItemValidator(RefinedStorageItems.UPGRADE, ItemUpgrade.TYPE_SPEED));
private SoldererItemHandler[] itemsFacade = new SoldererItemHandler[EnumFacing.values().length];
@@ -39,56 +46,61 @@ public class TileSolderer extends TileMachine {
@Override
public void updateMachine() {
if (working) {
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
if (progress >= recipe.getDuration()) {
ISoldererRecipe oldRecipe = recipe;
if (items.getStackInSlot(3) != null) {
items.getStackInSlot(3).stackSize += recipe.getResult().stackSize;
} else {
items.setStackInSlot(3, recipe.getResult());
}
for (int i = 0; i < 3; ++i) {
if (oldRecipe.getRow(i) != null) {
items.extractItem(i, oldRecipe.getRow(i).stackSize, false);
}
}
progress = 0;
markDirty();
}
}
}
public void refresh() {
boolean wasWorking = working;
if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && items.getStackInSlot(3) == null) {
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
if (newRecipe == null) {
stop();
} else {
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
} else if (newRecipe != recipe) {
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
if (newRecipe == null) {
stop();
} else if (newRecipe != recipe) {
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
recipe = newRecipe;
progress = 0;
working = true;
markDirty();
}
} else if (working) {
progress += 1 + RefinedStorageUtils.getUpgradeCount(upgrades, ItemUpgrade.TYPE_SPEED);
if (progress >= recipe.getDuration()) {
if (items.getStackInSlot(3) != null) {
items.getStackInSlot(3).stackSize += recipe.getResult().stackSize;
} else {
items.setStackInSlot(3, recipe.getResult());
}
for (int i = 0; i < 3; ++i) {
if (recipe.getRow(i) != null) {
items.extractItem(i, recipe.getRow(i).stackSize, false);
}
}
recipe = null;
progress = 0;
// Don't set working to false yet, wait till the next update because we may have
// another stack waiting.
markDirty();
}
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) {
recipe = newRecipe;
progress = 0;
working = true;
markDirty();
}
}
if (wasWorking != working) {
// We're checking if there is a world because this might be called from readFromNBT
if (worldObj != null && wasWorking != working) {
RefinedStorageUtils.updateBlock(worldObj, pos);
}
}
public void stop() {
recipe = null;
progress = 0;
working = false;
markDirty();
}
@Override
public void onDisconnected(World world) {
super.onDisconnected(world);
@@ -96,14 +108,6 @@ public class TileSolderer extends TileMachine {
stop();
}
public void stop() {
progress = 0;
working = false;
recipe = null;
markDirty();
}
@Override
public void read(NBTTagCompound nbt) {
super.read(nbt);