how to detect the nearest block of a specific type in a certain radius

Started by CluckNugget on

Topic category: Help with modding (Java Edition)

Last seen on 03:32, 6. Aug 2023
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
how to detect the nearest block of a specific type in a certain radius

I'm trying to make a simple NPC that you can find around breaking trees, but the "Break block" task makes the NPC jump on the block (like a zombie on turtle eggs) to break it. My solution would be to make a procedure that activates on spawn with a while loop that checks if there is a wood block near it and if not go in a random direction, but I don't think there's any way to find the nearest block of a type. Is there some workaround I could use that would allow me to make this NPC?

Last seen on 16:59, 25. Jun 2024
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Hello!You could use an 'On…
Wed, 08/02/2023 - 09:27

Hello!
You could use an 'On Entity Tick Update' procedure, then inside 'Procedure templates' [found above the list],

click on 'check for block in 6x6x6 box', then edit it to suit your needs.

Hope this helps!

Last seen on 03:32, 6. Aug 2023
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks! I think I can get my…
Wed, 08/02/2023 - 15:15

Thanks! I think I can get my mob to work using this.