Siqhter Posted January 8, 2019 Posted January 8, 2019 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. Quote
unassigned Posted January 8, 2019 Posted January 8, 2019 We can't help you if you don't provide us with code. Saying it's a logical error doesn't tell us or show us anything. Quote Currently developing: https://github.com/unassignedxd/Dynamic-Quarries
Siqhter Posted January 8, 2019 Author Posted January 8, 2019 (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 January 8, 2019 by Siqhter Quote
Siqhter Posted January 8, 2019 Author Posted January 8, 2019 On 1/8/2019 at 6:12 PM, 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. Expand 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. Quote
Siqhter Posted January 8, 2019 Author Posted January 8, 2019 (edited) Thanks for the explanation. I got it working, but I don't quite understand what I did: Reveal hidden contents /* 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 January 8, 2019 by Siqhter Quote
Cadiboo Posted January 8, 2019 Posted January 8, 2019 (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 January 8, 2019 by Cadiboo Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Cadiboo Posted January 8, 2019 Posted January 8, 2019 On 1/8/2019 at 7:45 PM, Siqhter said: /* Container Slots */ Expand ID -> slotIndex, pretty much the same thing tho Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Cadiboo Posted January 8, 2019 Posted January 8, 2019 In this (specific) case both need to be unique, which is what I meant Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Siqhter Posted January 8, 2019 Author Posted January 8, 2019 Now when you told me to get rid of IInventory and use IItemHandler, is that because I'm using InventoryPlayer? How do switch it? Quote
Cadiboo Posted January 8, 2019 Posted January 8, 2019 IInventory is legacy vanilla code, IItemHandler is forge’s intercompatible replacement Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Siqhter Posted January 8, 2019 Author Posted January 8, 2019 (edited) I guess I'm just unclear as to what I am supposed to replace with IItemHandler. Edited January 9, 2019 by Siqhter Quote
Siqhter Posted January 9, 2019 Author Posted January 9, 2019 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. Quote
Cadiboo Posted January 10, 2019 Posted January 10, 2019 The tile entity should override the has/getCapability methods appropriately replace everything from IInventory with the tile entities ItemstackHandler You can see an example at https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/tileentity/TileEntityModFurnace.java#L300-L340 and https://github.com/Cadiboo/WIPTech/blob/fb5883e9d76ef0361ec1ebbcb9c508611dd2ef6b/src/main/java/cadiboo/wiptech/inventory/ContainerModFurnace.java 1 Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Siqhter Posted January 10, 2019 Author Posted January 10, 2019 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. Quote
Cadiboo Posted January 11, 2019 Posted January 11, 2019 It gets drawn in drawGuiContainerForegroundLayer. You can draw it yourself Quote About Me Reveal hidden contents My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.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)
Siqhter Posted January 11, 2019 Author Posted January 11, 2019 On 1/11/2019 at 8:47 AM, Cadiboo said: It gets drawn in drawGuiContainerForegroundLayer. You can draw it yourself Expand 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? Quote
Recommended Posts
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.