From c4b43eb0cf567479541f87ed4472b3541cdcfe27 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 29 Dec 2013 23:52:00 -0600 Subject: [PATCH] Lots of Gui And Slot related Changes. --- container/AEBaseContainer.java | 29 ++++++++++++++++--------- container/slot/AppEngSlot.java | 13 +++++++++++ container/slot/ISlotPlayerSide.java | 8 ------- container/slot/SlotFake.java | 12 ++++++++-- container/slot/SlotPlayerHotBar.java | 3 ++- container/slot/SlotPlayerInv.java | 4 +++- container/slot/SlotRestrictedInput.java | 14 +++++++++--- 7 files changed, 58 insertions(+), 25 deletions(-) delete mode 100644 container/slot/ISlotPlayerSide.java diff --git a/container/AEBaseContainer.java b/container/AEBaseContainer.java index d8f67aa3..8f7a7902 100644 --- a/container/AEBaseContainer.java +++ b/container/AEBaseContainer.java @@ -18,7 +18,7 @@ import appeng.api.storage.IMEInventoryHandler; import appeng.api.storage.data.IAEItemStack; import appeng.client.me.InternalSlotME; import appeng.client.me.SlotME; -import appeng.container.slot.ISlotPlayerSide; +import appeng.container.slot.AppEngSlot; import appeng.container.slot.SlotCraftingMatrix; import appeng.container.slot.SlotDisabled; import appeng.container.slot.SlotFake; @@ -48,6 +48,15 @@ public abstract class AEBaseContainer extends Container return tileEntity; } + @Override + protected Slot addSlotToContainer(Slot newSlot) + { + if ( newSlot instanceof AppEngSlot ) + return super.addSlotToContainer( newSlot ); + else + throw new RuntimeException( "Invalid Slot for AE Container." ); + } + @Override public boolean canInteractWith(EntityPlayer entityplayer) { @@ -78,7 +87,7 @@ public abstract class AEBaseContainer extends Container } ItemStack tis = null; - Slot clickSlot = (Slot) this.inventorySlots.get( idx ); + AppEngSlot clickSlot = (AppEngSlot) this.inventorySlots.get( idx ); // require AE SLots! if ( clickSlot instanceof SlotDisabled || clickSlot instanceof SlotInaccessable ) return null; @@ -94,16 +103,16 @@ public abstract class AEBaseContainer extends Container /** * Gather a list of valid destinations. */ - if ( clickSlot instanceof ISlotPlayerSide ) + if ( clickSlot.isPlayerSide() ) { tis = shiftStoreItem( tis ); // target slots in the container... for (int x = 0; x < this.inventorySlots.size(); x++) { - Slot cs = (Slot) this.inventorySlots.get( x ); + AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); - if ( !(cs instanceof ISlotPlayerSide) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) + if ( !(cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) { if ( cs.isItemValid( tis ) ) selectedSlots.add( cs ); @@ -115,9 +124,9 @@ public abstract class AEBaseContainer extends Container // target slots in the container... for (int x = 0; x < this.inventorySlots.size(); x++) { - Slot cs = (Slot) this.inventorySlots.get( x ); + AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); - if ( (cs instanceof ISlotPlayerSide) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) + if ( (cs.isPlayerSide()) && !(cs instanceof SlotFake) && !(cs instanceof SlotCraftingMatrix) ) { if ( cs.isItemValid( tis ) ) selectedSlots.add( cs ); @@ -128,17 +137,17 @@ public abstract class AEBaseContainer extends Container /** * Handle Fake Slot Shift clicking. */ - if ( selectedSlots.isEmpty() && clickSlot instanceof ISlotPlayerSide ) + if ( selectedSlots.isEmpty() && clickSlot.isPlayerSide() ) { if ( tis != null ) { // target slots in the container... for (int x = 0; x < this.inventorySlots.size(); x++) { - Slot cs = (Slot) this.inventorySlots.get( x ); + AppEngSlot cs = (AppEngSlot) this.inventorySlots.get( x ); ItemStack dest = cs.getStack(); - if ( !(cs instanceof ISlotPlayerSide) && cs instanceof SlotFake ) + if ( !(cs.isPlayerSide()) && cs instanceof SlotFake ) { if ( Platform.isSameItem( dest, tis ) ) return null; diff --git a/container/slot/AppEngSlot.java b/container/slot/AppEngSlot.java index 819740d4..fab7ef28 100644 --- a/container/slot/AppEngSlot.java +++ b/container/slot/AppEngSlot.java @@ -12,6 +12,14 @@ public class AppEngSlot extends Slot NotAvailable, Valid, Invalid }; + public boolean isPlayerSide = false; + + public Slot setPlayerSide() + { + isPlayerSide = true; + return this; + } + public int icon = -1; public hasCalculatedValidness isValid; public int defX, defY; @@ -68,4 +76,9 @@ public class AppEngSlot extends Slot return icon; } + public boolean isPlayerSide() + { + return isPlayerSide; + } + } diff --git a/container/slot/ISlotPlayerSide.java b/container/slot/ISlotPlayerSide.java deleted file mode 100644 index 9b4b9402..00000000 --- a/container/slot/ISlotPlayerSide.java +++ /dev/null @@ -1,8 +0,0 @@ -package appeng.container.slot; - -// anything that implements this interface is treated as being part of the players interface, rather then the chests... - -public interface ISlotPlayerSide -{ - -} diff --git a/container/slot/SlotFake.java b/container/slot/SlotFake.java index 6a547e03..f86a6a8b 100644 --- a/container/slot/SlotFake.java +++ b/container/slot/SlotFake.java @@ -15,6 +15,11 @@ public class SlotFake extends AppEngSlot invSlot = idx; } + public boolean isEnabled() + { + return true; + } + public void addToInv(ItemStack is) { if ( is != null ) @@ -27,7 +32,8 @@ public class SlotFake extends AppEngSlot if ( current.stackSize > inventory.getInventoryStackLimit() ) current.stackSize = inventory.getInventoryStackLimit(); - } else + } + else { current = is.copy(); @@ -36,7 +42,8 @@ public class SlotFake extends AppEngSlot this.inventory.setInventorySlotContents( invSlot, current ); } - } else + } + else { this.inventory.setInventorySlotContents( invSlot, null ); } @@ -82,4 +89,5 @@ public class SlotFake extends AppEngSlot { return true; } + } diff --git a/container/slot/SlotPlayerHotBar.java b/container/slot/SlotPlayerHotBar.java index c080b5bc..287cea84 100644 --- a/container/slot/SlotPlayerHotBar.java +++ b/container/slot/SlotPlayerHotBar.java @@ -2,10 +2,11 @@ package appeng.container.slot; import net.minecraft.inventory.IInventory; -public class SlotPlayerHotBar extends AppEngSlot implements ISlotPlayerSide +public class SlotPlayerHotBar extends AppEngSlot { public SlotPlayerHotBar(IInventory par1iInventory, int par2, int par3, int par4) { super( par1iInventory, par2, par3, par4 ); + isPlayerSide = true; } } diff --git a/container/slot/SlotPlayerInv.java b/container/slot/SlotPlayerInv.java index 320b6928..9159d2c8 100644 --- a/container/slot/SlotPlayerInv.java +++ b/container/slot/SlotPlayerInv.java @@ -4,10 +4,12 @@ import net.minecraft.inventory.IInventory; // there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot. -public class SlotPlayerInv extends AppEngSlot implements ISlotPlayerSide +public class SlotPlayerInv extends AppEngSlot { public SlotPlayerInv(IInventory par1iInventory, int par2, int par3, int par4) { super( par1iInventory, par2, par3, par4 ); + ; + isPlayerSide = true; } } diff --git a/container/slot/SlotRestrictedInput.java b/container/slot/SlotRestrictedInput.java index df7a7c4b..044b62f7 100644 --- a/container/slot/SlotRestrictedInput.java +++ b/container/slot/SlotRestrictedInput.java @@ -11,6 +11,7 @@ import appeng.api.crafting.ICraftingPatternMAC; import appeng.api.implementations.ICraftingPatternItem; import appeng.api.implementations.ISpatialStorageCell; import appeng.api.implementations.IStorageComponent; +import appeng.api.implementations.IUpgradeModule; import appeng.util.Platform; public class SlotRestrictedInput extends AppEngSlot @@ -18,9 +19,9 @@ public class SlotRestrictedInput extends AppEngSlot public enum PlaceableItemType { - STORAGE_CELLS(15), ORE(1 * 16 + 15), STORAGE_COMPONENT(3 * 16 + 15), WIRELESS_TERMINAL(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUPUT(7 * 16 + 15), ENCODED_PATTERN_W_OUTPUT( - 7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15), RANGE_BOOSTER(6 * 16 + 15), QE_SINGULARTIY(10 * 16 + 15), SPATIAL_STORAGE_CELLS( - 11 * 16 + 15), FUEL(12 * 16 + 15); + STORAGE_CELLS(15), ORE(1 * 16 + 15), STORAGE_COMPONENT(3 * 16 + 15), WIRELESS_TERMINAL(4 * 16 + 15), TRASH(5 * 16 + 15), VALID_ENCODED_PATTERN_W_OUPUT( + 7 * 16 + 15), ENCODED_PATTERN_W_OUTPUT(7 * 16 + 15), ENCODED_PATTERN(7 * 16 + 15), BLANK_PATTERN(8 * 16 + 15), POWERED_TOOL(9 * 16 + 15), RANGE_BOOSTER( + 6 * 16 + 15), QE_SINGULARTIY(10 * 16 + 15), SPATIAL_STORAGE_CELLS(11 * 16 + 15), FUEL(12 * 16 + 15), UPGRADES(13 * 16 + 15); public final int icon; @@ -90,6 +91,9 @@ public class SlotRestrictedInput extends AppEngSlot if ( i.getItem() == null ) return false; + if ( !inventory.isItemValidForSlot( this.getSlotIndex(), i ) ) + return false; + IAppEngApi api = AEApi.instance(); switch (which) { @@ -133,6 +137,10 @@ public class SlotRestrictedInput extends AppEngSlot return true; case WIRELESS_TERMINAL: return AEApi.instance().registries().wireless().isWirelessTerminal( i ); + case UPGRADES: + return i.getItem() instanceof IUpgradeModule && ((IUpgradeModule) i.getItem()).getType( i ) != null; + default: + break; } return false;