Reflection - Get a instance of Item stored in Item

Discussion in 'Plugin Development' started by libraryaddict, Oct 17, 2012.

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

    libraryaddict

    Code:
        public static Item STONE_PICKAXE = (new ItemPickaxe(18, EnumToolMaterial.STONE)).b(1, 6).b("pickaxeStone");
    
    There is plenty of lines for each of these items.
    And rather then coding each one in I need/want to get a list of them each.

    The problem being I have never worked with reflection, Have no idea if this is the correct way.

    Code:
        try {
          Method method = net.minecraft.server.Item.class.getDeclaredMethod("a",
              boolean.class);
          if (method.getReturnType() == net.minecraft.server.Item.class) {
            method.setAccessible(true);
            Field[] list = net.minecraft.server.Item.class.getDeclaredFields();
            for (Field field : list) {
              String type = field.getType().getName();
              if (type.equals("net.minecraft.server.Item")
                  || type.equals("net.minecraft.server.ItemShears")) {
                method.invoke(field, false);
                System.out.println("Success");
              }
            }
          }
    
        } catch (Exception e) {
          System.out.println(e);
        }
    You will probably find problems with this.

    Basically, How would I get the instance "Item STONE_PICKAXE"
     
  2. Offline

    Njol

    You can simply use Item.byId[<id here>] ;)
     
    ferrybig and libraryaddict like this.
  3. Offline

    libraryaddict

    SDGLUHJSDBOIHJBSDOIJHUBDFOLJHSDB

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page