Trying to change item data

Discussion in 'Plugin Development' started by mig4ng, Nov 30, 2012.

Thread Status:
Not open for further replies.
  1. Maybe you know that i'm developing MoreThanFish plugin, but i'm having a trouble on trying to add a new feature.
    So, i want to add data customization to my plugin, but i'm not really understanding bukkit api this time.
    I tried this:
    Code:
                        item.getItemStack().setData(MaterialData(Material 0));
    But it isn't really working...
    And i've already tried a lot of other ones...
    PS: Item item = (Item) event.getCaught();
    And i've already seen the bukkit api page about it --> http://jd.bukkit.org/doxygen/d9/da1/classorg_1_1bukkit_1_1inventory_1_1ItemStack.html
     
  2. Offline

    Maybevin

    I don't think you can simply typecast Entity into Item, since the fishing pole can get caught on more than just fish, such as monsters and dirt. I would personally check if it's a fish first, place a new item with the same location and velocity, then remove() the fish.

    Or if you got McMMO, you can choose what you catch and at what level. I know you're making your own plugin, but McMMO is definitely worth getting for any server.
     
  3. Offline

    nisovin

    Use setDurability instead of setData.
     
    Batman500 likes this.
  4. Offline

    fireblast709

    mig4ng to be closer to your original code, use
    Code:java
    1. item.getItemStack().getData().setData(byte)

    The getData() gets you the MaterialData object for the ItemStack, the setData(byte) is used to set its data
     
  5. it will be more than just mcmmo, and my plugin also checks if it is a fish, btw i will test what fireblast said...
     
  6. Durability actually maps the data value like you need it, with the only difference that it's compatible with spout items as it is a short instead of a byte (accepting higher values). So nisovin gave the best solution. Why not use it?
     
    Batman500 likes this.
  7. But i want to add red wool for example, not durability to the wool...

    PS: I tried with durability and it worked, now i understand that the data of armors are durability...

    BTW thanks to all that helped or tried to help ;)
    I like very much bukkit community for the help we give to each other...
     
  8. Exactly. Data and Durability is always the same, sorry for not being clear here. ;)
     
    Batman500 likes this.
  9. No problem, thanks ;)
    now i can continue with MoreThanFish development :D
     
  10. Offline

    fireblast709

    V10lator if I set data to 1 and durability to 0, it will use 1 (tested on wool colours at least)
     
  11. same sh*t different smell :D, does anyone knows how to check if the "plugin.getConfig().getString(rate + ".itemid")" is on the array that i created called DurList.

    BTW If
    someone needs all the items that uses durability here you go:
    Code:
        public static void main(String[] args) {
        String[] DurList;
        //List of items with durability
            DurList = new String[10];
            DurList[0]    = "DIAMOND_BOOTS";
            DurList[1]    = "DIAMOND_CHESTPLATE";
            DurList[2]    = "DIAMOND_HELMET";
            DurList[3]    = "DIAMOND_LEGGINGS";
            DurList[4]    = "DIAMOND_HOE";
            DurList[5]    = "DIAMOND_AXE";
            DurList[6]    = "DIAMOND_PICKAXE";
            DurList[7]    = "DIAMOND_SPADE";
            DurList[8]    = "DIAMOND_SWORD";
            DurList[9]    = "GOLD_BOOTS";
            DurList[10] = "GOLD_CHESTPLATE";
            DurList[11] = "GOLD_HELMET";
            DurList[12] = "GOLD_LEGGINGS";
            DurList[13] = "GOLD_HOE";
            DurList[14] = "GOLD_AXE";
            DurList[15] = "GOLD_PICKAXE";
            DurList[16] = "GOLD_SPADE";
            DurList[17] = "GOLD_SWORD";
            DurList[19] = "IRON_BOOTS";
            DurList[20] = "IRON_CHESTPLATE";
            DurList[21] = "IRON_HELMET";
            DurList[22] = "IRON_LEGGINGS";
            DurList[23] = "IRON_HOE";
            DurList[24] = "IRON_AXE";
            DurList[25] = "IRON_PICKAXE";
            DurList[26] = "IRON_SPADE";
            DurList[27] = "IRON_SWORD";
            DurList[28]    = "LEATHER_BOOTS";
            DurList[29] = "LEATHER_CHESTPLATE";
            DurList[30] = "LEATHER_HELMET";
            DurList[31] = "LEATHER_LEGGINGS";
            DurList[32] = "STONE_HOE";
            DurList[33] = "STONE_AXE";
            DurList[34] = "STONE_PICKAXE";
            DurList[35] = "STONE_SPADE";
            DurList[36] = "STONE_SWORD";
            DurList[37]    = "CHAINMAIL_BOOTS";
            DurList[38] = "CHAINMAIL_CHESTPLATE";
            DurList[39] = "CHAINMAIL_HELMET";
            DurList[40] = "CHAINMAIL_LEGGINGS";
            DurList[41] = "SHEARS";
            DurList[42] = "FLINT_AND_STEEL";
            DurList[43] = "FISHING_ROD";
            DurList[44] = "CARROT_STICK";
        }
     
  12. fireblast709 and what does both give out if you read it a tick after? Also why are you setting both at the same time anyway?
     
    Batman500 likes this.
  13. Offline

    fireblast709

    Just to test the difference. Also the wool block just got the colour I set via the MaterialData, so all I know that variable has the last word when set. Though if you only use setDurability() it works, but I rather keep them separate as durability is also used for tool durability. Just to evade ambigious sounding methods :3
     
Thread Status:
Not open for further replies.

Share This Page