use of com.cjm721.overloaded.block.tile.TileItemInterface in project Overloaded by CJ-MC-Mods.
the class BlockItemInterface method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (worldIn.isRemote)
return true;
TileEntity te = worldIn.getTileEntity(pos);
if (!(te instanceof TileItemInterface))
return true;
TileItemInterface anInterface = (TileItemInterface) te;
ItemStack stack = anInterface.getStoredItem();
if (stack.isEmpty()) {
ItemStack handStack = playerIn.getHeldItem(hand);
if (handStack.isEmpty())
return true;
ItemStack returnedItem = anInterface.insertItem(0, handStack, false);
playerIn.setHeldItem(hand, returnedItem);
} else {
if (!playerIn.getHeldItem(hand).isEmpty())
return true;
ItemStack toSpawn = anInterface.extractItem(0, 1, false);
if (toSpawn.isEmpty())
return true;
worldIn.spawnEntity(new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ, toSpawn));
}
return true;
}
Aggregations