Posted June 14, 201411 yr Alright, I'm new here, so please don't spam hate comments directly at my face Anyway, I would like to right click this specific item, and it will repair everything that has durability in my inventory. Right now I have this code, but I can't really figure out why it crashes Minecraft upon usage: public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) { for (int i=player.inventory.getSizeInventory(); i > -1; i++) { if (player.inventory.getStackInSlot(i) != null) { player.inventory.getStackInSlot(i).setItemDamage(0); } } return is; } and the crash: 2014-06-14 22:43:18 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Ticking memory connection 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:63) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:583) 2014-06-14 22:43:18 [iNFO] [sTDERR] Caused by: java.lang.ArrayIndexOutOfBoundsException: 4 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.entity.player.InventoryPlayer.getStackInSlot(InventoryPlayer.java:658) 2014-06-14 22:43:18 [iNFO] [sTDERR] at mod.enhancer.RepairMedal.onItemRightClick(RepairMedal.java:25) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:177) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.item.ItemInWorldManager.tryUseItem(ItemInWorldManager.java:358) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.handlePlace(NetServerHandler.java:542) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.packet.Packet15Place.processPacket(Packet15Place.java:58) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) 2014-06-14 22:43:18 [iNFO] [sTDERR] at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) 2014-06-14 22:43:18 [iNFO] [sTDERR] ... 6 more Upon close inspection, this line is the cause of error if (player.inventory.getStackInSlot(i) != null) Thanks for reading, hope you will help I am newbie in Java
June 14, 201411 yr for (int i=player.inventory.getSizeInventory(); i > -1; i++) For loops don't work like this. You need to start integer i at 0, check if it's less then getSizeInventory and then you increment i. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
June 15, 201411 yr Author for (int i=player.inventory.getSizeInventory(); i > -1; i++) For loops don't work like this. You need to start integer i at 0, check if it's less then getSizeInventory and then you increment i. So, I changed the code to the following: for (int i=0; i < player.inventory.getSizeInventory(); i++) ... and it worked! Thanks for your help I am newbie in Java
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.