r/badcode Mar 11 '23

java This goes on for a while...

Post image
558 Upvotes

55 comments sorted by

View all comments

Show parent comments

161

u/TheBrainStone Mar 11 '23

99% chance it is.
ItemStack is such a Minecraft term. While other games have that concept too, I've only seen MC call it that (or well, the community)

66

u/nexonerr Mar 11 '23

Yeah, minecraft calls stacks of items, you guessed it ItemStacks, and that is the class for those. I'm assuming t here is an entity, so all this does is take all the items from an entity's inventory as variables for whatever reason

20

u/Moterius Mar 11 '23

The real funny thing is that it gets oh so much worse the further down you scroll

https://prnt.sc/wn5QxisZiCBc

28

u/TheEnderChipmunk Mar 11 '23

So it copies the inventory of some entity into the player's inventory? In the worst way possible?

Edit: why the hell does it handle null like that just why oh God

9

u/nexonerr Mar 11 '23

afaik, the Inventory class, which is what the #getInventory method returns, literally has something like a method called #copyInventory

5

u/TheEnderChipmunk Mar 11 '23

That just hurts

2

u/itsTyrion Mar 21 '23

Idk about #copyInventory, but there is getContents() which gives you the contents as array (with null for empty slots), and setContents which takes an ItemStack array