Interface inventory BC break for the better good

This commit is contained in:
Raoul Van den Berge
2016-05-25 20:13:33 +02:00
parent 3a5f8bc7c9
commit 7e5d6086ae
4 changed files with 44 additions and 71 deletions

View File

@@ -13,15 +13,15 @@ public class ContainerInterface extends ContainerBase {
super(player); super(player);
for (int i = 0; i < 9; ++i) { for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotItemHandler(tile.getItems(), i, 8 + (18 * i), 20)); addSlotToContainer(new SlotItemHandler(tile.getImportItems(), i, 8 + (18 * i), 20));
} }
for (int i = 9; i < 18; ++i) { for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotSpecimen(tile.getItems(), i, 8 + (18 * (i - 9)), 54, SlotSpecimen.SPECIMEN_SIZE)); addSlotToContainer(new SlotSpecimen(tile.getExportSpecimenItems(), i, 8 + (18 * i), 54, SlotSpecimen.SPECIMEN_SIZE));
} }
for (int i = 18; i < 27; ++i) { for (int i = 0; i < 9; ++i) {
addSlotToContainer(new SlotOutput(tile.getItems(), i, 8 + (18 * (i - 18)), 100)); addSlotToContainer(new SlotOutput(tile.getExportItems(), i, 8 + (18 * i), 100));
} }
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {

View File

@@ -1,32 +0,0 @@
package refinedstorage.inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
public class InterfaceItemHandler extends ProxyItemHandler {
private EnumFacing side;
public InterfaceItemHandler(BasicItemHandler interfaceHandler, EnumFacing side) {
super(interfaceHandler);
this.side = side;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if (side != EnumFacing.DOWN && slot >= 0 && slot <= 8) {
return super.insertItem(slot, stack, simulate);
}
return stack;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
if (side == EnumFacing.DOWN && slot >= 18 && slot <= 26) {
return super.extractItem(slot, amount, simulate);
}
return null;
}
}

View File

@@ -9,19 +9,21 @@ import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
import refinedstorage.RefinedStorageItems; import refinedstorage.RefinedStorageItems;
import refinedstorage.RefinedStorageUtils; import refinedstorage.RefinedStorageUtils;
import refinedstorage.container.ContainerInterface; import refinedstorage.container.ContainerInterface;
import refinedstorage.inventory.BasicItemHandler; import refinedstorage.inventory.BasicItemHandler;
import refinedstorage.inventory.BasicItemValidator; import refinedstorage.inventory.BasicItemValidator;
import refinedstorage.inventory.InterfaceItemHandler;
import refinedstorage.item.ItemUpgrade; import refinedstorage.item.ItemUpgrade;
import refinedstorage.tile.config.ICompareConfig; import refinedstorage.tile.config.ICompareConfig;
public class TileInterface extends TileMachine implements ICompareConfig { public class TileInterface extends TileMachine implements ICompareConfig {
public static final String NBT_COMPARE = "Compare"; public static final String NBT_COMPARE = "Compare";
private BasicItemHandler items = new BasicItemHandler(9 * 3, this); private BasicItemHandler importItems = new BasicItemHandler(9, this);
private BasicItemHandler exportSpecimenItems = new BasicItemHandler(9, this);
private BasicItemHandler exportItems = new BasicItemHandler(9, this);
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 int compare = 0; private int compare = 0;
@@ -35,25 +37,25 @@ public class TileInterface extends TileMachine implements ICompareConfig {
@Override @Override
public void updateMachine() { public void updateMachine() {
if (currentSlot > 8) { if (currentSlot >= importItems.getSlots()) {
currentSlot = 0; currentSlot = 0;
} }
ItemStack slot = items.getStackInSlot(currentSlot); ItemStack slot = importItems.getStackInSlot(currentSlot);
if (slot == null) { if (slot == null) {
currentSlot++; currentSlot++;
} else { } else {
if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) { if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) { if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) {
items.extractItem(currentSlot, 1, false); importItems.extractItem(currentSlot, 1, false);
} }
} }
} }
for (int i = 9; i < 18; ++i) { for (int i = 0; i < 9; ++i) {
ItemStack wanted = items.getStackInSlot(i); ItemStack wanted = exportSpecimenItems.getStackInSlot(i);
ItemStack got = items.getStackInSlot(i + 9); ItemStack got = exportItems.getStackInSlot(i);
if (wanted != null) { if (wanted != null) {
boolean mayTake = false; boolean mayTake = false;
@@ -61,7 +63,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
if (got != null) { if (got != null) {
if (!RefinedStorageUtils.compareStack(wanted, got, compare)) { if (!RefinedStorageUtils.compareStack(wanted, got, compare)) {
if (controller.push(got)) { if (controller.push(got)) {
items.setStackInSlot(i + 9, null); exportItems.setStackInSlot(i, null);
} }
} else { } else {
mayTake = true; mayTake = true;
@@ -71,7 +73,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
} }
if (mayTake) { if (mayTake) {
got = items.getStackInSlot(i + 9); got = exportItems.getStackInSlot(i);
int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize; int needed = got == null ? wanted.stackSize : wanted.stackSize - got.stackSize;
@@ -80,7 +82,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
if (took != null) { if (took != null) {
if (got == null) { if (got == null) {
items.setStackInSlot(i + 9, took); exportItems.setStackInSlot(i, took);
} else { } else {
got.stackSize += took.stackSize; got.stackSize += took.stackSize;
} }
@@ -89,7 +91,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
} }
} else if (got != null) { } else if (got != null) {
if (controller.push(got)) { if (controller.push(got)) {
items.setStackInSlot(i + 9, null); exportItems.setStackInSlot(i, null);
} }
} }
} }
@@ -111,8 +113,10 @@ public class TileInterface extends TileMachine implements ICompareConfig {
public void read(NBTTagCompound nbt) { public void read(NBTTagCompound nbt) {
super.read(nbt); super.read(nbt);
RefinedStorageUtils.readItems(items, 0, nbt); RefinedStorageUtils.readItems(importItems, 0, nbt);
RefinedStorageUtils.readItems(upgrades, 1, nbt); RefinedStorageUtils.readItems(exportSpecimenItems, 1, nbt);
RefinedStorageUtils.readItems(exportItems, 2, nbt);
RefinedStorageUtils.readItems(upgrades, 3, nbt);
if (nbt.hasKey(NBT_COMPARE)) { if (nbt.hasKey(NBT_COMPARE)) {
compare = nbt.getInteger(NBT_COMPARE); compare = nbt.getInteger(NBT_COMPARE);
@@ -123,8 +127,10 @@ public class TileInterface extends TileMachine implements ICompareConfig {
public NBTTagCompound write(NBTTagCompound tag) { public NBTTagCompound write(NBTTagCompound tag) {
super.write(tag); super.write(tag);
RefinedStorageUtils.writeItems(items, 0, tag); RefinedStorageUtils.writeItems(importItems, 0, tag);
RefinedStorageUtils.writeItems(upgrades, 1, tag); RefinedStorageUtils.writeItems(exportSpecimenItems, 1, tag);
RefinedStorageUtils.writeItems(exportItems, 2, tag);
RefinedStorageUtils.writeItems(upgrades, 3, tag);
tag.setInteger(NBT_COMPARE, compare); tag.setInteger(NBT_COMPARE, compare);
@@ -151,8 +157,16 @@ public class TileInterface extends TileMachine implements ICompareConfig {
return ContainerInterface.class; return ContainerInterface.class;
} }
public IItemHandler getItems() { public IItemHandler getImportItems() {
return items; return importItems;
}
public IItemHandler getExportSpecimenItems() {
return exportSpecimenItems;
}
public IItemHandler getExportItems() {
return exportItems;
} }
public IItemHandler getUpgrades() { public IItemHandler getUpgrades() {
@@ -161,27 +175,17 @@ public class TileInterface extends TileMachine implements ICompareConfig {
@Override @Override
public IItemHandler getDroppedItems() { public IItemHandler getDroppedItems() {
BasicItemHandler dummy = new BasicItemHandler(9 + 9 + 4); return new CombinedInvWrapper(importItems, exportItems);
for (int i = 0; i < 9; ++i) {
dummy.setStackInSlot(i, items.getStackInSlot(i));
}
for (int i = 0; i < 9; ++i) {
dummy.setStackInSlot(9 + i, items.getStackInSlot(18 + i));
}
for (int i = 0; i < 4; ++i) {
dummy.setStackInSlot(18 + i, upgrades.getStackInSlot(i));
}
return dummy;
} }
@Override @Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) { public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
return (T) new InterfaceItemHandler(items, facing); if (facing == EnumFacing.DOWN) {
return (T) exportItems;
} else {
return (T) importItems;
}
} }
return super.getCapability(capability, facing); return super.getCapability(capability, facing);

View File

@@ -67,6 +67,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>(); private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>();
private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>(); private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
private Stack<ICraftingTask> craftingTasks = new Stack<ICraftingTask>(); private Stack<ICraftingTask> craftingTasks = new Stack<ICraftingTask>();
private List<ICraftingTask> craftingTasksToAddAsLast = new ArrayList<ICraftingTask>(); private List<ICraftingTask> craftingTasksToAddAsLast = new ArrayList<ICraftingTask>();
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<ICraftingTask>(); private List<ICraftingTask> craftingTasksToAdd = new ArrayList<ICraftingTask>();