use of net.minecraftforge.items.IItemHandlerModifiable in project minecolonies by Minecolonies.
the class AbstractCombinedItemHandler method deserializeNBT.
@SuppressWarnings({ RAWTYPES, UNCHECKED })
@Override
public void deserializeNBT(final NBTTagCompound nbt) {
final NBTTagList handlerList = nbt.getTagList(NBT_KEY_NAME, Constants.NBT.TAG_COMPOUND);
final NBTTagList indexList = nbt.getTagList(NBT_KEY_HANDLERS_INDEXLIST, Constants.NBT.TAG_INT);
if (handlerList.tagCount() == handlers.length) {
for (int i = 0; i < handlerList.tagCount(); i++) {
final NBTTagCompound handlerCompound = handlerList.getCompoundTagAt(i);
final IItemHandlerModifiable modifiable = handlers[indexList.getIntAt(i)];
if (modifiable instanceof INBTSerializable) {
final INBTSerializable serializable = (INBTSerializable) modifiable;
serializable.deserializeNBT(handlerCompound);
}
}
}
setName(nbt.hasKey(NBT_KEY_NAME) ? nbt.getString(NBT_KEY_NAME) : null);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project minecolonies by Minecolonies.
the class TileEntityRack method upgradeItemStorage.
/**
* Upgrade the rack by 1. This adds 9 more slots and copies the inventory to the new one.
*/
public void upgradeItemStorage() {
++size;
final IItemHandlerModifiable tempInventory = new ItemStackHandler(DEFAULT_SIZE + size * SLOT_PER_LINE) {
@Override
protected void onContentsChanged(final int slot) {
updateItemStorage();
super.onContentsChanged(slot);
}
};
for (int slot = 0; slot < inventory.getSlots(); slot++) {
tempInventory.setStackInSlot(slot, inventory.getStackInSlot(slot));
}
inventory = tempInventory;
final IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 0x03);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project MineCamera by PorPit.
the class EntityTripod method setDead.
@Override
public void setDead() {
// System.out.println("death and drop");
if (!this.getEntityWorld().isRemote) {
Block.spawnAsEntity(this.getEntityWorld(), this.getPosition(), new ItemStack(ItemLoader.itemTripod, 1));
// last slot useless,so= -2 !=-1
for (int i = Inventory.getSlots() - 2; i >= 0; --i) {
if (Inventory.getStackInSlot(i) != null) {
Block.spawnAsEntity(this.getEntityWorld(), this.getPosition(), Inventory.getStackInSlot(i));
((IItemHandlerModifiable) Inventory).setStackInSlot(i, null);
}
}
}
super.setDead();
}
use of net.minecraftforge.items.IItemHandlerModifiable in project MineCamera by PorPit.
the class BlockPhotoProcessor method breakBlock.
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TileEntityPhotoProcessor te = (TileEntityPhotoProcessor) worldIn.getTileEntity(pos);
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
for (int i = inv.getSlots() - 1; i >= 0; --i) {
if (inv.getStackInSlot(i) != null) {
Block.spawnAsEntity(worldIn, pos, inv.getStackInSlot(i));
((IItemHandlerModifiable) inv).setStackInSlot(i, null);
}
}
super.breakBlock(worldIn, pos, state);
}
use of net.minecraftforge.items.IItemHandlerModifiable in project Metalworks by canitzp.
the class BlockSuperCharger method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getHeldItem(hand);
if (!stack.isEmpty()) {
if (stack.hasCapability(CapabilityEnergy.ENERGY, null)) {
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileSuperCharger) {
if (((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0).isEmpty()) {
player.setHeldItem(hand, ((TileSuperCharger) tile).getInventory(facing).insertItem(0, stack, false));
}
((TileSuperCharger) tile).syncToClients();
}
}
return true;
}
} else {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileSuperCharger) {
if (!((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0).isEmpty()) {
if (!world.isRemote) {
player.setHeldItem(hand, ((TileSuperCharger) tile).getInventory(facing).getStackInSlot(0));
((IItemHandlerModifiable) ((TileSuperCharger) tile).getInventory(facing)).setStackInSlot(0, ItemStack.EMPTY);
((TileSuperCharger) tile).syncToClients();
}
return true;
}
}
}
return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ);
}
Aggregations