@Override public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) { super.onInteract(entity, block, type, clickedface); if (type == Action.RIGHT_CLICK) { BlockMaterial clickedmat = block.getMaterial(); Cause<Entity> cause; if (entity instanceof Player) { cause = new PlayerCause((Player) entity); } else { cause = new EntityCause(entity); } if (clickedmat.equals(VanillaMaterials.TNT)) { // Detonate TntBlock VanillaMaterials.TNT.onIgnite(block, cause); } else { // Default fire creation Block target = block.translate(clickedface); // Default fire placement if (VanillaMaterials.FIRE.canCreate(target, (short) 0, cause)) { VanillaMaterials.FIRE.onCreate(target, (short) 0, cause); Slot held = PlayerUtil.getHeldSlot(entity); if (held != null && !PlayerUtil.isCostSuppressed(entity)) { held.addData(1); } } // Handle the creation of portals Point pos = target.translate(BlockFace.BOTTOM).getPosition(); VanillaObjects.NETHER_PORTAL.setActive( pos.getWorld(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), true); } } }
public void onInteract(Entity entity, Block block, Action type, BlockFace clickedFace) { super.onInteract(entity, block, type, clickedFace); if (type != Action.RIGHT_CLICK) { return; } Slot selected = PlayerUtil.getHeldSlot(entity); if (selected == null || selected.get() == null) { return; } Material held = selected.get().getMaterial(); int data; if (held == VanillaMaterials.ROSE) { data = 1; } else if (held == VanillaMaterials.DANDELION) { data = 2; } else if (held == Sapling.DEFAULT) { data = 3; } else if (held == Sapling.SPRUCE) { data = 4; } else if (held == Sapling.BIRCH) { data = 5; } else if (held == Sapling.JUNGLE) { data = 6; } else if (held == VanillaMaterials.RED_MUSHROOM) { data = 7; } else if (held == VanillaMaterials.BROWN_MUSHROOM) { data = 8; } else if (held == VanillaMaterials.CACTUS) { data = 9; } else if (held == VanillaMaterials.DEAD_BUSH) { data = 10; } else if (held == VanillaMaterials.TALL_GRASS) { data = 11; } else { return; } block.setData(data); selected.addAmount(-1); }
@Override public void onInteractBy(Entity entity, Block block, Action type, BlockFace clickedFace) { super.onInteractBy(entity, block, type, clickedFace); Slot inv = PlayerUtil.getHeldSlot(entity); if (inv != null && inv.get() != null && inv.get().isMaterial(Dye.BONE_MEAL) && type.equals(Action.RIGHT_CLICK)) { // This flag is used to determine if we should remove a Bone Meal if at least one block // gets a Tall Grass attached to the top of it, then we should remove a bone meal. boolean shouldConsume = false; final Random random = GenericMath.getRandom(); // Minecraft does grass growing by Bone Meal as follows. Keep in mind the radius is 8. // - Tall Grass is placed 9/10 times. // - If Tall Grass fails, place Dandelion 2/3 times (within the 1/10 window Tall Grass failed // on) // - If Dandelion fails, place Rose within the 1/3 times window that Dandelion failed (which // is within the 1/10 window Tall Grass failed on). for (int dx = -4; dx < 4; dx++) { for (int dy = -1; dy <= 1; dy++) { for (int dz = -4; dz < 4; dz++) { // Fertilization only occurs 1/3 times. if (random.nextInt(3) != 2) { continue; } // Grass/flowers have lower chance to go to a lower/higher height than the center block // is at. // It incurs another 1/3 times. Only do this when iterating over -1 or 1 on the dy, // otherwise its on the same // plane and we don't care. if (dy != 0) { if (random.nextInt(3) != 2) { continue; } } final Block around = block.translate(dx, dy, dz); // Only spread to Grass blocks if (!around.getMaterial().equals(VanillaMaterials.GRASS)) { continue; } final Block aboveAround = around.translate(BlockFace.TOP); // Make sure the block above the translated one is Air. if (!aboveAround.getMaterial().equals(VanillaMaterials.AIR)) { continue; } if (random.nextInt(10) != 0) { if (VanillaMaterials.TALL_GRASS.canAttachTo(around, BlockFace.TOP)) { aboveAround.setMaterial(VanillaMaterials.TALL_GRASS); shouldConsume = true; } } else if (random.nextInt(3) != 0) { if (VanillaMaterials.DANDELION.canAttachTo(around, BlockFace.TOP)) { aboveAround.setMaterial(VanillaMaterials.DANDELION); shouldConsume = true; } } else { if (VanillaMaterials.ROSE.canAttachTo(around, BlockFace.TOP)) { aboveAround.setMaterial(VanillaMaterials.ROSE); shouldConsume = true; } } } } } if (!PlayerUtil.isCostSuppressed(entity) && shouldConsume) { inv.addAmount(-1); } } }