Jump to content

1.18.2 Container Issues[SOLVED]


sFXprt

Recommended Posts

[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
Link to comment
Share on other sites

  • 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

    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
    • The Essential Role of Brunoe Quick Hack in Bitcoin Recovery Efforts The Brunoe Quick Hack has emerged as a vital tool in the ongoing efforts to recover lost or stolen Bitcoin. As the cryptocurrency landscape has evolved, the need for reliable and effective methods to regain access to misplaced or compromised digital assets has become increasingly pressing. The Brunoe Quick Hack, a specialized software solution, has stepped in to fill this critical void, offering Bitcoin users a lifeline when faced with the devastating prospect of permanently losing their hard-earned cryptocurrency holdings. At the core of this innovative technique lies a deep understanding of the underlying blockchain technology that powers Bitcoin, combined with a meticulous, methodical approach to identifying and exploiting vulnerabilities in the system. Through a series of carefully orchestrated steps, the Brunoe Quick Hack is able to bypass security measures, recover private keys, and restore access to Bitcoin wallets that were previously thought to be irretrievable. This process, while highly technical and requiring a skilled hand, has proven to be a game-changer for countless individuals and businesses who have fallen victim to the inherent risks of the cryptocurrency ecosystem. As the adoption of Bitcoin continues to grow, the Brunoe Quick Hack has emerged as an essential safeguard, providing a crucial safety net for those navigating the complex and ever-evolving world of digital finance. Contact this experts through: WhtasApp: + 170-"578-42"-635 Website: brunoequickhack.COM Email: brunoequickhack (AT) GMAIL (DOT) COM Thanks.
    • it doesnt let me import the zip that i use with curseforge
    • it doesnt let me import the zip that i use with curseforge
    • Halo semua, Kembali lagi bersama kami di situs Duta89 situs Aman, Terpercaya dan Situs yang memberikan hadiah terbesar kepada semua membernya. Pada kesempatan kali ini kami akan memberi tahu kalian semua mengenai situs permainan online yang bisa menghasilkan uang dengan cepat hanya dengan modal receh. Permainan apa kah itu? Saran bukan? >>>akungameaman<<< >>>akunminecrafsuper<<< >>>daftarsitus<<<
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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