Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

When I want to acces my block, the slots of the container won't show. I got here a screenshot and the error.

 

https://www.dropbox.com/s/631itzs3gcbnik3/2017-01-24_13.11.50.png?dl=0

 

[13:11:46] [Client thread/FATAL]: Error executing task
java.util.concurrent.ExecutionException: java.lang.IndexOutOfBoundsException: Index: 36, Size: 36
at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_101]
at net.minecraft.util.Util.runTask(Util.java:27) [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_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
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_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_101]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_101]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
at GradleStart.main(GradleStart.java:26) [start/:?]
Caused by: java.lang.IndexOutOfBoundsException: Index: 36, Size: 36
at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_101]
at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_101]
at net.minecraft.inventory.Container.getSlot(Container.java:128) ~[Container.class:?]
at net.minecraft.inventory.Container.setAll(Container.java:547) ~[Container.class:?]
at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1305) ~[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:15) ~[PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_101]
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_101]
at net.minecraft.util.Util.runTask(Util.java:26) ~[util.class:?]
... 15 more

  • Author

This is the container class code

 

package com.rowan662.infinitycraft.machines;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ContainerCompressor extends Container {

private final IInventory tileCompressor;
private int workTime;
private int totalWorkTime;
private int compressorWorkTime;
private int currentItemWorkTime;

public ContainerCompressor(InventoryPlayer playerInventory, IInventory compressorInventory){
	this.tileCompressor = compressorInventory;
	this.addSlotToContainer(new Slot(compressorInventory, 0, 56, 17));
	this.addSlotToContainer(new SlotCompressorFuel(compressorInventory, 1, 56, 53));
	this.addSlotToContainer(new SlotCompressorOutput(playerInventory.player, compressorInventory, 2, 116, 35));

	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 9; ++j){
			this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
		}
	}

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

@Override
public void addListener(IContainerListener listener){
	super.addListener(listener);
	listener.sendAllWindowProperties(this, this.tileCompressor);
}

@Override
public void detectAndSendChanges(){
	super.detectAndSendChanges();

	for(int i = 0; i < this.listeners.size(); ++i){
		IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i);

		if(this.workTime != this.tileCompressor.getField(2)){
			icontainerlistener.sendProgressBarUpdate(this, 2, this.tileCompressor.getField(2));
		}

		if(this.compressorWorkTime != this.tileCompressor.getField(0)){
			icontainerlistener.sendProgressBarUpdate(this, 0, this.tileCompressor.getField(0));
		}

		if(this.currentItemWorkTime != this.tileCompressor.getField(1)){
			icontainerlistener.sendProgressBarUpdate(this, 1, this.tileCompressor.getField(1));
		}

		if(this.totalWorkTime != this.tileCompressor.getField(3)){
			icontainerlistener.sendProgressBarUpdate(this, 3, this.tileCompressor.getField(3));
		}
	}
	this.workTime = this.tileCompressor.getField(2);
	this.compressorWorkTime = this.tileCompressor.getField(0);
	this.currentItemWorkTime = this.tileCompressor.getField(1);
	this.totalWorkTime = this.tileCompressor.getField(3);
}

@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int id, int data){
	this.tileCompressor.setField(id, data);
}

@Override
public boolean canInteractWith(EntityPlayer playerIn){
	return this.tileCompressor.isUsableByPlayer(playerIn);
}

@Override
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
    {
        ItemStack itemstack = ItemStack.EMPTY;
        Slot slot = (Slot)this.inventorySlots.get(index);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (index == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return ItemStack.EMPTY;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (index != 1 && index != 0)
            {
                if (!FurnaceRecipes.instance().getSmeltingResult(itemstack1).isEmpty())
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (TileEntityFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (index >= 3 && index < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
                else if (index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return ItemStack.EMPTY;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return ItemStack.EMPTY;
            }

            if (itemstack1.isEmpty())
            {
                slot.putStack(ItemStack.EMPTY);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.getCount() == itemstack.getCount())
            {
                return ItemStack.EMPTY;
            }

            slot.onTake(playerIn, itemstack1);
        }

        return itemstack;
    }
}

When you try to access number 36 in an array, you are actually trying to get number 37, which does not exist.

 

No, when you access 36, you access 36.  The problem is, arrays are zero-indexed.  Yes, it's the 37th item, but that's a different numbering system.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.