The item stacks used internally in the loot-tables allow users to specify their count greater than their max_stack_size
. This is actually normal, because at the end of the loot-table execution, these "overstacked" items will be split into multiple item stacks to fit their max_stack_size
. This behavior can be tested with this command.
/loot give @s loot {pools:[{rolls:1,entries:[{type:item,name:snowball,functions:[{function:set_count,count:64}]}]}]}
You specified 64 as the number of snowballs, which is greater than the max_stack_size
of 16 for snowballs, but it works fine, and you get 4 stacks of 16 snowballs.
The problem is, this "overstacking" behavior does not seem to be supported when changing max_stack_size
with set_components
item modifier, and it fails to change its max_stack_size
. Compared to the above, this seems unintentional.
/loot give @s loot {pools:[{rolls:1,entries:[{type:item,name:snowball,functions:[{function:set_count,count:64},{function:set_components,components:{max_stack_size:32}}]}]}]}
You tried to change the max_stack_size
to 32, but it didn't work, and you get 4 stacks of 16 snowballs again.
Here's the error message from the log.
Failed to apply component patch '{minecraft:max_stack_size=>32}' to item: 'Item stack with stack size of 64 was larger than maximum: 32'
Comments 5
You can reproduce it with just the commands in the description, the loot tables are defined inline.
Open a singleplayer world with cheats allowed and run the commands in chat. When you run the latter command, you'll see the set_components function fail to apply (expected to get 2 stacks of 32 snowballs, but instead got 4 stacks of 16 snowballs) and the error in the log.
Apologies for the confusion; I hadn't noticed the loot tables were inlined into the commands. After testing this issue myself, it seems that when you put the set_count
function after the set_components
function, the command does give you two stacks of 32 snowballs. This behavior matches what was described in MC-270134, so I believe this issue duplicates MC-270134.
I was a bit confused after reading that report, but I think I understand the difference between these bugs, so let me clarify.
It seems like MC-270134 is describing that set_count function does not allow overstacked items, and my report (MC-277803) is describing that set_components function does not allow overstacked items. The commands in MC-270134 are actually working fine in current release (1.21.3), so the set_count issue is fixed now, but the same issue is still present in set_components function.
I see that changing the order of the functions fixes this as well, but there are cases where you can't change the order, like this command.
/loot give @s loot {pools:[{rolls:1,entries:[{type:loot_table,value:"blocks/redstone_ore",functions:[{function:set_components,components:{max_stack_size:1}}]}]}]}
So I think this could be considered a valid bug.
Please attach a minimal setup data pack that can be used to reproduce this issue.