Jump to content

How to reopen container or replace?


WildHeart

Recommended Posts

player.openGui

? This is all I can say without more information of what you want to do.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

  • 3 weeks later...

like the creative menu?

Yes! Exactly as there. I looked the code, and there simply is replacing the slots of the container, but my container does not work. Reason: I have things stored in the player, i.e., there are 2 tabs with two containers. In the first tab standard player's inventory, second my container of the player(CapabilitySystem and etc)

Link to comment
Share on other sites

like the creative menu?

Yes! Exactly as there. I looked the code, and there simply is replacing the slots of the container, but my container does not work. Reason: I have things stored in the player, i.e., there are 2 tabs with two containers. In the first tab standard player's inventory, second my container of the player(CapabilitySystem and etc)

Show what you currently have.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

From the video, I'd say you are making new slots with the same IDs, thus having the same

ItemStack

in both slots.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

GuiInventoryCP(CustomPlayer)

 

 

package ru.ivasik.witcher.gui;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.achievement.GuiAchievements;
import net.minecraft.client.gui.achievement.GuiStats;
import net.minecraft.client.gui.inventory.GuiContainerCreative;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.InventoryEffectRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import ru.ivasik.witcher.api.utils.GuiTabs;
import ru.ivasik.witcher.capabilities.playerinventory.CPlayerInventory;
import ru.ivasik.witcher.gui.container.ContainerInventoryPlayer;
import ru.ivasik.witcher.gui.container.ContainerTabOne;
import ru.ivasik.witcher.network.PacketHandler;
import ru.ivasik.witcher.network.PacketInventoryToServer;
import ru.ivasik.witcher.util.RendersHelper;

import java.io.IOException;
import java.util.List;

@SideOnly(Side.CLIENT)
public class GuiInventoryPlayer extends InventoryEffectRenderer
{
    private static final ResourceLocation CREATIVE_INVENTORY_TABS = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
    private static int selectedTabIndex = GuiTabs.tabInventory.getTabIndex(), tabPage = 0;
    private float oldMouseX, oldMouseY;
    private List<Slot> originalSlots;

    public GuiInventoryPlayer(final EntityPlayer player, final CPlayerInventory inv)
    {
        super(new ContainerTabOne(player, inv));
        this.allowUserInput = true;
    }

    public void updateScreen()
    {
        if (this.mc.playerController.isInCreativeMode())
            this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
    }

    public void initGui()
    {
        this.buttonList.clear();

        if (this.mc.playerController.isInCreativeMode())
        {
            this.mc.displayGuiScreen(new GuiContainerCreative(this.mc.thePlayer));
        }
        else
        {
            super.initGui();
            this.buttonList.clear();
            Keyboard.enableRepeatEvents(true);
            this.setCurrentCreativeTab(GuiTabs.tabInventory);
        }
    }

    public void onGuiClosed()
    {
        super.onGuiClosed();
        Keyboard.enableRepeatEvents(false);
        PacketHandler.NETWORK.sendToServer(new PacketInventoryToServer(mc.thePlayer));
    }

    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
    {
        if (mouseButton == 0)
        {
            int i = mouseX - this.guiLeft;
            int j = mouseY - this.guiTop;

            for (GuiTabs creativetabs : GuiTabs.TABS)
            {
                if (this.isMouseOverTab(creativetabs, i, j))
                {
                    return;
                }
            }
        }

        super.mouseClicked(mouseX, mouseY, mouseButton);
    }

    protected void mouseReleased(int mouseX, int mouseY, int state)
    {
        if (state == 0)
        {
            int i = mouseX - this.guiLeft;
            int j = mouseY - this.guiTop;

            for (GuiTabs creativetabs : GuiTabs.TABS)
            {
                if (creativetabs != null && this.isMouseOverTab(creativetabs, i, j))
                {
                    this.setCurrentCreativeTab(creativetabs);
                    return;
                }
            }
        }

        super.mouseReleased(mouseX, mouseY, state);
    }

    private void setCurrentCreativeTab(GuiTabs tab)
    {
        if (tab == null) return;
        int i = selectedTabIndex;
        selectedTabIndex = tab.getTabIndex();
        ContainerTabOne containerGui = (ContainerTabOne)this.inventorySlots;
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;

        if (tab == GuiTabs.tabInventory)
        {
            Container container = new ContainerInventoryPlayer(player.inventory, !player.worldObj.isRemote, player);

            if (this.originalSlots == null)
            {
                this.originalSlots = containerGui.inventorySlots;
            }

            containerGui.inventorySlots = container.inventorySlots;
        }
        else if (i == GuiTabs.tabInventory.getTabIndex())
        {
            containerGui.inventorySlots = this.originalSlots;
            this.originalSlots = null;
        }
    }

    protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
    {
        GuiTabs creativetabs = GuiTabs.TABS[selectedTabIndex];

        if (creativetabs != null && creativetabs.drawInForegroundOfTab())
        {
            GlStateManager.disableBlend();
            this.fontRendererObj.drawString(I18n.format(creativetabs.getTranslatedTabLabel(), new Object[0]), 8, 6, 4210752);
        }
    }

    protected boolean isMouseOverTab(GuiTabs tab, int mouseX, int mouseY)
    {
        int i = tab.getTabColumn();
        int j = 28 * i;
        int k = 0;

        if (i == 5)
        {
            j = this.xSize - 28 + 2;
        }
        else if (i > 0)
        {
            j += i;
        }

        if (tab.isTabInFirstRow())
        {
            k = k - 32;
        }
        else
        {
            k = k + this.ySize;
        }

        return mouseX >= j && mouseX <= j + 28 && mouseY >= k && mouseY <= k + 32;
    }

    protected void drawTab(GuiTabs tab)
    {
        boolean flag = tab.getTabIndex() == selectedTabIndex;
        boolean flag1 = tab.isTabInFirstRow();
        int i = tab.getTabColumn();
        int j = i * 28;
        int k = 0;
        int l = this.guiLeft + 28 * i;
        int i1 = this.guiTop;

        if (flag)
        {
            k += 32;
        }

        if (i == 5)
        {
            l = this.guiLeft + this.xSize - 28;
        }
        else if (i > 0)
        {
            l += i;
        }

        if (flag1)
        {
            i1 = i1 - 28;
        }
        else
        {
            k += 64;
            i1 = i1 + (this.ySize - 4);
        }

        GlStateManager.disableLighting();
        GlStateManager.color(1F, 1F, 1F);
        GlStateManager.enableBlend();
        this.drawTexturedModalRect(l, i1, j, k, 28, 32);
        this.zLevel = 100.0F;
        this.itemRender.zLevel = 100.0F;
        l = l + 6;
        i1 = i1 + 8 + (flag1 ? 1 : -1);
        GlStateManager.enableLighting();
        GlStateManager.enableRescaleNormal();
        ItemStack itemstack = tab.getIconItemStack();
        this.itemRender.renderItemAndEffectIntoGUI(itemstack, l, i1);
        this.itemRender.renderItemOverlays(this.fontRendererObj, itemstack, l, i1);
        GlStateManager.disableLighting();
        this.itemRender.zLevel = 0.0F;
        this.zLevel = 0.0F;
    }

    public void drawScreen(final int mouseX, final int mouseY, final float partialTicks)
    {
        super.drawScreen(mouseX, mouseY, partialTicks);
        this.oldMouseX = (float)mouseX;
        this.oldMouseY = (float)mouseY;
    }

    protected void drawGuiContainerBackgroundLayer(final float partialTicks, final int mouseX, final int mouseY)
    {
        RendersHelper.renderBlackBackground(width, height);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        RenderHelper.enableGUIStandardItemLighting();
        GuiTabs creativetabs = GuiTabs.TABS[selectedTabIndex];

        int start = tabPage * 10;
        int end = Math.min(GuiTabs.TABS.length, ((tabPage + 1) * 10 + 2));
        int i = this.guiLeft;
        int j = this.guiTop;
        if (tabPage != 0) start += 2;

        for (GuiTabs creativetabs1 : java.util.Arrays.copyOfRange(GuiTabs.TABS, start, end))
        {
            this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);

            if (creativetabs1 == null) continue;
            if (creativetabs1.getTabIndex() != selectedTabIndex)
            {
                this.drawTab(creativetabs1);
            }
        }
        this.mc.getTextureManager().bindTexture(creativetabs.getBackgroundImageName());
        this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(CREATIVE_INVENTORY_TABS);
        this.drawTab(creativetabs);
        drawEntityOnScreen(i + 250, j + 170, 100, this.mc.thePlayer);
    }

    public static void drawEntityOnScreen(final int posX, final int posY, final int scale, final EntityLivingBase ent)
    {
        GlStateManager.enableColorMaterial();
        GlStateManager.pushMatrix();
        GlStateManager.translate((float)posX, (float)posY, 50.0F);
        GlStateManager.scale((float)(-scale), (float)scale, (float)scale);
        GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F);
        final float f = ent.renderYawOffset, f1 = ent.rotationYaw, f2 = ent.rotationPitch, f3 = ent.prevRotationYawHead, f4 = ent.rotationYawHead;
        RenderHelper.enableStandardItemLighting();
        GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F);
        ent.renderYawOffset = 40.0F;
        ent.rotationYaw = 0;
        ent.rotationPitch = 0.0F;
        ent.rotationYawHead = 40F;
        GlStateManager.translate(0.0F, 0.0F, 0.0F);
        RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager();
        rendermanager.setPlayerViewY(180.0F);
        rendermanager.setRenderShadow(false);
        rendermanager.doRenderEntity(ent, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false);
        rendermanager.setRenderShadow(true);
        ent.renderYawOffset = f;
        ent.rotationYaw = f1;
        ent.rotationPitch = f2;
        ent.prevRotationYawHead = f3;
        ent.rotationYawHead = f4;
        GlStateManager.popMatrix();
        RenderHelper.disableStandardItemLighting();
        GlStateManager.disableRescaleNormal();
        GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
        GlStateManager.disableTexture2D();
        GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
    }

    protected void actionPerformed(final GuiButton button)
    {
        switch (button.id)
        {
            case 0:
                this.mc.displayGuiScreen(new GuiAchievements(this, this.mc.thePlayer.getStatFileWriter()));
                break;
            case 1:
                this.mc.displayGuiScreen(new GuiStats(this, this.mc.thePlayer.getStatFileWriter()));
                break;
        }
    }
}

 

 

Link to comment
Share on other sites

From the video, I'd say you are making new slots with the same IDs, thus having the same

ItemStack

in both slots.

Well I have the player's inventory and the second tab 45 slots for a category of items.

Do you have a Container?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

ContainerCP

 

 

package ru.ivasik.witcher.gui.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import ru.ivasik.witcher.capabilities.playerinventory.CPPlayerInventory;

public class ContainerTabOne extends Container
{
    public ContainerTabOne(EntityPlayer player, CPPlayerInventory inv)
    {
        for (int j = 0; j < 5; ++j)
        {
            for (int k = 0; k < 9; ++k)
            {
                this.addSlotToContainer(new SlotCP(inv, k + j * 9, 9 + k * 18, 18 + j * 18));
            }
        }

        for (int i1 = 0; i1 < 9; ++i1)
        {
            this.addSlotToContainer(new Slot(player.inventory, i1, 9 + i1 * 18, 112));
        }
    }

    public boolean canInteractWith(EntityPlayer playerIn) {
        return true;
    }

    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(index);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (index < 45)
            {
                if (!this.mergeItemStack(itemstack1, 45, this.inventorySlots.size(), true))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 0, 45, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }
        }

        return itemstack;
    }
}

 

 

 

SlotCP

 

 

package ru.ivasik.witcher.gui.container;

import net.minecraftforge.items.SlotItemHandler;
import ru.ivasik.witcher.capabilities.playerinventory.CPlayerInventory;

public class SlotCP extends SlotItemHandler
{
public SlotCP(final CPlayerInventory itemHandler, final int index, final int xPosition, final int yPosition)
    {
	super(itemHandler.getTheCPInventory(), index, xPosition, yPosition);
}
}

 

 

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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