making entity be afraid of block?

Started by SleepyWhirl on

Topic category: Help with MCreator software

Last seen on 19:59, 10. Dec 2023
Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
making entity be afraid of block?
Sun, 10/29/2023 - 02:55 (edited)

sup,

im attempting to make one of my mobs afraid of a specific block i made, but i cant really figure out how, ive tried checking for the block each tick but i dunno how id make it so that the entity would start running away from the block once its in the blocks radius, does anybody have a solution to this problem? id appreciate the help.

thanks!

Edited by SleepyWhirl on Sun, 10/29/2023 - 02:55
Last seen on 05:40, 28. Feb 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The behavior is hard coded…
Sun, 10/29/2023 - 16:02

The behavior is hard coded into piglins, so you might be able to look at the code and find a way to reference the same behavior... but it'd probably be pretty complicated.

One workaround you could try is making an invisible, unkillable entity that despawns a couple of ticks after spawning in. Make your custom entity avoid the invisible entity with a high speed factor, (this is just an AI function.) Essentially, you'll spawn the invisible entity at the block you want to be avoided.

If it's a vanilla block, you can modify the 'check for block in 6*6 box' procedure template to spawn an entity at the offset position if it finds the correct block. But if it's just a modded block you made, you could just make the modded block spawn the invisible entity inside it when placed, and then make the invisible entity despawn whenever it's not inside the modded block. This is trickier if it's a naturally generated block, and you probably don't want to try this if you're going to have large quantities of the block in one place, but I've been able to do similar things using this process.