Set destination even for non NPCs

This commit is contained in:
fullwall 2022-06-22 12:35:01 +08:00
parent 1ca256753b
commit bf532728d1
13 changed files with 49 additions and 12 deletions

View File

@ -71,19 +71,24 @@ public abstract class AbstractBlockBreaker extends BlockBreaker {
return BehaviorStatus.SUCCESS;
}
currentTick = (int) (System.currentTimeMillis() / 50);
if (configuration.radius() > 0 && distance() >= configuration.radius()) {
startDigTick = currentTick;
if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC();
if (npc != null && !npc.getNavigator().isNavigating()) {
npc.getNavigator().setTarget(location);
npc.getNavigator().getLocalParameters().pathDistanceMargin(
Math.max(1, npc.getNavigator().getLocalParameters().pathDistanceMargin()));
npc.getNavigator().getLocalParameters().distanceMargin(Math.max(configuration.radius() - 1, 0.75));
setTarget = true;
if (configuration.radius() > 0) {
if (distance() >= configuration.radius()) {
startDigTick = currentTick;
if (entity instanceof NPCHolder) {
NPC npc = ((NPCHolder) entity).getNPC();
if (npc != null && !npc.getNavigator().isNavigating()) {
npc.getNavigator().setTarget(location);
npc.getNavigator().getLocalParameters().pathDistanceMargin(
Math.max(1, npc.getNavigator().getLocalParameters().pathDistanceMargin()));
npc.getNavigator().getLocalParameters()
.distanceMargin(Math.max(configuration.radius() - 1, 0.75));
setTarget = true;
}
} else if (NMS.getDestination(entity) == null) {
NMS.setDestination(entity, x, y, z, 1);
}
return BehaviorStatus.RUNNING;
}
return BehaviorStatus.RUNNING;
}
Util.faceLocation(entity, location);
if (entity instanceof Player && currentTick % 5 == 0) {

View File

@ -380,6 +380,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.a()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -399,6 +399,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.a()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -403,6 +403,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.b()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -425,6 +425,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.b()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -468,6 +468,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.b()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -477,6 +477,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.b()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -483,6 +483,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.b()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}

View File

@ -498,6 +498,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getMoveControl() : null;
if (controller == null || !controller.hasWanted()) {
return null;
}
return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(),
controller.getWantedZ());
}

View File

@ -503,6 +503,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getMoveControl() : null;
if (controller == null || !controller.hasWanted()) {
return null;
}
return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(),
controller.getWantedZ());
}

View File

@ -511,6 +511,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
MoveControl controller = handle instanceof Mob ? ((Mob) handle).getMoveControl()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getMoveControl() : null;
if (controller == null || !controller.hasWanted()) {
return null;
}
return new Location(entity.getWorld(), controller.getWantedX(), controller.getWantedY(),
controller.getWantedZ());
}

View File

@ -84,7 +84,6 @@ public class PlayerMoveControl extends MoveControl {
@Override
public void setWantedPosition(double d0, double d1, double d2, double d3) {
System.out.println("set pos: " + d0 + " " + d2);
this.tx = d0;
this.ty = d1;
this.tz = d2;

View File

@ -344,6 +344,9 @@ public class NMSImpl implements NMSBridge {
Entity handle = getHandle(entity);
ControllerMove controller = handle instanceof EntityInsentient ? ((EntityInsentient) handle).getControllerMove()
: handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getControllerMove() : null;
if (controller == null || !controller.a()) {
return null;
}
return new Location(entity.getWorld(), controller.d(), controller.e(), controller.f());
}