use of net.minecraft.server.v1_16_R3.EntityInsentient in project Citizens2 by CitizensDev.
the class PlayerPathfinder method a.
@Override
public PathEntity a(ChunkCache var0, EntityInsentient var1, Set<BlockPosition> var2, float var3, int var4, float var5) {
this.d.a();
this.c.a(var0, var1);
PathPoint var6 = this.c.b();
Map var7 = var2.stream().collect(Collectors.toMap((var0x) -> {
return this.c.a((double) var0x.getX(), (double) var0x.getY(), (double) var0x.getZ());
}, Function.identity()));
PathEntity var8 = this.a(var6, var7, var3, var4, var5);
this.c.a();
return var8;
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen by DenizenScript.
the class EntityHelperImpl method follow.
@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander, final boolean teleport) {
if (target == null || follower == null) {
return;
}
final net.minecraft.server.v1_16_R3.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
UUID uuid = follower.getUniqueId();
if (followTasks.containsKey(uuid)) {
followTasks.get(uuid).cancel();
}
final int locationNearInt = (int) Math.floor(lead);
final boolean hasMax = maxRange > lead;
followTasks.put(follower.getUniqueId(), new BukkitRunnable() {
private boolean inRadius = false;
public void run() {
if (!target.isValid() || !follower.isValid()) {
this.cancel();
}
followerNavigation.a(2F);
Location targetLocation = target.getLocation();
PathEntity path;
if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
if (!inRadius) {
if (teleport) {
follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
} else {
cancel();
}
} else {
inRadius = false;
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ(), 0);
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.o();
}
nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of net.minecraft.server.v1_16_R3.EntityInsentient in project Denizen by DenizenScript.
the class EntityHelperImpl method walkTo.
@Override
public void walkTo(final LivingEntity entity, Location location, Double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.server.v1_16_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
final PathEntity path;
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
entity.setAI(true);
try {
ENTITY_ONGROUND_SETTER.invoke(nmsEntity, true);
} catch (Throwable ex) {
Debug.echoError(ex);
}
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ(), 0);
if (path != null) {
entityNavigation.a(path, 1D);
entityNavigation.a(2D);
final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).getBaseValue();
if (speed != null) {
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
new BukkitRunnable() {
@Override
public void run() {
if (!entity.isValid()) {
if (callback != null) {
callback.run();
}
cancel();
return;
}
if (aiDisabled && entity instanceof Wolf) {
((Wolf) entity).setAngry(false);
}
if (entityNavigation.m() || path.c()) {
if (callback != null) {
callback.run();
}
if (speed != null) {
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
}
if (aiDisabled) {
entity.setAI(false);
}
cancel();
}
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
} else // if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
// TODO: generate waypoints to the target location?
{
entity.teleport(location);
}
}
Aggregations