Solved Get material by minecraft ingame name

Discussion in 'Plugin Development' started by MightyOne, Apr 22, 2018.

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

    MightyOne

    Hello,

    I was abot to create a command similarly built up like e.g. the worldedit command //set. So what I am aiming for is that a player can pass different types of blocks with arguments like "wool:14".
    The problem I am facing is that I cannot find out how to get a Material by its ingame name.
    What I specifically mean is the name you can read under an item name when you hover over it:

    2018-04-22_14.21.34.png

    However in bukkit e.g. this material is named Material.STAINED_CLAY, so I cant use the methods Material#getMaterial or #matchMaterial().

    Does anybody know how to get these ingame names, any method that could help me there?
    I would not like to use nms or make a giant List of all ingame block names.



    Any help would be appreciated
    MightyOne
     
  2. Offline

    JanTuck

    If you are not willing to use NMS, you would have to wait for 1.13, where the bukkit Material Enum gets updated with the correct names. Cheers.
     
  3. Offline

    MightyOne

    @JanTuck idk im just a conservative coder. I want to finish my plugin so different versions can use it. Was nms version dependent? I dont like it anyway xD
     
  4. Offline

    JanTuck

    Well here is one way.
    Code:
    MinecraftKey mk = new MinecraftKey(minecraftID);
    ItemStack item = CraftItemStack.asNewCraftStack(Item.REGISTRY.get(mk));
    Material mat = item.getType();
     
  5. Offline

    MightyOne

    @JanTuck its just like... idk i wanted to use my plugin for 1.8 and upwards. I really have no idea how to use this solution for at least 2 different mc versions?
     
  6. Offline

    JanTuck

  7. Offline

    MightyOne

    @JanTuck Guess you graduated in MNS? :D

    why is that gist secret?
     
  8. Offline

    JanTuck

    No need for it to be public.
     
  9. Offline

    MightyOne

    Ok i dont want to bother you, @JanTuck but my I ask what kind of plugin "lighning summon" is?
     
  10. Offline

    JanTuck

  11. Offline

    MightyOne

    @JanTuck oh yeah i remeber that guy. Am I allowed to use the provided piece of code in my own plugin which I will publisch perhaps for commercial use?
     
  12. Offline

    JanTuck

    Hehe, I didn't license it so sure.
     
  13. Offline

    MightyOne

    @JanTuck ok I could implement that class. when someone types a material wrong it will automatically be AIR. arg[xyz].equalIgnoreCase("air") of course tells me if the player actually wanted to place air. Do you know anything more directly by any chance?
     
  14. Offline

    JanTuck

    What do you mean?
     
  15. Offline

    MightyOne

    @JanTuck if I would type "/buildMyMazeWith anythingTypedWrong" the code would dectect Material.AIR. I don't know what happens there xD. I already have a workaround but was wondering if there is something more directly... where i can directly catch an exception or so... dunno
     
  16. Offline

    JanTuck

    The gerMaterial just returns null if there was no material with that name. So if material == null return air.
     
  17. Offline

    MightyOne

    @JanTuck well the getMaterial method never returns null. Whatever, "water" and "lava" dont seem to be materials... are named somehow different?
     
  18. Offline

    timtower Administrator Moderator

    @MightyOne Needs to be the same string as the Material enum uses.
    So "LAVA" and "WATER" would work.
     
  19. Offline

    MightyOne

    @timtower I am sorry but it doesnt seem to be the problem. any other materil works in lowercase and everything. but lava and water aren't so important
     
  20. Offline

    JanTuck

    Water is not really an Item, water_bucket is though
     
  21. Offline

    MightyOne

    @JanTuck mhhhh ok. I remember that in 1.7 there still were this water and lava-block items but they got removed. Well maybe its better if you can't build a maze out of lava xD

    but in worldedit it works. I better dont ask how they did it

    even if a maze out of end gateway would look pretty cool
     
  22. Offline

    JanTuck

    WorldEdit is opensource, look at the code if you want to.
     
  23. Offline

    MightyOne

    @JanTuck i've tried to look things up already a few times. the project is a bit big and so...
     
    Last edited: Apr 24, 2018
Thread Status:
Not open for further replies.

Share This Page