is it possible to make an entitie attracted to a block?

Started by CrystalWarrior1567 on

Topic category: Help with modding (Java Edition)

Last seen on 15:34, 16. Apr 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
is it possible to make an entitie attracted to a block?

so i'm making an ant mod, and i wanted the leafcutter ants to go up trees and attempt to break the leaf blocks, but i can't find any way to make them always try to find the leaf block, i have no idea how to write custom code.

my idea would be that the entite would look around and then if the leaves were within it's radius, it would go there and collect the block and return, if there weren't any leaves around it would just wander around until it found leaves

 

Last seen on 17:00, 15. Aug 2023
Joined Jul 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
same  
Sun, 08/28/2022 - 14:29

same

 

Last seen on 06:22, 13. Mar 2023
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
So you could do this with…
Tue, 08/30/2022 - 20:27

So you could do this with procedures instead of using entity AI. It would take a lot though. I'll try to make a more in depth tutorial on making custom entity "AI" using procedures. However, It is not real entity AI. You override the movement of the entity and turning the entity's AI off basically. I actually have been working on actually coding custom AI recently with custom code, and I plan to make a plugin for other people to be able to use them, or to try to get them added to MCreator or something if they work good eventually, but that's way down the line.

Step 1: Set a conditional statement on your Entity AI that enables movement. (wandering, flying, following, etc.)

Step 2: In your conditional statement check whether an nbt logic value customAI is true/false. If false, return true.
Step 3: On entity tick, detect if there is a leaf block within your desired area. This can be done easily using 3 repeat loops(x, y, and z iterator directions) to check a 3 dimensional area for a leaf block. If there is one, set nbt logic value of the entity customAI to true, else set it to false. This is what toggles your entity AI on/off to allow you to better override the entity movement vectors.

Step 4: *This is the hard part.* On your entity tick procedure, if your customAI nbt tag is true, do the following. You have to get the block positions of the block you are targeting, then repeatedly set the entity movement vector/rotations to go towards that block. A flying entity is a bit easier, as an entity on the ground has to account for jumping, climbing, etc. I will try to make an example of this eventually when I make the tutorial.

 

Last seen on 01:42, 28. Feb 2024
Joined Aug 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can u link the tutorial that…
Wed, 10/19/2022 - 03:11

Can u link the tutorial that you did when u make one