Gui/Container over haul to get Bus Guis working.

This commit is contained in:
AlgorithmX2
2014-01-01 02:57:16 -06:00
parent 2a4e4c0369
commit 6b37ef8847
10 changed files with 241 additions and 99 deletions
+60 -5
View File
@@ -43,6 +43,11 @@ public abstract class AEBaseContainer extends Container
tileEntity = te;
}
public boolean canDragIntoSlot(Slot s)
{
return ((AppEngSlot) s).isDraggable;
}
public TileEntity getTileEntity()
{
return tileEntity;
@@ -298,6 +303,7 @@ public abstract class AEBaseContainer extends Container
private void updateSlot(Slot clickSlot)
{
// ???
detectAndSendChanges();
}
@@ -329,11 +335,60 @@ public abstract class AEBaseContainer extends Container
public void doAction(EntityPlayerMP player, InventoryAction action, int slot, IAEItemStack slotItem)
{
/*
* boolean isValidSlot = true;
*
* if ( slot < 0 || slot >= inventorySlots.size() ) isValidSlot = false;
*/
if ( slot >= 0 && slot < inventorySlots.size() )
{
Slot s = getSlot( slot );
if ( s instanceof SlotFake )
{
ItemStack hand = player.inventory.getItemStack();
switch (action)
{
case PICKUP_OR_SETDOWN:
if ( hand == null )
s.putStack( null );
else
s.putStack( hand.copy() );
break;
case SPLIT_OR_PLACESINGLE:
ItemStack is = s.getStack();
if ( is != null )
{
if ( hand == null )
is.stackSize--;
else if ( hand.isItemEqual( is ) )
is.stackSize = Math.min( is.getMaxStackSize(), is.stackSize + 1 );
else
{
is = hand.copy();
is.stackSize = 1;
}
s.putStack( is );
}
else if ( hand != null )
{
is = hand.copy();
is.stackSize = 1;
s.putStack( is );
}
break;
case CREATIVE_DUPLICATE:
case MOVE_REGION:
case SHIFT_CLICK:
default:
break;
}
}
return;
}
switch (action)
{
+37 -27
View File
@@ -2,11 +2,13 @@ package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import appeng.api.config.Upgrades;
import appeng.api.implementations.IBusCommon;
import appeng.container.AEBaseContainer;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFake;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.tile.inventory.AppEngInternalInventory;
@@ -22,10 +24,10 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost
myte = te;
IInventory upgrades = myte.getInventoryByName( "upgrades" );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 ) );
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 ) );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 )).setNotDraggable() );
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 )).setNotDraggable() );
if ( hasToolbox() )
{
@@ -38,43 +40,51 @@ public class ContainerBus extends AEBaseContainer implements IOptionalSlotHost
int y = 40;
IInventory inv = myte.getInventoryByName( "config" );
addSlotToContainer( new SlotFake( inv, 0, x, y ) );
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 1, x, y, -1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 2, x, y, 1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 3, x, y, 0, -1, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 4, x, y, 0, 1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 5, x, y, -1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 6, x, y, 1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 7, x, y, -1, 1, 2 ) );
addSlotToContainer( new OptionalSlotFake( inv, this, 8, x, y, 1, 1, 2 ) );
/*
* addSlotToContainer( new OptionalSlotFake( inv, this, 9, x, y, -2, 0, 3 ) ); addSlotToContainer( new
* OptionalSlotFake( inv, this, 10, x, y, 2, 0, 3 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 11,
* x, y, 0, -2, 3 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 12, x, y, 0, 2, 3 ) );
*
* addSlotToContainer( new OptionalSlotFake( inv, this, 13, x, y, 2, 1, 4 ) ); addSlotToContainer( new
* OptionalSlotFake( inv, this, 14, x, y, 2, -1, 4 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 15,
* x, y, -2, -1, 4 ) ); addSlotToContainer( new OptionalSlotFake( inv, this, 16, x, y, -2, 1, 4 ) );
*/
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
bindPlayerInventory( ip, 0, 184 - /* height of playerinventory */82 );
}
@Override
public void detectAndSendChanges()
{
for (Object o : inventorySlots)
{
if ( o instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) o;
if ( !fs.isEnabled() && fs.getDisplayStack() != null )
((OptionalSlotFake) fs).clearStack();
}
}
super.detectAndSendChanges();
}
public boolean hasToolbox()
{
// TODO Auto-generated method stub
return true;
return false;
}
@Override
public boolean isSlotEnabled(int idx, OptionalSlotFake osf)
{
if ( idx == 1 )
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
if ( idx == 1 && upgrades > 0 )
return true;
if ( idx == 2 )
if ( idx == 2 && upgrades > 1 )
return true;
return false;
+50
View File
@@ -1,5 +1,6 @@
package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
@@ -12,8 +13,15 @@ public class AppEngSlot extends Slot
NotAvailable, Valid, Invalid
};
public boolean isDraggable = true;
public boolean isPlayerSide = false;
public Slot setNotDraggable()
{
isDraggable = false;
return this;
}
public Slot setPlayerSide()
{
isPlayerSide = true;
@@ -24,6 +32,17 @@ public class AppEngSlot extends Slot
public hasCalculatedValidness isValid;
public int defX, defY;
@Override
public boolean func_111238_b()
{
return isEnabled();
}
public boolean isEnabled()
{
return true;
}
public String getTooltip()
{
return null;
@@ -48,6 +67,9 @@ public class AppEngSlot extends Slot
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
return null;
if ( isDisplay )
{
isDisplay = false;
@@ -56,6 +78,34 @@ public class AppEngSlot extends Slot
return super.getStack();
}
@Override
public void putStack(ItemStack par1ItemStack)
{
if ( isEnabled() )
super.putStack( par1ItemStack );
}
public void clearStack()
{
super.putStack( null );
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
if ( isEnabled() )
return super.canTakeStack( par1EntityPlayer );
return false;
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
if ( isEnabled() )
return super.isItemValid( par1ItemStack );
return false;
}
public ItemStack getDisplayStack()
{
return super.getStack();
+19 -2
View File
@@ -1,6 +1,7 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFake extends SlotFake
{
@@ -9,8 +10,8 @@ public class OptionalSlotFake extends SlotFake
final int groupNum;
IOptionalSlotHost host;
int srcX;
int srcY;
public int srcX;
public int srcY;
public OptionalSlotFake(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, idx, x + offX * 18, y + offY * 18 );
@@ -18,11 +19,27 @@ public class OptionalSlotFake extends SlotFake
srcY = y;
invSlot = idx;
this.groupNum = groupNum;
host = containerBus;
}
@Override
public ItemStack getStack()
{
if ( !isEnabled() )
{
if ( getDisplayStack() != null )
clearStack();
}
return super.getStack();
}
@Override
public boolean isEnabled()
{
if ( host == null )
return false;
return host.isSlotEnabled( groupNum, this );
}
@@ -0,0 +1,27 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class OptionalSlotFakeTypeOnly extends OptionalSlotFake
{
public OptionalSlotFakeTypeOnly(IInventory inv, IOptionalSlotHost containerBus, int idx, int x, int y, int offX, int offY, int groupNum) {
super( inv, containerBus, idx, x, y, offX, offY, groupNum );
}
@Override
public void putStack(ItemStack is)
{
if ( is != null )
{
is = is.copy();
if ( is.stackSize > 1 )
is.stackSize = 1;
else if ( is.stackSize < -1 )
is.stackSize = -1;
}
super.putStack( is );
}
}
+6 -50
View File
@@ -3,7 +3,6 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.util.Platform;
public class SlotFake extends AppEngSlot
{
@@ -15,40 +14,6 @@ public class SlotFake extends AppEngSlot
invSlot = idx;
}
public boolean isEnabled()
{
return true;
}
public void addToInv(ItemStack is)
{
if ( is != null )
{
ItemStack current = this.inventory.getStackInSlot( invSlot );
if ( current != null && Platform.isSameItem( current, is ) )
{
current.stackSize += is.stackSize;
if ( current.stackSize > inventory.getInventoryStackLimit() )
current.stackSize = inventory.getInventoryStackLimit();
}
else
{
current = is.copy();
if ( current.stackSize > inventory.getInventoryStackLimit() )
current.stackSize = inventory.getInventoryStackLimit();
this.inventory.setInventorySlotContents( invSlot, current );
}
}
else
{
this.inventory.setInventorySlotContents( invSlot, null );
}
}
@Override
public boolean canTakeStack(EntityPlayer par1EntityPlayer)
{
@@ -58,18 +23,6 @@ public class SlotFake extends AppEngSlot
@Override
public ItemStack decrStackSize(int par1)
{
ItemStack current = this.inventory.getStackInSlot( invSlot );
if ( current != null )
{
current.stackSize--;
if ( current.stackSize <= 0 )
{
this.inventory.setInventorySlotContents( invSlot, null );
}
}
return null;
}
@@ -79,15 +32,18 @@ public class SlotFake extends AppEngSlot
}
@Override
public void putStack(ItemStack par1ItemStack)
public void putStack(ItemStack is)
{
this.inventory.setInventorySlotContents( invSlot, par1ItemStack );
if ( is != null )
is = is.copy();
super.putStack( is );
}
@Override
public boolean isItemValid(ItemStack par1ItemStack)
{
return true;
return false;
}
}
-12
View File
@@ -10,18 +10,6 @@ public class SlotFakeTypeOnly extends SlotFake
super( inv, idx, x, y );
}
@Override
public void addToInv(ItemStack is)
{
if ( is != null )
{
is = is.copy();
is.stackSize = 1;
}
super.putStack( is );
}
@Override
public void putStack(ItemStack is)
{