Line 14: |
Line 14: |
| public void onBlockBreak(final BlockEvent.BreakEvent event) | | public void onBlockBreak(final BlockEvent.BreakEvent event) |
| { | | { |
| + | IWorld world = event.getWorld(); |
| if (!world.isClientSide() && event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is | | if (!world.isClientSide() && event.getState().is(Blocks.SAND)) // use the base event to get the state and see what it is |
| { | | { |
| event.setExpToDrop(10); // change the amount of experience we'll be dropping | | event.setExpToDrop(10); // change the amount of experience we'll be dropping |
| PlayerEntity player = event.getPlayer(); | | PlayerEntity player = event.getPlayer(); |
− | if (player.getUseItem().getItem().is(Items.SHEARS)) // check if the player is holding shears | + | if (player.getMainHandItem().getItem().equals(Items.DIAMOND_SHOVEL)) // check what we're holding |
| { | | { |
− | ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone to the player! | + | ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(Items.BONE)); // give a bone |
| } | | } |
| } | | } |
Line 46: |
Line 47: |
| public void onEntityPlace(final BlockEvent.EntityPlaceEvent event) | | public void onEntityPlace(final BlockEvent.EntityPlaceEvent event) |
| { | | { |
− | Entity entity = event.getEntity(); | + | IWorld world = event.getWorld(); |
− | if (!world.isClientSide() && entity != null) // check if the entity is null | + | if (!world.isClientSide() && event.getEntity() instanceof EndermanEntity) |
| { | | { |
− | Block block = event.getState().getBlock(); // get the block that was placed | + | event.setCanceled(true); // prevent enderman placement |
− | if (entity instanceof PlayerEntity && block.is(Blocks.FROSTED_ICE))
| |
− | {
| |
− | event.setCanceled(true); // cancel the placing
| |
− | event.getWorld().setBlock(event.getPos(), Blocks.COBBLESTONE.defaultBlockState(), 3); // set cobble instead
| |
− | }
| |
| } | | } |
| } | | } |
Line 81: |
Line 77: |
| public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event) | | public void onNeighborNotify(final BlockEvent.NeighborNotifyEvent event) |
| { | | { |
− | if (!world.isClientSide()) return; | + | IWorld world = event.getWorld(); |
| + | if (world.isClientSide()) return; |
| BlockPos eventPos = event.getPos(); | | BlockPos eventPos = event.getPos(); |
− | for (Direction direction : event.getNotifiedSides()) // cycle through notified directions | + | if (event.getState().is(Blocks.REDSTONE_WIRE)) // only do it for redstone |
| { | | { |
− | BlockPos pos = eventPos.relative(direction); // move to the direction given | + | for (Direction direction : event.getNotifiedSides()) // cycle through notified directions |
− | double x = pos.getX() + 0.5D; // move to center of the block | + | { |
− | double y = pos.getY() + 0.5D;
| + | BlockPos pos = eventPos.relative(direction); // move to that spot |
− | double z = pos.getZ() + 0.5D;
| + | if (world.isEmptyBlock(pos)) |
− | // add particle
| + | { |
− | event.getWorld().addParticle(ParticleTypes.CLOUD, x, y, z, 0.0D, 0.0D, 0.0D);
| + | world.setBlock(pos, Blocks.GLOWSTONE.defaultBlockState(), 3); // place glowstone |
| + | } |
| + | } |
| } | | } |
| } | | } |
Line 106: |
Line 105: |
| public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event) | | public void onFluidSourceCreate(final BlockEvent.CreateFluidSourceEvent event) |
| { | | { |
| + | IWorldReader world = event.getWorld(); |
| if (!world.isClientSide() && event.getPos().getY() > 100) | | if (!world.isClientSide() && event.getPos().getY() > 100) |
| { | | { |