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

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 :P

I am newbie in Java

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/

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

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.