Started by
Unmiet
on
Topic category: Help with Minecraft modding (Java Edition)
I wanted to make a chestplate, that you wear it, and any mob that gets close to you (if you are using the chestplate) the mob despawns, but no matter what I do, I can't do it right, if anyone knows how do this, help me pls
Edited by Unmiet on Wed, 04/03/2024 - 22:40
There are a couple ways to do this, depends on how specifically you want it to work. The easiest would probably be to make an 'on armor tick' or 'on player tick update' procedure that checks if a living entity exists in a 16-block radius or so, and if it does, despawns the nearest entity. (You can do this using the 'does entity of type X exist in X block radius' function, and the 'nearest entity of type X in X block radius' function.) It is VERY IMPORTANT you use an if bracket to check that an entity exists before attempting to despawn it, otherwise this procedure will crash the game.
Another method would be to use an entity iterator bracket to check every entity nearby. Essentially, the bracket lets you run a procedure on every entity within its radius. Inside the bracket, check if the entity iterator, (the currently selected entity in the radius), meets your criteria, and if it does, despawn it. This is generally the better method, as it lets you be more specific about the conditions for your procedure.
I did this, and technically it's working, but particles don't appear, nor does it make the noise I set it to make when the mob gets close to me, but the mob is despawning, but the mob's model is visible, the model only disappears when I leave the server and log in again