use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method updateNavigationWorld.
@Override
public void updateNavigationWorld(org.bukkit.entity.Entity entity, World world) {
if (NAVIGATION_WORLD_FIELD == null)
return;
Entity en = NMSImpl.getHandle(entity);
if (en == null || !(en instanceof EntityInsentient))
return;
EntityInsentient handle = (EntityInsentient) en;
WorldServer worldHandle = ((CraftWorld) world).getHandle();
try {
NAVIGATION_WORLD_FIELD.invoke(handle.getNavigation(), worldHandle);
} catch (Exception e) {
Messaging.logTr(Messages.ERROR_UPDATING_NAVIGATION_WORLD, e.getMessage());
} catch (Throwable e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method updatePathfindingRange.
@Override
public void updatePathfindingRange(NPC npc, float pathfindingRange) {
if (!npc.isSpawned() || !npc.getEntity().getType().isAlive())
return;
EntityLiving en = NMSImpl.getHandle((LivingEntity) npc.getEntity());
if (!(en instanceof EntityInsentient)) {
if (en instanceof EntityHumanNPC) {
((EntityHumanNPC) en).updatePathfindingRange(pathfindingRange);
}
return;
}
if (PATHFINDING_RANGE == null)
return;
EntityInsentient handle = (EntityInsentient) en;
NavigationAbstract navigation = handle.getNavigation();
try {
AttributeInstance inst = (AttributeInstance) PATHFINDING_RANGE.invoke(navigation);
inst.setValue(pathfindingRange);
} catch (Throwable e) {
e.printStackTrace();
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class PlayerControllerMove method a.
@Override
public void a() {
this.a.bd = 0F;
if (this.f) {
this.f = false;
int i = MathHelper.floor(this.a.getBoundingBox().minY + 0.5D);
double d0 = this.b - this.a.locX;
double d1 = this.d - this.a.locZ;
double d2 = this.c - i;
double d3 = d0 * d0 + d2 * d2 + d1 * d1;
if (d3 < 2.500000277905201E-007D) {
this.a.bd = 0.0F;
return;
}
float f = (float) Math.toDegrees(Math.atan2(d1, d0)) - 90.0F;
this.a.yaw = a(this.a.yaw, f, 90.0F);
NMS.setHeadYaw(a.getBukkitEntity(), this.a.yaw);
AttributeInstance speed = this.a.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED);
if (this.a instanceof EntitySlime) {
speed.setValue(0.3D * this.e);
} else {
speed.setValue(0.2D * this.e);
}
float movement = (float) (this.e * speed.getValue());
this.a.o(movement);
this.a.bd = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
this.h /= 3;
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().jump();
} else {
((EntityInsentient) this.a).getControllerJump().jump();
}
}
}
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class PlayerPathfinder method a.
@Override
public PathEntity a(IWorldReader var0, EntityInsentient var1, Set<BlockPosition> var2, float var3, int var4) {
this.a.a();
this.e.a(var0, var1);
PathPoint var5 = this.e.b();
Map var6 = var2.stream().collect(Collectors.toMap((var0x) -> {
return this.e.a((double) var0x.getX(), (double) var0x.getY(), (double) var0x.getZ());
}, Function.identity()));
PathEntity var7 = this.a(var5, var6, var3, var4);
this.e.a();
return var7;
}
use of net.minecraft.server.v1_14_R1.EntityInsentient in project Citizens2 by CitizensDev.
the class NMSImpl method getTargetNavigator.
private MCNavigator getTargetNavigator(final org.bukkit.entity.Entity entity, final NavigatorParameters params, final Function<NavigationAbstract, Boolean> function) {
net.minecraft.server.v1_12_R1.Entity raw = getHandle(entity);
raw.onGround = true;
// not sure of a better way around this - if onGround is false, then
// navigation won't execute, and calling entity.move doesn't
// entirely fix the problem.
final NavigationAbstract navigation = NMSImpl.getNavigation(entity);
final float oldWater = raw instanceof EntityPlayer ? ((EntityHumanNPC) raw).a(PathType.WATER) : ((EntityInsentient) raw).a(PathType.WATER);
if (params.avoidWater() && oldWater >= 0) {
if (raw instanceof EntityPlayer) {
((EntityHumanNPC) raw).a(PathType.WATER, oldWater + 1F);
} else {
((EntityInsentient) raw).a(PathType.WATER, oldWater + 1F);
}
}
return new MCNavigator() {
float lastSpeed;
CancelReason reason;
@Override
public CancelReason getCancelReason() {
return reason;
}
@Override
public Iterable<Vector> getPath() {
return new NavigationIterable(navigation);
}
@Override
public void stop() {
if (params.debug() && navigation.l() != null) {
for (Player player : Bukkit.getOnlinePlayers()) {
for (int i = 0; i < navigation.l().d(); i++) {
PathPoint pp = navigation.l().a(i);
org.bukkit.block.Block block = new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()).getBlock();
player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
}
}
}
if (oldWater >= 0) {
if (raw instanceof EntityPlayer) {
((EntityHumanNPC) raw).a(PathType.WATER, oldWater);
} else {
((EntityInsentient) raw).a(PathType.WATER, oldWater);
}
}
stopNavigation(navigation);
}
@Override
public boolean update() {
if (params.speed() != lastSpeed) {
if (Messaging.isDebugging() && lastSpeed > 0) {
Messaging.debug("Repathfinding " + ((NPCHolder) entity).getNPC().getId() + " due to speed change");
}
Entity handle = getHandle(entity);
float oldWidth = handle.width;
if (handle instanceof EntityHorse) {
handle.width = Math.min(0.99f, oldWidth);
}
if (!function.apply(navigation)) {
reason = CancelReason.STUCK;
}
// minecraft requires that an entity fit onto both blocks if width >= 1f,
handle.width = oldWidth;
// but we'd prefer to make it just fit on 1 so hack around it a bit.
lastSpeed = params.speed();
}
if (params.debug() && !NMSImpl.isNavigationFinished(navigation)) {
for (Player player : Bukkit.getOnlinePlayers()) {
for (int i = 0; i < navigation.l().d(); i++) {
PathPoint pp = navigation.l().a(i);
player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), Material.YELLOW_FLOWER, (byte) 0);
}
}
}
navigation.a(params.speed());
return NMSImpl.isNavigationFinished(navigation);
}
};
}
Aggregations