How to create an entity that would have the purpose of approaching a block?

Started by Daniel1123 on

Topic category: Help with Minecraft modding (Java Edition)

Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to create an entity that would have the purpose of approaching a block?

How to create an entity that would have the purpose of approaching a given block but not destroying it? 

e.g. to the sweet berry block to take the fruit?

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Possible, but also possibly…
Tue, 11/07/2023 - 04:58

Possible, but also possibly not worth the effort. Speaking from the experience of programming termite AI, I do not recommend it.

...That being said, if you really want to, there's now a 'Make entity pathfind to x/y/z' function that's quite useful for this. The problem is that, if you somehow weren't already aware, Minecraft pathfinding is really, really bad. The specific issue with the function is there's no way to check if there's an available path, so if you tell it to pathfind to the nearest sweet berry bush but there isn't a clear path to get there, the entity will get as close as possible, and then just freeze until a path is available. You then have to get into a complicated system of prioritizing blocks in positions more likely to have available access points, using invisible entities to mark accessible locations, potion effects to determine entity states, and lots of other bizarre workarounds not really worth getting into.

But for most purposes, the pathfinding thing, combined with a 'check for block in 6*6*6 box' procedure template configured to prioritize the nearest block, (the one with the least total offset), and possibly couple of custom NBT tags to keep track of the entity's state, might just work. I recommend playing around with these before committing to anything though, this was easily one of the most frustrating things I've worked on.

Joined Sep 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I would try to do it, but I…
Tue, 11/07/2023 - 23:30

I would try to do it, but I don't even know what commands to use???

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In entity management, there…
Wed, 11/08/2023 - 00:18

In entity management, there is an 'attempt to make (entity) pathfind to (x/y/z)' function. If you combine this with the 'check for block in 6*6*6 box' procedure template, (you can find procedure templates in the upper right-hand corner of a code workspace), you can both locate a block and then make the entity pathfind for it in the 'on entity update tick procedure.' 

The 'attempt to make entity pathfind to x/y/z' function sets a navigation target for an entity, and the entity will then continue to move towards that goal until you either set another navigation target, or use the 'stop navigation of entity' function. The default navigation does not allow the entity to jump over gaps, or to fall more than three blocks.

You are correct though, anything involving entities and pathfinding tends to inspire headaches.