Check the result of slotClick
Guichaguri opened this issue ยท 6 comments
Minecraft Version: 1.11.2
Inventory Tweaks Version: 1.62+beta.84
Currently, InventoryTweaks just crashes when a slotClick
doesn't do its expected work.
My mod returns an empty item in slotClick
when it needs to prevent a slot from being moved. It works fine in vanilla, but not with InventoryTweaks shortcuts. I don't know if I'm not doing it in "the right way", so let me know if this is not an InvTweaks issue and what would be the right way to prevent an item from being moved.
I think this can be fixed by checking the result of Container.slotClick
and PlayerControllerMP.windowClick
in ClientProxy.slotClick and ignoring it instead of just crashing
Most mods I know of that want to prevent interaction make custom slots that return false
from getStack()
and isItemValid()
(if you also want to prevent placing new items into it -- the only reason I can think of to not is some sort of trashcan-type thing), then do some rendering bits to show the item there anyway.
This would be more friendly to other mods than your current method, since instead of actually preventing movement it's saying 'there is no item in this slot and no item is allowed to go here'
That would definitely work, the problem is that I don't know about custom slots, I wanted it to work on everything without having to patch every custom slot implementation, but I guess there is no reason to implement a custom slot if it's not for a special behavior that I shouldn't be messing with anyway
I think I'll roll with that for now. I'll do some testing and if custom slots become a problem, I can keep the old method just for them.
Thanks for the suggestion :)
It still didn't solve the issue. The mod is client-side, handling those slot methods in the client without the slotClick
just makes items desync, they're still movable. I can't find any other solution.
Edit: I think I can use the slot methods when the mod is present in both client and server (which would be the most likely for modpacks) and I can use slotClick
when the mod is only present in the client (which would be the most likely for vanilla servers). This certainly helps with mod compatibility, but InvTweaks also works client-side, which would crash.
You cannot lock the slots client-side only.
Even if I 'fixed' that crash all that'd happen is they move the next server refresh anyway, because they're getting moved on the server
I'll add a response to your edit: Overriding slotClick
doesn't work right even on a normal client: It'll send the packet to the server anyway, which will run slotClick
there (without your changes), and if the two return values from slotClick
do not match, will go and send a full inventory refresh to the client because they're obviously desynced.
Sorry, I meant windowClick
from PlayerControllerMP
, which actually prevents the packet from being sent.
windowClick
returns the result of slotClick
, so they're basically the same but windowClick
sends a packet. In your ClientProxy.slotClick, you actually use that to send your own packet instead of the vanilla one.
I'm currently patching both, even though the patch to slotClick
doesn't do anything in vanilla