#The best way to stop players from breaking blocks in a area?
1 messages · Page 1 of 1 (latest)
You could just every tick see whether a person was within a region and give them mining fatigue for 5 ticks, giving it to them every tick if they are within the region and 5 ticks later the effect would wear off if the player wasn't in the area. You would have to make the area around 10 blocks larger on all sides though to account for how far inside the area the player can reach outside of the area.
yeah, nah, thats too laggy, and causes problems with crosshairs
too laggy? and what problems would happen with the crosshairs? I believe the mining fatigue effect does nothing to the players screen (other than the small icon). You could use deny blocks
I just tested it, deny blocks work fine. They don't interfere with the players ability to interact with blocks that have a container, and you can't build or place blocks as long as you aren't in creative
For a split sec
Smart idea forgot about the deny
loop every player
get block from view
check to see if its in the range
somehow, disable player breaking block
yes deny blocks work, however what if you want to make a claim system, this would not work
world.events.blockBreak.subscribe(
({ block, brokenBlockPermutation, player, dimension }) => {
dimension.getBlock(block.location).setPermutation(brokenBlockPermutation);
if (BLOCK_CONTAINERS.includes(block.typeId))
system.run(() => {
const container = block.getComponent("inventory").container;
dimension
.getEntitiesAtBlockLocation(block.location)
.filter((e) => e.typeId == "minecraft:item")
.forEach((e) => {
container.addItem(e.getComponent("item").itemStack);
e.kill();
});
});
}
);```
this is what i have rn
it works pretty well however, some times if the item spawns outside the block it will ignore it, (which makes sense)
you could fix the item spawning outside the block and not being killed by using an entity query and .getEntities().
Use the location and maxDistance options and it should be fine. 1.5 would probably be a good value for maxDistance. Also the type option being set to "minecraft:item".
what's the issue with gamemode switching?
?
why not adventure mode
because you would have to test if a player is inside the region, and 10 blocks before the region