Applied-Energistics-2-tiler.../container/implementations/ContainerUpgradeable.java

238 lines
6.7 KiB
Java
Raw Normal View History

2013-12-30 06:56:43 +01:00
package appeng.container.implementations;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
2013-12-30 06:56:43 +01:00
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;
import appeng.api.config.FuzzyMode;
import appeng.api.config.RedstoneMode;
import appeng.api.config.SecurityPermissions;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
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;
2013-12-30 06:56:43 +01:00
import appeng.container.AEBaseContainer;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.OptionalSlotFakeTypeOnly;
import appeng.container.slot.SlotFakeTypeOnly;
2013-12-30 06:56:43 +01:00
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
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;
import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
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-01-23 20:02:48 +01:00
IUpgradeableHost myte;
2014-01-23 17:28:12 +01:00
int tbslot;
2014-01-23 20:02:48 +01:00
NetworkToolViewer tbinv;
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) );
2013-12-30 06:56:43 +01:00
myte = te;
2014-01-23 17:28:12 +01:00
World w = null;
int xCoor = 0, yCoor = 0, zCoor = 0;
if ( te instanceof TileEntity )
{
TileEntity myTile = (TileEntity) te;
w = myTile.getWorldObj();
xCoor = myTile.xCoord;
yCoor = myTile.yCoord;
zCoor = myTile.zCoord;
}
if ( te instanceof IPart )
{
2014-01-23 20:02:48 +01:00
IUpgradeableHost myTile = (IUpgradeableHost) te;
2014-01-23 17:28:12 +01:00
TileEntity mk = myTile.getTile();
w = mk.getWorldObj();
xCoor = mk.xCoord;
yCoor = mk.yCoord;
zCoor = mk.zCoord;
}
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 );
tbslot = x;
2014-01-23 20:02:48 +01:00
tbinv = (NetworkToolViewer) ((ToolNetworkTool) pii.getItem()).getGuiObject( pii, w, xCoor, yCoor, zCoor );
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-01-23 17:28:12 +01:00
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, tbinv, u + v * 3, 186 + u * 18, getHeight() - 82 + v * 18 ))
2014-01-20 17:41:37 +01:00
.setPlayerSide() );
}
setupConfig();
bindPlayerInventory( ip, 0, getHeight() - /* height of playerinventory */82 );
}
protected void setupConfig()
{
int x = 80;
int y = 40;
2013-12-30 06:56:43 +01:00
IInventory upgrades = myte.getInventoryByName( "upgrades" );
if ( availableUpgrades() > 0 )
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 0, 187, 8 + 18 * 0 )).setNotDraggable() );
if ( availableUpgrades() > 1 )
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 1, 187, 8 + 18 * 1 )).setNotDraggable() );
if ( availableUpgrades() > 2 )
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2 )).setNotDraggable() );
if ( availableUpgrades() > 3 )
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3 )).setNotDraggable() );
2013-12-30 06:56:43 +01:00
IInventory inv = myte.getInventoryByName( "config" );
addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
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()
{
return 4;
}
protected boolean supportCapacity()
{
return true;
}
public RedstoneMode rsMode = RedstoneMode.IGNORE;
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
2014-01-23 17:28:12 +01:00
public void checkToolbox()
{
if ( hasToolbox() )
{
ItemStack currentItem = getPlayerInv().getStackInSlot( tbslot );
if ( currentItem != tbinv.getItemStack() )
{
if ( currentItem != null )
{
if ( Platform.isSameItem( tbinv.getItemStack(), currentItem ) )
getPlayerInv().setInventorySlotContents( tbslot, tbinv.getItemStack() );
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
}
}
}
@Override
public void detectAndSendChanges()
{
verifyPermissions( SecurityPermissions.BUILD, false );
if ( Platform.isServer() )
{
for (int i = 0; i < this.crafters.size(); ++i)
{
ICrafting icrafting = (ICrafting) this.crafters.get( i );
if ( this.rsMode != this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED ) )
{
icrafting.sendProgressBarUpdate( this, 0, (int) this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED ).ordinal() );
}
if ( this.fzMode != this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ) )
{
icrafting.sendProgressBarUpdate( this, 1, (int) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE ).ordinal() );
}
}
this.fzMode = (FuzzyMode) this.myte.getConfigManager().getSetting( Settings.FUZZY_MODE );
this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
}
2014-01-23 17:28:12 +01:00
checkToolbox();
for (Object o : inventorySlots)
{
if ( o instanceof OptionalSlotFake )
{
OptionalSlotFake fs = (OptionalSlotFake) o;
if ( !fs.isEnabled() && fs.getDisplayStack() != null )
((OptionalSlotFake) fs).clearStack();
}
}
standardDetectAndSendChanges();
}
protected void standardDetectAndSendChanges()
{
super.detectAndSendChanges();
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int idx, int value)
{
if ( idx == 0 )
this.rsMode = RedstoneMode.values()[value];
if ( idx == 1 )
this.fzMode = FuzzyMode.values()[value];
}
2013-12-30 06:56:43 +01:00
public boolean hasToolbox()
{
2014-01-23 17:28:12 +01:00
return tbinv != 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
{
int upgrades = myte.getInstalledUpgrades( Upgrades.CAPACITY );
if ( idx == 1 && upgrades > 0 )
2013-12-30 06:56:43 +01:00
return true;
if ( idx == 2 && upgrades > 1 )
2013-12-30 06:56:43 +01:00
return true;
return false;
}
}