Search in sources :

Example 6 with BOPPlants

use of biomesoplenty.api.enums.BOPPlants in project BiomesOPlenty by Glitchfiend.

the class BlockBOPPlant method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    switch((BOPPlants) state.getValue(this.variantProperty)) {
        case BERRYBUSH:
            // an activated berry bush turns into a regular bush and drops a berry
            worldIn.setBlockState(pos, paging.getVariantState(BOPPlants.BUSH));
            EntityItem berries = new EntityItem(worldIn, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), new ItemStack(BOPItems.berries));
            if (!worldIn.isRemote) {
                worldIn.spawnEntity(berries);
                if (!(playerIn instanceof FakePlayer)) {
                    berries.onCollideWithPlayer(playerIn);
                }
            }
            return true;
    }
    return super.onBlockActivated(worldIn, pos, state, playerIn, hand, side, hitX, hitY, hitZ);
}
Also used : BOPPlants(biomesoplenty.api.enums.BOPPlants) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Example 7 with BOPPlants

use of biomesoplenty.api.enums.BOPPlants 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)7 ItemStack (net.minecraft.item.ItemStack)4 IBlockState (net.minecraft.block.state.IBlockState)2 BlockBOPPlant (biomesoplenty.common.block.BlockBOPPlant)1 Random (java.util.Random)1 Block (net.minecraft.block.Block)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 ItemBlock (net.minecraft.item.ItemBlock)1 PotionEffect (net.minecraft.potion.PotionEffect)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 World (net.minecraft.world.World)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1