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);
}
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);
}
Aggregations