Applied-Energistics-2-tiler.../items/contents/NetworkToolViewer.java
AlgorithmX2 496a67abb9 Never rotate while sneaking!
Fixed Crash.
2014-02-01 20:26:30 -06:00

118 lines
2.3 KiB
Java

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
public String getInvName()
{
return inv.getInvName();
}
@Override
public boolean isInvNameLocalized()
{
return inv.isInvNameLocalized();
}
@Override
public int getInventoryStackLimit()
{
return inv.getInventoryStackLimit();
}
@Override
public void onInventoryChanged()
{
inv.onInventoryChanged();
inv.writeToNBT( Platform.openNbtData( is ), "inv" );
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
{
return inv.isUseableByPlayer( entityplayer );
}
@Override
public void openChest()
{
inv.openChest();
}
@Override
public void closeChest()
{
inv.closeChest();
}
@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;
}
}