Started by
Vladius120
on
Topic category: Help with Minecraft modding (Java Edition)
I have a boss and a condition. I want him to be able to teleport to the nearest player. How can this be done? If possible, attach a photo, please.
Edited by Vladius120 on Tue, 04/22/2025 - 18:37
There is a procedure block that says "For each entity as (entity iterator) at x y z in a square cube with size (4)". Change the 4 for a bigger number that you think would cover the reach of the enemy.
Inside that block, you are going to put "Attempt to make (Event/target entity) find path and move to x y z with speed factor (1)", except that you are going to change the x y and z blocks for "X position of (Entity Iterator)" "Y position of (Entity Iterator)" and "Z position of (Entity Iterator)" respectively. Also change the speed if you want it to move faster.
I think that should do the trick.
I didn't fully understand how it should look and how it would work. It's easy to build a boss and it won't find a way to the player.
I think you just need to put an if block does entity of type (type) exist in a (number) block radius. Set number to 64 and type to player. Then, inside that if block, set location of event/target entity to X: (number) Y: (number) Z: (number)
Replace the number blocks with get X, get Y, and get Z of event/target entity respectively. Then finally replace the event/target entity blocks in the get X, get Y, and get Z with get nearest entity of type (type) in radius (number), again setting type to player and number to 64.
The end result is that you will have a very small procedure that checks if there is a player within 64 blocks (this is needed or the game will crash) and if there is a player, it will set the location of the boss, event/target entity, to the location of the nearest player by replacing the boss's X, Y, and Z coordinates with the player's coordinates.
You will want to set the procedure to run on entity tick update for your boss. You will also probably want some sort of cooldown or other condition to prevent the boss from teleporting 20 times per second and keeping the player basically trapped inside it.
The cooldown isn't necessary though, but here is how it could be implemented.
A possible cooldown mechanic could be done by having another if block that encloses the one that checks if there is a player nearby. Have the new if block's condition set to the does event/target entity have active potion (type), setting the type to luck, and putting a not procedure block before that so that it only runs if the boss doesn't have the luck potion effect. Then, inside that new if block, place an add potion effect to event/target entity of type (type) for duration (number) and amplifier (number). Set the type to luck, the duration to however long you want between teleports in ticks (20 ticks in a second), and the amplifier to 0.
If you want the cooldown to not have green particles around the boss, you could use the alternate apply potion procedure block that allows you to set particles to false.
Finally, you can add a few procedure blocks to display particles and play sounds at X, Y, and Z, and at the player's X, Y, and Z. This is purely cosmetic and not needed at all for the functionality of the boss teleport mechanic, which is why I am not elaborating on how to implement it.
Thank you! It worked!
I'm glad I was able to help