Posted June 17, 201411 yr I been working on a custom crafting table, its is a 5x5 grid with 4 slots to hold tools. When I go to open the table I get. java.lang.ArrayIndexOutOfBoundsException: 265 at com.bigbaddevil7.rustic.tileentity.TileEntityPrototypingTable.getStackInSlot(TileEntityPrototypingTable.java:34) at net.minecraft.inventory.Slot.getStack(Slot.java:88) at net.minecraft.client.gui.inventory.GuiContainer.func_146977_a(GuiContainer.java:223) at net.minecraft.client.gui.inventory.GuiContainer.drawScreen(GuiContainer.java:118) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1143) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1023) at net.minecraft.client.Minecraft.run(Minecraft.java:910) at net.minecraft.client.main.Main.main(Main.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Here is the code package com.bigbaddevil7.rustic.tileentity; import com.bigbaddevil7.rustic.Rustic; import com.bigbaddevil7.rustic.items.ItemModTool; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; public class TileEntityPrototypingTable extends TileEntity implements ISidedInventory{ private static final int[] slotsHammer = new int[] {0}; private static final int[] slotsPliers = new int[] {0}; private static final int[] slotsScrewdriver = new int[] {0}; private static final int[] slotsWrench = new int[] {0}; private ItemStack[] ProtoItemStacks = new ItemStack[4]; private String localizedName; @Override public int getSizeInventory() { return this.ProtoItemStacks.length; } @Override public ItemStack getStackInSlot(int var1) { return this.ProtoItemStacks[var1]; } @Override public ItemStack decrStackSize(int var1, int var2) { if(this.ProtoItemStacks[var1] != null){ ItemStack itemstack; if(this.ProtoItemStacks[var1].stackSize <= var2){ itemstack = this.ProtoItemStacks[var1]; this.ProtoItemStacks[var1] = null; return itemstack; }else{ itemstack = this.ProtoItemStacks[var1].splitStack(var2); if(this.ProtoItemStacks[var1].stackSize == 0){ this.ProtoItemStacks[var1] = null; } return itemstack; } } else{ return null; } } @Override public ItemStack getStackInSlotOnClosing(int var1) { if(this.ProtoItemStacks[var1] != null){ ItemStack itemstack = this.ProtoItemStacks[var1]; this.ProtoItemStacks[var1] = null; return itemstack; }else{ return null; } } @Override public void setInventorySlotContents(int slot, ItemStack itemstack) { this.ProtoItemStacks[slot] = itemstack; if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){ itemstack.stackSize = this.getInventoryStackLimit(); } } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.localizedName : "container.PrototypingTable"; } @Override public boolean hasCustomInventoryName() { return localizedName != null && this.localizedName.length() > 0; } public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); NBTTagList nbttaglist = nbt.getTagList("Items", 10); this.ProtoItemStacks = new ItemStack[this.getSizeInventory()]; for(int i = 0; i < nbttaglist.tagCount(); ++i){ NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); byte b0 = nbttagcompound1.getByte("slot"); if(b0 >= 0 && b0 < this.ProtoItemStacks.length){ this.ProtoItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } if(nbt.hasKey("CustomName", ){ this.localizedName = nbt.getString("CustomeName"); } } public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); NBTTagList nbttaglist = new NBTTagList(); for(int i = 0; i < this.ProtoItemStacks.length; ++i){ if(this.ProtoItemStacks[i] != null){ NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.ProtoItemStacks[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbt.setTag("Items", nbttaglist); if(this.hasCustomInventoryName()){ nbt.setString("CustomName", this.localizedName); } } public void setGuiDisplayName(String name){ this.localizedName = name; } @Override public int getInventoryStackLimit() { return 1; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false: player.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { // TODO Auto-generated method stub } @Override public void closeInventory() { // TODO Auto-generated method stub } @Override public boolean isItemValidForSlot(int slot, ItemStack itemstack) { Item item = itemstack.getItem(); for(int i = 0; i < this.ProtoItemStacks.length; i ++){ if(slot == i && (item instanceof ItemModTool)){ return true; } } return false; } @Override public int[] getAccessibleSlotsFromSide(int var1) { // TODO Auto-generated method stub return null; } @Override public boolean canInsertItem(int var1, ItemStack var2, int var3) { // TODO Auto-generated method stub return false; } @Override public boolean canExtractItem(int var1, ItemStack var2, int var3) { // TODO Auto-generated method stub return false; } }
June 17, 201411 yr Author package com.bigbaddevil7.rustic.container; import com.bigbaddevil7.rustic.Rustic; import com.bigbaddevil7.rustic.crafting.PrototypingTableCraftingManager; import com.bigbaddevil7.rustic.tileentity.TileEntityCookStove; import com.bigbaddevil7.rustic.tileentity.TileEntityPrototypingTable; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ContainerPrototypingTable extends Container { public InventoryCrafting craftMatrix; public IInventory craftResult; private World worldObj; private int posX, posY, posZ; public ContainerPrototypingTable(InventoryPlayer invPlayer, TileEntityPrototypingTable entity){ craftMatrix = new InventoryCrafting(this,5 ,5); craftResult = new InventoryCraftResult(); /*worldObj = world; posX = x; posY = y; posZ = z;*/ this.addSlotToContainer(new SlotCrafting(invPlayer.player, craftMatrix, craftResult, 0, 141, 11)); this.addSlotToContainer(new Slot(entity, 265, 115, 43)); this.addSlotToContainer(new Slot(entity, 266, 115, 79)); this.addSlotToContainer(new Slot(entity, 267, 151, 43)); this.addSlotToContainer(new Slot(entity, 268, 151, 79)); for(int i = 0; i < 5; i++){ for(int k = 0; k < 5; k++){ this.addSlotToContainer(new Slot(craftMatrix, k + i * 5, 8 + k * 18, 7 + i * 18)); } } for(int i = 0; i < 3; i++){ for(int k = 0; k < 9; k++){ this.addSlotToContainer(new Slot(invPlayer, k + i * 9 + 9, 8 + k * 18, 106 + i * 18)); } } for(int i = 0; i < 9; i++){ this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 164)); } onCraftMatrixChanged(craftMatrix); } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 == 0) { if (!this.mergeItemStack(itemstack1, 10, 46, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 >= 10 && par2 < 37) { if (!this.mergeItemStack(itemstack1, 37, 46, false)) { return null; } } else if (par2 >= 37 && par2 < 46) { if (!this.mergeItemStack(itemstack1, 10, 37, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 10, 46, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(par1EntityPlayer, itemstack1); } return itemstack; } public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); if (!this.worldObj.isRemote) { for (int i = 0; i < 25; ++i) { ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); if (itemstack != null) { par1EntityPlayer.dropPlayerItemWithRandomChoice(itemstack, false); } } } } public void onCraftMatrixChanged(IInventory inventory){ craftResult.setInventorySlotContents(0, PrototypingTableCraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj)); } @Override public boolean canInteractWith(EntityPlayer player) { if(worldObj.getBlock(posX, posY, posZ) != Rustic.prototypingTable){ return false; }else{ return player.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64.0D; } } }
June 17, 201411 yr Author Yea, ok I feel dumb as hell. For some reason I thought I had to add to the others and.... yea... I got that fix, but now I am getting a null pointer. I can't wait for class to start up again so I know more of what I'm doing. Anyways, the error is as follows. java.lang.NullPointerException: Ticking player at com.bigbaddevil7.rustic.container.ContainerPrototypingTable.canInteractWith(ContainerPrototypingTable.java:143) at net.minecraftforge.event.entity.player.PlayerOpenContainerEvent.<init>(PlayerOpenContainerEvent.java:27) at net.minecraftforge.common.ForgeHooks.canInteractWith(ForgeHooks.java:377) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:344) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:326) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:232) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:716) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:604) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) What is, "Ticking Player"? Does that just have to do with updates to the player?
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.