Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Note: method names and variables start with lowercase
- * Class names start with uppercase
- *
- */
- @EventHandler
- public void spawnerChanger (PlayerInteractEvent event) {
- // if the event has no block, boooom, so we make a check
- if (!event.hasBlock()) return;
- Player player = event.getPlayer();
- Block block = event.getClickedBlock();
- // We combine the check
- if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && block.getType() == Material.MOB_SPAWNER) {
- // Check for egg in hand
- if (player.getItemInHand().getType() == Material.MONSTER_EGG) {
- // The egg "carries" the type of the mob, stored in the durability field (383:90 e.g)
- short ID = player.getItemInHand().getDurability();
- CreatureSpawner cs = (CreatureSpawner) block.getState();
- // Set the type from the spawner to our ID [first get the type, we can use the EntityType.fromId() method]
- cs.setSpawnedType(EntityType.fromId(ID));
- cs.update();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment