DasHomi / preventer

A mod that prevents you from doing dumb things
https://modrinth.com/mod/preventer
MIT License
10 stars 6 forks source link

Disabling firework usage prevents interaction with chests, crafting tables, etc. #15

Closed Encrypted-Thoughts closed 1 year ago

Encrypted-Thoughts commented 1 year ago

Noticed that if I hold rockets in my off hand and try to interact with any block it seems to be prevented if rocket usage is disabled.

This PR changes the prevent rocket use setting to check the current hand and item in that hand before disabling interacting with the block.

DasHomi commented 1 year ago

Thanks, I didn't even notice that bug. But with your changes, now I can't open a chest with a rocket in the main hand if the "prevent rocket use" module for the main hand enabled (at least in my tests).

Encrypted-Thoughts commented 1 year ago

hmm yeah you're right, when it's in the mainhand it winds up just seeing "oh you have fireworks in the hand you're using lets stop here" whereas when it's in the offhand it sees you're not actually using the fireworks yet so it gives it a chance to open the chest before trying the offhand and shortcircuiting...

Not sure how you solve that without either maintaining a list of target blocks not to disable or making an event that doesn't just trigger at the top of interactBlock like the built in fabric one? What do you think? I may play with seeing what other options there are for mixing in for an event.

Ah think I might see some of the problem with mixing in elsewhere now and keeping it client side only. It short circuits client side before sending packets to the server based solely on what's in your hand so I don't think you can really tell client side if it would have been successful for any random block since the server determines that?

I'm just going to check the targeted block for the moment unless you have a better idea?

Encrypted-Thoughts commented 1 year ago

Feel like I've almost certainly missed some interactive block in the list to check. Might be a better way but I can't think of an obvious solution at the moment without getting into serverside mod territory. Off hand rockets will still work better since it doesn't need to check this list.

DasHomi commented 1 year ago

Yeah I can't realy think of an easier way if there isn't some fabric function that checks if you can interact with blocks, but i guess if it works it works.

Encrypted-Thoughts commented 1 year ago

played with it some more and think this might work better? realized if you check and make sure you're client side it seems to be ok to just call onUse on the targeted block and check the ActionResult returned instead of having to maintain a list of blocks. Did make eating cake and using repeaters look a bit wonky though so I left in checks for them just so they would look normal.

DasHomi commented 1 year ago

Ok, i just testet it and it seems to be working perfectly. So can i merge it?

Encrypted-Thoughts commented 1 year ago

Sure, I can't think of any better way to do it. Think this should work for vanilla blocks and most modded blocks.

When using main hand rockets there might be some weirdness with modded blocks that change appearance or make sounds client side onUse like repeaters do, but I'm not really sure how to account for that other than to let whoever finds it submit a compatability request and then to potentially add a check for whatever block id it is to canInteractWithBlock.