mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 10:36:10 +01:00
Update PlayerNavigation
This commit is contained in:
parent
fc43e6aa12
commit
bf7f92cd8f
@ -18,36 +18,40 @@ import net.minecraft.server.v1_11_R1.PathEntity;
|
|||||||
import net.minecraft.server.v1_11_R1.PathPoint;
|
import net.minecraft.server.v1_11_R1.PathPoint;
|
||||||
import net.minecraft.server.v1_11_R1.PathType;
|
import net.minecraft.server.v1_11_R1.PathType;
|
||||||
import net.minecraft.server.v1_11_R1.Pathfinder;
|
import net.minecraft.server.v1_11_R1.Pathfinder;
|
||||||
|
import net.minecraft.server.v1_11_R1.PathfinderAbstract;
|
||||||
import net.minecraft.server.v1_11_R1.Vec3D;
|
import net.minecraft.server.v1_11_R1.Vec3D;
|
||||||
import net.minecraft.server.v1_11_R1.World;
|
import net.minecraft.server.v1_11_R1.World;
|
||||||
|
|
||||||
public class PlayerNavigation extends NavigationAbstract {
|
public class PlayerNavigation extends NavigationAbstract {
|
||||||
protected EntityHumanNPC a;
|
protected EntityHumanNPC a;
|
||||||
|
protected World b;
|
||||||
|
protected PathEntity c;
|
||||||
|
protected double d;
|
||||||
protected PlayerPathfinderNormal e;
|
protected PlayerPathfinderNormal e;
|
||||||
|
private final AttributeInstance f;
|
||||||
private boolean f2;
|
private boolean f2;
|
||||||
private final AttributeInstance g;
|
private int g;
|
||||||
private int h;
|
private int h;
|
||||||
private int i;
|
private Vec3D i = Vec3D.a;
|
||||||
private Vec3D j = Vec3D.a;
|
private Vec3D j = Vec3D.a;
|
||||||
private Vec3D k = Vec3D.a;
|
private long k;
|
||||||
private long l = 0L;
|
private long l;
|
||||||
private long m = 0L;
|
private double m;
|
||||||
private double n;
|
private float n = 0.5F;
|
||||||
private float o = 0.5F;
|
private boolean o;
|
||||||
private boolean p;
|
private long p;
|
||||||
private long q;
|
private BlockPosition q;
|
||||||
private BlockPosition r;
|
private final PlayerPathfinder r;
|
||||||
private final PlayerPathfinder s;
|
|
||||||
|
|
||||||
public PlayerNavigation(EntityHumanNPC entityinsentient, World world) {
|
public PlayerNavigation(EntityHumanNPC entityinsentient, World world) {
|
||||||
super(getDummyInsentient(entityinsentient, world), world);
|
super(getDummyInsentient(entityinsentient, world), world);
|
||||||
this.a = entityinsentient;
|
this.a = entityinsentient;
|
||||||
this.b = world;
|
this.b = world;
|
||||||
this.g = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
|
this.f = entityinsentient.getAttributeInstance(GenericAttributes.FOLLOW_RANGE);
|
||||||
this.g.setValue(24);
|
this.f.setValue(24);
|
||||||
this.e = new PlayerPathfinderNormal();
|
this.e = new PlayerPathfinderNormal();
|
||||||
this.e.a(true);
|
this.e.a(true);
|
||||||
this.s = new PlayerPathfinder(this.e);
|
this.r = new PlayerPathfinder(this.e);
|
||||||
// this.b.C().a(this);
|
// this.b.C().a(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +70,7 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
localBlockPosition = localBlockPosition.down();
|
localBlockPosition = localBlockPosition.down();
|
||||||
}
|
}
|
||||||
if (localBlockPosition.getY() > 0) {
|
if (localBlockPosition.getY() > 0) {
|
||||||
return supera(localBlockPosition.up());
|
return a2(localBlockPosition.up());
|
||||||
}
|
}
|
||||||
while ((localBlockPosition.getY() < this.b.getHeight())
|
while ((localBlockPosition.getY() < this.b.getHeight())
|
||||||
&& (this.b.getType(localBlockPosition).getMaterial() == Material.AIR)) {
|
&& (this.b.getType(localBlockPosition).getMaterial() == Material.AIR)) {
|
||||||
@ -96,24 +100,18 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4) {
|
public boolean a(double paramDouble1, double paramDouble2, double paramDouble3, double paramDouble4) {
|
||||||
PathEntity localPathEntity = a(MathHelper.floor(paramDouble1), (int) paramDouble2,
|
return a(a(paramDouble1, paramDouble2, paramDouble3), paramDouble4);
|
||||||
MathHelper.floor(paramDouble3));
|
|
||||||
return a(localPathEntity, paramDouble4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PathEntity a(Entity paramEntity) {
|
public PathEntity a(Entity paramEntity) {
|
||||||
BlockPosition localBlockPosition = new BlockPosition(paramEntity);
|
return a(new BlockPosition(paramEntity));
|
||||||
return a(localBlockPosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean a(Entity paramEntity, double paramDouble) {
|
public boolean a(Entity paramEntity, double paramDouble) {
|
||||||
PathEntity localPathEntity = a(paramEntity);
|
PathEntity localPathEntity = a(paramEntity);
|
||||||
if (localPathEntity != null) {
|
return (localPathEntity != null) && (a(localPathEntity, paramDouble));
|
||||||
return a(localPathEntity, paramDouble);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6,
|
private boolean a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6,
|
||||||
@ -170,36 +168,36 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
}
|
}
|
||||||
this.d = paramDouble;
|
this.d = paramDouble;
|
||||||
Vec3D localVec3D = c();
|
Vec3D localVec3D = c();
|
||||||
this.i = this.h;
|
this.h = this.g;
|
||||||
this.j = localVec3D;
|
this.i = localVec3D;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void a(Vec3D paramVec3D) {
|
protected void a(Vec3D paramVec3D) {
|
||||||
if (this.h - this.i > 100) {
|
if (this.g - this.h > 100) {
|
||||||
if (paramVec3D.distanceSquared(this.j) < 2.25D) {
|
if (paramVec3D.distanceSquared(this.i) < 2.25D) {
|
||||||
o();
|
o();
|
||||||
}
|
}
|
||||||
this.i = this.h;
|
this.h = this.g;
|
||||||
this.j = paramVec3D;
|
this.i = paramVec3D;
|
||||||
}
|
}
|
||||||
if ((this.c != null) && (!this.c.b())) {
|
if ((this.c != null) && (!this.c.b())) {
|
||||||
Vec3D localVec3D = this.c.f();
|
Vec3D localVec3D = this.c.f();
|
||||||
if (!localVec3D.equals(this.k)) {
|
if (localVec3D.equals(this.j)) {
|
||||||
this.k = localVec3D;
|
this.k += System.currentTimeMillis() - this.l;
|
||||||
double d1 = paramVec3D.f(this.k);
|
|
||||||
this.n = (this.a.cq() > 0.0F ? d1 / this.a.cq() * 1000.0D : 0.0D);
|
|
||||||
} else {
|
} else {
|
||||||
this.l += System.currentTimeMillis() - this.m;
|
this.j = localVec3D;
|
||||||
|
double d1 = paramVec3D.f(this.j);
|
||||||
|
this.m = (this.a.cq() > 0.0F ? d1 / this.a.cq() * 1000.0D : 0.0D);
|
||||||
}
|
}
|
||||||
if ((this.n > 0.0D) && (this.l > this.n * 3.0D)) {
|
if ((this.m > 0.0D) && (this.k > this.m * 3.0D)) {
|
||||||
this.k = Vec3D.a;
|
this.j = Vec3D.a;
|
||||||
this.l = 0L;
|
this.k = 0L;
|
||||||
this.n = 0.0D;
|
this.m = 0.0D;
|
||||||
o();
|
o();
|
||||||
}
|
}
|
||||||
this.m = System.currentTimeMillis();
|
this.l = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,10 +265,10 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
if (!b()) {
|
if (!b()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ((this.c != null) && (!this.c.b()) && (paramBlockPosition.equals(this.r))) {
|
if ((this.c != null) && (!this.c.b()) && (paramBlockPosition.equals(this.q))) {
|
||||||
return this.c;
|
return this.c;
|
||||||
}
|
}
|
||||||
this.r = paramBlockPosition;
|
this.q = paramBlockPosition;
|
||||||
|
|
||||||
float f1 = h();
|
float f1 = h();
|
||||||
this.b.methodProfiler.a("pathfind");
|
this.b.methodProfiler.a("pathfind");
|
||||||
@ -279,7 +277,29 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
|
|
||||||
ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition.a(-i1, -i1, -i1),
|
ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition.a(-i1, -i1, -i1),
|
||||||
localBlockPosition.a(i1, i1, i1), 0);
|
localBlockPosition.a(i1, i1, i1), 0);
|
||||||
PathEntity localPathEntity = this.s.a(localChunkCache, this.a, this.r, f1);
|
PathEntity localPathEntity = this.r.a(localChunkCache, this.a, this.q, f1);
|
||||||
|
this.b.methodProfiler.b();
|
||||||
|
return localPathEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathEntity a2(Entity paramEntity) {
|
||||||
|
if (!b()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BlockPosition localBlockPosition1 = new BlockPosition(paramEntity);
|
||||||
|
if ((this.c != null) && (!this.c.b()) && (localBlockPosition1.equals(this.q))) {
|
||||||
|
return this.c;
|
||||||
|
}
|
||||||
|
this.q = localBlockPosition1;
|
||||||
|
|
||||||
|
float f1 = h();
|
||||||
|
this.b.methodProfiler.a("pathfind");
|
||||||
|
BlockPosition localBlockPosition2 = new BlockPosition(this.a).up();
|
||||||
|
int i1 = (int) (f1 + 16.0F);
|
||||||
|
|
||||||
|
ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition2.a(-i1, -i1, -i1),
|
||||||
|
localBlockPosition2.a(i1, i1, i1), 0);
|
||||||
|
PathEntity localPathEntity = this.r.a(localChunkCache, this.a, paramEntity, f1);
|
||||||
this.b.methodProfiler.b();
|
this.b.methodProfiler.b();
|
||||||
return localPathEntity;
|
return localPathEntity;
|
||||||
}
|
}
|
||||||
@ -325,7 +345,6 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void d() {
|
protected void d() {
|
||||||
super.d();
|
|
||||||
PathPoint localPathPoint;
|
PathPoint localPathPoint;
|
||||||
for (int i = 0; i < this.c.d(); i++) {
|
for (int i = 0; i < this.c.d(); i++) {
|
||||||
localPathPoint = this.c.a(i);
|
localPathPoint = this.c.a(i);
|
||||||
@ -347,7 +366,7 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
MathHelper.floor(this.a.locZ)))) {
|
MathHelper.floor(this.a.locZ)))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (i = 0; i < this.c.d(); i++) {
|
for (int i = 0; i < this.c.d(); i++) {
|
||||||
localPathPoint = this.c.a(i);
|
localPathPoint = this.c.a(i);
|
||||||
if (this.b.h(new BlockPosition(localPathPoint.a, localPathPoint.b, localPathPoint.c))) {
|
if (this.b.h(new BlockPosition(localPathPoint.a, localPathPoint.b, localPathPoint.c))) {
|
||||||
this.c.b(i - 1);
|
this.c.b(i - 1);
|
||||||
@ -357,6 +376,10 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void d(boolean paramBoolean) {
|
||||||
|
this.f2 = paramBoolean;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean f() {
|
public boolean f() {
|
||||||
return this.e.c();
|
return this.e.c();
|
||||||
}
|
}
|
||||||
@ -367,25 +390,25 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float h() {
|
public float h() {
|
||||||
return (float) this.g.getValue();
|
return (float) this.f.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean i() {
|
public boolean i() {
|
||||||
return this.p;
|
return this.o;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void j() {
|
public void j() {
|
||||||
if (this.b.getTime() - this.q > f) {
|
if (this.b.getTime() - this.p > 20L) {
|
||||||
if (this.r != null) {
|
if (this.q != null) {
|
||||||
this.c = null;
|
this.c = null;
|
||||||
this.c = a(this.r);
|
this.c = a(this.q);
|
||||||
this.q = this.b.getTime();
|
this.p = this.b.getTime();
|
||||||
this.p = false;
|
this.o = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.p = true;
|
this.o = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,8 +419,8 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void l() {
|
public void l() {
|
||||||
this.h += 1;
|
this.g += 1;
|
||||||
if (this.p) {
|
if (this.o) {
|
||||||
j();
|
j();
|
||||||
}
|
}
|
||||||
if (n()) {
|
if (n()) {
|
||||||
@ -422,7 +445,7 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Object localObject = new BlockPosition(localVec3D).down();
|
Object localObject = new BlockPosition(localVec3D).down();
|
||||||
AxisAlignedBB localAxisAlignedBB = this.b.getType((BlockPosition) localObject).c(this.b,
|
AxisAlignedBB localAxisAlignedBB = this.b.getType((BlockPosition) localObject).d(this.b,
|
||||||
(BlockPosition) localObject);
|
(BlockPosition) localObject);
|
||||||
localVec3D = localVec3D.a(0.0D, 1.0D - localAxisAlignedBB.e, 0.0D);
|
localVec3D = localVec3D.a(0.0D, 1.0D - localAxisAlignedBB.e, 0.0D);
|
||||||
|
|
||||||
@ -440,14 +463,15 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.o = (this.a.width > 0.75F ? this.a.width / 2.0F : 0.75F - this.a.width / 2.0F);
|
this.n = (this.a.width > 0.75F ? this.a.width / 2.0F : 0.75F - this.a.width / 2.0F);
|
||||||
Vec3D localVec3D2 = this.c.f();
|
Vec3D localVec3D2 = this.c.f();
|
||||||
if ((MathHelper.e((float) (this.a.locX - (localVec3D2.x + 0.5D))) < this.o)
|
if ((MathHelper.e((float) (this.a.locX - (localVec3D2.x + 0.5D))) < this.n)
|
||||||
&& (MathHelper.e((float) (this.a.locZ - (localVec3D2.z + 0.5D))) < this.o)) {
|
&& (MathHelper.e((float) (this.a.locZ - (localVec3D2.z + 0.5D))) < this.n)
|
||||||
|
&& (Math.abs(this.a.locY - localVec3D2.y) < 1.0D)) {
|
||||||
this.c.c(this.c.e() + 1);
|
this.c.c(this.c.e() + 1);
|
||||||
}
|
}
|
||||||
int i3 = MathHelper.f(this.a.width);
|
int i3 = MathHelper.f(this.a.width);
|
||||||
int i4 = (int) this.a.length + 1;
|
int i4 = MathHelper.f(this.a.length);
|
||||||
int i5 = i3;
|
int i5 = i3;
|
||||||
for (int i6 = i1 - 1; i6 >= this.c.e(); i6--) {
|
for (int i6 = i1 - 1; i6 >= this.c.e(); i6--) {
|
||||||
if (a(localVec3D1, this.c.a(this.a, i6), i3, i4, i5)) {
|
if (a(localVec3D1, this.c.a(this.a, i6), i3, i4, i5)) {
|
||||||
@ -473,6 +497,11 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
return (this.a.isInWater()) || (this.a.ao());
|
return (this.a.isInWater()) || (this.a.ao());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PathfinderAbstract q() {
|
||||||
|
return this.e;
|
||||||
|
}
|
||||||
|
|
||||||
private int r() {
|
private int r() {
|
||||||
if ((!this.a.isInWater()) || (!g())) {
|
if ((!this.a.isInWater()) || (!g())) {
|
||||||
return (int) (this.a.getBoundingBox().b + 0.5D);
|
return (int) (this.a.getBoundingBox().b + 0.5D);
|
||||||
@ -495,32 +524,11 @@ public class PlayerNavigation extends NavigationAbstract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setRange(float pathfindingRange) {
|
public void setRange(float pathfindingRange) {
|
||||||
this.g.setValue(pathfindingRange);
|
this.f.setValue(pathfindingRange);
|
||||||
}
|
|
||||||
|
|
||||||
public PathEntity supera(BlockPosition paramBlockPosition) {
|
|
||||||
if (!b()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if ((this.c != null) && (!this.c.b()) && (paramBlockPosition.equals(this.r))) {
|
|
||||||
return this.c;
|
|
||||||
}
|
|
||||||
this.r = paramBlockPosition;
|
|
||||||
|
|
||||||
float f1 = h();
|
|
||||||
BlockPosition localBlockPosition = new BlockPosition(this.a);
|
|
||||||
int i1 = (int) (f1 + 8.0F);
|
|
||||||
|
|
||||||
ChunkCache localChunkCache = new ChunkCache(this.b, localBlockPosition.a(-i1, -i1, -i1),
|
|
||||||
localBlockPosition.a(i1, i1, i1), 0);
|
|
||||||
PathEntity localPathEntity = this.s.a(localChunkCache, this.a, this.r, f1);
|
|
||||||
return localPathEntity;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EntityInsentient getDummyInsentient(EntityHumanNPC from, World world) {
|
private static EntityInsentient getDummyInsentient(EntityHumanNPC from, World world) {
|
||||||
return new EntityInsentient(world) {
|
return new EntityInsentient(world) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int f = 20;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user