mirror of
https://github.com/GTNewHorizons/StorageDrawers.git
synced 2026-11-28 07:55:38 +00:00
Add interface to expose drawer priority; update AE2 integration to respect priority
This commit is contained in:
1 parent
5db29123c4
commit
c0790b45c3
4 files changed
+54
-15
No files matched your search
@@ -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 ();
|
||||
}
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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<IAEItemStack>
|
||||
@@ -26,12 +26,17 @@ public class DrawerMEInventory implements IMEInventory<IAEItemStack>
|
||||
|
||||
@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<IAEItemStack>
|
||||
}
|
||||
|
||||
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<IAEItemStack>
|
||||
|
||||
@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<IAEItemStack>
|
||||
|
||||
@Override
|
||||
public IItemList<IAEItemStack> getAvailableItems (IItemList<IAEItemStack> 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()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user