Started by
fleWaf
on
Topic category: Help with Minecraft modding (Java Edition)
I want to make a mob that attacks the player after 5 seconds of being near it (7 blocks, and also play a sound of being detected). I tried using procedures, conditions, and so on, but nothing really worked. Any ideas?
You'll need to make sure the entity doesn't attack players by default, or its AI will override your procedures. You can give your entity a custom NBT number tag that increases by one for every tick there's a player within a certain radius, and decreases by one (or resets to zero) for every tick there isn't a player within a certain radius, making sure this doesn't go past zero. Then, if the NBT tag reaches 100 ticks, (5 seconds, or whatever your desired time), set the entity's attack target to the nearest player. (Keep in mind it's pretty difficult to reset an entity's attack target once you've set it. As long as you don't want the entity to have a special stop condition, this shouldn't be an issue.)
The 'Attempt to set attack target of (entity),' 'Does entity exist of (type) in (radius),' and 'Nearest entity of (type) in (radius)' functions should all be helpful. Just make sure the radiuses are all consistent, if you try to target an entity in a radius that doesn't exist, it will generally crash the game.