Jump to content

[Unsolved] Array-related crash when opening container GUI


Qwertygiy

Recommended Posts

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:

 

 

 

2012-09-19 19:29:57 [iNFO] [sTDERR] java.lang.IndexOutOfBoundsException: Index: 45, Size: 45
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at java.util.ArrayList.rangeCheck(ArrayList.java:604)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at java.util.ArrayList.get(ArrayList.java:382)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.Container.getSlot(Container.java:123)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.Container.putStacksInSlots(Container.java:341)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.NetClientHandler.handleWindowItems(NetClientHandler.java:985)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.Packet104WindowItems.processPacket(Packet104WindowItems.java:69)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.MemoryConnection.processReadPackets(MemoryConnection.java:75)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.NetClientHandler.processReadPackets(NetClientHandler.java:103)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.src.WorldClient.tick(WorldClient.java:66)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1777)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:834)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:764)
2012-09-19 19:29:57 [iNFO] [sTDERR] 	at java.lang.Thread.run(Thread.java:722)

 

 

 

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:

 

 

 

package KBI.agricrafture.core;

import net.minecraft.src.*;
import KBI.agricrafture.api.*;
import java.util.logging.Level;
import cpw.mods.fml.common.FMLLog;

public class ContainerCulinary extends Container 
{

        protected TileEntityCulinary tileEntity;
       
        public ContainerCulinary (InventoryPlayer inventoryPlayer, TileEntityCulinary te)
	{
			FMLLog.log(Level.FINE, "ContainerCulinary intitiated");
                tileEntity = te;

                //the Slot constructor takes the IInventory and the slot number in that it binds to
                //and the x-y coordinates it resides on-screen
			//0-5 are ingredients
                addSlotToContainer(new Slot(tileEntity, 0, 7, 15));
			addSlotToContainer(new Slot(tileEntity, 1, 25, 15));
			addSlotToContainer(new Slot(tileEntity, 2, 7, 33));
			addSlotToContainer(new Slot(tileEntity, 3, 25, 33));
			addSlotToContainer(new Slot(tileEntity, 4, 7, 51));
			addSlotToContainer(new Slot(tileEntity, 5, 25, 51));
			//tool slot, for knife, spoon, etc.
			addSlotToContainer(new Slot(tileEntity, 6, 60, 7));
			//dish slot, for plate, bowl, jar, etc.
			addSlotToContainer(new Slot(tileEntity, 7, 60, 61));
			//main output
			addSlotToContainer(new Slot(tileEntity, 8, 147, 35));
			//secondary output 1
			addSlotToContainer(new Slot(tileEntity, 9, 147, 7));
			//secondary output 2
			addSlotToContainer(new Slot(tileEntity, 10, 147, 61));

                //commonly used vanilla code that adds the player's inventory
                bindPlayerInventory(inventoryPlayer);
			FMLLog.log(Level.FINE, "ContainerCulinary initiation complete.");
        }

        @Override
        public boolean canInteractWith(EntityPlayer player) 
	{
                return tileEntity.isUseableByPlayer(player);
        }


        protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) 
	{
                for (int i = 0; i < 3; i++) 
			{
                        for (int j = 0; j < 9; j++) 
					{
                                addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
                        }
                }

                for (int i = 0; i < 9; i++) 
			{
                        addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
                }
        }

	@Override
        public ItemStack transferStackInSlot(int slot) 
	{
                ItemStack stack = null;
                Slot slotObject = (Slot) inventorySlots.get(slot);

                //null checks and checks if the item can be stacked (maxStackSize > 1)
                if (slotObject != null && slotObject.getHasStack()) 
			{
                        ItemStack stackInSlot = slotObject.getStack();
                        stack = stackInSlot.copy();

                        //merges the item into player inventory since its in the tileEntity
                        if (slot >= 0 && slot <= 10)
					{
                                if (!mergeItemStack(stackInSlot, 11, inventorySlots.size(), true)) 
							{
                                        return null;
                                }
                        //places it into the tileEntity is possible since its in the player inventory
                        } 
					else if (!mergeItemStack(stackInSlot, 0, 7, false)) 
					{
                                return null;
                        }

                        if (stackInSlot.stackSize == 0) 
					{
                                slotObject.putStack(null);
                        } 
					else {
                                slotObject.onSlotChanged();
                        }
                }

                return stack;
        }
}

 

 

 

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?

Link to comment
Share on other sites

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?

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.   Kesimpulan OLXTOTO adalah situs slot gacor terbaik yang memberikan pengalaman bermain judi slot online yang tak terlupakan. Dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering, OLXTOTO menjadi pilihan terbaik bagi para pemain yang mencari kesenangan dan kemenangan besar dalam perjudian online. Di samping itu, OLXTOTO juga menawarkan layanan pelanggan yang ramah dan responsif, siap membantu setiap pemain dalam mengatasi masalah teknis atau pertanyaan seputar perjudian online. Kami menjaga integritas game dan memberikan lingkungan bermain yang adil serta menjalankan kebijakan perlindungan pelanggan yang cermat. Bergabunglah dengan OLXTOTO sekarang dan nikmati pengalaman bermain slot online yang luar biasa. Jadilah bagian dari komunitas perjudian yang mengagumkan ini dan raih kesempatan untuk meraih kemenangan besar. Dapatkan akses mudah dan praktis ke situs OLXTOTO dan rasakan sensasi bermain judi slot yang tak terlupakan.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa Di dunia perjudian online yang begitu kompetitif, mencari platform yang dapat memberikan kemenangan maksimal (Maxwin) dan hasil terbaik (Gacor) adalah prioritas bagi para penjudi yang cerdas. Dalam upaya ini, OLXTOTO telah muncul sebagai pemain kunci yang mengubah lanskap perjudian online dengan menawarkan pengalaman tanpa tandingan.     Sejak diluncurkan, OLXTOTO telah menjadi sorotan industri perjudian online. Dikenal sebagai "Platform Maxwin dan Gacor Terbesar Sepanjang Masa", OLXTOTO telah menarik perhatian pemain dari seluruh dunia dengan reputasinya yang solid dan kinerja yang luar biasa. Salah satu fitur utama yang membedakan OLXTOTO dari pesaingnya adalah komitmen mereka untuk memberikan pengalaman berjudi yang unik dan memuaskan. Dengan koleksi game yang luas dan beragam, termasuk togel, slot online, live casino, dan banyak lagi, OLXTOTO menawarkan sesuatu untuk semua orang. Dibangun dengan teknologi terkini dan didukung oleh tim ahli yang berdedikasi, platform ini memastikan bahwa setiap pengalaman berjudi di OLXTOTO tidak hanya menghibur, tetapi juga menguntungkan. Namun, keunggulan OLXTOTO tidak hanya terletak pada permainan yang mereka tawarkan. Mereka juga terkenal karena keamanan dan keadilan yang mereka berikan kepada para pemain mereka. Dengan sistem keamanan tingkat tinggi dan audit rutin yang dilakukan oleh otoritas regulasi independen, para pemain dapat yakin bahwa setiap putaran permainan di OLXTOTO adalah adil dan transparan. Tidak hanya itu, OLXTOTO juga dikenal karena layanan pelanggan yang luar biasa. Dengan tim dukungan yang ramah dan responsif, para pemain dapat yakin bahwa setiap pertanyaan atau masalah mereka akan ditangani dengan cepat dan efisien. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi platform pilihan bagi para penjudi online yang mencari kemenangan maksimal dan hasil terbaik. Jadi, jika Anda ingin bergabung dengan jutaan pemain yang telah merasakan keajaiban OLXTOTO, jangan ragu untuk mendaftar dan mulai bermain hari ini!  
    • OLXTOTO adalah bandar slot yang terkenal dan terpercaya di Indonesia. Mereka menawarkan berbagai jenis permainan slot yang menarik dan menghibur. Dengan tampilan yang menarik dan grafis yang berkualitas tinggi, pemain akan merasa seperti berada di kasino sungguhan. OLXTOTO juga menyediakan layanan pelanggan yang ramah dan responsif, siap membantu pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Daftar =  https://surkale.me/Olxtotodotcom1
    • DAFTAR & LOGIN BIGO4D   Bigo4D adalah situs slot online yang populer dan menarik perhatian banyak pemain slot di Indonesia. Dengan berbagai game slot yang unik dan menarik, Bigo4D menjadi tempat yang ideal untuk pemula dan pahlawan slot yang berpengalaman. Dalam artikel ini, kami akan membahas tentang Bigo4D sebagai situs slot terbesar dan menarik yang saat ini banyak dijajaki oleh pemain slot online.
  • Topics

×
×
  • Create New...

Important Information

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