[SPIGOT-4718] Can not create Inventory with an custom size Created: 23/Apr/19  Updated: 28/Jun/19  Resolved: 24/Apr/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: derNiklaas Assignee: Unassigned
Resolution: Fixed Votes: 3
Labels: 1.14
Environment:

OS: Linux, openjdk version "1.8.0_191"


Attachments: File SpigotSutff.jar    
Issue Links:
Duplicate
is duplicated by SPIGOT-4719 Broken custom chest inventory Resolved
is duplicated by SPIGOT-4728 player.openInventory(player.getEnderC... Resolved
Version: git-Spigot-6dbf995-0ec9b61
Guidelines Read: Yes

 Description   

You can not create an Inventory with an custom size.

Source Code: https://hastebin.com/tiqoqazuxa.java

The JavaDocs mentions that you can use multiples of nine: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html#createInventory-org.bukkit.inventory.InventoryHolder-int-java.lang.String-

but only 27 and 54 works

Error: 
java.lang.IllegalArgumentException: Container size 18 is smaller than expected 27
at net.minecraft.server.v1_14_R1.Container.a(Container.java:80) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.ContainerChest.<init>(ContainerChest.java:74) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer.setupSlots(CraftContainer.java:171) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer.<init>(CraftContainer.java:53) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.inventory.CraftContainer.<init>(CraftContainer.java:82) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity.openCustomInventory(CraftHumanEntity.java:451) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:336) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at de.derniklaas.spigot.Spigot.onEnable(Spigot.java:15) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:346) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:408) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:458) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:372) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:805) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.Bukkit.reload(Bukkit.java:576) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:145) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:707) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.PlayerConnection.handleCommand(PlayerConnection.java:1667) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.PlayerConnection.a(PlayerConnection.java:1507) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:13) ~[server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.TickTask.run(SourceFile:18) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.h(SourceFile:135) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandlerReentrant.h(SourceFile:23) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.p(SourceFile:114) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.MinecraftServer.aW(MinecraftServer.java:876) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.MinecraftServer.p(MinecraftServer.java:869) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.IAsyncTaskHandler.c(SourceFile:123) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.MinecraftServer.sleepForTick(MinecraftServer.java:853) [server.jar:git-Spigot-6dbf995-0ec9b61]
at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:793) [server.jar:git-Spigot-6dbf995-0ec9b61]



 Comments   
Comment by detig_iii [ 28/Jun/19 ]

@md_5 Could you maybe state how we're going to handle custom inventories in the future? As of now it is impossible to create anything outside of the 9x3 size (SPIGOT-4719 describes what happens if you try 9x6). Reason for that is in the code @Nassim posted.

Comment by detig_iii [ 15/Jun/19 ]

So does this mean we can no longer create inventories with sizes other than 27 or 54?

 

Comment by derNiklaas [ 23/Apr/19 ]

Oh, I am just dumb. Sorry xD

Comment by Nassim [ 23/Apr/19 ]

Didn't think I had to specifically mention it, but take a look 2 lines above the one I sent, then you'll find the problem, too 👀

Comment by derNiklaas [ 23/Apr/19 ]

@Nassim: The default type of an Inventory created by Bukkit#createInventory(InventoryHolder,int,String) is a chest, not a barrel. It should trigger https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java#225 because no delegate should be defined.

Comment by Nassim [ 23/Apr/19 ]

Found the problem, https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java#171 is always setting 3 rows for any type of chests, resulting in the error.

Comment by Jocke155 [ 23/Apr/19 ]

I can confirm that also size 0 no longer works. In 1.13.2 having an inventory with size 0 resulted in no slots in the top inventory, but still possible to to access the InventoryHolder and Title, this was very useful for selecting items in the players inventory etc.

Generated at Fri Mar 14 17:31:30 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.