List of usage examples for net.minecraftforge.common.util BlockSnapshot restore
public boolean restore(boolean force, boolean notifyNeighbors)
From source file:com.mcgoodtime.gti.common.items.ItemWaterHyacinth.java
License:MIT License
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true); if (movingobjectposition == null) { return itemStack; } else {/*from w w w .ja va 2s . co m*/ 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 itemStack; } if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) { return itemStack; } if (world.getBlock(i, j, k).getMaterial() == Material.water && world.getBlockMetadata(i, j, k) == 0 && world.isAirBlock(i, j + 1, k)) { // special case for handling block placement with water lilies, moved to water hyacinth net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot .getBlockSnapshot(world, i, j + 1, k); world.setBlock(i, j + 1, k, GtiBlocks.waterHyacinth); if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(player, blocksnapshot, net.minecraftforge.common.util.ForgeDirection.UP).isCanceled()) { blocksnapshot.restore(true, false); return itemStack; } if (!player.capabilities.isCreativeMode) { itemStack.stackSize--; } } } return itemStack; } }
From source file:com.mcgoodtime.productionline.common.items.ItemWaterHyacinth.java
License:MIT License
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true); if (movingobjectposition == null) { return itemStack; } else {//from w w w.j av a 2s. c om 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 itemStack; } if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, itemStack)) { return itemStack; } if (world.getBlock(i, j, k).getMaterial() == Material.water && world.getBlockMetadata(i, j, k) == 0 && world.isAirBlock(i, j + 1, k)) { // special case for handling block placement with water lilies, moved to water hyacinth net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot .getBlockSnapshot(world, i, j + 1, k); world.setBlock(i, j + 1, k, PLBlocks.waterHyacinth); if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(player, blocksnapshot, net.minecraftforge.common.util.ForgeDirection.UP).isCanceled()) { blocksnapshot.restore(true, false); return itemStack; } if (!player.capabilities.isCreativeMode) { itemStack.stackSize--; } } } return itemStack; } }