private boolean placeBlock(ItemStack itemstack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float xOffset, float yOffset, float zOffset) { IBlockState iblockstate = world.getBlockState(pos); Block block = iblockstate.getBlock(); if(!block.isReplaceable(world, pos)) { pos = pos.offset(side); } if(itemstack.isEmpty()) { return false; } else if(!player.canPlayerEdit(pos, side, itemstack)) { return false; } else if(world.mayPlace(Blocks.MOB_SPAWNER, pos, false, side, null)) { int meta = this.getMetadata(itemstack.getMetadata()); IBlockState iblockstate1 = Blocks.MOB_SPAWNER.getStateForPlacement(world, pos, side, xOffset, yOffset, zOffset, meta, player); if (placeBlockAt(itemstack, player, world, pos, side, xOffset, yOffset, zOffset, iblockstate1)) { world.playSound(null, pos, Blocks.MOB_SPAWNER.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (Blocks.MOB_SPAWNER.getSoundType().getVolume() + 1.0F) / 2.0F, Blocks.MOB_SPAWNER.getSoundType().getPitch() * 0.8F); player.renderBrokenItemStack(itemstack); itemstack.shrink(1); for(int i = 0; i < 100; i++) Botania.proxy.sparkleFX(pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), (float) Math.random(), (float) Math.random(), (float) Math.random(), 0.45F + 0.2F * (float) Math.random(), 6); } return true; } else { return false; } }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) { ItemStack stack = player.getHeldItem(hand); if(ManaItemHandler.requestManaExactForTool(stack, player, COST, false) && !world.provider.doesWaterVaporize()) { // Adapted from bucket code RayTraceResult mop = rayTrace(world, player, false); if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos hitPos = mop.getBlockPos(); if(!world.isBlockModifiable(player, hitPos)) return EnumActionResult.FAIL; BlockPos placePos = hitPos.offset(mop.sideHit); if(player.canPlayerEdit(placePos, mop.sideHit, stack)) { if (ManaItemHandler.requestManaExactForTool(stack, player, COST, true) && ((ItemBucket) Items.WATER_BUCKET).tryPlaceContainedLiquid(player, world, placePos)) { for(int i = 0; i < 6; i++) Botania.proxy.sparkleFX(pos.getX() + side.getXOffset() + Math.random(), pos.getY() + side.getYOffset() + Math.random(), pos.getZ() + side.getZOffset() + Math.random(), 0.2F, 0.2F, 1F, 1F, 5); return EnumActionResult.SUCCESS; } } } return EnumActionResult.FAIL; } return EnumActionResult.PASS; }
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { RayTraceResult rtr = rayTrace(world, player, true); ItemStack stack = player.getHeldItem(hand); if(rtr == null) return ActionResult.newResult(EnumActionResult.PASS, stack); else { if(rtr.typeOfHit == net.minecraft.util.math.RayTraceResult.Type.BLOCK) { BlockPos pos = rtr.getBlockPos(); if(!world.isBlockModifiable(player, pos)) return ActionResult.newResult(EnumActionResult.PASS, stack); if(!player.canPlayerEdit(pos, rtr.sideHit, stack)) return ActionResult.newResult(EnumActionResult.PASS, stack); IBlockState state = world.getBlockState(pos); Fluid fluid = FluidRegistry.lookupFluidForBlock(state.getBlock()); boolean isFull = state.getBlock() instanceof BlockLiquid && state.getValue(BlockLiquid.LEVEL) == 0 || state.getBlock() instanceof IFluidBlock && Math.abs(((IFluidBlock) state.getBlock()).getFilledPercentage(world, pos)) >= 1; if(fluid != null && isFull) { player.playSound(fluid.getFillSound(world, pos), 1.0f, 1.0f); world.setBlockToAir(pos); for(int x = 0; x < 5; x++) world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 0, 0, 0); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } return ActionResult.newResult(EnumActionResult.PASS, stack); } }
ItemStack stack = player.getHeldItem(hand); if(!player.canPlayerEdit(pos, side, stack)) return EnumActionResult.PASS; else {
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { // Copy of ItemBlock.onItemUse IBlockState iblockstate = world.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(world, pos)) { pos = pos.offset(facing); } ItemStack stack = player.getHeldItem(hand); if (!stack.isEmpty() && player.canPlayerEdit(pos, facing, stack) && world.mayPlace(ModBlocks.buriedPetals, pos, false, facing, null)) { int i = this.getMetadata(stack.getMetadata()); IBlockState iblockstate1 = ModBlocks.buriedPetals.getStateForPlacement(world, pos, facing, hitX, hitY, hitZ, i, player); if (placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, iblockstate1)) { SoundType soundtype = ModBlocks.buriedPetals.getSoundType(); world.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); stack.shrink(1); } return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } }
if( !p.canPlayerEdit( pos, side, item ) ) if( !p.canPlayerEdit( offsetPos, side, item ) )
if(player.canPlayerEdit(pos, side, stack) && (!(block instanceof BlockCommandBlock) || player.canUseCommandBlock()) && block.rotateBlock(world, pos, side)) {
if (playerIn.canPlayerEdit(pos, facing, itemstack) && Blocks.SKULL.canPlaceBlockAt(worldIn, pos)) { if (worldIn.isRemote) { return EnumActionResult.SUCCESS;
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { return player.canPlayerEdit(pos.offset(facing), facing, player.getHeldItem(hand)) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { return player.canPlayerEdit(pos.offset(facing), facing, player.getHeldItem(hand)) ? EnumActionResult.SUCCESS : EnumActionResult.PASS; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if (world.isRemote && side != EnumFacing.DOWN && side != EnumFacing.UP) { BlockPos offset = pos.offset(side); if (player.canPlayerEdit(offset, side, stack)) { JurassiCraft.PROXY.openSelectDino(offset, side, hand); } } return EnumActionResult.PASS; } }
@SuppressWarnings("unchecked") private int plantSeedAt(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing facing, Crop crop, int planted, BlockPos original) { if (player.canPlayerEdit(pos, facing, stack) && player.canPlayerEdit(pos.up(), facing, stack) && world.isAirBlock(pos)) { IBlockState down = world.getBlockState(pos.down()); if (crop.getGrowthHandler().canPlantSeedAt(world, pos, down, crop, original)) { HFApi.crops.plantCrop(player, world, pos, crop, 1); planted++; } } return planted; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos.offset(facing), facing, stack)) { return EnumActionResult.PASS; } int radius = 1 + ItemHelper.getItemDamage(stack); if (onApplyBonemeal(stack, world, pos, player, hand, radius)) { return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos, side, stack)) { return EnumActionResult.FAIL; } if(!tryPaintBlock(world, pos, side)) { return EnumActionResult.PASS; } useItemDurability(player, hand, stack, empty.copy()); return EnumActionResult.SUCCESS; }
@Override public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos, side, stack)) { return EnumActionResult.FAIL; } if(!tryIgniteBlock(world, pos.offset(side))) { return EnumActionResult.PASS; } useItemDurability(player, hand, stack, ItemStack.EMPTY); return EnumActionResult.SUCCESS; }
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { pos = pos.offset(facing); if (!player.canPlayerEdit(pos, facing, player.getHeldItem(hand))) { return EnumActionResult.FAIL; } else { if (worldIn.isAirBlock(pos)) { worldIn.playSound(player, pos, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F); worldIn.setBlockState(pos, ModBlocks.alchemical_fire.getDefaultState().withProperty(BlockAlchemicalFire.AGE, 15), 11); } return EnumActionResult.SUCCESS; } }
public boolean placeBlockAtTested(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, IBlockState newState) { return player.canPlayerEdit(pos, facing, stack) && world.getBlockState(pos).getBlock().isReplaceable(world, pos) && block.canPlaceBlockAt(world, pos) && block.canPlaceBlockOnSide(world, pos, facing) && super.placeBlockAt(stack, player, world, pos, facing, hitX, hitY, hitZ, newState); }
@Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); IBlockState state = world.getBlockState(pos); if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, stack) && state.getBlock().canSustainPlant(state, world, pos, EnumFacing.UP, this) && world.isAirBlock(pos.up())) { world.setBlockState(pos.up(), this.sapling.getDefaultState()); stack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } }
@SubscribeEvent(priority = EventPriority.LOWEST) // allow others to cancel this public static void onClick(@Nonnull PlayerInteractEvent.LeftClickBlock event) { final World world = event.getWorld(); if (world != null && !world.isRemote && event.getUseBlock() != Result.DENY) { final EntityPlayer player = event.getEntityPlayer(); if (player != null && !player.isSpectator() && !world.isAirBlock(event.getPos())) { final EnumFacing face = NullHelper.first(event.getFace(), EnumFacing.DOWN); final BlockPos pos = event.getPos().offset(face); if (world.getBlockState(pos).getBlock() instanceof BlockColdFire && player.canPlayerEdit(pos, face, Prep.getEmpty())) { world.playEvent(null, 1009, pos, 0); world.setBlockToAir(pos); } } } }
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); IBlockState state = worldIn.getBlockState(pos); if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, stack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) { worldIn.setBlockState(pos.up(), ModBlocks.PLANTED_FLOWER.getDefaultState().withProperty(BlockPlantedGiantFlower.TYPE, BlockPlantedGiantFlower.EnumFlowerType.values()[stack.getItemDamage()]), 11); stack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } }