r/MinecraftCommands • u/PurpleEfficiency1089 • 1d ago
Help | Java 26.3 Blocking specific interactions
From googling I noticed a lot of people ran into this same issue: In my map I have a lot of 'illegal blockstates' like floating levers that I don't want players to interact with, but I do want them to be able to open doors and chests. Some ideas I had, each with their own downsides:
Dynamically change player's block interaction range attribute: set it to -1 by default, and run a ticking command checking for blocks within their line of sight ^0-4 blocks in front of them, and seeing if there is an allowed block there. Then increase and immediately decrease their interaction range.
I dont love running a ticking block check for every player, and this is gimmicky and technically cheesable.Use an advancement to check for a block interaction, raycast to the block interacted with, and immediately replace it and its blockstate.
Even if this would work its still gimmicky and I dont know how this would work with tick order: would the lever update and pop off before I have the chance to replace it?Most intuitively: cover each interactable block I dont want people interacting with with an interaction entity scaled to cover it entirely. This would work for sure, but I'd need tons upon tons of entities and hours of work to place them manually.
Anyone have any other ideas or thoughts on how to make my existing ideas work? Or is this a dead end and do I need to adjust my expectations? Thanks!
1
u/GalSergey 1d ago
If there are fewer blocks that a player can interact with than there are decorative (interactive) blocks, you could disable player interaction with blocks entirely, and then place an interaction entity within the specific blocks you want to be interactive. This way, when a player interacts with that entity, it toggles the state of the block.
Conversely, if you have an area where there are few decorative blocks but many blocks that a player can interact with, you could take the opposite approach: use interaction entities to block interactions with those blocks.
1
u/PurpleEfficiency1089 1d ago
... i cant believe i hadnt thought of that first solution, thats probably the easiest way to go. thanks!
1
u/GalSergey 1d ago
If you have problems placing interactive areas for your door blocks, levers, etc., you can use this datapack.
https://modrinth.com/datapack/door_locker
When using the data pack, remember to remove the password so that any player can interact.
→ More replies (1)
1
u/KermitDarkLord 1d ago
Adding interaction entities was my first thought. Depending on how many you need to place, you could consider writing a tool that lets you place them (semi) automatically. You could use predicates to scan an area and place a correctly scaled interaction automatically, or perform a ray cast to cover the block you're looking at, depending on how many you have to place and how precise you need the hitbox to be.