use of com.teamwizardry.wizardry.common.tile.TilePearlHolder in project Wizardry by TeamWizardry.
the class BlockPearlHolder method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
ItemStack heldItem = playerIn.getHeldItem(hand);
if (!worldIn.isRemote) {
TilePearlHolder te = getTE(worldIn, pos);
if (!te.containsSomething()) {
if (heldItem.getItem() == ModItems.ORB || heldItem.getItem() == ModItems.PEARL_NACRE) {
te.setItemStack(heldItem.copy());
te.getItemStack().setCount(1);
heldItem.shrink(1);
} else
return false;
} else {
ItemStack stack = te.getItemStack().copy();
CapManager manager1 = new CapManager(stack).setEntity(playerIn);
manager1.sync();
te.setItemStack(ItemStack.EMPTY);
if (playerIn.inventory.addItemStackToInventory(stack))
playerIn.openContainer.detectAndSendChanges();
else {
EntityItem entityItem = new EntityItem(worldIn, pos.getX(), pos.getY() + 1, pos.getZ(), stack);
worldIn.spawnEntity(entityItem);
}
}
te.markDirty();
}
return true;
}
use of com.teamwizardry.wizardry.common.tile.TilePearlHolder in project Wizardry by TeamWizardry.
the class BlockPearlHolder method breakBlock.
@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
TilePearlHolder holder = getTE(worldIn, pos);
if (holder == null) {
super.breakBlock(worldIn, pos, state);
return;
}
ItemStack itemStack = holder.getItemStack();
if (itemStack != null && !itemStack.isEmpty()) {
InventoryHelper.spawnItemStack(worldIn, pos.getX(), pos.getY(), pos.getZ(), itemStack);
}
super.breakBlock(worldIn, pos, state);
}
Aggregations