How to scroll thru all known blocks and items?

Discussion in 'Plugin Development' started by UltraMC, Jul 14, 2013.

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

    UltraMC

    Hi,

    I want to get Block object of each block in Minecraft; the same for items.

    How do that automaticly?
     
  2. Offline

    Paper

    Material.values() returns an array of every Material in the game. Iterate through it with a loop.
     
    UltraMC likes this.
  3. Offline

    UltraMC

    Wow thanks that's what I was looking for. How you found that?

    But it creates an issue:
    Item ID 38 (WOOL) is just one item, but WOOL, POTION and items like that have an "Sub ID" - how to get that?

    Code:java
    1. Material[] allItems = Material.values();
    2.  
    3. for ( Material val : allItems) {
    4.  
    5. Material itemName = val;
    6. int itemId = val.getId();
    7. int itemMaxStack = val.getMaxStackSize();
    8. short itemMaxDurability = val.getMaxDurability();
    9.  
    10. String msg = itemId + "," + itemName + "," + itemMaxStack + "," + itemMaxDurability;
    11.  
    12. FileLog.logToFile( msg + "" );
    13.  
    14. }
     
  4. Offline

    MUG806

    you need to iterate through data values too then, although i'm not sure there is a method built in which knows which data values each material has.
     
  5. Offline

    Loogeh

    I think he could use the getData() method to get the data of the material but i'm not sure.
     
  6. Offline

    UltraMC

    I'm close yet failing with following approach:

    1. for each Material do for loop (32k times)
    2. in this loop I create new ItemStack and insert current for loop index as item's durability/itemSubId (
    Code:java
    1. new ItemStack(Material, 1, index)
    )
    3. read values - if arent unique (for ex. if they are null what means thay have no subid) plugin does nothing, otherwise gives me item's subID with its name ;-)

    BUT it's
    a) slow
    b) gives error @ signs (dont know why, it crashes plugins as soon as it gets to them)
    c) lame

    Anyone who can, please contribute: https://github.com/UltraMC/CraftBukkitItemLister

    bump

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

    savagesun

    Why are you doing a for loop 32 thousand times...? I don't think you can figure this out in a fesible and automatic way. Just use some if statements or something. I can't really tell what you're trying to do with the loop. But it for now you're just logging the id, so in the case that it's wool or something just loop through a group of strings that have the sub-ids of wool and attach it to the original wool id.
     
  8. Offline

    UltraMC

    Dear savagesun,

    I don't know what all sub-id's are for every type of block (that's why I'm trying to automate it btw.), so I look thru all values that possibly they can have (they are declared as (short) type, thats why 32k)

    You say like my code knew that he's scrolling thru WOOL, which has some SubID's. The trick is that I dont want manually declare where to look for subid's and where not. Maybe Ive misunderstood you; you shall present some code for that statement.
     
  9. Offline

    Rocoty

    What I think is....for whatever you are trying to do....maybe there is another apporach than to have to loop through all the materials?
     
  10. Offline

    foodyling

    I believe Material.SOMEMATERIAL.getMaxDurability() might help out
     
  11. Offline

    UltraMC

    It returns
    Code:java
    1. int 0
    on
    Code:java
    1. Material.WOOL
    It's clearly not an subid

    bump

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

    jayfella

    There is no catalog of item variants. Not possible. The only way to do it it create your own known list of variants for each item (wool, potions, etc) and use those.
     
  13. Offline

    Loogeh

    jayfella Yeah UltraMC just spend about an hour doing it and it will be worth it. You have 227 items to write down. Not that bad
     
  14. Offline

    UltraMC

    Every time when Minecraft gets updated my friend. Im sick of it thus want craete that dynamic listing
     
  15. Offline

    Tarestudio

    Right, this method returns 0 for every Material, not having a durability. So look at it the other way: Every Material giving you an durability > 0 cant have subIDs, so the loop to check isnt needed. Will optimize the speed a bit.

    I dont know how you check the Materials for having real subIDs, but you just need to check every subID against subID 0 for been different in my opinion. As soon as an equal is found, or the 32k is reached, there should be no new real subIDs, as they are just repeating from this point, I think.
     
  16. Offline

    xTrollxDudex

    If your too lazy maybe developing isn't your thing. All developers have to work hard to keep their projects up to date with the latest bukkit build, pretty much no way around that.
    Anyway, I think you might be able to use NMS for that?
     
  17. Offline

    UltraMC

    Could you provide more details into it?
    If I get
    Code:java
    1. int 0
    it mean's there's no SubID, right?
    Nope:
    Code:java
    1. Material.WOOL.getMaxDurability()
    returns 0! Yet it HAS SubID's. :(

    lawl, coder works hard, programmer builds tools to not work hard
     
  18. Offline

    Tarestudio

    UltraMC: The other way...
    Every Material returning 0 for getMaxDurability() can have subIDs. Can, but dont have to.
    Every Material returning >0 (more than zero) for getMaxDurability() CANT have subIDs. The .getData() is used to save how often they were used.
     
  19. Offline

    molenzwiebel

    Wrote a function which orders the items in tools, items with subtypes (potions, coal & charcoal, ink sack...) and normal items. Currently working on the blocks.
     
  20. Offline

    UltraMC

    Are item groups are predefined? Im striking for dynamic list.

    That's right buddy, still it's just an enchacement, but not an solution
     
  21. Offline

    molenzwiebel

    Yes, it is taken directly from the Item NMS class
     
  22. Offline

    UltraMC

    Can we look into your code, please?
     
  23. Offline

    molenzwiebel

  24. Offline

    UltraMC

    Way more advanced (in a Pro way)

    Code:java
    1. //THERE YOU HAVE IT! THE 3 ARRAYS ARE NOW FILLED WITH ITEMSTACKS. I HAVE NOT YET WRITTEN A WAY TO DETERMINE THEIR MAX ID

    Do
    Code:java
    1. Material.<ID>.getData() || Material.<ID>.getData().getData()
    it should return SubId and SubItemName, or null/0 if there's no such thing - scrolling thru all of them could be achieved with simple while loop

    PS I hope am right
     
  25. Offline

    UltraMC

    It returns what follows. But where is WOOL?

    Code:java
    1. [
    2. ItemStack{APPLE x 1},
    3. ItemStack{ARROW x 1},
    4. ItemStack{DIAMOND x 1},
    5. ItemStack{IRON_INGOT x 1},
    6. ItemStack{GOLD_INGOT x 1},
    7. ItemStack{STICK x 1},
    8. ItemStack{BOWL x 1},
    9. ItemStack{MUSHROOM_SOUP x 1},
    10. ItemStack{STRING x 1},
    11. ItemStack{FEATHER x 1},
    12. ItemStack{SULPHUR x 1},
    13. ItemStack{SEEDS x 1},
    14. ItemStack{WHEAT x 1},
    15. ItemStack{BREAD x 1},
    16. ItemStack{FLINT x 1},
    17. ItemStack{PORK x 1},
    18. ItemStack{GRILLED_PORK x 1},
    19. ItemStack{PAINTING x 1},
    20. ItemStack{SIGN x 1},
    21. ItemStack{WOOD_DOOR x 1},
    22. ItemStack{BUCKET x 1},
    23. ItemStack{WATER_BUCKET x 1},
    24. ItemStack{LAVA_BUCKET x 1},
    25. ItemStack{MINECART x 1},
    26. ItemStack{SADDLE x 1},
    27. ItemStack{IRON_DOOR x 1},
    28. ItemStack{REDSTONE x 1},
    29. ItemStack{SNOW_BALL x 1},
    30. ItemStack{BOAT x 1},
    31. ItemStack{LEATHER x 1},
    32. ItemStack{MILK_BUCKET x 1},
    33. ItemStack{CLAY_BRICK x 1},
    34. ItemStack{CLAY_BALL x 1},
    35. ItemStack{SUGAR_CANE x 1},
    36. ItemStack{PAPER x 1},
    37. ItemStack{BOOK x 1},
    38. ItemStack{SLIME_BALL x 1},
    39. ItemStack{STORAGE_MINECART x 1},
    40. ItemStack{POWERED_MINECART x 1},
    41. ItemStack{EGG x 1},
    42. ItemStack{COMPASS x 1},
    43. ItemStack{WATCH x 1},
    44. ItemStack{GLOWSTONE_DUST x 1},
    45. ItemStack{RAW_FISH x 1},
    46. ItemStack{COOKED_FISH x 1},
    47. ItemStack{BONE x 1},
    48. ItemStack{SUGAR x 1},
    49. ItemStack{CAKE x 1},
    50. ItemStack{BED x 1},
    51. ItemStack{DIODE x 1},
    52. ItemStack{COOKIE x 1},
    53. ItemStack{MELON x 1},
    54. ItemStack{PUMPKIN_SEEDS x 1},
    55. ItemStack{MELON_SEEDS x 1},
    56. ItemStack{RAW_BEEF x 1},
    57. ItemStack{COOKED_BEEF x 1},
    58. ItemStack{RAW_CHICKEN x 1},
    59. ItemStack{COOKED_CHICKEN x 1},
    60. ItemStack{ROTTEN_FLESH x 1},
    61. ItemStack{ENDER_PEARL x 1},
    62. ItemStack{BLAZE_ROD x 1},
    63. ItemStack{GHAST_TEAR x 1},
    64. ItemStack{GOLD_NUGGET x 1},
    65. ItemStack{NETHER_STALK x 1},
    66. ItemStack{GLASS_BOTTLE x 1},
    67. ItemStack{SPIDER_EYE x 1},
    68. ItemStack{FERMENTED_SPIDER_EYE x 1},
    69. ItemStack{BLAZE_POWDER x 1},
    70. ItemStack{MAGMA_CREAM x 1},
    71. ItemStack{BREWING_STAND_ITEM x 1},
    72. ItemStack{CAULDRON_ITEM x 1},
    73. ItemStack{EYE_OF_ENDER x 1},
    74. ItemStack{SPECKLED_MELON x 1},
    75. ItemStack{EXP_BOTTLE x 1},
    76. ItemStack{FIREBALL x 1},
    77. ItemStack{BOOK_AND_QUILL x 1},
    78. ItemStack{WRITTEN_BOOK x 1},
    79. ItemStack{EMERALD x 1},
    80. ItemStack{ITEM_FRAME x 1},
    81. ItemStack{FLOWER_POT_ITEM x 1},
    82. ItemStack{CARROT_ITEM x 1},
    83. ItemStack{POTATO_ITEM x 1},
    84. ItemStack{BAKED_POTATO x 1},
    85. ItemStack{POISONOUS_POTATO x 1},
    86. ItemStack{GOLDEN_CARROT x 1},
    87. ItemStack{NETHER_STAR x 1},
    88. ItemStack{PUMPKIN_PIE x 1},
    89. ItemStack{FIREWORK x 1},
    90. ItemStack{FIREWORK_CHARGE x 1},
    91. ItemStack{ENCHANTED_BOOK x 1},
    92. ItemStack{REDSTONE_COMPARATOR x 1},
    93. ItemStack{NETHER_BRICK_ITEM x 1},
    94. ItemStack{QUARTZ x 1},
    95. ItemStack{EXPLOSIVE_MINECART x 1},
    96. ItemStack{HOPPER_MINECART x 1},
    97. ItemStack{IRON_BARDING x 1},
    98. ItemStack{GOLD_BARDING x 1},
    99. ItemStack{DIAMOND_BARDING x 1},
    100. ItemStack{LEASH x 1},
    101. ItemStack{NAME_TAG x 1},
    102. ItemStack{GOLD_RECORD x 1},
    103. ItemStack{GREEN_RECORD x 1},
    104. ItemStack{RECORD_3 x 1},
    105. ItemStack{RECORD_4 x 1},
    106. ItemStack{RECORD_5 x 1},
    107. ItemStack{RECORD_6 x 1},
    108. ItemStack{RECORD_7 x 1},
    109. ItemStack{RECORD_8 x 1},
    110. ItemStack{RECORD_9 x 1},
    111. ItemStack{RECORD_10 x 1},
    112. ItemStack{RECORD_11 x 1},
    113. ItemStack{RECORD_12 x 1}
    114. ]
    115.  
    116. [
    117. ItemStack{IRON_SPADE x 1},
    118. ItemStack{IRON_PICKAXE x 1},
    119. ItemStack{IRON_AXE x 1},
    120. ItemStack{FLINT_AND_STEEL x 1},
    121. ItemStack{BOW x 1},
    122. ItemStack{IRON_SWORD x 1},
    123. ItemStack{WOOD_SWORD x 1},
    124. ItemStack{WOOD_SPADE x 1},
    125. ItemStack{WOOD_PICKAXE x 1},
    126. ItemStack{WOOD_AXE x 1},
    127. ItemStack{STONE_SWORD x 1},
    128. ItemStack{STONE_SPADE x 1},
    129. ItemStack{STONE_PICKAXE x 1},
    130. ItemStack{STONE_AXE x 1},
    131. ItemStack{DIAMOND_SWORD x 1},
    132. ItemStack{DIAMOND_SPADE x 1},
    133. ItemStack{DIAMOND_PICKAXE x 1},
    134. ItemStack{DIAMOND_AXE x 1},
    135. ItemStack{GOLD_SWORD x 1},
    136. ItemStack{GOLD_SPADE x 1},
    137. ItemStack{GOLD_PICKAXE x 1},
    138. ItemStack{GOLD_AXE x 1},
    139. ItemStack{WOOD_HOE x 1},
    140. ItemStack{STONE_HOE x 1},
    141. ItemStack{IRON_HOE x 1},
    142. ItemStack{DIAMOND_HOE x 1},
    143. ItemStack{GOLD_HOE x 1},
    144. ItemStack{LEATHER_HELMET x 1},
    145. ItemStack{LEATHER_CHESTPLATE x 1},
    146. ItemStack{LEATHER_LEGGINGS x 1},
    147. ItemStack{LEATHER_BOOTS x 1},
    148. ItemStack{CHAINMAIL_HELMET x 1},
    149. ItemStack{CHAINMAIL_CHESTPLATE x 1},
    150. ItemStack{CHAINMAIL_LEGGINGS x 1},
    151. ItemStack{CHAINMAIL_BOOTS x 1},
    152. ItemStack{IRON_HELMET x 1},
    153. ItemStack{IRON_CHESTPLATE x 1},
    154. ItemStack{IRON_LEGGINGS x 1},
    155. ItemStack{IRON_BOOTS x 1},
    156. ItemStack{DIAMOND_HELMET x 1},
    157. ItemStack{DIAMOND_CHESTPLATE x 1},
    158. ItemStack{DIAMOND_LEGGINGS x 1},
    159. ItemStack{DIAMOND_BOOTS x 1},
    160. ItemStack{GOLD_HELMET x 1},
    161. ItemStack{GOLD_CHESTPLATE x 1},
    162. ItemStack{GOLD_LEGGINGS x 1},
    163. ItemStack{GOLD_BOOTS x 1},
    164. ItemStack{FISHING_ROD x 1},
    165. ItemStack{SHEARS x 1},
    166. ItemStack{CARROT_STICK x 1}
    167. ]
    168.  
    169. [
    170. ItemStack{COAL x 1},
    171. ItemStack{GOLDEN_APPLE x 1},
    172. ItemStack{INK_SACK x 1},
    173. ItemStack{POTION x 1},
    174. ItemStack{MONSTER_EGG x 1},
    175. ItemStack{SKULL_ITEM x 1}
    176. ]
     
  26. Offline

    UltraMC

  27. Offline

    molenzwiebel

    Note that it only processes ITEMS and no blocks. I am currently away for 4 weeks so I won't be able to work on the blocks
     
  28. Offline

    UltraMC

  29. Offline

    1Rogue

  30. Offline

    UltraMC

Thread Status:
Not open for further replies.

Share This Page