Advertisement
Guest User

Untitled

a guest
Aug 13th, 2015
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. public void fillChest() {
  2. Material[] items1 = new Material[] { Material.GOLDEN_APPLE, Material.IRON_SWORD, Material.IRON_CHESTPLATE, Material.IRON_SWORD };
  3. Material[] items2 = new Material[] { Material.APPLE, Material.WOOD_SWORD, Material.LEATHER_CHESTPLATE, Material.BOW, Material.ARROW };
  4.  
  5. Random r = new Random();
  6.  
  7. int numItems = r.nextInt(5) + 1; // A random number between 1 and 5.
  8.  
  9. for (int i = 0; i < numItems; i++) {
  10. Material material = null;
  11.  
  12. if (tier == 1) {
  13. material = items1[r.nextInt(items1.length)]; // A random Materials from the items1 array.
  14. }
  15.  
  16. else if (tier == 2) {
  17. material = items2[r.nextInt(items2.length)]; // A random Materials from the items2 array.
  18. }
  19.  
  20. ItemStack item = new ItemStack(material, 1);
  21.  
  22. int index;
  23.  
  24. do {
  25. index = r.nextInt(chest.getInventory().getSize());
  26. } while (chest.getInventory().getItem(index) != null);
  27.  
  28. chest.getInventory().setItem(index, item);
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement