diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java new file mode 100644 index 0000000..97b293e --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/IPriorityGroup.java @@ -0,0 +1,10 @@ +package com.jaquadro.minecraft.storagedrawers.api.storage; + + +public interface IPriorityGroup +{ + /** + * Gets the list of available drawer slots in priority order. + */ + int[] getAccessibleDrawerSlots (); +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index c134a74..4d8d89b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -2,10 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; -import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; -import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; -import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroupInteractive; -import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked; +import com.jaquadro.minecraft.storagedrawers.api.storage.*; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IShroudable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable; @@ -25,7 +22,7 @@ import net.minecraftforge.common.util.ForgeDirection; import java.util.*; -public class TileEntityController extends TileEntity implements IDrawerGroup, ISidedInventory +public class TileEntityController extends TileEntity implements IDrawerGroup, IPriorityGroup, ISidedInventory { private static final int PRI_VOID = 0; private static final int PRI_LOCKED = 1; @@ -593,6 +590,11 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IS return group.isDrawerEnabled(getLocalDrawerSlot(slot)); } + @Override + public int[] getAccessibleDrawerSlots () { + return drawerSlots; + } + @Override public void markDirty () { for (StorageRecord record : storage.values()) { diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntitySlave.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntitySlave.java index 500f551..3377922 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntitySlave.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntitySlave.java @@ -3,6 +3,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; +import com.jaquadro.minecraft.storagedrawers.api.storage.IPriorityGroup; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; @@ -13,12 +14,13 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.Constants; -public class TileEntitySlave extends TileEntity implements IDrawerGroup, ISidedInventory +public class TileEntitySlave extends TileEntity implements IDrawerGroup, IPriorityGroup, ISidedInventory { private BlockCoord controllerCoord; private BlockCoord selfCoord; private int[] inventorySlots = new int[] { 0 }; + private int[] drawerSlots = new int[] { 0 }; public void ensureInitialized () { if (selfCoord == null) { @@ -90,6 +92,15 @@ public class TileEntitySlave extends TileEntity implements IDrawerGroup, ISidedI return (TileEntityController)te; } + @Override + public int[] getAccessibleDrawerSlots () { + TileEntityController controller = getController(); + if (controller == null || !controller.isValidSlave(selfCoord)) + return drawerSlots; + + return controller.getAccessibleDrawerSlots(); + } + @Override public int[] getAccessibleSlotsFromSide (int side) { TileEntityController controller = getController(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java index ea76c72..451b24d 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ae2/DrawerMEInventory.java @@ -10,10 +10,10 @@ import appeng.api.storage.data.IItemList; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawerGroup; import com.jaquadro.minecraft.storagedrawers.api.storage.IFractionalDrawer; +import com.jaquadro.minecraft.storagedrawers.api.storage.IPriorityGroup; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.ILockable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IVoidable; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; -import com.jaquadro.minecraft.storagedrawers.storage.IUpgradeProvider; import net.minecraft.item.ItemStack; public class DrawerMEInventory implements IMEInventory @@ -26,12 +26,17 @@ public class DrawerMEInventory implements IMEInventory @Override public IAEItemStack injectItems (IAEItemStack input, Actionable type, BaseActionSource src) { + int[] order = null; + if (group instanceof IPriorityGroup) + order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); + long itemsLeft = input.getStackSize(); for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - if (!group.isDrawerEnabled(i)) + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) continue; - IDrawer drawer = group.getDrawer(i); + IDrawer drawer = group.getDrawer(slot); ItemStack itemProto = drawer.getStoredItemPrototype(); if (itemProto != null) { if (drawer.canItemBeStored(input.getItemStack())) { @@ -45,13 +50,14 @@ public class DrawerMEInventory implements IMEInventory } for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - if (!group.isDrawerEnabled(i)) + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) continue; if (group instanceof ILockable && ((ILockable) group).isLocked(LockAttribute.LOCK_EMPTY)) continue; - IDrawer drawer = group.getDrawer(i); + IDrawer drawer = group.getDrawer(slot); ItemStack itemProto = drawer.getStoredItemPrototype(); if (itemProto == null && drawer instanceof ILockable && ((ILockable) drawer).isLocked(LockAttribute.LOCK_EMPTY)) @@ -104,12 +110,17 @@ public class DrawerMEInventory implements IMEInventory @Override public IAEItemStack extractItems (IAEItemStack request, Actionable mode, BaseActionSource src) { + int[] order = null; + if (group instanceof IPriorityGroup) + order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); + long itemsLeft = request.getStackSize(); for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - if (!group.isDrawerEnabled(i)) + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) continue; - IDrawer drawer = group.getDrawer(i); + IDrawer drawer = group.getDrawer(slot); if (drawer.canItemBeExtracted(request.getItemStack())) { int itemCount = drawer.getStoredItemCount(); if (itemsLeft > itemCount) { @@ -137,11 +148,16 @@ public class DrawerMEInventory implements IMEInventory @Override public IItemList getAvailableItems (IItemList out) { + int[] order = null; + if (group instanceof IPriorityGroup) + order = ((IPriorityGroup) group).getAccessibleDrawerSlots(); + for (int i = 0, n = group.getDrawerCount(); i < n; i++) { - if (!group.isDrawerEnabled(i)) + int slot = (order != null) ? order[i] : i; + if (!group.isDrawerEnabled(slot)) continue; - IDrawer drawer = group.getDrawer(i); + IDrawer drawer = group.getDrawer(slot); if (!drawer.isEmpty()) out.add(AEApi.instance().storage().createItemStack(drawer.getStoredItemCopy())); }