[lib] VillagerTradingLib Custom Villager Trades ; Quick, Easy and Clean

Discussion in 'Resources' started by jtjj222, Nov 18, 2012.

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

    jtjj222

    I am looking into it

    So far, it seems like you need to do:
    ((CraftPlayer)player).getHandle().activeContainer.windowId = (whatever) to set the window id that the player is looking in.

    Ok, I got it running, and I will update the code! I will elaborate further soon.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    lucasdidur

    Thank you :)
     
  3. Offline

    UbuntuFreak

    First of all, I would like to thank you for that great library! It saved me many hours of refreshing the world because my villagers often respawn for no reason. But reloading the world means that all games (I used the villagers for) need to be cancelled.
    Actually, it did not work with the newest Minecraft (1.6.2), so I needed to update it.
    You can PM me that I send you the updated code, if you wish.
     
  4. Offline

    jtjj222

    Can you post it here? Thanks :D
     
    UbuntuFreak likes this.
  5. Offline

    UbuntuFreak

    Okay.

    The way how to use your Library didn't change in any way. But the imports are different now, and one method now has an optional parameter, that doesn't to anything.
    (I have not been able to figure out what this parameter does - so I just set it to false)

    The "new" code works, and I am happy with that :)

    Download here: http://ubuntuone.com/4oRVnEjZyDlCVOgbJ8hevD

    Note: If you just want to have the new code, and you are not interested in what had changed, you can skip the rest of this post.
    (1) Changed the package name from me.jtjj222.BlockReplace to TradingLibrary (you can change the name back, if you want)
    (2) Adjusted the most imports, for example from net.minecraft.server.EntityPlayer to net.minecraft.server.v1_6_R2.EntityPlayer
    (3) Fixed the call of Packet100OpenWindow in VillagerTradingLib.java on line 97
    (4) Fixed netServerHandler now being playerConnection in VillagerTradingLib on line 99 & 100.

    @jtjj222: If you want, you can upload the ZIP file in the original post, and ask a moderator to remove it from my post (or I remove it, if I have permission. I am new to Bukkit Forums)

    EDIT:
    I noticed that extended item features to not work. I tried to enchant the items being selled and change their display name, but I still see the default items.
    My code is:
    Code:java
    1. ItemStack hemd1 = new ItemStack(303, 1);
    2. ItemMeta hemd1meta = hemd1.getItemMeta();
    3. hemd1meta.setDisplayName("┬žbLeichtes Kettenhemd");
    4. hemd1meta.setLore(lore);
    5. hemd1.setItemMeta(hemd1meta);
    6. hemd1.addEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 1);


    BTW: If you set the last parameter from false to true in VillagerTradingLib on line 107, you can use the window titles (the string arg)
     
  6. Offline

    jtjj222

    Update:
    I fixed the creative mode issues, and made it a lot easier to use and make future proof. It now successfully works. Thanks to everyone on this thread for their suggestions, especially UbuntuFreak (whom's choice of operating system is great).

    In the next update:
    - Reflection to stop your plugins from breaking on future updates
    - Support for enchantments, metadata and whatnot

    Allov
    I ended up doing what we discussed. It was a lot easier with an extra year of java experience :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  7. Offline

    FinnForTheWin

    Can it block certain trades? If not, would you be willing to make a seperate plugin that enables the choice to block certain trades? ^_^
     
  8. Offline

    mcandy007

    Since I have also the problem must act Meta modified items ...

    I am now unfortunately know how to rewrite the Lib

    problematic is the function:
    public static net.minecraft.server.v1_6_R2.ItemStack convertItemStackToNMS(ItemStack i) {
    int amount = i.getAmount();
    int id = i.getType().getId();
    short durability = i.getDurability();

    return new net.minecraft.server.v1_6_R2.ItemStack(id,amount,durability);
    }

    How, then, can be passed to the NMS of a normal meta ItemStack?


    Thank you for your help
     
  9. Offline

    jtjj222

    Replace with return CraftItemStack.asNMSCopy(i)
     
    mcandy007 likes this.
  10. Offline

    mcandy007

    THX!!!!
     
  11. Offline

    ase34

    For "convertItemStackToNMS" in VillagerTraderOffer.java , why not using CraftItemStack.asNMSCopy(ItemStack) which won't loose the enchantments and the metadata. That happens when I forgot reading the upper posts... sry :D
     
    jtjj222 likes this.
  12. Offline

    jtjj222

    I know that, but when I wrote the library, I wanted to keep it as decoupled from nms/obc code as possible. Icyene and I have been working on making it version independent with reflection, so that will not be an issue.
     
  13. Offline

    mcandy007

    Hello,
    Unfortunately I have a problem again!

    For some reason can not sell the same item multiple times.
    For example different enchanted bows. It is then only the first display.

    Unfortunately, the rename of the item is useless ...

    Could someone please help me?
     
  14. Offline

    jtjj222

    Can you give us a SSCCE? (sscce.org)
     
  15. Offline

    mcandy007

    http://pastebin.com/ciZgtVfz

    But only chestplatelvl1 will be display..

    The same Problem by bows...

    What could be wrong?

    thanks for helping...
     
  16. Offline

    jtjj222

    Can we see the set name method? also, please post the code in hastebin some other paste site
     
  17. Offline

    mcandy007

    here: http://pastebin.com/77n5HGP5

    The items are also properly named only just not displayed.
    The same items are just displayed only once.

    thx
    edit:
    Could it perhaps be because:
    public static net.minecraft.server.v1_6_R2.ItemStack convertItemStackToNMS(ItemStack i) {
    return CraftItemStack.asNMSCopy(i);

    }
     
  18. Offline

    jtjj222

    Where is eisen1 defined?
     
  19. Offline

    mcandy007

  20. Offline

    jtjj222

  21. The itemmeta is not displayed in the shop! Please help
     
  22. Offline

    UbuntuFreak

    I think this comes from the conversion of org.bukkit.* ItemStacks to net.minecraft.* ItemStacks. I am not advanced enough to help you fixing that, sorry

    (That means that I didn't get it fixed :eek:)
     
  23. Offline

    jtjj222

    Did you change
    public static net.minecraft.server.v1_6_R2.ItemStack convertItemStackToNMS(ItemStack i) {
    int amount = i.getAmount();
    int id = i.getType().getId();
    short durability = i.getDurability();

    return new net.minecraft.server.v1_6_R2.ItemStack(id,amount,durability);
    }

    to call CraftItemStack.asNMSCopy(i) instead?
     
    MinecraftShamrock likes this.
  24. jtjj222 Cool :D Does it also copy enchantments and lores?
     
  25. Offline

    jtjj222

  26. Offline

    mcandy007

    Have're sorry, but problems with 1.7.2

    The window popt only sometimes for a brief instant.

    Does anyone have a solution?
     
  27. Offline

    Goblom

    Any progress on the Reflection part ?
     
  28. Offline

    ArthurMaker

    I'm trying to convert it to the 1.7.2 version, but I'm getting this error on Eclipse:
    [​IMG]
    What can I do to solve it? :s
     
  29. Offline

    jtjj222

    ArthurMaker there were major changes to the way the mc protocol works. I'm trying to find a way to do this with the bukkit api (or to propose a new api if necessary)
     
  30. Offline

    ArthurMaker

    oh, okay... that is sad ;-;
     
Thread Status:
Not open for further replies.

Share This Page