timbru31

Untitled

Jan 17th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1.     /*
  2.      * Note: method names and variables start with lowercase
  3.      * Class names start with uppercase
  4.      *
  5.      */
  6.     @EventHandler
  7.     public void spawnerChanger (PlayerInteractEvent event) {
  8.         // if the event has no block, boooom, so we make a check
  9.         if (!event.hasBlock()) return;
  10.         Player player = event.getPlayer();
  11.         Block block = event.getClickedBlock();
  12.         // We combine the check
  13.         if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && block.getType() == Material.MOB_SPAWNER) {
  14.             // Check for egg in hand
  15.             if (player.getItemInHand().getType() == Material.MONSTER_EGG) {
  16.                 // The egg "carries" the type of the mob, stored in the durability field (383:90 e.g)
  17.                 short ID = player.getItemInHand().getDurability();
  18.                 CreatureSpawner cs = (CreatureSpawner) block.getState();
  19.                 // Set the type from the spawner to our ID [first get the type, we can use the EntityType.fromId() method]
  20.                 cs.setSpawnedType(EntityType.fromId(ID));
  21.                 cs.update();
  22.             }
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment