Java Code Examples for net.minecraft.entity.player.EntityPlayer#canPlayerEdit()
The following examples show how to use
net.minecraft.entity.player.EntityPlayer#canPlayerEdit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemGenericSlab.java From Et-Futurum with The Unlicense | 6 votes |
@Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (stack.stackSize == 0) return false; else if (!player.canPlayerEdit(x, y, z, side, stack)) return false; else { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); boolean flag = meta == 1; if (block == field_150939_a && (side == 1 && !flag || side == 0 && flag)) { if (world.checkNoEntityCollision(field_150939_a.getCollisionBoundingBoxFromPool(world, x, y, z)) && world.setBlock(x, y, z, field_150939_a, 2, 3)) { world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, field_150939_a.stepSound.func_150496_b(), (field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F, field_150939_a.stepSound.getPitch() * 0.8F); stack.stackSize--; } return true; } else return func_150946_a(stack, player, world, x, y, z, side) ? true : super.onItemUse(stack, player, world, x, y, z, side, hitX, hitY, hitZ); } }
Example 2
Source File: ItemSeedBase.java From ExNihiloAdscensio with MIT License | 6 votes |
@Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!facing.equals(EnumFacing.UP)) return EnumActionResult.PASS; if (player.canPlayerEdit(pos, facing, stack) && player.canPlayerEdit(pos.add(0, 1, 0), facing, stack)) { IBlockState soil = world.getBlockState(pos); if (soil != null && soil.getBlock().canSustainPlant(soil, world, pos, EnumFacing.UP, this) && world.isAirBlock(pos.add(0, 1, 0)) && this.getPlant(world, pos) != null) { world.setBlockState(pos.add(0, 1, 0), this.getPlant(world, pos)); --stack.stackSize; return EnumActionResult.SUCCESS; } } return EnumActionResult.PASS; }
Example 3
Source File: ItemSeeds.java From customstuff4 with GNU General Public License v3.0 | 6 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); IBlockState state = worldIn.getBlockState(pos); if (facing == EnumFacing.UP && player.canPlayerEdit(pos.offset(facing), facing, itemstack) && state.getBlock().canSustainPlant(state, worldIn, pos, EnumFacing.UP, this) && worldIn.isAirBlock(pos.up())) { worldIn.setBlockState(pos.up(), content.plant.createState()); if (player instanceof EntityPlayerMP) { CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP) player, pos.up(), itemstack); } itemstack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } }
Example 4
Source File: ItemPlasticPlants.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
/** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){ BlockPneumaticPlantBase plant = (BlockPneumaticPlantBase)getPlantBlockIDFromSeed(stack.getItemDamage()); if(plant == Blockss.squidPlant) { MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, true); if(mop != null) { int x = mop.blockX; int y = mop.blockY; int z = mop.blockZ; if(player.canPlayerEdit(x, y, z, 1, stack) && player.canPlayerEdit(x, y + 1, z, 1, stack)) { if(plant.canBlockStay(world, x, y + 1, z) && world.isAirBlock(x, y + 1, z)) { stack.stackSize--; world.setBlock(x, y + 1, z, Blockss.squidPlant, 7, 3); } } } } return stack; }
Example 5
Source File: ItemEntityEgg.java From Et-Futurum with The Unlicense | 5 votes |
@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (world.isRemote) return stack; else { MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(world, player, true); if (movingobjectposition == null) return stack; else { if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; if (!world.canMineBlock(player, i, j, k)) return stack; if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack)) return stack; if (world.getBlock(i, j, k) instanceof BlockLiquid) { Entity entity = spawnEntity(world, stack.getItemDamage(), i, j, k); if (entity != null) { if (entity instanceof EntityLivingBase && stack.hasDisplayName()) ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName()); if (!player.capabilities.isCreativeMode) stack.stackSize--; } } } return stack; } } }
Example 6
Source File: ItemCompost.java From GardenCollection with MIT License | 5 votes |
@Override public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (!player.canPlayerEdit(x, y, z, side, itemStack)) return false; return applyEnrichment(itemStack, world, x, y, z, player); }
Example 7
Source File: ItemEngineeringTable.java From Cyberware with MIT License | 5 votes |
/** * Called when a Block is right-clicked with this Item */ public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (facing != EnumFacing.UP) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(worldIn, pos)) { pos = pos.offset(facing); } if (playerIn.canPlayerEdit(pos, facing, stack) && this.block.canPlaceBlockAt(worldIn, pos)) { EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw); int i = enumfacing.getFrontOffsetX(); int j = enumfacing.getFrontOffsetZ(); placeDoor(worldIn, pos, enumfacing, this.block); SoundType soundtype = this.block.getSoundType(); worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); --stack.stackSize; return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } } }
Example 8
Source File: WandOverlord.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 5 votes |
public boolean hellfire(World world, ItemStack wand, EntityPlayer player, int x, int y, int z, int side) { if (world.isRemote || wand == null || !(wand.getItem() instanceof ItemWandCasting) || ((ItemWandCasting) wand.getItem()).getFocusItem(wand) != null || !ResearchManager.isResearchComplete(player.getCommandSenderName(), "HELLFIRE") || !player.canPlayerEdit(x, y, z, side, new ItemStack(Items.fire_charge))) return false; if (world.isAirBlock(x, y + 1, z) && ((ItemWandCasting) wand.getItem()).consumeVis(wand, player, Aspect.FIRE, 2, false)) { world.playSoundEffect((double) x + 0.5D, (double) y + 1.5D, (double) z + 0.5D, "fire.ignite", 1.0F, world.rand.nextFloat() * 0.4F + 0.8F); world.setBlock(x, y + 1, z, Blocks.fire); player.swingItem(); return true; } else return false; }
Example 9
Source File: ItemSlab.java From customstuff4 with GNU General Public License v3.0 | 5 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!itemstack.isEmpty() && player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { int subtype = getMetadata(itemstack); IBlockState currentState = worldIn.getBlockState(pos); if (currentState.getBlock() == singleSlab) { int subtype1 = this.singleSlabCS.getSubtype(currentState); net.minecraft.block.BlockSlab.EnumBlockHalf half = currentState.getValue(net.minecraft.block.BlockSlab.HALF); if ((facing == EnumFacing.UP && half == net.minecraft.block.BlockSlab.EnumBlockHalf.BOTTOM || facing == EnumFacing.DOWN && half == net.minecraft.block.BlockSlab.EnumBlockHalf.TOP) && subtype1 == subtype) { IBlockState stateDouble = this.makeState(subtype1); AxisAlignedBB axisalignedbb = stateDouble == null ? Block.NULL_AABB : stateDouble.getCollisionBoundingBox(worldIn, pos); if (stateDouble != null && axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(pos)) && worldIn.setBlockState(pos, stateDouble, 11)) { SoundType soundtype = stateDouble.getBlock().getSoundType(stateDouble, worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); itemstack.shrink(1); } return EnumActionResult.SUCCESS; } } return this.tryPlace(player, itemstack, worldIn, pos.offset(facing), subtype) ? EnumActionResult.SUCCESS : super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ); } else { return EnumActionResult.FAIL; } }
Example 10
Source File: ItemTraverseWoodDoor.java From Traverse-Legacy-1-12-2 with MIT License | 5 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (facing != EnumFacing.UP) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(worldIn, pos)) { pos = pos.offset(facing); } ItemStack itemstack = player.getHeldItem(hand); if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) { EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw); int i = enumfacing.getFrontOffsetX(); int j = enumfacing.getFrontOffsetZ(); boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; placeDoor(worldIn, pos, enumfacing, this.block, flag); SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); itemstack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } } }
Example 11
Source File: ItemTranslocator.java From Translocators with MIT License | 5 votes |
@Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { Block block = world.getBlock(x, y, z); if (block == Blocks.snow_layer && (world.getBlockMetadata(x, y, z) & 7) < 1) { side = 1; } else if (block != Blocks.vine && block != Blocks.tallgrass && block != Blocks.deadbush && !block.isReplaceable(world, x, y, z)) { if (side == 0) --y; if (side == 1) ++y; if (side == 2) --z; if (side == 3) ++z; if (side == 4) --x; if (side == 5) ++x; } if (stack.stackSize == 0 || !player.canPlayerEdit(x, y, z, side, stack)) return false; if (placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, stack.getItemDamage())) { world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, field_150939_a.stepSound.func_150496_b(), (field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F, field_150939_a.stepSound.getPitch() * 0.8F); --stack.stackSize; return true; } return false; }
Example 12
Source File: ItemTraverseWoodDoor.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (facing != EnumFacing.UP) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (!block.isReplaceable(worldIn, pos)) { pos = pos.offset(facing); } ItemStack itemstack = player.getHeldItem(hand); if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) { EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw); int i = enumfacing.getXOffset(); int j = enumfacing.getYOffset(); boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F; placeDoor(worldIn, pos, enumfacing, this.block, flag); SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player); worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); itemstack.shrink(1); return EnumActionResult.SUCCESS; } else { return EnumActionResult.FAIL; } } }
Example 13
Source File: ItemBroom.java From Sakura_mod with MIT License | 5 votes |
/** * Called when a Block is right-clicked with this Item */ @Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItem(hand); if (!player.canPlayerEdit(pos.offset(facing), facing, itemstack)) { return EnumActionResult.FAIL; } IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (facing != EnumFacing.DOWN && worldIn.getBlockState(pos.up()).getMaterial() == Material.AIR && ((worldIn.getBlockState(pos).getMaterial() == Material.GROUND||worldIn.getBlockState(pos).getMaterial() ==Material.GRASS) && !(block instanceof BlockFarmland||block instanceof BlockGrassPath))) { IBlockState iblockstate1 = Blocks.GRASS_PATH.getDefaultState(); worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_STEP, SoundCategory.BLOCKS, 1.2F, 1.2F); worldIn.playSound(player, pos, SoundEvents.BLOCK_GRASS_PLACE, SoundCategory.BLOCKS, 1.2F, 1.2F); if (!worldIn.isRemote) { worldIn.setBlockState(pos, iblockstate1, 11); itemstack.damageItem(1, player); } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 14
Source File: ItemWoodSupport.java From TFC2 with GNU General Public License v3.0 | 4 votes |
@Override public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos origPos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack stack = playerIn.getHeldItem(hand); IBlockState iblockstate = worldIn.getBlockState(origPos); Block block = iblockstate.getBlock(); BlockPos pos = origPos.offset(side); if (stack.getMaxStackSize() == 0) { return EnumActionResult.FAIL; } if (!playerIn.canPlayerEdit(pos, side, stack)) { return EnumActionResult.FAIL; } if (worldIn.mayPlace(this.block, pos, false, side, (Entity)null)) { int meta = getMetadata(stack.getMetadata()); IBlockState scanState; //Scan out to make sure there is another beam in the facing direction int range = WoodType.getTypeFromMeta(stack.getItemDamage()).getSupportRange(); BlockPos scanPos; int foundRange = -1; if(side == EnumFacing.UP || side == EnumFacing.DOWN) { foundRange = 1; } for(int i = 1; i <= range && foundRange == -1; i++) { scanPos = origPos.offset(side, i); scanState = worldIn.getBlockState(scanPos); scanState = scanState.getBlock().getActualState(scanState, worldIn, scanPos); if(scanState.getBlock() instanceof BlockWoodSupport) { if(!scanState.getValue(BlockWoodSupport.SPAN)) { foundRange = i; break; } } else if(scanState.getBlock().isReplaceable(worldIn, pos)) { continue; } else { break; } } if(foundRange != -1 && stack.getMaxStackSize() >= foundRange) { for(int i = 1; i <= foundRange; i++) { scanPos = origPos.offset(side, i); IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, scanPos.offset(side.getOpposite()), side, hitX, hitY, hitZ, meta, playerIn); if (placeBlockAt(stack, playerIn, worldIn, scanPos, side, hitX, hitY, hitZ, iblockstate1)) { worldIn.playSound(scanPos.getX() + 0.5F, scanPos.getY() + 0.5F, scanPos.getZ() + 0.5F, this.block.getSoundType().getPlaceSound(), SoundCategory.BLOCKS, (this.block.getSoundType().getVolume() + 1.0F) / 2.0F, this.block.getSoundType().getPitch() * 0.8F, true); stack.shrink(1); } } } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; }
Example 15
Source File: ItemWaterHyacinth.java From Production-Line with MIT License | 4 votes |
@Nonnull public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true); if (raytraceresult == null) { return new ActionResult<>(EnumActionResult.PASS, itemStackIn); } else { if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockpos = raytraceresult.getBlockPos(); if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn)) { return new ActionResult<>(EnumActionResult.FAIL, itemStackIn); } BlockPos blockpos1 = blockpos.up(); IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getMaterial() == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL) == 0 && worldIn.isAirBlock(blockpos1)) { // special case for handling block placement with water lilies net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, blockpos1); worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState()); if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP).isCanceled()) { blocksnapshot.restore(true, false); return new ActionResult<>(EnumActionResult.FAIL, itemStackIn); } worldIn.setBlockState(blockpos1, PLBlocks.waterHyacinth.getDefaultState(), 11); if (!playerIn.capabilities.isCreativeMode) { --itemStackIn.stackSize; } playerIn.addStat(StatList.getObjectUseStats(this)); worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); return new ActionResult<>(EnumActionResult.SUCCESS, itemStackIn); } } return new ActionResult<>(EnumActionResult.FAIL, itemStackIn); } }
Example 16
Source File: ItemFuton.java From Sakura_mod with MIT License | 4 votes |
@Override public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) { return EnumActionResult.SUCCESS; } else if (facing != EnumFacing.UP) { return EnumActionResult.FAIL; } else { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); boolean flag = block.isReplaceable(worldIn, pos); if (!flag) { pos = pos.up(); } int i = MathHelper.floor(playerIn.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; EnumFacing enumfacing = EnumFacing.getHorizontal(i); BlockPos blockpos = pos.offset(enumfacing); ItemStack itemstack = playerIn.getHeldItem(hand); if (playerIn.canPlayerEdit(pos, facing, itemstack) && playerIn.canPlayerEdit(blockpos, facing, itemstack)) { boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos); boolean flag2 = flag || worldIn.isAirBlock(pos); boolean flag3 = flag1 || worldIn.isAirBlock(blockpos); if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid() && worldIn.getBlockState(blockpos.down()).isFullCube()) { IBlockState iblockstate1 = BlockLoader.FUTON.getDefaultState() .withProperty(BlockFuton.OCCUPIED, Boolean.valueOf(false)) .withProperty(BlockHorizontal.FACING, enumfacing) .withProperty(BlockFuton.PART, BlockFuton.EnumPartType.FOOT); if (worldIn.setBlockState(pos, iblockstate1, 11)) { IBlockState iblockstate2 = iblockstate1.withProperty(BlockFuton.PART, BlockFuton.EnumPartType.HEAD); worldIn.setBlockState(blockpos, iblockstate2, 11); } SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn); worldIn.playSound(null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F); itemstack.shrink(1); return EnumActionResult.SUCCESS; } return EnumActionResult.FAIL; } return EnumActionResult.FAIL; } }
Example 17
Source File: ItemTrowel.java From GardenCollection with MIT License | 4 votes |
@Override public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (!player.canPlayerEdit(x, y, z, side, itemStack)) return false; UseTrowelEvent event = new UseTrowelEvent(player, itemStack, world, x, y, z); if (MinecraftForge.EVENT_BUS.post(event)) return false; if (event.getResult() == Event.Result.ALLOW) { itemStack.damageItem(1, player); return true; } if (side == 0) return false; Block block = world.getBlock(x, y, z); if (block instanceof BlockGarden) { player.openGui(GardenCore.instance, GuiHandler.gardenLayoutGuiID, world, x, y, z); return true; } else if (block instanceof IPlantProxy) { IPlantProxy proxy = (IPlantProxy) block; TileEntityGarden te = proxy.getGardenEntity(world, x, y, z); if (te != null) { player.openGui(GardenCore.instance, GuiHandler.gardenLayoutGuiID, world, te.xCoord, te.yCoord, te.zCoord); return true; } } /*if (world.getBlock(x, y + 1, z).isAir(world, x, y + 1, z) && (block == Blocks.grass || block == Blocks.dirt)) { Block.SoundType stepSound = ModBlocks.gardenSoil.stepSound; world.playSoundEffect( + .5f, y + .5f, z + .5f, stepSound.getStepResourcePath(), (stepSound.getVolume() + .5f) / 2, stepSound.getPitch() * .8f); if (!world.isRemote) { world.setBlock(x, y, z, ModBlocks.gardenSoil); itemStack.damageItem(1, player); } return true; }*/ return false; }
Example 18
Source File: ItemArcaneCake.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
@Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World yWorld, int z, int par5, int par6, int par7, float par8, float par9, float par10) { Block block = yWorld.getBlock(z, par5, par6); if (block == Blocks.snow_layer && (yWorld.getBlockMetadata(z, par5, par6) & 7) < 1) { par7 = 1; } else if (block != Blocks.vine && block != Blocks.tallgrass && block != Blocks.deadbush) { if (par7 == 0) { --par5; } if (par7 == 1) { ++par5; } if (par7 == 2) { --par6; } if (par7 == 3) { ++par6; } if (par7 == 4) { --z; } if (par7 == 5) { ++z; } } if (!player.canPlayerEdit(z, par5, par6, par7, stack)) { return false; } else if (stack.stackSize == 0) { return false; } else { Block cake = ForbiddenBlocks.arcaneCake; if (yWorld.canPlaceEntityOnSide(cake, z, par5, par6, false, par7, (Entity) null, stack)) { int j1 = cake.onBlockPlaced(yWorld, z, par5, par6, par7, par8, par9, par10, 0); if (yWorld.setBlock(z, par5, par6, cake, j1, 3)) { if (yWorld.getBlock(z, par5, par6) == cake) { cake.onBlockPlacedBy(yWorld, z, par5, par6, player, stack); cake.onPostBlockPlaced(yWorld, z, par5, par6, j1); } yWorld.playSoundEffect((double) ((float) z + 0.5F), (double) ((float) par5 + 0.5F), (double) ((float) par6 + 0.5F), block.stepSound.soundName, (block.stepSound.getVolume() + 1.0F) / 2.0F, block.stepSound.getPitch() * 0.8F); --stack.stackSize; } } return true; } }
Example 19
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
/** * Checks if the player can edit the target block */ public boolean isTargetUsable(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) { // Spawn safe zone checks etc. return world.isBlockModifiable(player, pos) && player.canPlayerEdit(pos, side, stack); }
Example 20
Source File: ItemArmourStand.java From Et-Futurum with The Unlicense | 4 votes |
@Override @SuppressWarnings("unchecked") public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (side == 0) return false; else { if (side == 1) y++; if (side == 2) z--; if (side == 3) z++; if (side == 4) x--; if (side == 5) x++; if (!player.canPlayerEdit(x, y, z, side, stack)) return false; else { boolean flag1 = !world.isAirBlock(x, y, z) && !world.getBlock(x, y, z).isReplaceable(world, x, y, z); flag1 |= !world.isAirBlock(x, y + 1, z) && !world.getBlock(x, y + 1, z).isReplaceable(world, x, y + 1, z); if (flag1) return false; else { double d0 = x; double d1 = y; double d2 = z; List<Entity> list = world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB.getBoundingBox(d0, d1, d2, d0 + 1.0D, d1 + 2.0D, d2 + 1.0D)); if (list.size() > 0) return false; else { if (!world.isRemote) { world.setBlockToAir(x, y, z); world.setBlockToAir(x, y + 1, z); EntityArmourStand stand = new EntityArmourStand(world, d0 + 0.5D, d1, d2 + 0.5D); float f3 = MathHelper.floor_float((MathHelper.wrapAngleTo180_float(player.rotationYaw - 180.0F) + 22.5F) / 45.0F) * 45.0F; stand.setLocationAndAngles(d0 + 0.5D, d1, d2 + 0.5D, f3, 0.0F); applyRandomRotations(stand, world.rand); NBTTagCompound nbt = stack.getTagCompound(); if (nbt != null && nbt.hasKey("EntityTag", 10)) { NBTTagCompound nbt1 = new NBTTagCompound(); stand.writeToNBTOptional(nbt1); merge(nbt1, nbt.getCompoundTag("EntityTag")); stand.readFromNBT(nbt1); } world.spawnEntityInWorld(stand); } stack.stackSize--; return true; } } } } }