2013-12-30 06:56:43 +01:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-01-23 17:28:12 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-06 07:54:25 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-01-23 17:28:12 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
|
|
|
import appeng.api.config.RedstoneMode;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.config.Settings;
|
2014-01-01 09:57:16 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.api.config.YesNo;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
2014-01-06 07:54:25 +01:00
|
|
|
import appeng.api.parts.IPart;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.api.util.IConfigManager;
|
2013-12-30 06:56:43 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
2014-05-07 07:22:42 +02:00
|
|
|
import appeng.container.guisync.GuiSync;
|
2013-12-30 06:56:43 +01:00
|
|
|
import appeng.container.slot.IOptionalSlotHost;
|
|
|
|
import appeng.container.slot.OptionalSlotFake;
|
2014-01-01 09:57:16 +01:00
|
|
|
import appeng.container.slot.OptionalSlotFakeTypeOnly;
|
|
|
|
import appeng.container.slot.SlotFakeTypeOnly;
|
2013-12-30 06:56:43 +01:00
|
|
|
import appeng.container.slot.SlotRestrictedInput;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.items.contents.NetworkToolViewer;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.items.tools.ToolNetworkTool;
|
2014-07-06 08:48:21 +02:00
|
|
|
import appeng.parts.automation.PartExportBus;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost
|
2013-12-30 06:56:43 +01:00
|
|
|
{
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
IUpgradeableHost upgradeable;
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
int tbSlot;
|
|
|
|
NetworkToolViewer tbInventory;
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-01-23 20:02:48 +01:00
|
|
|
public ContainerUpgradeable(InventoryPlayer ip, IUpgradeableHost te) {
|
2014-01-06 07:54:25 +01:00
|
|
|
super( ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null) );
|
2014-09-28 11:47:17 +02:00
|
|
|
upgradeable = te;
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
World w = null;
|
2014-09-28 11:47:17 +02:00
|
|
|
int xCoord = 0, yCoord = 0, zCoord = 0;
|
2014-01-23 17:28:12 +01:00
|
|
|
|
|
|
|
if ( te instanceof TileEntity )
|
|
|
|
{
|
|
|
|
TileEntity myTile = (TileEntity) te;
|
|
|
|
w = myTile.getWorldObj();
|
2014-09-28 11:47:17 +02:00
|
|
|
xCoord = myTile.xCoord;
|
|
|
|
yCoord = myTile.yCoord;
|
|
|
|
zCoord = myTile.zCoord;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( te instanceof IPart )
|
|
|
|
{
|
2014-09-28 20:56:16 +02:00
|
|
|
IUpgradeableHost myTile = te;
|
2014-01-23 17:28:12 +01:00
|
|
|
TileEntity mk = myTile.getTile();
|
|
|
|
w = mk.getWorldObj();
|
2014-09-28 11:47:17 +02:00
|
|
|
xCoord = mk.xCoord;
|
|
|
|
yCoord = mk.yCoord;
|
|
|
|
zCoord = mk.zCoord;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IInventory pi = getPlayerInv();
|
|
|
|
for (int x = 0; x < pi.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
ItemStack pii = pi.getStackInSlot( x );
|
|
|
|
if ( pii != null && pii.getItem() instanceof ToolNetworkTool )
|
|
|
|
{
|
|
|
|
lockPlayerInventorySlot( x );
|
2014-09-28 11:47:17 +02:00
|
|
|
tbSlot = x;
|
|
|
|
tbInventory = (NetworkToolViewer) ((ToolNetworkTool) pii.getItem()).getGuiObject( pii, w, xCoord, yCoord, zCoord );
|
2014-01-23 17:28:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( hasToolbox() )
|
|
|
|
{
|
|
|
|
for (int v = 0; v < 3; v++)
|
|
|
|
for (int u = 0; u < 3; u++)
|
2014-09-28 11:47:17 +02:00
|
|
|
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, tbInventory, u + v * 3, 186 + u * 18, getHeight() - 82 + v * 18,
|
2014-07-13 03:03:17 +02:00
|
|
|
invPlayer )).setPlayerSide() );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setupConfig();
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
bindPlayerInventory( ip, 0, getHeight() - /* height of player inventory */82 );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
protected void setupUpgrades()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
IInventory upgrades = upgradeable.getInventoryByName( "upgrades" );
|
2014-01-05 09:49:08 +01:00
|
|
|
if ( availableUpgrades() > 0 )
|
2014-09-21 02:38:51 +02:00
|
|
|
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0, invPlayer )).setNotDraggable() );
|
2014-01-05 09:49:08 +01:00
|
|
|
if ( availableUpgrades() > 1 )
|
2014-09-21 02:38:51 +02:00
|
|
|
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1, invPlayer )).setNotDraggable() );
|
2014-01-05 09:49:08 +01:00
|
|
|
if ( availableUpgrades() > 2 )
|
2014-09-21 02:38:51 +02:00
|
|
|
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, invPlayer )).setNotDraggable() );
|
2014-01-05 09:49:08 +01:00
|
|
|
if ( availableUpgrades() > 3 )
|
2014-09-21 02:38:51 +02:00
|
|
|
addSlotToContainer( (new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, invPlayer )).setNotDraggable() );
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void setupConfig()
|
|
|
|
{
|
|
|
|
int x = 80;
|
|
|
|
int y = 40;
|
|
|
|
setupUpgrades();
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
IInventory inv = upgradeable.getInventoryByName( "config" );
|
2014-01-01 09:57:16 +01:00
|
|
|
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
if ( supportCapacity() )
|
|
|
|
{
|
|
|
|
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 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 ) );
|
|
|
|
}
|
2014-01-06 07:54:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected int getHeight()
|
|
|
|
{
|
|
|
|
return 184;
|
2013-12-30 06:56:43 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public int availableUpgrades()
|
2014-01-05 09:49:08 +01:00
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean supportCapacity()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-07 07:22:42 +02:00
|
|
|
@GuiSync(0)
|
2014-01-02 06:51:41 +01:00
|
|
|
public RedstoneMode rsMode = RedstoneMode.IGNORE;
|
2014-05-07 07:22:42 +02:00
|
|
|
|
|
|
|
@GuiSync(1)
|
2014-01-02 06:51:41 +01:00
|
|
|
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
|
|
|
|
|
2014-07-05 18:53:16 +02:00
|
|
|
@GuiSync(5)
|
2014-07-05 03:59:50 +02:00
|
|
|
public YesNo cMode = YesNo.NO;
|
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
public void checkToolbox()
|
|
|
|
{
|
|
|
|
if ( hasToolbox() )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
ItemStack currentItem = getPlayerInv().getStackInSlot( tbSlot );
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
if ( currentItem != tbInventory.getItemStack() )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
|
|
|
if ( currentItem != null )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
if ( Platform.isSameItem( tbInventory.getItemStack(), currentItem ) )
|
|
|
|
getPlayerInv().setInventorySlotContents( tbSlot, tbInventory.getItemStack() );
|
2014-01-23 17:28:12 +01:00
|
|
|
else
|
2014-02-09 02:34:52 +01:00
|
|
|
isContainerValid = false;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
else
|
2014-02-09 02:34:52 +01:00
|
|
|
isContainerValid = false;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-01-27 05:00:36 +01:00
|
|
|
verifyPermissions( SecurityPermissions.BUILD, false );
|
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
IConfigManager cm = this.upgradeable.getConfigManager();
|
2014-07-05 03:59:50 +02:00
|
|
|
loadSettingsFromHost( cm );
|
2014-01-02 06:51:41 +01:00
|
|
|
}
|
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
checkToolbox();
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
for (Object o : inventorySlots)
|
|
|
|
{
|
|
|
|
if ( o instanceof OptionalSlotFake )
|
|
|
|
{
|
|
|
|
OptionalSlotFake fs = (OptionalSlotFake) o;
|
|
|
|
if ( !fs.isEnabled() && fs.getDisplayStack() != null )
|
2014-09-28 20:56:16 +02:00
|
|
|
fs.clearStack();
|
2014-01-01 09:57:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
standardDetectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
protected void loadSettingsFromHost(IConfigManager cm)
|
|
|
|
{
|
|
|
|
this.fzMode = (FuzzyMode) cm.getSetting( Settings.FUZZY_MODE );
|
|
|
|
this.rsMode = (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED );
|
2014-09-28 11:47:17 +02:00
|
|
|
if ( upgradeable instanceof PartExportBus )
|
2014-07-06 08:48:21 +02:00
|
|
|
this.cMode = (YesNo) cm.getSetting( Settings.CRAFT_ONLY );
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:49:08 +01:00
|
|
|
protected void standardDetectAndSendChanges()
|
|
|
|
{
|
2014-01-01 09:57:16 +01:00
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
|
|
|
|
2013-12-30 06:56:43 +01:00
|
|
|
public boolean hasToolbox()
|
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
return tbInventory != null;
|
2013-12-30 06:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public boolean isSlotEnabled(int idx)
|
2013-12-30 06:56:43 +01:00
|
|
|
{
|
2014-09-28 11:47:17 +02:00
|
|
|
int upgrades = upgradeable.getInstalledUpgrades( Upgrades.CAPACITY );
|
2014-01-01 09:57:16 +01:00
|
|
|
|
|
|
|
if ( idx == 1 && upgrades > 0 )
|
2013-12-30 06:56:43 +01:00
|
|
|
return true;
|
2014-01-01 09:57:16 +01:00
|
|
|
if ( idx == 2 && upgrades > 1 )
|
2013-12-30 06:56:43 +01:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|