Posted December 19, 20159 yr How to make more than 45 slots in the gui? crash package com.svk.generateChests.Tile; import java.util.ArrayList; import com.svk.generateChests.base.CommonProxy; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; 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; public class TileGenerateChest extends TileEntity implements IInventory { public ItemStack[] slots = new ItemStack[60]; public int[] procentSlot = null; public boolean setGen = false; public String customName = null; public TileGenerateChest(){} public void updateEntity() { super.updateEntity(); } public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList nbttaglist = nbt.getTagList("Items", 10); this.slots = new ItemStack[this.getSizeInventory()]; if (nbt.hasKey("CustomName", ) { this.customName = nbt.getString("CustomName"); } for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound1.getByte("Slot") & 255; if (j >= 0 && j < this.slots.length) { this.slots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1); } } this.procentSlot = nbt.getIntArray("procentSlots"); this.setGen = nbt.getBoolean("setGen"); } public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.slots.length; ++i) { if (this.slots[i] != null) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setByte("Slot", (byte)i); this.slots[i].writeToNBT(nbttagcompound1); nbttaglist.appendTag(nbttagcompound1); } } nbt.setTag("Items", nbttaglist); if (this.hasCustomInventoryName()) { nbt.setString("CustomName", this.customName); } nbt.setIntArray("procentSlots", this.procentSlot); nbt.setBoolean("setGen",this.setGen); } public int getSizeInventory() { return 60; } @Override public ItemStack getStackInSlot(int i) { return this.slots[i]; } public ItemStack decrStackSize(int i, int j) { if(this.slots[i] != null) { ItemStack itemstack; if(this.slots[i].stackSize < j) { itemstack = this.slots[i]; this.slots[i] = null; return itemstack; } else { itemstack = this.slots[i].splitStack(j); if(this.slots[i].stackSize == 0) { this.slots[i] = null; } return itemstack; } } return null; } public ItemStack getStackInSlotOnClosing(int i) { if(this.slots[i] != null) { ItemStack itemstack = this.slots[i]; this.slots[i] = null; return itemstack; } return null; } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { this.slots[i] = itemstack; if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) { itemstack.stackSize = this.getInventoryStackLimit(); } } public void setInventoryName(String string) { } public String getInventoryName() { return "CustomName"; } @Override public boolean hasCustomInventoryName() { return true; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { return false; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int slot, ItemStack itemStack) { if(slots[slot] != null) { return true; } else { return false; } } } package com.svk.generateChests.GUI.container; import java.util.ArrayList; import java.util.Random; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import com.svk.generateChests.Tile.TileGenerateChest; import com.svk.generateChests.base.BaseClassMod; import com.svk.generateChests.base.CommonProxy; import com.svk.generateChests.packets.PacketsID; import com.svk.generateChests.util.UtilPackerDataSet; public class ContainerEditGenerateChest extends Container { public ContainerEditGenerateChest(InventoryPlayer inventoryPlayer, TileGenerateChest tileChest) { tileChest.openInventory(); this.addCustomSlots(tileChest); this.addPlayerSlots(inventoryPlayer); } public void addCustomSlots(TileGenerateChest chest) { for(int i = 0; i < 8; i++) { this.addSlotToContainer(new Slot(chest, i, 8, 12 + 18*i)); this.addSlotToContainer(new Slot(chest, i + 8, 53, 12 + 18*i)); } } public void addPlayerSlots(InventoryPlayer inventoryPlayer) { for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+18*j, 166+i*18)); } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 224)); } } public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) { return null; } @Override public boolean canInteractWith(EntityPlayer p_75145_1_) { return true; } }
December 19, 20159 yr Author If you have a crash, post it. There is no arbitrary limitation on the number of slots you can have. Sorry, I forgot java.lang.IndexOutOfBoundsException: Index: 45, Size: 45 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source) at net.minecraft.inventory.Container.getSlot(Container.java:130) at net.minecraft.inventory.Container.putStacksInSlots(Container.java:558) at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1197) at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:70) at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:78) at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) 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(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:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
December 20, 20159 yr If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 20, 20159 yr Author If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. Inside the chest is more than 45 slots. 4x9 player's inventory and 6x3 inventory chest ...
December 20, 20159 yr Author Show where you open the GUI (most likely your block). Does it matter? if(world.isRemote) { return false; } else { player.openGui(BaseClassMod.instance, GuiID.guiGenerateChest, world, x, y, z); return true; }
December 20, 20159 yr If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. Inside the chest is more than 45 slots. 4x9 player's inventory and 6x3 inventory chest ... And two of those have Slot #0. Slot #0 (player's inventory) and Slot #0 (chest inventory). for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+18*j, 166+i*18)); // "9+j+i*9" why is there a +9 here? } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 224)); // "8 + i * 18" why is there a +9 here? } 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.
December 20, 20159 yr Author If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. Inside the chest is more than 45 slots. 4x9 player's inventory and 6x3 inventory chest ... And two of those have Slot #0. Slot #0 (player's inventory) and Slot #0 (chest inventory). for(int j = 0; j < 9; j++) { this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+18*j, 166+i*18)); // "9+j+i*9" why is there a +9 here? } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 224)); // "8 + i * 18" why is there a +9 here? } I corrected, but still crash package com.svk.generateChests.GUI.container; import java.util.ArrayList; import java.util.Random; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import com.svk.generateChests.Tile.TileGenerateChest; import com.svk.generateChests.base.BaseClassMod; import com.svk.generateChests.base.CommonProxy; import com.svk.generateChests.packets.PacketsID; import com.svk.generateChests.util.UtilPackerDataSet; public class ContainerEditGenerateChest extends Container { private TileGenerateChest table; private EntityPlayer player; public ContainerEditGenerateChest(InventoryPlayer inventoryPlayer, TileGenerateChest table) { this.table = table; table.openInventory(); player = inventoryPlayer.player; this.addPlayersSlots(inventoryPlayer); this.addChestSlots(table); } public void addPlayersSlots(InventoryPlayer inventoryPlayer) { for(int i = 0; i < 9; i++) { addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 224)); } for(int i = 0;i < 3; i++) { for(int j = 0; j < 9;j++) { addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+18*j, 166+i*18)); } } } public void addChestSlots(TileGenerateChest table) { for(int i = 0; i < 8; i++) { addSlotToContainer(new Slot(table, i, 8, 12 + 18*i)); addSlotToContainer(new Slot(table, i + 8, 53, 12 + 18*i)); } } @Override public void onContainerClosed(EntityPlayer p_75134_1_) { table.closeInventory(); } public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_) { return null; } @Override public boolean canInteractWith(EntityPlayer p_75145_1_) { return true; } }
December 20, 20159 yr If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. Inside the chest is more than 45 slots. 4x9 player's inventory and 6x3 inventory chest ... Are you saying you are storing the players inventory in your chest? I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 20, 20159 yr Author If you have an array of 45 slots, you cannot access slot 45 as there is no slot called that. The highest slot number is 44 as the first slot number is 0. Inside the chest is more than 45 slots. 4x9 player's inventory and 6x3 inventory chest ... Are you saying you are storing the players inventory in your chest? What? I add slots players, and they are stored in the player's inventory? this.addSlotToContainer(new Slot(inventoryPlayer, 9+j+i*9, 8+18*j, 166+i*18)); And I add slots chest in the chest this.addSlotToContainer(new Slot(chest, i, 8, 12 + 18*i)); I wrote an example that keeps the chest more than 45 slots
December 20, 20159 yr Author - You have to call super.initGui if you override it. - If you override mouseClicked to do nothing the inventory part of your GUI will be non-functional. Same with keyTyped. - What the hell is that packet sending stuff there? - You showed your GuiContainer, not your IGuiHandler. Oh, wrong: D Where comments I hidden code I have delivered the packages to save the settings on the server that are in gui. package com.svk.generateChests.base; import com.svk.generateChests.GUI.GuiEditGenerateChest; import com.svk.generateChests.GUI.container.ContainerEditGenerateChest; import com.svk.generateChests.Tile.TileGenerateChest; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileentity = world.getTileEntity(x, y, z); switch(ID) { case GuiID.guiGenerateChest: return new ContainerEditGenerateChest(player.inventory, (TileGenerateChest) tileentity); } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity tileentity = world.getTileEntity(x, y, z); switch(ID) { case GuiID.guiGenerateChest: return new GuiEditGenerateChest(player.inventory, (TileGenerateChest) tileentity); } return null; } }
December 20, 20159 yr Why do you store 60 slots in your TileEntity when you only add 16 in your Container? I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.
December 20, 20159 yr Author Why do you store 60 slots in your TileEntity when you only add 16 in your Container? just in case ... Right now I try 16
December 20, 20159 yr Author Oh, wrong: DWhat is wrong? Have you fixed these issues? The first one is most likely your problem. that the first? P.S. "Google Translate"
December 20, 20159 yr Author - You have to call super.initGui if you override it. - If you override mouseClicked to do nothing the inventory part of your GUI will be non-functional. Same with keyTyped. - What the hell is that packet sending stuff there? - You showed your GuiContainer, not your IGuiHandler. Thank you so much!!! I killed 2 days on this problem!
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.