[Feature Request] Add Trinket#getMaxCount(ItemStack stack, SlotReference slot, LivingEntity entity)
Sollace opened this issue ยท 3 comments
Currently all trinket slots are hardcoded to take the maximum stack count for whatever item you put into it. I have items for which I'd actually like these to function like armour slots, but not without losing the ability to stack the item when storing it normally.
i.e. In the case of a glove, though you can stack it up to 64 in a chest, it doesn't make sense to be able to wear more than one on each hand.
This is pretty significantly difficult to implement due to certain vanilla systems. Shift clicking in particular would basically have to be removed in order to properly support items that vary in stack size based on slot.
Um... No?
Armour slots already do this. If I implemented it would you accept a pull request?
You are incorrect, armor slots do not support what you are suggesting. Shift clicking ignores slot max size, and this is the reason that beacons don't support shift clicking, and why brewing stands, the enchantment table, and the player inventory have very specific, custom (sometimes broken) logic for shift clicking. You can easily display a fault by placing a bunch of stacks of 1 glass bottle in the inventory and shift clicking them into a brewing stand, despite the slot only supporting a single item, they'll stack up to 64. You can even use this to get stacks larger than 64 in your cursor.
The reason you can shift click carved pumpkins onto your head is because the vanilla inventory hardcodes a solution for them, it only attempts normal shift click behavior if the slot is empty (this is non standard). This is fine, because transferSlot
works for moving items to empty slots okay, but breaks when combining. This means trinkets could only ever support a max stack size of 1. Simple experiment, set a slot's max count to 2, place a single item in it, and shift click 64 of the item in your inventory, the limited slot will have a full stack in it.
Remedying this properly is non-trivial. Invasively patching the vanilla method is prone to breakage of expectations for other modders beyond what can be anticipated. Reimplementing the method can cause broken compatibility with other mods, and since trinkets is messing with the quick moving of the vanilla inventory, I do not want to poke that.
A more fundamental API problem is that vanilla slots do not support contextual max counts. That is, you cannot have a slot that can hold 2 apples, or 4 sticks. You can only set a max count for the slot. Trying to work around this restriction statefully in hardcoded interactions is extremely prone to breakage.
If you have a clean, well tested, compatible, properly working solution that I have not thought about, by all means, feel free to PR it. Until then, this is an issue that may take a while to solve without compromise due to vanilla limitations.