Revert solderer changes

This commit is contained in:
Raoul Van den Berge
2016-06-04 12:12:42 +02:00
parent 3f78747744
commit 611014b20c

View File

@@ -1,4 +1,4 @@
package refinedstorage.tile; package refinedstorage.tile.solderer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@@ -11,26 +11,18 @@ import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.wrapper.CombinedInvWrapper; import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import refinedstorage.RefinedStorageItems; import refinedstorage.RefinedStorageItems;
import refinedstorage.RefinedStorageUtils; import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.solderer.ISoldererRecipe;
import refinedstorage.api.solderer.SoldererRegistry;
import refinedstorage.container.ContainerSolderer; import refinedstorage.container.ContainerSolderer;
import refinedstorage.inventory.BasicItemHandler; import refinedstorage.inventory.BasicItemHandler;
import refinedstorage.inventory.BasicItemValidator; import refinedstorage.inventory.BasicItemValidator;
import refinedstorage.inventory.SoldererItemHandler; import refinedstorage.inventory.SoldererItemHandler;
import refinedstorage.item.ItemUpgrade; import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.TileMachine;
public class TileSolderer extends TileMachine { public class TileSolderer extends TileMachine {
public static final String NBT_WORKING = "Working"; public static final String NBT_WORKING = "Working";
public static final String NBT_PROGRESS = "Progress"; 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 BasicItemHandler upgrades = new BasicItemHandler(4, this, new BasicItemValidator(RefinedStorageItems.UPGRADE, ItemUpgrade.TYPE_SPEED));
private SoldererItemHandler[] itemsFacade = new SoldererItemHandler[EnumFacing.values().length]; private SoldererItemHandler[] itemsFacade = new SoldererItemHandler[EnumFacing.values().length];
@@ -47,61 +39,56 @@ public class TileSolderer extends TileMachine {
@Override @Override
public void updateMachine() { 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; boolean wasWorking = working;
ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items); if (items.getStackInSlot(1) == null && items.getStackInSlot(2) == null && items.getStackInSlot(3) == null) {
if (newRecipe == null) {
stop(); stop();
} else if (newRecipe != recipe) { } else {
boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false; ISoldererRecipe newRecipe = SoldererRegistry.getRecipe(items);
if (items.getStackInSlot(3) == null || (isSameItem && ((items.getStackInSlot(3).stackSize + newRecipe.getResult().stackSize) <= items.getStackInSlot(3).getMaxStackSize()))) { if (newRecipe == null) {
recipe = newRecipe; stop();
progress = 0; } else if (newRecipe != recipe) {
working = true; boolean isSameItem = items.getStackInSlot(3) != null ? RefinedStorageUtils.compareStackNoQuantity(items.getStackInSlot(3), newRecipe.getResult()) : false;
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();
}
} 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();
}
} }
} }
// We're checking if there is a world because this might be called from readFromNBT if (wasWorking != working) {
if (worldObj != null && wasWorking != working) {
RefinedStorageUtils.updateBlock(worldObj, pos); RefinedStorageUtils.updateBlock(worldObj, pos);
} }
} }
public void stop() {
recipe = null;
progress = 0;
working = false;
markDirty();
}
@Override @Override
public void onDisconnected(World world) { public void onDisconnected(World world) {
super.onDisconnected(world); super.onDisconnected(world);
@@ -109,6 +96,14 @@ public class TileSolderer extends TileMachine {
stop(); stop();
} }
public void stop() {
progress = 0;
working = false;
recipe = null;
markDirty();
}
@Override @Override
public void read(NBTTagCompound nbt) { public void read(NBTTagCompound nbt) {
super.read(nbt); super.read(nbt);