4
Best way to freeze a player/mob in place
I am currently making a datapack, where a tool can make any mob or player freeze in place unable to move or escape.
I originally made an armor stand spawn in the entity's place and execute a command every tick that teleported the tagged "frozen" entity to this armor stand. This proved to work very well. Every mob I tested this on got not only frozen in it's curent position, but they also got frozen mid-air!
However, when I tried this datapack on my multiplayer server, players could easily just walk away from being frozen, which broke the loop and unfroze them. My current theory is that there are way too many other datapacks running on this server every tick, making the function to teleport them unreliable.
Now I'm trying to think of a better option to freeze them both in-place AND hopefully mid-air. It should work more reliably than the teleport function, so it has to execute once and not every tick.
I'm not sure if that's possible so here are my current ideas of options:
I originally made an armor stand spawn in the entity's place and execute a command every tick that teleported the tagged "frozen" entity to this armor stand. This proved to work very well. Every mob I tested this on got not only frozen in it's curent position, but they also got frozen mid-air!
However, when I tried this datapack on my multiplayer server, players could easily just walk away from being frozen, which broke the loop and unfroze them. My current theory is that there are way too many other datapacks running on this server every tick, making the function to teleport them unreliable.
Now I'm trying to think of a better option to freeze them both in-place AND hopefully mid-air. It should work more reliably than the teleport function, so it has to execute once and not every tick.
I'm not sure if that's possible so here are my current ideas of options:
- Give the entity extreme slowness and jump-boost lvl 128, which makes anything unable to jump (but this way things won't ever freeze mid-air)
- Stick to the armor stand method and make mobs freeze mid-air, but players get an exception and intentionally don't freeze mid-air
- Setblock a barrier block under the frozen entity and give it slowness like in Option 1, but then I need a reliable way to delete this barrier block
- Setblock a cobweb into the frozen entity and use the armor stand method, but then replace back any non-hitbox block that the entity was standing in (which I have no idea how to do)
Create an account or sign in to comment.
5
3
For any entity except players you can just remove their AI and gravity to freeze them and give it back, to make the move again.
Freeze nearest non-player entity:
tag @e[limit=1,sort=nearest,type=!minecraft:player] add frozen
data merge entity @e[tag=frozen] {NoAI:1b,NoGravity:1b}
Unfreeze nearest non-player entity with tag frozen:
data merge entity @e[limit=1,sort=nearest,tag=frozen,type=!minecraft:player] {NoAI:0b,NoGravity:0b}
tag @e[limit=1,sort=nearest] remove frozen
This is way more efficient, because you only need to execute the commands once when an entity is frozen/unfrozen and not permanently, like in your example. NOTE: If someone summons an entity with {NoAI:1b} or {NoGravity:1b}, that entity would still regain AI/Gravity after being frozen and then unfrozen with my method. That is something you might have to consider.
Since player data can't be modified with /data there is no really good way for players to be frozen. There are multiple methods, which all have disadvantages (if you are interested, 3 of them are explained in this youtube video) and I personally think you should just use the one you also suggested with slowness/jumpboost. Freezing the player mid-air is just not worth the very high amount of effort you'd need to put in, if teleportation is not reliable.
Freeze nearest non-player entity:
tag @e[limit=1,sort=nearest,type=!minecraft:player] add frozen
data merge entity @e[tag=frozen] {NoAI:1b,NoGravity:1b}
Unfreeze nearest non-player entity with tag frozen:
data merge entity @e[limit=1,sort=nearest,tag=frozen,type=!minecraft:player] {NoAI:0b,NoGravity:0b}
tag @e[limit=1,sort=nearest] remove frozen
This is way more efficient, because you only need to execute the commands once when an entity is frozen/unfrozen and not permanently, like in your example. NOTE: If someone summons an entity with {NoAI:1b} or {NoGravity:1b}, that entity would still regain AI/Gravity after being frozen and then unfrozen with my method. That is something you might have to consider.
Since player data can't be modified with /data there is no really good way for players to be frozen. There are multiple methods, which all have disadvantages (if you are interested, 3 of them are explained in this youtube video) and I personally think you should just use the one you also suggested with slowness/jumpboost. Freezing the player mid-air is just not worth the very high amount of effort you'd need to put in, if teleportation is not reliable.
2
Once again you blew my mind. Thanks, this has helped me immensely.
3
For players, have you considered changing their gamemode to specator then forcing them to spectate an armorstand?
2
I have but sadly that's not what I'm looking for. I need them to stay vulnerable and visible to others.
1
you could just give the an extreme slowness effect, it would easily work on players and mobs.