Material Lapis Lazuli?

Discussion in 'Plugin Development' started by BloodShura, Feb 16, 2012.

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


    How to return a Lapis Lazuli to a material?

    For example, I have args[0], and I use Material.matchMaterial(args[0]). But, obviously, lapis lazuli isn't a material... so, how can I get Lapis Lazuli to material?
  2. Offline


  3. Offline


    Yes, but, how can I use data values in materials?
  4. Depends on what you want to use them for.

    If you just want to compare against some values, you could use MaterialData class to store them (or just use int id and int data), if you want to make an item or such, just create a ItemStack class...
  5. Offline


    As you said, lapis lazulis isn't a material. And since Material is an enum it can't be modified. You'll have to write your own code to get an ItemStack out of an input string.
    1. static ItemStack parseItem(String s) {
    2. Material m = Material.matchMaterial(s);
    3. if (m != null)
    4. return new ItemStack(m);
    5. //materials is a HashMap where you already put in some <string, itemstack> pairs, e.g materials.put("lapis_lazuli", new ItemStack(351, 4));
    6. return materials.get(s);
    7. }
  6. Offline


    So, the data value is in ItemStack, like: new ItemStack(ID, Data); ?

    If yes... THANK YOU! =]
  7. Offline


    Just checked, it's new ItemStack(id, amount) actually. The correct one is new ItemStack(id, 1, 0, data).
    Sorry for that, I usually get this wrong :rolleyes:.
    Also I found a class called MaterialData which only stores the item id and data value, and also has subclasses which can be used like:
    1. static HashMap<String, MaterialData> materials = new HashMap<String, MaterialData>();
    2. static {
    3. Dye ll = new Dye();
    4. ll.setColor(DyeColor.BLUE);
    5. //ll represents lapis lazuli now
    6. materials.put("lapis lazuli", ll);
    7. // you could also use materials.put("lapis lazuli", new MaterialData(351, 4));
    8. }
  8. Also, if that's the only exception, Lapis is really just Material.LAPIS so you could do
    2. if (args[0].equalsIgnoreCase("Lapis Lazuli") {
    3. args[0] = "Lapis";
    4. }
  9. Offline


    There's no material for lapis lazuli, because lapis lazuli doesn't have it's own item id.
  10. Hmm...
  11. Offline

    Father Of Time

  12. Offline

    Father Of Time

    You know what I do to track this down when I can't seem to find out how to create (like I did with potions before the Item ids became available), I make a command that takes the item in my hand and prints to the console its materialID, its data value, its durability and its damage; every item in minecraft is made by utilizing some kind of combination of these variables.

    Simple make a command that does as described above, log in game, equip a lapis item, and then use the command to get a console print of the lapis data. Then all you have to do is is:

        ItemStack lapisstack = new ItemStack( ITEMID, 1 );
        lapisstack.setData( MATERIALDATA );
        setDurability( SHORTDURABILITY );
    Where ITEMID, MATERIALDATA and SHORTDURABILITY are all the data gathered from the "item in hand harvest" you performed. Working backwards is a great way to identify data that isn't publicly documented.

    This should get you the data you need, I hope this helps!
  13. Offline


    Not true, enums can be modified using reflection! And some mods actually do modify Material to add new items. But it usually isn't needed.
  14. Offline


    Just felt like saying I found it useful, thank you treedome36
    treedome36 likes this.
  15. Offline


    I also found this useful, thanks.
  16. Offline


    Cheers for this!
Thread Status:
Not open for further replies.

Share This Page