Solved Brainstorming for plugin feature implementation!

Discussion in 'Plugin Development' started by Tim_M, Aug 3, 2021.

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

    Tim_M

    I am currently working on a plugin that will alow users to right click a certain item to bring up a menu (similiar to bundles in 1.17, but not quite). The issue is keeping track of what each item holds without losing any information on restart. Then I remembered that chests can be middle-clicked to get picked up with all the items in them. This is obviously an NBT Tag. I have tried to google, but haven't been able to find anything on this. I was planning to add an option so users can select what items should be "backpacks", but if this Tag is only available to chests then that wouldn't work. If it's impossible (without TONS of memory leaking) how can I set the Tag on the chests? (I code for bukkit 1.8.9 and can manager Reflection myself, so no need to post that).

    Any responses are appreciated!

    I have started trying to set the NBTTag of a chest. First of all I gave myself (with /give) a chest with items and made my plugin type in chat nms.ItemStack.getTag() which got me:
    Code:
    {BlockEntityTag:{Items:[0:{Slot:0,id:"leaves",Count:1,Damage:2},1:{Slot:1,id:"leaves",Count:2,Damage:3}]}}
    
    Then I tried to figure out what key holds it by trying:
    Code:
    tag.get("Items");
    
    which returned null. Any ideas on how to get the tag that holds the items and write to it?
    Edit:
    I dont know how I missed it but its BlockEntityTag.
     
    Last edited: Aug 4, 2021
  2. Offline

    CraftCreeper6

    @Tim_M
    For 1.8.9 it's tough because everything you use Google for will be for a newer Minecraft version.

    If it's possible in 1.8.9, create your own NBT tag and just store a List of every item you need to store within the tag.

    This tutorial came out a year after 1.8.9 so I'm not confident on its validity but nevertheless worth a try.
     
  3. Offline

    KarimAKL

    @Tim_M Storing items in NBT tags should not be an issue.
     
  4. Offline

    Tim_M

    This tutorial did it! Thanks! "Marking solved."
    Edit:
    Actually when I tried it, it just gives me an empty chest. What a bummer!
     
    Last edited: Aug 4, 2021
  5. Offline

    CraftCreeper6

    @Tim_M
    I doubt it'll automatically use the stored information, probably have to do that yourself.
     
  6. Offline

    Tim_M

    Here's my code:
    Code:
                        net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(new ItemStack(Material.TRAPPED_CHEST));
                        NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
                      
                        NBTTagCompound bet = compound.getCompound("BlockEntityTag");
                        NBTTagList items = new NBTTagList();
                      
                        NBTTagCompound item = new NBTTagCompound();
                        item.set("Count", new NBTTagByte((byte)1));
                        item.set("Slot", new NBTTagByte((byte)0));
                        item.set("id", new NBTTagString("OBSIDIAN"));
                      
                        items.add(item);
                        bet.set("Items", items);
                        compound.set("BlockEntityTag", bet);
                        nmsStack.setTag(compound);
    
                        player.getInventory().setItemInHand(CraftItemStack.asBukkitCopy(nmsStack));
    
    as you can see I properly set the items, compound and nmsStack. Yet, it gives me an empty chest.

    I FIXED IT! Turns out the code was bricked. Marking solved.
     
    Last edited: Aug 4, 2021
Thread Status:
Not open for further replies.

Share This Page