Commit 65311b60 by Jonathan Thomas

Debug code for follow player goal

parent 101f2c27
Pipeline #11925 passed with stage
in 22 seconds
...@@ -6,11 +6,14 @@ import net.minecraft.entity.mob.MobEntity; ...@@ -6,11 +6,14 @@ import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import java.util.EnumSet; import java.util.EnumSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* The {@code FollowPlayerGoal} class instructs a Mob Entity to follow the current player. * The {@code FollowPlayerGoal} class instructs a Mob Entity to follow the current player.
*/ */
public class FollowPlayerGoal extends Goal { public class FollowPlayerGoal extends Goal {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
private final MobEntity entity; private final MobEntity entity;
private ServerPlayerEntity targetPlayer; private ServerPlayerEntity targetPlayer;
private final EntityNavigation navigation; private final EntityNavigation navigation;
...@@ -26,25 +29,40 @@ public class FollowPlayerGoal extends Goal { ...@@ -26,25 +29,40 @@ public class FollowPlayerGoal extends Goal {
@Override @Override
public boolean canStart() { public boolean canStart() {
return this.targetPlayer != null; boolean canStart = this.targetPlayer != null;
LOGGER.info("[FollowPlayerGoal] canStart: " + canStart);
return canStart;
} }
@Override @Override
public boolean shouldContinue() { public boolean shouldContinue() {
return this.targetPlayer != null && this.targetPlayer.isAlive(); boolean shouldContinue = this.targetPlayer != null && this.targetPlayer.isAlive();
LOGGER.info("[FollowPlayerGoal] shouldContinue: " + shouldContinue);
return shouldContinue;
} }
@Override @Override
public void stop() { public void stop() {
this.targetPlayer = null; this.targetPlayer = null;
this.navigation.stop(); this.navigation.stop();
LOGGER.info("[FollowPlayerGoal] stop goal");
} }
@Override @Override
public void tick() { public void tick() {
this.entity.getLookControl().lookAt(this.targetPlayer, 10.0F, (float) this.entity.getMaxLookPitchChange()); this.entity.getLookControl().lookAt(this.targetPlayer, 10.0F, (float) this.entity.getMaxLookPitchChange());
if (this.entity.squaredDistanceTo(this.targetPlayer) > 2.25) {
// Calculate the squared distance between the entity and the player
double squaredDistanceToPlayer = this.entity.squaredDistanceTo(this.targetPlayer);
// Check if the entity is further away than 4 blocks (16 when squared)
if (squaredDistanceToPlayer > 16) {
// Entity is more than 4 blocks away, start moving towards the player
LOGGER.info("[FollowPlayerGoal] tick - Start moving towards player. Squared distance to player: " + squaredDistanceToPlayer);
this.navigation.startMovingTo(this.targetPlayer, this.speed); this.navigation.startMovingTo(this.targetPlayer, this.speed);
} else if (squaredDistanceToPlayer < 9) {
// Entity is closer than 3 blocks, stop moving to maintain distance
this.navigation.stop();
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment