use of biomesoplenty.common.block.BlockBOPPlant in project BiomesOPlenty by Glitchfiend.
the class ItemBOPPlant method onItemRightClick.
// The code for right clicking needs to be overridden to handle the unique way reeds are placed - on top of the water
// (usually when you point the cursor at water the picked block is whatever is underneath the water - when placing reeds the water itself has to be picked)
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
ItemStack itemStackIn = playerIn.getHeldItem(hand);
if (this.block instanceof BlockBOPPlant) {
BlockBOPPlant block = (BlockBOPPlant) this.block;
IBlockState state = block.getStateFromMeta(itemStackIn.getMetadata());
BOPPlants plant = ((BOPPlants) state.getValue(block.variantProperty));
if (plant == BOPPlants.REED) {
RayTraceResult movingobjectposition = this.rayTrace(worldIn, playerIn, true);
if (movingobjectposition == null) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
} else {
if (movingobjectposition.typeOfHit == RayTraceResult.Type.BLOCK) {
BlockPos blockpos = movingobjectposition.getBlockPos();
if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn)) {
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
BlockPos blockpos1 = blockpos.up();
IBlockState iblockstate = worldIn.getBlockState(blockpos);
if (iblockstate.getMaterial() == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0 && worldIn.isAirBlock(blockpos1)) {
// special case for handling block placement with reeds
net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1);
worldIn.setBlockState(blockpos1, BlockBOPPlant.paging.getVariantState(BOPPlants.REED));
if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, hand).isCanceled()) {
blocksnapshot.restore(true, false);
return new ActionResult<ItemStack>(EnumActionResult.FAIL, itemStackIn);
}
if (!playerIn.capabilities.isCreativeMode) {
itemStackIn.setCount(itemStackIn.getCount() - 1);
}
// TODO: 1.9 playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn);
}
}
}
// in all other cases take the default action
return super.onItemRightClick(worldIn, playerIn, hand);
}
Aggregations