Applied-Energistics-2-tiler.../items/contents/NetworkToolViewer.java

119 lines
2.3 KiB
Java
Raw Normal View History

package appeng.items.contents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import appeng.api.implementations.guiobjects.INetworkTool;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.api.networking.IGridHost;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.Platform;
public class NetworkToolViewer implements INetworkTool
{
final AppEngInternalInventory inv;
final ItemStack is;
final IGridHost gh;
public NetworkToolViewer(ItemStack is, IGridHost gHost) {
this.is = is;
gh = gHost;
inv = new AppEngInternalInventory( null, 9 );
if ( is.hasTagCompound() ) // prevent crash when opening network status creen.
inv.readFromNBT( Platform.openNbtData( is ), "inv" );
}
@Override
public int getSizeInventory()
{
return inv.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i)
{
return inv.getStackInSlot( i );
}
@Override
public ItemStack decrStackSize(int i, int j)
{
return inv.decrStackSize( i, j );
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
{
return inv.getStackInSlotOnClosing( i );
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
{
inv.setInventorySlotContents( i, itemstack );
}
@Override
2014-02-09 02:34:52 +01:00
public String getInventoryName()
{
2014-02-09 02:34:52 +01:00
return inv.getInventoryName();
}
@Override
2014-02-09 02:34:52 +01:00
public boolean hasCustomInventoryName()
{
2014-02-09 02:34:52 +01:00
return inv.hasCustomInventoryName();
}
@Override
public int getInventoryStackLimit()
{
return inv.getInventoryStackLimit();
}
@Override
2014-02-09 02:34:52 +01:00
public void markDirty()
{
2014-02-09 02:34:52 +01:00
inv.markDirty();
inv.writeToNBT( Platform.openNbtData( is ), "inv" );
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return inv.isUseableByPlayer( entityplayer );
}
@Override
2014-02-09 02:34:52 +01:00
public void openInventory()
{
2014-02-09 02:34:52 +01:00
inv.openInventory();
}
@Override
2014-02-09 02:34:52 +01:00
public void closeInventory()
{
2014-02-09 02:34:52 +01:00
inv.closeInventory();
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
return inv.isItemValidForSlot( i, itemstack ) && itemstack.getItem() instanceof IUpgradeModule
&& ((IUpgradeModule) itemstack.getItem()).getType( itemstack ) != null;
}
@Override
public ItemStack getItemStack()
{
return is;
}
@Override
public IGridHost getGridHost()
{
return gh;
}
}