2014-11-14 12:02:52 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Applied Energistics 2.
|
|
|
|
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
|
|
|
*/
|
|
|
|
|
2013-12-30 06:56:43 +01:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
2014-11-28 04:36:46 +01:00
|
|
|
|
2013-12-30 06:56:43 +01:00
|
|
|
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-11-28 04:36:46 +01:00
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
|
|
|
import appeng.api.config.RedstoneMode;
|
2015-07-10 02:55:03 +02:00
|
|
|
import appeng.api.config.SchedulingMode;
|
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;
|
2015-05-09 00:00:52 +02:00
|
|
|
import appeng.api.implementations.guiobjects.IGuiItem;
|
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
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSlotHost
|
2013-12-30 06:56:43 +01:00
|
|
|
{
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private final IUpgradeableHost upgradeable;
|
2015-04-03 08:54:31 +02:00
|
|
|
@GuiSync( 0 )
|
|
|
|
public RedstoneMode rsMode = RedstoneMode.IGNORE;
|
|
|
|
@GuiSync( 1 )
|
|
|
|
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
|
|
|
|
@GuiSync( 5 )
|
|
|
|
public YesNo cMode = YesNo.NO;
|
2015-07-10 02:55:03 +02:00
|
|
|
@GuiSync( 6 )
|
|
|
|
public SchedulingMode schedulingMode = SchedulingMode.DEFAULT;
|
2015-10-08 15:42:42 +02:00
|
|
|
private int tbSlot;
|
|
|
|
private NetworkToolViewer tbInventory;
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public ContainerUpgradeable( final InventoryPlayer ip, final IUpgradeableHost te )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
super( ip, (TileEntity) ( te instanceof TileEntity ? te : null ), (IPart) ( te instanceof IPart ? te : null ) );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.upgradeable = te;
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-01-23 17:28:12 +01:00
|
|
|
World w = null;
|
2015-03-26 12:13:34 +01:00
|
|
|
int xCoord = 0;
|
|
|
|
int yCoord = 0;
|
|
|
|
int zCoord = 0;
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof TileEntity )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileEntity myTile = (TileEntity) te;
|
2014-01-23 17:28:12 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IPart )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TileEntity mk = te.getTile();
|
2014-01-23 17:28:12 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IInventory pi = this.getPlayerInv();
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < pi.getSizeInventory(); x++ )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack pii = pi.getStackInSlot( x );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( pii != null && pii.getItem() instanceof ToolNetworkTool )
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.lockPlayerInventorySlot( x );
|
|
|
|
this.tbSlot = x;
|
2015-05-09 00:00:52 +02:00
|
|
|
this.tbInventory = (NetworkToolViewer) ( (IGuiItem) pii.getItem() ).getGuiObject( pii, w, xCoord, yCoord, zCoord );
|
2014-01-23 17:28:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.hasToolbox() )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int v = 0; v < 3; v++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int u = 0; u < 3; u++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory, u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setupConfig();
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.bindPlayerInventory( ip, 0, this.getHeight() - /* height of player inventory */82 );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean hasToolbox()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.tbInventory != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int getHeight()
|
|
|
|
{
|
|
|
|
return 184;
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void setupConfig()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setupUpgrades();
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
|
2015-09-25 23:10:56 +02:00
|
|
|
final int y = 40;
|
|
|
|
final int x = 80;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) );
|
2014-01-01 09:57:16 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.supportCapacity() )
|
2014-01-05 09:49:08 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 1, x, y, -1, 0, 1 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 2, x, y, 1, 0, 1 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 3, x, y, 0, -1, 1 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 4, x, y, 0, 1, 1 ) );
|
|
|
|
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 5, x, y, -1, -1, 2 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 6, x, y, 1, -1, 2 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 7, x, y, -1, 1, 2 ) );
|
|
|
|
this.addSlotToContainer( new OptionalSlotFakeTypeOnly( inv, this, 8, x, y, 1, 1, 2 ) );
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
2014-01-06 07:54:25 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void setupUpgrades()
|
2014-01-05 09:49:08 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.availableUpgrades() > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ).setNotDraggable() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.availableUpgrades() > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 1, 187, 8 + 18, this.getInventoryPlayer() ) ).setNotDraggable() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.availableUpgrades() > 2 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 2, 187, 8 + 18 * 2, this.getInventoryPlayer() ) ).setNotDraggable() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.availableUpgrades() > 3 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 3, 187, 8 + 18 * 3, this.getInventoryPlayer() ) ).setNotDraggable() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean supportCapacity()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public int availableUpgrades()
|
2014-01-23 17:28:12 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 4;
|
2014-01-23 17:28:12 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 09:57:16 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.verifyPermissions( SecurityPermissions.BUILD, false );
|
2014-01-27 05:00:36 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isServer() )
|
2014-01-02 06:51:41 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final IConfigManager cm = this.getUpgradeable().getConfigManager();
|
2014-12-29 15:13:47 +01:00
|
|
|
this.loadSettingsFromHost( cm );
|
2014-01-02 06:51:41 +01:00
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.checkToolbox();
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final Object o : this.inventorySlots )
|
2014-01-01 09:57:16 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof OptionalSlotFake )
|
2014-01-01 09:57:16 +01:00
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final OptionalSlotFake fs = (OptionalSlotFake) o;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !fs.isEnabled() && fs.getDisplayStack() != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-09-28 20:56:16 +02:00
|
|
|
fs.clearStack();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-01-01 09:57:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.standardDetectAndSendChanges();
|
2014-01-05 09:49:08 +01:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
protected void loadSettingsFromHost( final IConfigManager cm )
|
2014-07-05 03:59:50 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setFuzzyMode( (FuzzyMode) cm.getSetting( Settings.FUZZY_MODE ) );
|
|
|
|
this.setRedStoneMode( (RedstoneMode) cm.getSetting( Settings.REDSTONE_CONTROLLED ) );
|
|
|
|
if( this.getUpgradeable() instanceof PartExportBus )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setCraftingMode( (YesNo) cm.getSetting( Settings.CRAFT_ONLY ) );
|
|
|
|
this.setSchedulingMode( (SchedulingMode) cm.getSetting( Settings.SCHEDULING_MODE ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
private void checkToolbox()
|
2014-01-05 09:49:08 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.hasToolbox() )
|
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final ItemStack currentItem = this.getPlayerInv().getStackInSlot( this.tbSlot );
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
if( currentItem != this.tbInventory.getItemStack() )
|
|
|
|
{
|
|
|
|
if( currentItem != null )
|
|
|
|
{
|
|
|
|
if( Platform.isSameItem( this.tbInventory.getItemStack(), currentItem ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.getPlayerInv().setInventorySlotContents( this.tbSlot, this.tbInventory.getItemStack() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setValidContainer( false );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
this.setValidContainer( false );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
2014-01-01 09:57:16 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
protected void standardDetectAndSendChanges()
|
2013-12-30 06:56:43 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
super.detectAndSendChanges();
|
2013-12-30 06:56:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
public boolean isSlotEnabled( final int idx )
|
2013-12-30 06:56:43 +01:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
final int upgrades = this.getUpgradeable().getInstalledUpgrades( Upgrades.CAPACITY );
|
2014-01-01 09:57:16 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( idx == 1 && upgrades > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-30 06:56:43 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( idx == 2 && upgrades > 1 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-30 06:56:43 +01:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-30 06:56:43 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-08 15:42:42 +02:00
|
|
|
|
|
|
|
public FuzzyMode getFuzzyMode()
|
|
|
|
{
|
|
|
|
return this.fzMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setFuzzyMode( final FuzzyMode fzMode )
|
|
|
|
{
|
|
|
|
this.fzMode = fzMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public YesNo getCraftingMode()
|
|
|
|
{
|
|
|
|
return this.cMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCraftingMode( final YesNo cMode )
|
|
|
|
{
|
|
|
|
this.cMode = cMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RedstoneMode getRedStoneMode()
|
|
|
|
{
|
|
|
|
return this.rsMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRedStoneMode( final RedstoneMode rsMode )
|
|
|
|
{
|
|
|
|
this.rsMode = rsMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SchedulingMode getSchedulingMode()
|
|
|
|
{
|
|
|
|
return this.schedulingMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void setSchedulingMode( final SchedulingMode schedulingMode )
|
|
|
|
{
|
|
|
|
this.schedulingMode = schedulingMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUpgradeableHost getUpgradeable()
|
|
|
|
{
|
|
|
|
return this.upgradeable;
|
|
|
|
}
|
2013-12-30 06:56:43 +01:00
|
|
|
}
|