List all available items and blocks

Discussion in 'Plugin Development' started by frdmn, Oct 27, 2013.

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

    frdmn

    My goal is to list all available Minecraft items and blocks. Currently I stuck with these attempts:

    Code:java
    1. package mn.frd.mcrecipes_scraper;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.inventory.ItemStack;
    6. import org.bukkit.inventory.Recipe;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. import java.util.ArrayList;
    10. import java.util.Iterator;
    11.  
    12. public class Plugin extends JavaPlugin {
    13. // ArrayList to store items
    14. private ArrayList<String> foundItems = new ArrayList<String>();
    15.  
    16. public void onEnable(){
    17. // Get all possible recipes
    18. Iterator<Recipe> recipeIterator = Bukkit.recipeIterator();
    19.  
    20. while(recipeIterator.hasNext()) {
    21. Recipe recipe = recipeIterator.next();
    22. ItemStack result = recipe.getResult();
    23.  
    24. foundItems.add(result.getTypeId() + ":" + result.getData().getData());
    25. }
    26.  
    27. // Get all items without data values
    28. for(Material m : Material.values()) {
    29. if(!foundItems.contains(m.getId() + ":0")) {
    30. foundItems.add(m.getId() + ":0");
    31. }
    32. }
    33.  
    34. // Output to console
    35. for(String foundItem : foundItems) {
    36. getLogger().info(foundItem);
    37. }
    38.  
    39. // Output total items
    40. getLogger().info("Found " + foundItems.size() + " Items");
    41. }
    42. }


    Hover I still don't have non-craftable items in my ArrayList.

    Is there a better way to list ALL of them, including their datavalues?

    Thanks
     
  2. Offline

    qhenckel

  3. Offline

    frdmn

    qhenckel I don't want to rely on 3rd party services. Thats why I came up with this Bukkit plugin. To get the informations directly from the Bukkit API.
     
  4. Offline

    qhenckel

    here is a place to start:
    if you want more help i can.
    Code:java
    1. Material[] m = Material.values();
    2. int page = Integer.parseInt(args[1]);
    3. for(int i = (20 * page) - 20; i < m.length && i < 20 * page; i++){
    4. ItemStack is = new ItemStack(m[i]);
    5. if(is.getDurability() == 0){
    6. sender.sendMessage(m[i].name() + " " + m[i].getId());
    7. }else{
    8. sender.sendMessage(m[i].name() + " " + is.getTypeId() + ":" + is.getDurability());
    9. }
    10. }[/i][/i][/i][/i]
     
  5. Offline

    frdmn

    qhenckel thanks a lot! :)

    However, there are still a lot of items missing. All potions, different types of wood, etc. Can you give me a hint how to get these as well?
     
  6. Offline

    HGPDev

    make a piece of code that reads after ':' i dont know if it usefull.. but maby...

    Im new too;)
     
  7. Offline

    frdmn

    HGPDev Thanks for the comment, but that doesnt really help me :/
     
  8. Offline

    HGPDev


    Aw im sorry. Im new too you know ;) in coding..
     
  9. Offline

    frdmn

    @HGPDev No problem :)

    anyone an idea?
     
  10. Offline

    NathanWolf

    I don't think Bukkit has the list you're looking for. As far as I know there's nothing in the code that explicitly will get you a list of data values from a Material type.

    You'd have to code all those special cases yourself, though I think for most (if not all) of the data values have enums in Bukkit- e.g. see the "TreeSpecies" class. You can look at all the MaterialData-derived classes to find the meanings of the data, but this would have to be set up manually as far as I can tell.

    And if you want to start talking about potions, or colored armor, or enchanted items- that's going to be a mess. There are 255 possible combinations of armor colors and I don't know how many different potion effect combinations. - maybe a hundred or so? Do you want to list all of those?

    The same kind of goes for enchanted items, way too many possible combinations to list.
     
  11. Offline

    frdmn

    NathanWolf thank you for your reply. I understand the problem but i do not want colour combination, enchanted items or potion combinations. I just would like to get all the items that you can see in the creative gamemode inventory as well.
     
  12. Offline

    NathanWolf

    You should be able to get there with what you've got (iterating over Material.values()), plus a few hand-selected variants like the TreeSpecies for different blocks of wood.
     
  13. Offline

    frdmn

    With some help from qhenckel i've got it working :)

    Thanks.
     
Thread Status:
Not open for further replies.

Share This Page