Search in sources :

Example 1 with BlockBOPPlant

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);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BOPPlants(biomesoplenty.api.enums.BOPPlants) BlockBOPPlant(biomesoplenty.common.block.BlockBOPPlant)

Aggregations

BOPPlants (biomesoplenty.api.enums.BOPPlants)1 BlockBOPPlant (biomesoplenty.common.block.BlockBOPPlant)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1