Jump to content

[Unsolved] Array-related crash when opening container GUI


Recommended Posts

Posted

I have a block with a tile entity inventory, and after spending a couple hours fixing some rookie mistakes, I have run into an actual crash that does not mention any of my code anywhere.

 

Here's the direct crash trace:

 

 

  Reveal hidden contents

 

 

Now, the first three lines appear to be rather obvious; since 0 is inclusive, something is looking for the 46th item in a 45-item array.

 

The next line isn't too helpful, but the fifth is slightly enlightening. Here's the relevant functions in Container.java:

 

public Slot getSlot(int par1)
    {
        return (Slot)this.inventorySlots.get(par1); //line 123
    }

public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack)
    {
        for (int var2 = 0; var2 < par1ArrayOfItemStack.length; ++var2)
        {
            this.getSlot(var2).putStack(par1ArrayOfItemStack[var2]); //line 341
        }
    }

 

So, to me, putStacksInSlots would appear to be the 'true culprit' of the stack trace. The array here apparently has more than 45 slots, while the Container does not, and so it crashes. I'm using the Recommended Forge, #251; is it a bug with the API or am I doing something incorrectly to set it off? I looked through the change log on Jenkins to make sure it wasn't a bug fixed in a recent release, and it wasn't mentioned.

 

Here's my Container class:

 

 

  Reveal hidden contents

 

 

Counting slots, there should be 47 of them -- 36 for the player inventory, and 11 for the tile entity.

 

Any ideas what's going on and how to fix it?

Posted

What about your TileEntity, does it actually have the array size of 11 (or 12, if I misread your post. It needs to be 1 more than the highest number you use in the code, at least). If it doesn't, there is your problem. Else, I have no clue what the problem is...

Posted

inv = new ItemStack[11];

 

Yep, my TE's array size is fine.

 

You may notice this line in the class file:

 

FMLLog.log(Level.FINE, "ContainerCulinary initiation complete.");

 

and that line DOES show up in the log just before the crash.

Posted

Are you sending any packets for this container of yours? how are you sending them? I'm asking since right before the crash it is working with packets so I assume there might be from there the array which is out of bounds comes from?

 

  Quote

If you guys dont get it.. then well ya.. try harder...

Posted

I am not, so any packet handling is being done either by Forge or by vanilla code, but I may have to use packets in the future. I'm 99% sure of that, and my utter lack of knowledge on how to do so may somehow be involved with the crash, but I don't want to add 300 more lines of code that won't fix the crash.

Posted
  On 9/21/2012 at 12:30 PM, Qwertygiy said:

It's when I right-click the block to open the GUI.

 

Here's TileEntityCulinary.java: http://pastebin.com/h3Qm3LDY

 

Note: everything after line 174 is code involving CulinaryRecipe.java.

And yes, before it's a true API I need to remove that import core.* line.

try setting the size of the array directly private ItemStack[] inv = new ItemStack[11]; might not be the issue but could. Also add an if statement to getSlot too check if requrest slot is not over the length.

Posted

Added this function to ContainerCulinary:

 

@Override
	public Slot getSlot(int par1)
	{
		if(par1 < this.inventorySlots.size())
		{
			return (Slot)this.inventorySlots.get(par1);
		}
		else
		{
			return (Slot)null;
		}
	}

 

and also defined inv in TileEntityCulinary immediately instead of in the constructor.

 

I get the same crash as before upon right-clicking the block.

Posted

still reading threw the code but i noticed in you block class that on activate you don't check to make sure the world isn't remote. You need to do this so the server tells the client to open a GUI with the correct info.

if (par1World.isRemote)
        {
            return true;
        }
        else
        {//rest of your code here

 

Also why is your GUI id so high. If i'm not mistaken GUI ids are used only per mod meaning several mods can have GUI id 0 or 1.

Posted

The high ID was an attempt at bug fixing mostly; because I think I found that the ID I was using (either 0 or 1, I forget) might have been the one used by the vanilla Crafting Table GUI, causing confusion in the code. As it still happened with the high ID, that must not be the case and I'll change it back.

 

I added the remote world check, no obvious difference in the result.

Posted

Okay, I did some further work. This time, I basically just copied the vanilla Furnace class and modified it to have 2 burn slots and 4 recipe slots. Same problem as before -- upon right-clicking the block, something tries to access the 46th slot in a 45-slot Array. Since both Containers have more than 45 slots, I suspect I am missing some code somewhere.

Posted

I've put my code up on GitHub at https://github.com/Qwertygiy/Agricrafture to make it easier to get help figuring out how to get this working. In addition to it really not liking containers with over 45 slots, my packets and crafting don't appear to be working properly. All in all it's a big mess and I've looked through other code to try to figure out how to fix it but so far am getting nowhere.

Posted

You can take a look at a couple of the mods that I've written that have working GUI's if you want an idea of how to do it correctly. I'm at work at the moment so I don't have time to look over your code for any specific details or help. I'll try to get something more up here to help you out later. In the mean time, take a look at the mods below. The Charging Bench code shows off how to transfer variables from server -> client using the container and the Inventory Stocker has a full on GUI with custom packets implemented.

 

https://github.com/pantheis/ChargingBench and https://github.com/pantheis/InventoryStocker

 

 

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

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issues you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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