[Tutorial] MCreator 2024.2 Entity that Detecting for and Breaks TREES

Started by dkrdjdi on

Topic category: User side tutorials

Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
[Tutorial] MCreator 2024.2 Entity that Detecting for and Breaks TREES
Fri, 09/13/2024 - 01:11 (edited)

I need some code.
The reason code needs to be added is that the procedure provided by the existing template only applies to one entity.
When completed, the entity finds and breaks the tree, as shown in the image below.
https://imgur.com/9yyt8ig

Create a custom entity before creating the procedure and apply it to 'On entity tick update' on the Trigger tab.



STEP.1
Extract the procedure to detect 6x6x6 blocks from the main template.
Please refer to the image.
https://imgur.com/eABMByg

 

STEP.2

Add variables and specify the type as a number.
Three variables are required for each XYZ.
https://imgur.com/K23mGE9

 

STEP.3
We now produce the procedure as shown in the image shown below.
Please refer to the image.
https://imgur.com/ACY1oMx

 

STEP.4
Enter the code editor of the procedure
Add import.
https://imgur.com/8HgCBld


import net.minecraft.world.phys.AABB;
import java.util.List;


 

STEP.5
Please find the code and change it.
https://imgur.com/erqHuEd


Basic code


public class DetectingProcedure {
   public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
       if (entity == null)
           return;



Change code


public class DetectingProcedure {
   public static void execute(LevelAccessor world, double x, double y, double z) { //Entity entity Delete
       AABB boundingBox = new AABB(x - 5, y - 5, z - 5, x + 5, y + 5, z + 5);
       List<Entity> entities = world.getEntitiesOfClass(Entity.class, boundingBox);
       for (Entity entity : entities) { //Add Code
           if (entity == null)
               continue; //Change Code


 

STEP.6
Go to the bottom of the entire code and add '}'
https://imgur.com/S482V3u
 

STEP.7
open the Entity's code editor.
Find the code and remove ',this'.


@Override
   public void baseTick() {
       super.baseTick();
       DetectingProcedure.execute(this.level(), this.getX(), this.getY(), this.getZ(), this);
   }
 


 

Edited by dkrdjdi on Fri, 09/13/2024 - 01:11
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
When using this procedure,…
Fri, 09/13/2024 - 01:37

When using this procedure,

if there is a wooden block on top of another block,

other blocks are also destroyed,

so I think we should create a separate block recognition trigger and block Breaker trigger without using 'OR' in the procedure.