use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.
the class PlayerPathfinderNormal method b.
@Override
public PathPoint b() {
int var0;
BlockPosition var1;
if (this.e() && this.b.isInWater()) {
var0 = MathHelper.floor(this.b.locY());
MutableBlockPosition varx = new MutableBlockPosition(this.b.locX(), var0, this.b.locZ());
for (IBlockData var2 = this.a.getType(varx); var2.getBlock() == Blocks.WATER || var2.getFluid() == FluidTypes.WATER.a(false); var2 = this.a.getType(varx)) {
++var0;
varx.c(this.b.locX(), var0, this.b.locZ());
}
--var0;
} else if (this.b.onGround) {
var0 = MathHelper.floor(this.b.locY() + 0.5D);
} else {
for (var1 = new BlockPosition(this.b); (this.a.getType(var1).isAir() || this.a.getType(var1).a(this.a, var1, PathMode.LAND)) && var1.getY() > 0; var1 = var1.down()) {
}
var0 = var1.up().getY();
}
var1 = new BlockPosition(this.b);
PathType var2 = this.a(this.b, var1.getX(), var0, var1.getZ());
if (this.b.a(var2) < 0.0F) {
Set<BlockPosition> var3 = Sets.newHashSet();
var3.add(new BlockPosition(this.b.getBoundingBox().minX, var0, this.b.getBoundingBox().minZ));
var3.add(new BlockPosition(this.b.getBoundingBox().minX, var0, this.b.getBoundingBox().maxZ));
var3.add(new BlockPosition(this.b.getBoundingBox().maxX, var0, this.b.getBoundingBox().minZ));
var3.add(new BlockPosition(this.b.getBoundingBox().maxX, var0, this.b.getBoundingBox().maxZ));
Iterator<BlockPosition> var5 = var3.iterator();
while (var5.hasNext()) {
BlockPosition varb = var5.next();
PathType var6 = this.a(this.b, varb);
if (this.b.a(var6) >= 0.0F) {
return this.a(varb.getX(), varb.getY(), varb.getZ());
}
}
}
return this.a(var1.getX(), var0, var1.getZ());
}
use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.
the class PlayerPathfinderAbstract method a.
@Override
protected PathPoint a(int paramInt1, int paramInt2, int paramInt3) {
int j = PathPoint.b(paramInt1, paramInt2, paramInt3);
PathPoint localPathPoint = this.c.get(j);
if (localPathPoint == null) {
localPathPoint = new PathPoint(paramInt1, paramInt2, paramInt3);
this.c.a(j, localPathPoint);
}
return localPathPoint;
}
use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.
the class PlayerPathfinder method a.
private PathEntity a(PathPoint paramPathPoint1, PathPoint paramPathPoint2) {
int i = 1;
PathPoint localPathPoint = paramPathPoint2;
while (localPathPoint.h != null) {
i++;
localPathPoint = localPathPoint.h;
}
PathPoint[] arrayOfPathPoint = new PathPoint[i];
localPathPoint = paramPathPoint2;
arrayOfPathPoint[(--i)] = localPathPoint;
while (localPathPoint.h != null) {
localPathPoint = localPathPoint.h;
arrayOfPathPoint[(--i)] = localPathPoint;
}
return new PathEntity(arrayOfPathPoint);
}
use of net.minecraft.server.v1_15_R1.PathPoint in project Citizens2 by CitizensDev.
the class PlayerPathfinderNormal method a.
private PathPoint a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, double paramDouble, EnumDirection paramEnumDirection) {
PathPoint localPathPoint = null;
BlockPosition localBlockPosition1 = new BlockPosition(paramInt1, paramInt2, paramInt3);
BlockPosition localBlockPosition2 = localBlockPosition1.down();
double d1 = paramInt2 - (1.0D - this.a.getType(localBlockPosition2).d(this.a, localBlockPosition2).e);
if (d1 - paramDouble > 1.125D) {
return null;
}
PathType localPathType1 = a(this.b, paramInt1, paramInt2, paramInt3);
float f = this.b.a(localPathType1);
double d2 = this.b.width / 2.0D;
if (f >= 0.0F) {
localPathPoint = a(paramInt1, paramInt2, paramInt3);
localPathPoint.m = localPathType1;
localPathPoint.l = Math.max(localPathPoint.l, f);
}
if (localPathType1 == PathType.WALKABLE) {
return localPathPoint;
}
if ((localPathPoint == null) && (paramInt4 > 0) && (localPathType1 != PathType.FENCE) && (localPathType1 != PathType.TRAPDOOR)) {
localPathPoint = a(paramInt1, paramInt2 + 1, paramInt3, paramInt4 - 1, paramDouble, paramEnumDirection);
if ((localPathPoint != null) && ((localPathPoint.m == PathType.OPEN) || (localPathPoint.m == PathType.WALKABLE)) && (this.b.width < 1.0F)) {
double d3 = paramInt1 - paramEnumDirection.getAdjacentX() + 0.5D;
double d4 = paramInt3 - paramEnumDirection.getAdjacentZ() + 0.5D;
AxisAlignedBB localAxisAlignedBB1 = new AxisAlignedBB(d3 - d2, paramInt2 + 0.001D, d4 - d2, d3 + d2, paramInt2 + this.b.length, d4 + d2);
AxisAlignedBB localAxisAlignedBB2 = this.a.getType(localBlockPosition1).d(this.a, localBlockPosition1);
AxisAlignedBB localAxisAlignedBB3 = localAxisAlignedBB1.b(0.0D, localAxisAlignedBB2.e - 0.002D, 0.0D);
if (this.b.world.b(localAxisAlignedBB3)) {
localPathPoint = null;
}
}
}
if (localPathType1 == PathType.OPEN) {
AxisAlignedBB localAxisAlignedBB4 = new AxisAlignedBB(paramInt1 - d2 + 0.5D, paramInt2 + 0.001D, paramInt3 - d2 + 0.5D, paramInt1 + d2 + 0.5D, paramInt2 + this.b.length, paramInt3 + d2 + 0.5D);
if (this.b.world.b(localAxisAlignedBB4)) {
return null;
}
if (this.b.width >= 1.0F) {
PathType localPathType2 = a(this.b, paramInt1, paramInt2 - 1, paramInt3);
if (localPathType2 == PathType.BLOCKED) {
localPathPoint = a(paramInt1, paramInt2, paramInt3);
localPathPoint.m = PathType.WALKABLE;
localPathPoint.l = Math.max(localPathPoint.l, f);
return localPathPoint;
}
}
int i = 0;
while ((paramInt2 > 0) && (localPathType1 == PathType.OPEN)) {
paramInt2--;
if (i++ >= Setting.MC_NAVIGATION_MAX_FALL_DISTANCE.asInt()) {
return null;
}
localPathType1 = a(this.b, paramInt1, paramInt2, paramInt3);
f = this.b.a(localPathType1);
if ((localPathType1 != PathType.OPEN) && (f >= 0.0F)) {
localPathPoint = a(paramInt1, paramInt2, paramInt3);
localPathPoint.m = localPathType1;
localPathPoint.l = Math.max(localPathPoint.l, f);
} else if (f < 0.0F) {
return null;
}
}
}
return localPathPoint;
}
use of net.minecraft.server.v1_15_R1.PathPoint 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_14_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().e(); 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.getBlockData());
}
}
}
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);
EntitySize size = null;
try {
size = (EntitySize) SIZE_FIELD_GETTER.invoke(handle);
if (handle instanceof EntityHorse) {
SIZE_FIELD_SETTER.invoke(handle, new EntitySize(Math.min(0.99F, size.width), size.height, false));
}
} catch (Throwable e) {
e.printStackTrace();
}
if (!function.apply(navigation)) {
reason = CancelReason.STUCK;
}
try {
SIZE_FIELD_SETTER.invoke(handle, size);
} catch (Throwable e) {
e.printStackTrace();
// minecraft requires that an entity fit onto both blocks if width >= 1f, 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)) {
BlockData data = Material.DANDELION.createBlockData();
for (Player player : Bukkit.getOnlinePlayers()) {
for (int i = 0; i < navigation.l().e(); i++) {
PathPoint pp = navigation.l().a(i);
player.sendBlockChange(new Vector(pp.a, pp.b, pp.c).toLocation(player.getWorld()), data);
}
}
}
navigation.a(params.speed());
return NMSImpl.isNavigationFinished(navigation);
}
};
}
Aggregations