Insane96MCP Posted September 29, 2017 Posted September 29, 2017 (edited) I'm trying to copy the anvil container. But as soon as I try to make this.addSlotToContainer(new Slot(...)); and I open the GUI, I get a java.lang.IndexOutOfBoundsException: Index: 39, Size: 39: [11:27:18] [Client thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 39, Size: 39 at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_141] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_141] at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1109) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_141] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_141] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_141] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] Caused by: java.lang.IndexOutOfBoundsException: Index: 39, Size: 39 at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_141] at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_141] at net.minecraft.inventory.Container.getSlot(Container.java:135) ~[Container.class:?] at net.minecraft.inventory.Container.setAll(Container.java:554) ~[Container.class:?] at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1306) ~[NetHandlerPlayClient.class:?] at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:72) ~[SPacketWindowItems.class:?] at net.minecraft.network.play.server.SPacketWindowItems.processPacket(SPacketWindowItems.java:13) ~[SPacketWindowItems.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_141] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_141] at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?] ... 15 more Here's the code Another problem is that seems like the server is not getting input properly so I can't output nothing from the anvil. But I think that fixing the excpetion will solve this too. Edited September 29, 2017 by Insane96MCP Quote
jeffryfisher Posted September 29, 2017 Posted September 29, 2017 When you stepped into and through this.addSlotToContainer(new Slot(...)); in the debugger, did you see the array being extended? Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
Insane96MCP Posted September 30, 2017 Author Posted September 30, 2017 (edited) 11 hours ago, jeffryfisher said: When you stepped into and through this.addSlotToContainer(new Slot(...)); in the debugger, did you see the array being extended? Nope, no exception is given going through addSlotToContainer in the debugger . It happens later Edited September 30, 2017 by Insane96MCP Quote
jeffryfisher Posted October 2, 2017 Posted October 2, 2017 Well then, if the array isn't getting bigger, but you try to access more elements than were allocated, then you're going to run off the end. Fix it. Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
Insane96MCP Posted October 4, 2017 Author Posted October 4, 2017 On 2/10/2017 at 8:13 PM, jeffryfisher said: Well then, if the array isn't getting bigger, but you try to access more elements than were allocated, then you're going to run off the end. Fix it. The problem is that I'm using a vanilla method, and it should work alone. Quote
Choonster Posted October 4, 2017 Posted October 4, 2017 You're using Containers with a different number of Slots on the client and server. The client uses ContainerRepair; but the server uses GuiServer, which extends ContainerRepair and adds an extra Slot. The client-side Container doesn't have a Slot at this index, so the update packets throw an IndexOutOfBoundsException. You need to use Containers with the same number of slots on both sides, usually instances of the same class. GuiRepair doesn't have a constructor that lets you provide your own Container, so you'll probably need to copy rather than extend it. If you extend a class, you don't need to copy all of its fields and methods; you only need to override the methods that should have different behaviour. To access the private IInventory fields in ContainerRepair, either use reflection or get the corresponding Slots from Container#inventorySlots and get the inventory from the Slot#inventory field. GuiServer isn't a good name, since it's not a GUI and the server doesn't have GUIs. I recommend following the MCP naming conventions and naming it something like ContainerGoldenAnvil. 1 Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.