How to give a certain mob levitation if it is in a 6-block radius?
(I have the scoreboard set up, use "Levi" for it in comments)
Example: I hold a stick. All creepers in a 6 block radius around would get Levitation until I stop holding the diamond or (Optional) they leave the 6-block vicinity.
I want to hold an item, give the set mob type mobs in my radius Levitation, but only in that radius.
Help is very much appreciated! :)
Best Answer
First, create a new scoreboard objective:
/scoreboard objectives add holdingItem dummy
The following commands should be placed in Repeat Always Active comand blocks:
To track players holding your preferred item (I'll assume it's a diamond) you need to give all players holding a diamond a
holdingItemscore of one:/scoreboard players set @a holdingItem 1 {SelectedItem:{id:"minecraft:diamond"}}You'll need to reset the score every tick, so the Creeper doesn't go flying every time you get close:
/scoreboard players set @a holdingItem 0Now, all you have to do is execute the command for all creepers around any player with a
holdingItemscore of 1:/execute @a[score_holdingItem_min=1] ~ ~ ~ /effect @e[type=Creeper,r=6] minecraft:levitation 1
TL;DR Edit: One-command version
Copy-paste this simplified command into a regular impulse command block and run:
/summon minecraft:falling_block ~ ~1 ~ {Block:command_block,Time:1,TileEntityData:{Command:/scoreboard objectives add holdingItem dummy},Passengers:[{id:minecraft:falling_block,Block:repeating_command_block,Time:1,TileEntityData:{Command:/scoreboard players set @a holdingItem 1 {SelectedItem:{id:"minecraft:diamond"}}},Passengers:[{id:minecraft:falling_block,Block:repeating_command_block,Time:1,TileEntityData:{Command:/execute @a[score_holdingItem_min=1] ~ ~ ~ /effect @e[type=Creeper,r=6] minecraft:levitation 1},Passengers:[{id:minecraft:falling_block,Block:repeating_command_block,Time:1,TileEntityData:{Command:/scoreboard players set @a holdingItem 0},Passengers:[{id:minecraft:falling_block,Block:command_block,Time:1,TileEntityData:{Command:/fill ~ ~-5 ~-1 ~ ~1 ~-1 redstone_block},Passengers:[{id:minecraft:falling_block,Block:redstone_block,Time:1}]}]}]}]}]}
It will throw a few command blocks above it (one impulse, then 3 repeat, then 1 impulse). To stop it, destroy all the command blocks.
Pictures about "How to give a certain mob levitation if it is in a 6-block radius?"



How do you give specific entities in a specific radius a potion effect?
First off, use the procedure Execute Command / [Command] at x: [x] y: [y] z: [z]. Here are some examples of commands, you can use. This command gives every entity in a 15 block radius poison level 1 for 10 seconds. This command gives every entity except players in a 20 block radius regeneration level 2 for 15 seconds.How to Make Mobs Named Dinnerbone Fly | 1.17.1 Command Blocks Java
More answers regarding how to give a certain mob levitation if it is in a 6-block radius?
Answer 2
Use /effect to add the levitation effect to mob and use @e[r=6] to seelct all entities in radius of 6 to add the effect.
So, /effect @e[r=6] minecraft:levitation 1 in a repeat command block would work giving all entities in the radius of 6.
If you want to that players are exluded, you should use @e[type=!Player,r=6] instead of @e[r=6].
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Valentin Antonucci, Pixabay, Taryn Elliott, 熊大 旅遊趣
