Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • Author

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

  • Author
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.

  • Author

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

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)

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)

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)

  • Author

Now when you told me to get rid of IInventory and use IItemHandler, is that because I'm using InventoryPlayer? How do switch it?

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)

  • Author

I guess I'm just unclear as to what I am supposed to replace with IItemHandler.

Edited by Siqhter

  • Author

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.

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)

  • Author

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.

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)

  • Author
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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.