Jump to content

Recommended Posts

Posted

So I have a custom GUI with one row of 9 slots, and then a single slot above them all (which is supposed to act just like all the others, it's not an output). I loop through the row of 9 slots and add them to the container, which works fine. Then I add just the top slot and it's coordinates to the container. However, everytime I put an item in the top slot, it duplicates into the corresponding slot in the for loop. I know it's a logical error, but I'm not able to figure out how to fix it.

Posted (edited)

Sorry.

public CustomContainer(InventoryPlayer player, TestTileEntity tileEntity)
{
    this.tileEntity = tileEntity;

    // single slot
    this.addSlotToContainer(new Slot(tileEntity, 0, 80, 32));

    // row of 9
    for (int i = 0; i < 9; i++)
    {
        this.addSlotToContainer(new Slot(tileEntity, i, 8 + i * 18, 53));
    }


    /* Player Inventory and Hotbar */
    for (int y = 0; y < 3; y++)
    {
        for (int x = 0; x < 9; x++)
        {
            this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
        }
    }

    for (int x = 0; x < 9; x++)
    {
        this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    }
}
Edited by Siqhter
Posted
14 minutes ago, diesieben07 said:

You tell the "single slot" to use inventory index 0.

You also tell the first slot in the loop to use inventory index 0.

I know, that's why it duplicates the item because it's essentially the same slot. I don't know how to give it it's own index after looping through the first row. It's crashes the game with an out of bounds exception.

Posted (edited)

Thanks for the explanation. I got it working, but I don't quite understand what I did:

Spoiler

/* Single Slot */
this.addSlotToContainer(new Slot(tileEntity, 9, 80, 32));

/* Container Slots */
for (int i = 0; i < 9; i++)
{
    this.addSlotToContainer(new Slot(tileEntity, i, 8 + i * 18, 53));
}

The "single slot" index is 9. How does the "index" relate to the "actual" slot in which an item can be placed?

Edited by Siqhter
Posted (edited)

You have an arbitrary number of slots, you were assigning: 

slot 0 to single slot

slot 0 to container slot 0

slot 1 to container slot 1

slot 2 to container slot 2

...

slot 8 to container slot 8

 

now you are assigning

slot 9 to single slot

slot 0 to container slot 0

slot 1 to container slot 1

slot 2 to container slot 2

...

slot 8 to container slot 8

 

Previously you were assigning to slots to the same slot ID index, hence the duplicate slots

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
13 minutes ago, Siqhter said:

/* Container Slots */

ID -> slotIndex, pretty much the same thing tho

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

In this (specific) case both need to be unique, which is what I meant 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

IInventory is legacy vanilla code, IItemHandler is forge’s intercompatible replacement

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Edit:

I've done some research on IItemHandler and Capabilites, so rather, where am I supposed to implement using capabilities. The tileentity? And what needs to change in my container class so that I'm not implementing IInventory.

Posted
  • Thanks 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Thank you, I'm taking a look at that. I'm wondering in your example, where do you set a display name for the container? Originally I had something like "container.name" after the createContainer method. But I believe that's from IInventory.

Posted

It gets drawn in drawGuiContainerForegroundLayer. You can draw it yourself 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
9 hours ago, Cadiboo said:

It gets drawn in drawGuiContainerForegroundLayer. You can draw it yourself 

Ok, I didn't think of that. There's also a method called getDisplayName that works in the tileentity. Last question, I don't understand what's going on in your read and write to NBT methods. Mine aren't saving any items after quitting, but that's obvious because there's nothing in them. Not sure if I use set integer?

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.