[Tutorial] MCreator 2024.2 Ride if there are other entities around the entity.

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 Ride if there are other entities around the entity.
Sat, 08/10/2024 - 11:49 (edited)

An entity is currently unable to board another entity due to an event such as an entity tick in the MCreator.
 

If you use this method
A custom entity ride an entity that is nearby.



1. Create a custom entity.

2. Open the Code Editor.

3. Add import
Finally, add the code to the last line of the code.


import net.mcreator.test.init.'WorkspaceName'ModEntities;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.player.Player;
import java.util.List;


    public static AttributeSupplier.Builder createAttributes() {
AttributeSupplier.Builder builder = Mob.createMobAttributes();
builder = builder.add(Attributes.MOVEMENT_SPEED, 0.3);
builder = builder.add(Attributes.MAX_HEALTH, 10);
builder = builder.add(Attributes.ARMOR, 0);
builder = builder.add(Attributes.ATTACK_DAMAGE, 3);
builder = builder.add(Attributes.FOLLOW_RANGE, 16);
return builder;
}
//Paste under this code.


@Override
public void tick() {
super.tick();

double radius = 5.0;

List<Mob> nearbyEntities = this.level().getEntitiesOfClass(Mob.class, new AABB(this.getX() - radius, this.getY() - radius, this.getZ() - radius, this.getX() + radius, this.getY() + radius, this.getZ() + radius));

for (Mob entity : nearbyEntities) {
if (entity != this && !entity.isVehicle() && !this.isPassenger() && entity.getType() == EntityType.COW) {
this.startRiding(entity, true);
break;
}
}

if (this.isPassenger()) {
this.setPose(Pose.SITTING);
} else {
this.setPose(Pose.STANDING);
}
}

@Override
public void dismountTo(double x, double y, double z) {
}

@Override
public void removeVehicle() {
}
}
 
Edited by dkrdjdi on Sat, 08/10/2024 - 11:49
Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If you want to base a…
Sat, 08/10/2024 - 11:49

If you want to base a particular entity, change its code.

if (entity != this && !entity.isVehicle() && !this.isPassenger()) { 

//Before the change

 

if (entity != this && !entity.isVehicle() && !this.isPassenger() && entity.getType() == EntityType.COW) {

//After the change

I took a cow as an example.
Replace the COW with the entity you want.

 

 

Joined May 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
if (entity != this && …
Sat, 08/10/2024 - 13:29

if (entity != this && !entity.isVehicle() && !this.isPassenger() && entity.getType() == TestModEntities.TEST.get()) {

For custom entities, please change it like this.

You can change the test part to the name of the custom entity.