Jump to content

ArrayOutOfBounds TileEntity


camerpon900

Recommended Posts

Hi I am making a mod and i am getting a ArrayOutOfBounds error i know it means that its looking for something out of my bounds but i cant find it pls help thx

 

---- Minecraft Crash Report ----

// Hey, that tickles! Hehehe!

 

Time: 04/12/15 18:54

Description: Rendering screen

 

java.lang.ArrayIndexOutOfBoundsException: 2

at com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube.getStackInSlot(TileEntityEnergyCube.java:95)

at net.minecraft.inventory.Slot.getStack(Slot.java:88)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:219)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1137)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1067)

at net.minecraft.client.Minecraft.run(Minecraft.java:962)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube.getStackInSlot(TileEntityEnergyCube.java:95)

at net.minecraft.inventory.Slot.getStack(Slot.java:88)

at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:219)

at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:114)

 

-- Screen render details --

Details:

Screen name: com.camerpon900.realauto2.gui.GuiEnergyCube

Mouse location: Scaled: (213, 119). Absolute: (427, 240)

Screen size: Scaled: (427, 240). Absolute: (854, 480). Scale factor of 2

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player750'/117, l='MpServer', x=-127.07, y=64.62, z=227.85]]

Chunk stats: MultiplayerChunkCache: 25, 25

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (-136,64,240), Chunk: (at 8,4,0 in -9,15; contains blocks -144,0,240 to -129,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 8436 game time, 8436 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 15 total; [EntityBat['Bat'/72, l='MpServer', x=-127.75, y=20.10, z=200.66], EntityCreeper['Creeper'/73, l='MpServer', x=-123.50, y=30.00, z=220.50], EntityCreeper['Creeper'/74, l='MpServer', x=-128.00, y=38.00, z=233.56], EntityClientPlayerMP['Player750'/117, l='MpServer', x=-127.07, y=64.62, z=227.85], EntitySkeleton['Skeleton'/55, l='MpServer', x=-136.34, y=24.00, z=192.31], EntitySkeleton['Skeleton'/54, l='MpServer', x=-139.53, y=18.00, z=192.97], EntitySkeleton['Skeleton'/59, l='MpServer', x=-134.22, y=29.00, z=220.00], EntityZombie['Zombie'/58, l='MpServer', x=-131.75, y=30.00, z=220.69], EntityZombie['Zombie'/57, l='MpServer', x=-135.13, y=27.00, z=215.31], EntitySquid['Squid'/56, l='MpServer', x=-139.63, y=35.00, z=191.63], EntitySkeleton['Skeleton'/89, l='MpServer', x=-110.53, y=26.00, z=192.31], EntityCreeper['Creeper'/63, l='MpServer', x=-133.51, y=37.00, z=241.20], EntityCreeper['Creeper'/62, l='MpServer', x=-134.37, y=37.00, z=240.36], EntityZombie['Zombie'/61, l='MpServer', x=-135.47, y=37.00, z=240.30], EntityCreeper['Creeper'/60, l='MpServer', x=-132.78, y=29.00, z=218.91]]

Retry entities: 0 total; []

Server brand: fml,forge

Server type: Integrated singleplayer server

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566)

at net.minecraft.client.Minecraft.run(Minecraft.java:984)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.7.0_79, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 676448536 bytes (645 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95

FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1448 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar)

UCHIJAAAA Forge{10.13.4.1448} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar)

UCHIJAAAA ra2{V1.0 PRE-ALPHA} [RealAuto 2] (RealAuto2)

GL info: ' Vendor: 'Intel' Version: '4.3.0 - Build 10.18.14.4112' Renderer: 'Intel® HD Graphics'

Launched Version: 1.7.10

LWJGL: 2.9.1

OpenGL: Intel® HD Graphics GL version 4.3.0 - Build 10.18.14.4112, Intel

GL Caps: Using GL 1.3 multitexturing.

Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.

Anisotropic filtering is supported and maximum anisotropy is 16.

Shaders are available because OpenGL 2.1 is supported.

 

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Resource Packs: []

Current Language: English (US)

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Anisotropic Filtering: Off (1)

 

 

 

package com.camerpon900.realauto2.blocks.TileEntities;

 

import com.camerpon900.realauto2.blocks.Blocks;

import com.camerpon900.realauto2.utils.WorldHelper;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import net.minecraft.world.biome.BiomeGenDesert;

import net.minecraftforge.common.util.ForgeDirection;

 

public class TileEntityEnergyCube extends TileEntity implements ISidedInventory {

 

    private ItemStack[] slots = new ItemStack[2];

 

    public int power = 0;

    private int maxPower = 5000000;

 

    public void updateEntity() {

        System.out.println("Slots: " + this.slots.length);

    }

 

    public void readFromNBT(NBTTagCompound nbt) {

        super.readFromNBT(nbt);

 

        System.out.println("slots "  + this.slots);

 

        System.out.println("reading nbt");

 

        NBTTagList list = nbt.getTagList("Slots", 10);

        NBTTagList powerList = nbt.getTagList("Power",power);

        this.slots = new ItemStack[getSizeInventory()];

 

        for(int i = 0; i < list.tagCount(); i++) {

            NBTTagCompound item = list.getCompoundTagAt(i);

            NBTTagCompound power = list.getCompoundTagAt(i);

            byte b = item.getByte("Item");

            int p = item.getInteger("Power");

 

            if (b >= 0 && b < this.slots.length) {

                this.slots = ItemStack.loadItemStackFromNBT(item);

            }

 

            if(p >= 0 && p < this.maxPower) {

                this.power = power.getInteger("Power");

            }

        }

    }

 

    public void writeToNBT(NBTTagCompound nbt) {

        super.writeToNBT(nbt);

        System.out.println("Writing To NBT at x: " + xCoord + " y: " + yCoord + " z: " + zCoord);

 

        NBTTagList list = new NBTTagList();

 

        for(int i = 0; i < slots.length; i++) {

            if(this.slots != null) {

                NBTTagCompound item = new NBTTagCompound();

                item.setByte("Item", (byte)i);

                this.slots.writeToNBT(item);

                list.appendTag(item);

            }

        }

 

        if(power >= 1) {

            NBTTagCompound power = new NBTTagCompound();

            power.setInteger("Power", this.power);

            list.appendTag(power);

        }

        nbt.setTag("Power", list);

        nbt.setTag("Slots", list);

    }

 

    public int getSizeInventory() {

        return this.slots.length;

    }

 

    public int[] getAccessibleSlotsFromSide(int p_94128_1_) {

        return new int[0];

    }

 

    public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) {

        return this.isItemValidForSlot(p_102007_1_,p_102007_2_);

    }

 

    public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) {

        return true;

    }

 

    public ItemStack getStackInSlot(int i) {

        if(i < 3) {

            return this.slots[2];

        }

        return this.slots;

    }

 

    public ItemStack decrStackSize(int i, int j) {

        if(this.slots != null) {

            System.out.println(this.slots);

            ItemStack itemStack;

            if(this.slots.stackSize <= j) {

                itemStack = this.slots;

                this.slots = null;

                return itemStack;

            } else {

                itemStack = this.slots.splitStack(j);

                if(this.slots.stackSize == 0) {

                    this.slots = null;

                }

            }

            return itemStack;

        }

 

        return null;

    }

 

    public ItemStack getStackInSlotOnClosing(int p_70304_1_) {

        return null;

    }

 

    public void setInventorySlotContents(int i, ItemStack itemStack) {

        this.slots = itemStack;

 

        if(itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) {

            itemStack.stackSize = this.getInventoryStackLimit();

        }

    }

 

    public String getInventoryName() {

        return null;

    }

 

    public boolean hasCustomInventoryName() {

        return false;

    }

 

    public int getInventoryStackLimit() {

        return 64;

    }

 

    public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {

        return true;

    }

 

    public void openInventory() {

 

    }

 

    public void closeInventory() {

 

    }

 

    public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {

        return true;

    }

}

 

 

Link to comment
Share on other sites

Well arrays start at the 'key' value of zero. so you have an array[x, y] which is accessed by either array[0] for x or array[1] for y... So your index is out of bounds since calling for the array[2] is looking for the third value in a two value array

 

 

Look here in your code:

    public ItemStack getStackInSlot(int i) {
        if(i < 3) {
            return this.slots[2];
        }
        return this.slots;
    }

slots[2] is actually the third value in a two value array, hence the index error

I think its my java of the variables.

Link to comment
Share on other sites

Here is my container code

 

package com.camerpon900.realauto2.container;

 

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityCompressor;

import com.camerpon900.realauto2.blocks.TileEntities.TileEntityEnergyCube;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.Slot;

 

public class ContainerEnergyCube extends Container {

 

    private TileEntityEnergyCube energyCube;

 

    public static final int INPUT = 0, OUTPUT = 1;

 

    public ContainerEnergyCube(InventoryPlayer invPlayer, TileEntityEnergyCube tileEntity) {

        this.energyCube = tileEntity;

 

        //0 = Input, 1 = Fuel, 2 = Output

        this.addSlotToContainer(new Slot(energyCube, INPUT, 56, 23));

        this.addSlotToContainer(new Slot(energyCube, OUTPUT, 56, 53));

 

        for(int i = 0; i < 3; i++) {

            for(int j = 0; j < 9; j++) {

                this.addSlotToContainer(new Slot(invPlayer,9+j+i*9,8+18*j,84+i*18));

            }

        }

 

        for(int i = 0; i < 9; i++) {

            this.addSlotToContainer(new Slot(invPlayer,i,8 + i*18,142));

        }

    }

 

    public boolean canInteractWith(EntityPlayer p_75145_1_) {

        return true;

    }

}

 

 

Link to comment
Share on other sites

The container code is not necessary. RANKSHANK is correct: your getStackInSlot() method is trying to return this.slots[2], which is the third element in the slots array, but you've initialized slots to only have 2 elements. Hence your index of 2 is out of bounds.

Whatever Minecraft needs, it is most likely not yet another tool tier.

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.