Jump to content

Recommended Posts

Posted (edited)

[SOLVED] - Yep I feel stupid, after looking over this post I saw I called the shop_menu on both classes like an idiot and I also called playerInv.player instead of just this.p on Knight class...

I have two containers, one that is a Vault container for a player and one that is for my Knight entity. They both are designed to store player items in it and have the same code(with one alteration). Except if I put items in my Vault and try to open up my Knight entities container it completely removes my CompoundTag that holds all the itemstacks in the Vault container. The really weird thing is I am not accessing the Players persistent data at all in the Knight's container.

And the item in the Knight's container will still stay even if I open up other Knight's container and my Vault container will not store of the knights containers items.

 

Knight Container

public class KnightInventoryMenu extends AbstractContainerMenu {
    private final Knight p;
    public KnightInventoryMenu(int pContainerId, Inventory playerInv){
        this(pContainerId, playerInv, null, new ItemStackHandler(27));
    }

    public KnightInventoryMenu(int pContainerId, Inventory playerInv,Knight k, ItemStackHandler itemStackHandler) {
        super(ContainerInit.SHOP_MENU.get(), pContainerId);
        this.p = k;
        final int slotSizePlus2 = 18, startX = 8, startY = 86, hotbarY = 144, inventoryY = 18;
        for (int row = 0; row < 3; row++) {
            for (int column = 0; column < 9; column++) {
                addSlot(new SlotItemHandler(itemStackHandler, row * 9 + column, startX + column * slotSizePlus2,
                        inventoryY + row * slotSizePlus2));
            }
        }

        for (int row = 0; row < 3; row++) {
            for (int column = 0; column < 9; column++) {
                addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2,
                        startY + row * slotSizePlus2));
            }
        }

        for (int column = 0; column < 9; column++) {
            addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY));
        }
        if(!this.p.getPersistentData().contains("container.items")){
            CompoundTag tag = new CompoundTag();
            playerInv.player.getPersistentData().put("container.items", tag);
        } else {
            CompoundTag tag = this.p.getPersistentData().getCompound("container.items");
            for(String key : tag.getAllKeys()){
                int index = Integer.valueOf(key);
                this.getSlot(index).set(ItemStack.of(tag.getCompound(key)));
            }
        }

    }

    @Override
    public void broadcastChanges() {
        CompoundTag tag = new CompoundTag();
        int i = 0;
        for(ItemStack item : this.getItems()){
            if(i > 27)
                break;
            CompoundTag itemTag = new CompoundTag();
            tag.put(String.valueOf(i), item.save(itemTag));
            i++;
        }
        p.getPersistentData().put("container.items", tag);
    }

    @Override
    protected boolean moveItemStackTo(ItemStack pStack, int pStartIndex, int pEndIndex, boolean pReverseDirection) {
        return super.moveItemStackTo(pStack, pStartIndex, pEndIndex, pReverseDirection);
    }

    @Override
    public ItemStack quickMoveStack(Player player, int index) {
        var retStack = ItemStack.EMPTY;
        final Slot slot = getSlot(index);
        if (slot.hasItem()) {
            final ItemStack item = slot.getItem();
            retStack = item.copy();
            if (index < 27) {
                if (!moveItemStackTo(item, 27, this.slots.size(), true))
                {
                    return ItemStack.EMPTY;
                }
            } else if (!moveItemStackTo(item, 0, 27, false)){
                return ItemStack.EMPTY;
            }

            if (item.isEmpty()) {
                slot.set(ItemStack.EMPTY);
            } else {
                slot.setChanged();
            }
        }
        return retStack;
    }

    @Override
    public boolean stillValid(Player pPlayer) {
        return true;
    }

}

 

 

Player's Vault Container

public class VaultMenu extends AbstractContainerMenu{
    private final Player p;
    public VaultMenu(int pContainerId, Inventory playerInv){
        this(pContainerId, playerInv, new ItemStackHandler(27));
    }

    public VaultMenu(int pContainerId, Inventory playerInv, ItemStackHandler itemStackHandler) {
        super(ContainerInit.SHOP_MENU.get(), pContainerId);
        this.p = playerInv.player;
        final int slotSizePlus2 = 18, startX = 8, startY = 86, hotbarY = 144, inventoryY = 18;
        for (int row = 0; row < 3; row++) {
            for (int column = 0; column < 9; column++) {
                addSlot(new SlotItemHandler(itemStackHandler, row * 9 + column, startX + column * slotSizePlus2,
                        inventoryY + row * slotSizePlus2));
            }
        }

        for (int row = 0; row < 3; row++) {
            for (int column = 0; column < 9; column++) {
                addSlot(new Slot(playerInv, 9 + row * 9 + column, startX + column * slotSizePlus2,
                        startY + row * slotSizePlus2));
            }
        }

        for (int column = 0; column < 9; column++) {
            addSlot(new Slot(playerInv, column, startX + column * slotSizePlus2, hotbarY));
        }
        if(!this.p.getPersistentData().contains("container.items")){
            CompoundTag tag = new CompoundTag();
            playerInv.player.getPersistentData().put("container.items", tag);
        } else {
            CompoundTag tag = this.p.getPersistentData().getCompound("container.items");
            for(String key : tag.getAllKeys()){
                int index = Integer.valueOf(key);
                this.getSlot(index).set(ItemStack.of(tag.getCompound(key)));
            }
        }

    }

    @Override
    public void broadcastChanges() {
        CompoundTag tag = new CompoundTag();
        int i = 0;
        for(ItemStack item : this.getItems()){
            if(i > 27)
                break;
            CompoundTag itemTag = new CompoundTag();
            tag.put(String.valueOf(i), item.save(itemTag));
            i++;
        }
        p.getPersistentData().put("container.items", tag);
    }

    @Override
    protected boolean moveItemStackTo(ItemStack pStack, int pStartIndex, int pEndIndex, boolean pReverseDirection) {
        return super.moveItemStackTo(pStack, pStartIndex, pEndIndex, pReverseDirection);
    }

    @Override
    public ItemStack quickMoveStack(Player player, int index) {
        var retStack = ItemStack.EMPTY;
        final Slot slot = getSlot(index);
        if (slot.hasItem()) {
            final ItemStack item = slot.getItem();
            retStack = item.copy();
            if (index < 27) {
                if (!moveItemStackTo(item, 27, this.slots.size(), true))
                {
                    return ItemStack.EMPTY;
                }
            } else if (!moveItemStackTo(item, 0, 27, false)){
                return ItemStack.EMPTY;
            }

            if (item.isEmpty()) {
                slot.set(ItemStack.EMPTY);
            } else {
                slot.setChanged();
            }
        }
        return retStack;
    }

    @Override
    public boolean stillValid(Player pPlayer) {
        return true;
    }

    public static MenuConstructor getServerContainer() {
        return (id, playerInv, player) -> new ShopMenu(id, playerInv, new ItemStackHandler(27));
    }

}

 

 

Like I said the code is the exact same except in the Vault container I am modifying player persistent data to hold all the current items in the container from index 0-27, and on the Knights container its only affecting the Knight's persistent data. I am extremely confused, the only explanations I can come up with is somehow on the first instance of the knights container, it copys all the data to my players persistent data(but yet I am not calling it at all) or upon opening the knights container its deleting my persistent data tag that holds all the items.

Edited by sFXprt
  • sFXprt changed the title to 1.18.2 Container Issues[SOLVED]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Maximize Savings With [acu639380] T e m u Promo Code $100 Off 2025 brings you unbeatable savings on T e m u , one of the most popular online shopping destinations. With the exclusive T e m u  Promo code (acu639380), you can unlock incredible discounts, including $100 off for new and existing users. Whether you’re a first-time shopper or a loyal customer, T e m u  ensures a seamless shopping experience with fast delivery, free shipping in 67 countries, and up to 90% off on a wide range of products. Why Choose T e m u ? T e m u  is a treasure trove of trending items at unbeatable prices. From fashion and beauty to electronics and home essentials, T e m u ’s vast collection caters to all your shopping needs. Here are some key features that make T e m u  stand out: Free shipping: Available in 67 countries. Unbeatable prices: Discounts up to 90% off. Fast delivery: Ensures your items arrive promptly. Exclusive Benefits of T e m u  Promo Code (acu639380) Using the T e m u  Promo code (acu639380) in 2025 can help you save more than ever before. Here’s a breakdown of the benefits: $100 Off for New Users: New shoppers can enjoy a flat $100 discount with the T e m u  first-time user Promo. $100 Off for Existing Users: Loyal customers can also take advantage of this substantial discount with the same code. 40% Extra Off: Apply the T e m u  Promo code (acu639380) to receive an additional 40% discount on selected products. $100 Promo Bundle: Get a $100 Promo bundle to maximize savings across multiple purchases. Free Gifts for New Users: First-time shoppers are rewarded with exclusive gifts. How to Redeem T e m u  Promo Code (acu639380) Redeeming your T e m u  Promo code (acu639380) is simple and straightforward: Visit the T e m u  website or app. Add your favorite items to your shopping cart. Enter the promo code (acu639380) at checkout. Watch the savings apply instantly! T e m u  Promos for 2025 This month is packed with incredible offers tailored for both new and existing users: For New Users: T e m u  Promo code (acu639380) $100 off: Enjoy a significant discount on your first order. T e m u  first-time user Promo: Unlock exclusive savings and free gifts. T e m u  discount code (acu639380) for 2025: Enhance your shopping experience with additional discounts. For Existing Users: T e m u  Promo code (acu639380) $100 off: Loyal customers can continue to enjoy massive savings. T e m u  Promo code (acu639380) 40% off: Apply this code for extra discounts on selected items. T e m u  Promo bundle: A $100 Promo bundle available for repeated use. Country-Specific T e m u  Promo Codes T e m u  offers regional discounts to ensure everyone can benefit from their amazing deals. Here’s how the T e m u  Promo code (acu639380) can be used worldwide: North America USA: $100 off your next purchase with T e m u  Promo code (acu639380). Canada: Enjoy a $100 discount using the same code. South America Mexico: Save 40% on selected items with T e m u  Promo code (acu639380). Brazil: Get exclusive 40% discounts on your shopping. Europe UK: Apply the T e m u  Promo code (acu639380) for $100 off. Germany: Take advantage of the $100 Promo bundle. Asia Japan: First-time users can use T e m u  new user Promo for $100 off. India: Use the Promo bundle for multiple savings. T e m u ’s New Offers in 2025 This month, T e m u  has introduced fresh deals to elevate your shopping experience. Enjoy free shipping, trending items at up to 90% off, and exclusive discounts with the T e m u  promo code (acu639380). Benefits of T e m u  Promos T e m u  Promos are designed to enhance your shopping experience. Here are the standout advantages: $100 Off: Ideal for significant savings, whether you’re a new or existing user. 40% Extra Discount: Perfect for those looking to stock up on essentials. Free Gifts: Specially curated for first-time shoppers. $100 Promo Bundle: Offers flexibility across multiple purchases. How T e m u  Makes Shopping Easy T e m u ’s user-friendly platform ensures a hassle-free shopping experience. With options like fast delivery, detailed product descriptions, and seamless payment methods, T e m u  is a one-stop shop for all your needs. FAQs about T e m u  Promo Code (acu639380) Can I combine multiple T e m u  Promo codes? No, only one Promo code can be used per transaction. However, the $100 Promo bundle can be split across multiple orders.  Is the T e m u  Promo code (acu639380) valid on all items? The code applies to a wide range of products but July exclude certain categories.  How often can I use the T e m u  Promo code (acu639380)? The usage frequency depends on the specific terms and conditions of each code. Final Thoughts T e m u  is setting new standards in online shopping with its incredible deals and discounts. With the T e m u  Promo code (acu639380), you can maximize your savings and enjoy a premium shopping experience. Whether you’re new to T e m u  or a returning customer, these offers ensure that every purchase is a win. Don’t wait—use the T e m u  promo code (acu639380) today and start saving big!
    • Typically—at least in my case—the broken datapack thing always turns out to be a broken mod. Someone else here might have a better answer for you than I do, but when that happens, I go through all my mods, disabling them one by one until I locate the culprit. It’s a headache, but it’s the only way I know how to do it.
    • Is there any mod for creating world templates for 1.20.1 forge, I found a fabric mod for such as purpose but can't seem to find one for forge. I know connector and forgeified fabric api exist but i'd prefer a forge mod to adding like 50 mods to my 200 mod modpack. Does anyone know of such a mod or is my only option using the fabric mod with connector?  
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post logs as described there to a site such as https://mclo.gs and post the link here.
    • I'm trying to play with the origins mod but even after adding it to the mod folder it doesn't show up in minecraft forge. I'm using 1.20.2 because that is the last update from the origins and I'm using the same version of forge.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.