Is there a list of the item numbers?

  • I am trying to put something in a players hands during an interaction with a sign. The old ID I had for a saddle was 900. Is there are list of the ID numbers anywhere or do I have to make a routine and look at them one by one. Maybe I need to look at a SQLdatabase? If so point me in the right direction. Thanks.

  • I wouldn't recommend using IDs for items and objects. These may change in the future, so it's better to work with the internal item name (which will never change). The API provides access to the item definitions, so if you know the internal item name (the same name that's used ingame to spawn an item), you can get the item definition for that:

    Java
    //Get definition of pickaxe
    Items.ItemDefinition def = Definitions.getItemDefinition("pickaxe");
    //Print some information of that item
    if (def != null) {
    System.out.println("Item: " + def.name + " (ID: " + def.id + "), Variants: " + def.variations + ", Type: " + def.type + ", Stack size: " + def.stacksize);
    }


    If you want to compare items or item definitions, it's safe to use the id field of course.


    If you have an Item instance, there is also a getDefinition() method to get the definition of that item. This way you can easily check what kind of item that is.

    Example: if a player picks up an item from the ground and you want to check if it's a saddle:

    Java
    @EventMethod
    public void onPlayerPickupItem(PlayerPickupItemEvent e) {
    //Get definition
    Items.ItemDefinition itemDef = e.getItem().getDefinition();
    //Check if item is a food item
    if (itemDef.type == Items.Type.Food) {
    System.out.println("Player " + e.getPlayer().getName() + " picked up some food (" + itemDef.name + ")");
    }
    }


    Alternatively you can also check the item name of course. Saddles for horses are called "saddlehorse", so the check would look like this:

    Java
    if (itemDef.name.equals("saddlehorse")) {
    System.out.println("Item is a saddle!");
    }


    Or alternatively get the related clothing definition (since saddles are considered "Clothing" items) and check if it's a saddle (clothing defs have a so called "function" which defines special behaviour):


    To give a new item to the player (e.g. a torch), it could look like this:

    Java
    //Get torch def
    Items.ItemDefinition itemDef = Definitions.getItemDefinition("torch");
    //Add item to player inventory
    player.getInventory().addItem(itemDef.id, 0, 1);
  • To give a new item to the player (e.g. a torch), it could look like this:

    Java
    //Get torch def
    Items.ItemDefinition itemDef = Definitions.getItemDefinition("torch");
    //Add item to player inventory
    player.getInventory().addItem(itemDef.id, 0, 1);

    So to Give a player something I was trying to put it into their equipped hand slot but I keep getting a lossy conversion error with the getQuckslotFocu. I was using the item id (not def) because it allowed for slot


    This was giving back the player some like leather, which had to be in his hands when he was making it, if the routine was not able to make what he was buying for some reason like full inventory.

    player.getInventory().addItemToSlot((short)178, 0, 10, inventory.getQuickslotFocus(), Inventory.SlotType.Quickslot);


    additemtoslot calls for an int for slot number. Are they returned in long or short from getQuickslotFocus()? The API is not clear to me what precision format is returned from getQuickslotFocus().

  • Nevermind I got this to work and likely it was the problem of Properties being set to Java8 or that it tried to pull in the old RisingworldAPI933 that was in the old Netbeans project I was modifying.


    I do have a question on chat colors. Can you still imbed them in chat statements?


    player.sendTextMessage("[#cc0000] Checking");


    What did it change too? Can you force the chat screen open to show messages. Seems when I send them they are not showing unless I hit T.

  • they should show automatically. i believe to set chat color it would be something like

    Java
    player.sendTextMessage("<color=red>yourtexthere</color>");

    im not sure if you can use color(int) for text in chat. if your setting font color to a UIElement i do


    Java
    UILabel.setFontColor(0xffffffff);//white color

    if you use an rgba to hex color picker it will show as #ffffffff but you can remove the # and add 0x to get your color.

  • Oh I thought that was why you left gaps in the item number list for additions and changes. I used the item numbers in my older JAVA day routines. Thanks for the pointers.

    Yes, but if a certain update adds lots of new items, for example, the existing IDs may change. My previous post was perhaps a bit misleading: You still have to work with the IDs, but I just wouldn't recommend to use hard-coded IDs. So instead of

    Java
    inventory.addItem((short) 178, 0, 1);


    It's usually better to do it this way:

    Java
    Items.ItemDefinition itemDef = Definitions.getItemDefinition("leather");
    inventory.addItem(itemDef.id, 0, 1);


    That code will remain compatible with future updates (and it's also obvious which item is about to be added, while the first snippet doesn't provide this information unless you add comments) ;)


    OH drat I just missed it in the API, Sorry, you have to add color = and turn it off /color

    You don't necessarily have to add a closing tag (unless you want the remaining text to be drawn with default color). But apart from color changes, the new version also supports a lot more rich text tags (identical to the ones that are shown in the sign editor formatting help) ^^

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!