Jump to content

[1.15.2] OutOfBounds Exception When Opening Container


Paperclippy

Recommended Posts

I have a 9x3 container opened by a button in the inventory. Whenever I open it, it gives me this error:

Spoiler

�[m�[1;31m[01:48:40] [Render thread/FATAL] [minecraft/ThreadTaskExecutor]: Error executing task on Client
java.lang.ArrayIndexOutOfBoundsException: 27
	at java.util.Arrays$ArrayList.set(Unknown Source) ~[?:1.8.0_251] {}
	at net.minecraft.util.NonNullList.set(NonNullList.java:50) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.Inventory.setInventorySlotContents(Inventory.java:114) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.container.Slot.putStack(Slot.java:83) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.inventory.container.Container.setAll(Container.java:462) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.client.network.play.ClientPlayNetHandler.handleWindowItems(ClientPlayNetHandler.java:1186) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.network.play.server.SWindowItemsPacket.processPacket(SWindowItemsPacket.java:58) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.network.play.server.SWindowItemsPacket.processPacket(SWindowItemsPacket.java:13) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.network.PacketThreadUtil.lambda$checkThreadAndEnqueue$0(PacketThreadUtil.java:19) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.run(ThreadTaskExecutor.java:140) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.RecursiveEventLoop.run(RecursiveEventLoop.java:22) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.driveOne(ThreadTaskExecutor.java:110) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.concurrent.ThreadTaskExecutor.drainTasks(ThreadTaskExecutor.java:97) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:930) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:554) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:177) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_251] {}
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251] {}
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_251] {}
	at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_251] {}
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55) ~[forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65) [modlauncher-5.0.0-milestone.4.jar:?] {}
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102) [forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar:?] {}

 

In the container, the inventory of the player gets messed up. The only items that appear are in a 3x3 area on the far left of the inventory (slots 1-3, 10-12, 19-21). In the new inventory, the only items able to be placed are in, again, a 3x3 area in those same slots, but in the new inventory. The hotbar is unaffected. I have tried increasing the size of the inventory that is created, but it will give the same error just with whatever number I put in instead of 27. I would try to figure this out on my own but I can't figure out exactly what the error message means (Is 27 the index it is trying to access? The size of the array? Then how would I know the index/size?) and I've run out of leads for what the problem could be.

 

Here is my code:

 

EventSpellBookButton.java (Opens Container)

Spoiler

@SubscribeEvent
	@OnlyIn(Dist.CLIENT)
	public void guiOpen(GuiScreenEvent.InitGuiEvent.Post event) {
		Screen gui = event.getGui();
		if(!(gui instanceof InventoryScreen))
			return;
		
		int[] pos = calculateButtonPosition(gui); // Is another method in this class. If needed I can post the code for it.
		int x = pos[0];
		int y = pos[1];
		
		event.addWidget(spellBookButton = new ImageButton(x, y, 20, 20, 14, 0, 21, SPELLBOOK_ICON, (button) -> {
			ClientPlayerEntity player = Minecraft.getInstance().player;
			ServerWorld world = event.getGui().getMinecraft().getIntegratedServer().getWorld(player.dimension);
			if(!world.isRemote) {
				NetworkHooks.openGui((ServerPlayerEntity) world.getPlayerByUuid(player.getUniqueID()), new INamedContainerProvider() {
					public Container createMenu(int id, PlayerInventory playerInv, PlayerEntity player) {
						Inventory inv = new Inventory(27);
						return new CardContainer(id, playerInv, inv);
					}
					
					@Override
					public ITextComponent getDisplayName() {
						 return new StringTextComponent("Spell Book");
					}
				});
			}
		}));

 

CardContainer.java

Spoiler

public CardContainer(int windowId, PlayerInventory playerInv, PacketBuffer extraData) {
		this(windowId, playerInv, new Inventory(27));
	}
	
	public CardContainer(int windowId, PlayerInventory playerInv, Inventory inv) {
		super(SpellDeck.CARD_CONTAINER, windowId);
		int rowLength = 9;
		int xOffset = 8;
		int yOffset = 84;
		
		// Chest
		for (int row = 0; row < 3; row++) {
			for(int col = 0; col < 9; col++) {
				this.addSlot(new Slot(inv, row + col * rowLength, xOffset + col * 18, 18 + row * 18));
			}
		}
		
		// Player Inv
		for (int row = 0; row < 3; row++) {
			for(int col = 0; col < 9; col++) {
				this.addSlot(new Slot(playerInv, row + col * 9 + 9, xOffset + col * 18, yOffset + row * 18));
			}
		}
		
		for(int col = 0; col < 9; col++) {
			this.addSlot(new Slot(playerInv, col, xOffset + col * 18, 142));
		}
		
	}

	@Override
	public boolean canInteractWith(PlayerEntity playerIn) {
		return true;
	}

 

 

To be honest I'm not entirely sure where the problem is, but hopefully this is enough information. Let me know if you need any more info or if you need me to create a GitHub repository for all my code.

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



×
×
  • Create New...

Important Information

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