Falling Chest With Items

Discussion in 'Plugin Development' started by 5scb8, Mar 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    5scb8

    Ok so i have the falling chest fixed but now i have a prob with setting random items in it. heres my code for that atm
    Code:java
    1. @EventHandler
    2. public void checkBlock(EntityChangeBlockEvent e) {
    3. if(e.getEntity() instanceof FallingBlock) {
    4. FallingBlock fblock = (FallingBlock) e.getEntity();
    5. if(fblock.getMaterial() == Material.CHEST) {
    6. e.getBlock().setType(Material.CHEST);
    7. if(e.getBlock().getType() == Material.CHEST) {
    8. Chest chest = (Chest) e.getBlock().getState();
    9. Random random = new Random();
    10. for (int i = 0; i < 27; i++) {
    11. Integer num = Integer.valueOf(random.nextInt(801));
    12. if ((num.intValue() == 1) || (num.intValue() == 2)) {
    13. Integer num2 = Integer.valueOf(random.nextInt(5));
    14. if (num2.intValue() == 1) {
    15. new ItemStack(Material.DIAMOND_SWORD);
    16. }
    17. else if (num2.intValue() == 2) {
    18. new ItemStack(Material.DIAMOND_BOOTS);
    19. }
    20. else if (num2.intValue() == 3) {
    21. new ItemStack(Material.DIAMOND_LEGGINGS);
    22. }
    23. else if (num2.intValue() == 4) {
    24. new ItemStack(Material.DIAMOND_CHESTPLATE);
    25. }
    26. else if (num2.intValue() == 5) {
    27. new ItemStack(Material.DIAMOND_HELMET);
    28. }
    29. }
    30. else if (num.intValue() == 6) {
    31. new ItemStack(Material.IRON_SWORD);
    32. }
    33. else if (num.intValue() == 7) {
    34. new ItemStack(Material.IRON_BOOTS);
    35. }
    36. else if (num.intValue() == 8) {
    37. new ItemStack(Material.IRON_LEGGINGS);
    38. }
    39. else if (num.intValue() == 9) {
    40. new ItemStack(Material.IRON_CHESTPLATE);
    41. }
    42. else if (num.intValue() == 10) {
    43. new ItemStack(Material.IRON_HELMET);
    44. }
    45. else if ((num.intValue() == 12) || (num.intValue() == 13)) {
    46. new ItemStack(Material.GOLD_SWORD);
    47. }
    48. else if ((num.intValue() == 14) || (num.intValue() == 15)) {
    49. new ItemStack(Material.GOLD_BOOTS);
    50. }
    51. else if ((num.intValue() == 11) || (num.intValue() == 16)) {
    52. new ItemStack(Material.GOLD_LEGGINGS);
    53. }
    54. else if ((num.intValue() == 17) || (num.intValue() == 19)) {
    55. new ItemStack(Material.GOLD_CHESTPLATE);
    56. }
    57. else if ((num.intValue() == 20) || (num.intValue() == 18)) {
    58. new ItemStack(Material.GOLD_HELMET);
    59. }
    60. else if ((num.intValue() == 22) || (num.intValue() == 23)) {
    61. new ItemStack(Material.STONE_SWORD);
    62. }
    63. else if ((num.intValue() == 24) || (num.intValue() == 25)) {
    64. new ItemStack(Material.CHAINMAIL_BOOTS);
    65. }
    66. else if ((num.intValue() == 21) || (num.intValue() == 26)) {
    67. new ItemStack(Material.CHAINMAIL_LEGGINGS);
    68. }
    69. else if ((num.intValue() == 27) || (num.intValue() == 29)) {
    70. new ItemStack(Material.CHAINMAIL_CHESTPLATE);
    71. }
    72. else if ((num.intValue() == 30) || (num.intValue() == 28)) {
    73. new ItemStack(Material.CHAINMAIL_HELMET);
    74. }
    75. else if ((num.intValue() == 34) || (num.intValue() == 35)) {
    76. new ItemStack(Material.LEATHER_BOOTS);
    77. }
    78. else if ((num.intValue() == 31) || (num.intValue() == 36)) {
    79. new ItemStack(Material.LEATHER_LEGGINGS);
    80. }
    81. else if ((num.intValue() == 37) || (num.intValue() == 39)) {
    82. new ItemStack(Material.LEATHER_CHESTPLATE);
    83. }
    84. else if ((num.intValue() == 40) || (num.intValue() == 38)) {
    85. new ItemStack(Material.LEATHER_HELMET);
    86. }
    87. else if ((num.intValue() == 32) || (num.intValue() == 33) || (num.intValue() == 44) || (num.intValue() == 43) || (num.intValue() == 42) || (num.intValue() == 41) || (num.intValue() == 45)) {
    88. new ItemStack(Material.WOOD_SWORD);
    89. }
    90. else if ((num.intValue() == 50) || (num.intValue() == 46)) {
    91. new ItemStack(Material.COOKED_BEEF, 6);
    92. }
    93. else if ((num.intValue() == 51) || (num.intValue() == 47)) {
    94. new ItemStack(Material.COOKED_FISH, 4);
    95. }
    96. else if ((num.intValue() == 52) || (num.intValue() == 754) || (num.intValue() == 536)) {
    97. new ItemStack(Material.BAKED_POTATO, 7);
    98. }
    99. else if (num.intValue() == 53) {
    100. new ItemStack(Material.APPLE, 11);
    101. }
    102. else if (num.intValue() == 54) {
    103. new ItemStack(Material.COOKED_BEEF, 2);
    104. }
    105. else if ((num.intValue() == 55) || (num.intValue() == 56)) {
    106. new ItemStack(Material.COOKED_BEEF, 3);
    107. }
    108. else if ((num.intValue() == 57) || (num.intValue() == 58)) {
    109. new ItemStack(Material.POTATO_ITEM, 1);
    110. }
    111. else if ((num.intValue() == 59) || (num.intValue() == 60)) {
    112. if (num.intValue() == 59) {
    113. new ItemStack(Material.RAW_FISH, 6);
    114. }
    115. else {
    116. new ItemStack(Material.RAW_FISH, 3);
    117. }
    118. }
    119. else if ((num.intValue() == 61) || (num.intValue() == 62)) {
    120. new ItemStack(Material.RAW_CHICKEN, 2);
    121. }
    122. else if ((num.intValue() == 63) || (num.intValue() == 64) || (num.intValue() == 65)) {
    123. new ItemStack(Material.RAW_BEEF, 4);
    124. }
    125. else if (num.intValue() == 66) {
    126. new ItemStack(Material.GOLDEN_APPLE);
    127. }
    128. else if (num.intValue() == 67) {
    129. new ItemStack(Material.GOLDEN_APPLE, 2);
    130. }
    131. else if ((num.intValue() == 68) || (num.intValue() == 69)) {
    132. new ItemStack(Material.COOKED_CHICKEN, 3);
    133. }
    134. else if ((num.intValue() == 70) || (num.intValue() == 71)) {
    135. new ItemStack(Material.COOKED_CHICKEN);
    136. }
    137. else if ((num.intValue() == 72) || (num.intValue() == 73)) {
    138. new ItemStack(Material.BOW);
    139. }
    140. else if ((num.intValue() == 74) || (num.intValue() == 75) || (num.intValue() == 76)) {
    141. new ItemStack(Material.ARROW, random.nextInt(25));
    142. }
    143. else if ((num.intValue() == 76) || (num.intValue() == 77)) {
    144. new ItemStack(Material.EXP_BOTTLE, random.nextInt(22));
    145. }
    146. else if ((num.intValue() == 100) || (num.intValue() == 101)) {
    147. new ItemStack(Material.WOOD_AXE);
    148. }
    149. else if (num.intValue() == 102) {
    150. new ItemStack(Material.STONE_AXE);
    151. }
    152. else if (num.intValue() == 103) {
    153. new ItemStack(Material.GOLD_AXE);
    154. }
    155. else if (num.intValue() == 104) {
    156. new ItemStack(Material.IRON_AXE);
    157. }
    158. else if (num.intValue() == 105) {
    159. new ItemStack(Material.ENDER_PEARL, random.nextInt(3));
    160. }
    161. else if ((num.intValue() == 107) || (num.intValue() == 108)) {
    162. new ItemStack(Material.BOWL);
    163. }
    164. else if (num.intValue() == 109) {
    165. new ItemStack(Material.BOWL, 2);
    166. }
    167. }
    168. chest.update();
    169. e.setCancelled(true);
    170. }
    171. }
    172. }
    173. }
    174. }
    175.  
    Can any one tell me whats wrong. And also when i tested this the chest had no items in it.
     
  2. Offline

    Jnorr44

    you're just making itemstack objects, you arent putting them in the chest.
     
  3. Offline

    Desle

    5scb8
    Just saying.. you can't make chests fall and make them look like chests. When they are a falling block, they look like a regular wood block.
     
  4. Offline

    5scb8

    ik idc. It still spawns the chest on the ground so its all good

    You mean something like this chest.getInventory().setContents(arg0);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    Jnorr44

    yes... set the contents to the itemstacks selected
     
  6. Offline

    5scb8

    so like chest.getInventory().setContents(random); or just list all the Materials
     
  7. Offline

    Jnorr44

    the itemstack which you select at random
     
  8. Offline

    5scb8

    what do u mean?
     
  9. Offline

    MCForger

    5scb8
    You create an ItemStack but never do anything with it. Where you have the new ItemStack(whatever), put that in chest.getInventory().add or something like that inside the if statement.
     
  10. Offline

    5scb8

    Ok i already found out what was wrong i was just being stupid thz for the help.
     
Thread Status:
Not open for further replies.

Share This Page