Interface inventory BC break for the better good
This commit is contained in:
@@ -13,15 +13,15 @@ public class ContainerInterface extends ContainerBase {
|
||||
super(player);
|
||||
|
||||
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) {
|
||||
addSlotToContainer(new SlotSpecimen(tile.getItems(), i, 8 + (18 * (i - 9)), 54, SlotSpecimen.SPECIMEN_SIZE));
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new SlotSpecimen(tile.getExportSpecimenItems(), i, 8 + (18 * i), 54, SlotSpecimen.SPECIMEN_SIZE));
|
||||
}
|
||||
|
||||
for (int i = 18; i < 27; ++i) {
|
||||
addSlotToContainer(new SlotOutput(tile.getItems(), i, 8 + (18 * (i - 18)), 100));
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new SlotOutput(tile.getExportItems(), i, 8 + (18 * i), 100));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -9,19 +9,21 @@ import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import net.minecraftforge.items.wrapper.CombinedInvWrapper;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.RefinedStorageUtils;
|
||||
import refinedstorage.container.ContainerInterface;
|
||||
import refinedstorage.inventory.BasicItemHandler;
|
||||
import refinedstorage.inventory.BasicItemValidator;
|
||||
import refinedstorage.inventory.InterfaceItemHandler;
|
||||
import refinedstorage.item.ItemUpgrade;
|
||||
import refinedstorage.tile.config.ICompareConfig;
|
||||
|
||||
public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
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 int compare = 0;
|
||||
@@ -35,25 +37,25 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
|
||||
@Override
|
||||
public void updateMachine() {
|
||||
if (currentSlot > 8) {
|
||||
if (currentSlot >= importItems.getSlots()) {
|
||||
currentSlot = 0;
|
||||
}
|
||||
|
||||
ItemStack slot = items.getStackInSlot(currentSlot);
|
||||
ItemStack slot = importItems.getStackInSlot(currentSlot);
|
||||
|
||||
if (slot == null) {
|
||||
currentSlot++;
|
||||
} else {
|
||||
if (ticks % RefinedStorageUtils.getSpeed(upgrades) == 0) {
|
||||
if (controller.push(ItemHandlerHelper.copyStackWithSize(slot, 1))) {
|
||||
items.extractItem(currentSlot, 1, false);
|
||||
importItems.extractItem(currentSlot, 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 9; i < 18; ++i) {
|
||||
ItemStack wanted = items.getStackInSlot(i);
|
||||
ItemStack got = items.getStackInSlot(i + 9);
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack wanted = exportSpecimenItems.getStackInSlot(i);
|
||||
ItemStack got = exportItems.getStackInSlot(i);
|
||||
|
||||
if (wanted != null) {
|
||||
boolean mayTake = false;
|
||||
@@ -61,7 +63,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
if (got != null) {
|
||||
if (!RefinedStorageUtils.compareStack(wanted, got, compare)) {
|
||||
if (controller.push(got)) {
|
||||
items.setStackInSlot(i + 9, null);
|
||||
exportItems.setStackInSlot(i, null);
|
||||
}
|
||||
} else {
|
||||
mayTake = true;
|
||||
@@ -71,7 +73,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
}
|
||||
|
||||
if (mayTake) {
|
||||
got = items.getStackInSlot(i + 9);
|
||||
got = exportItems.getStackInSlot(i);
|
||||
|
||||
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 (got == null) {
|
||||
items.setStackInSlot(i + 9, took);
|
||||
exportItems.setStackInSlot(i, took);
|
||||
} else {
|
||||
got.stackSize += took.stackSize;
|
||||
}
|
||||
@@ -89,7 +91,7 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
}
|
||||
} else if (got != null) {
|
||||
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) {
|
||||
super.read(nbt);
|
||||
|
||||
RefinedStorageUtils.readItems(items, 0, nbt);
|
||||
RefinedStorageUtils.readItems(upgrades, 1, nbt);
|
||||
RefinedStorageUtils.readItems(importItems, 0, nbt);
|
||||
RefinedStorageUtils.readItems(exportSpecimenItems, 1, nbt);
|
||||
RefinedStorageUtils.readItems(exportItems, 2, nbt);
|
||||
RefinedStorageUtils.readItems(upgrades, 3, nbt);
|
||||
|
||||
if (nbt.hasKey(NBT_COMPARE)) {
|
||||
compare = nbt.getInteger(NBT_COMPARE);
|
||||
@@ -123,8 +127,10 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
public NBTTagCompound write(NBTTagCompound tag) {
|
||||
super.write(tag);
|
||||
|
||||
RefinedStorageUtils.writeItems(items, 0, tag);
|
||||
RefinedStorageUtils.writeItems(upgrades, 1, tag);
|
||||
RefinedStorageUtils.writeItems(importItems, 0, tag);
|
||||
RefinedStorageUtils.writeItems(exportSpecimenItems, 1, tag);
|
||||
RefinedStorageUtils.writeItems(exportItems, 2, tag);
|
||||
RefinedStorageUtils.writeItems(upgrades, 3, tag);
|
||||
|
||||
tag.setInteger(NBT_COMPARE, compare);
|
||||
|
||||
@@ -151,8 +157,16 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
return ContainerInterface.class;
|
||||
}
|
||||
|
||||
public IItemHandler getItems() {
|
||||
return items;
|
||||
public IItemHandler getImportItems() {
|
||||
return importItems;
|
||||
}
|
||||
|
||||
public IItemHandler getExportSpecimenItems() {
|
||||
return exportSpecimenItems;
|
||||
}
|
||||
|
||||
public IItemHandler getExportItems() {
|
||||
return exportItems;
|
||||
}
|
||||
|
||||
public IItemHandler getUpgrades() {
|
||||
@@ -161,27 +175,17 @@ public class TileInterface extends TileMachine implements ICompareConfig {
|
||||
|
||||
@Override
|
||||
public IItemHandler getDroppedItems() {
|
||||
BasicItemHandler dummy = new BasicItemHandler(9 + 9 + 4);
|
||||
|
||||
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;
|
||||
return new CombinedInvWrapper(importItems, exportItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
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);
|
||||
|
||||
@@ -67,6 +67,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
private List<ClientSideMachine> clientSideMachines = new ArrayList<ClientSideMachine>();
|
||||
|
||||
private List<CraftingPattern> patterns = new ArrayList<CraftingPattern>();
|
||||
|
||||
private Stack<ICraftingTask> craftingTasks = new Stack<ICraftingTask>();
|
||||
private List<ICraftingTask> craftingTasksToAddAsLast = new ArrayList<ICraftingTask>();
|
||||
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<ICraftingTask>();
|
||||
|
||||
Reference in New Issue
Block a user