mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-22 17:18:20 +01:00
First pass at fall damage
This commit is contained in:
parent
21e924f04c
commit
840f32469b
@ -71,7 +71,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final CitizensNPC npc;
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -152,7 +151,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
world.removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -284,7 +283,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
g(0, 0);
|
||||
moveWithFallDamage(0, 0);
|
||||
}
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
@ -351,13 +350,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
bf *= 0.98F;
|
||||
bg *= 0.98F;
|
||||
bh *= 0.9F;
|
||||
g(bf, bg); // movement method
|
||||
moveWithFallDamage(bf, bg); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(float mx, float my) {
|
||||
double y = this.locY;
|
||||
|
||||
g(mx, my);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMoveDestination(double x, double y, double z, double speed) {
|
||||
controllerMove.a(x, y, z, speed);
|
||||
}
|
||||
@ -510,7 +518,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
private static final float EPSILON = 0.005F;
|
||||
|
||||
private static final float EPSILON = 0.003F;
|
||||
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||
}
|
||||
|
@ -73,7 +73,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final CitizensNPC npc;
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -171,7 +170,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
world.removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -322,13 +321,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
be *= 0.98F;
|
||||
bf *= 0.98F;
|
||||
bg *= 0.9F;
|
||||
g(be, bf); // movement method
|
||||
moveWithFallDamage(be, bf); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(float mx, float my) {
|
||||
double y = this.locY;
|
||||
|
||||
g(mx, my);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick() {
|
||||
if (npc == null) {
|
||||
@ -340,7 +348,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
g(0, 0);
|
||||
moveWithFallDamage(0, 0);
|
||||
}
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
@ -518,6 +526,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
private static final float EPSILON = 0.005F;
|
||||
private static final float EPSILON = 0.003F;
|
||||
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private PlayerlistTrackerEntry trackerEntry;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -349,13 +348,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
be *= 0.98F;
|
||||
bg *= 0.98F;
|
||||
bh *= 0.9F;
|
||||
a(be, bf, bg); // movement method
|
||||
moveWithFallDamage(be, bf, bg); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(double mx, double my, double mz) {
|
||||
double y = this.locY;
|
||||
|
||||
a(mx, my, mz);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick() {
|
||||
if (npc == null) {
|
||||
@ -367,7 +375,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
a(0, 0, 0);
|
||||
moveWithFallDamage(0, 0, 0);
|
||||
}
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
|
@ -77,7 +77,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private PlayerlistTrackerEntry trackerEntry;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -323,13 +322,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
bh *= 0.98F;
|
||||
bj *= 0.98F;
|
||||
bk *= 0.9F;
|
||||
a(bh, bi, bj); // movement method
|
||||
moveWithFallDamage(bh, bi, bj); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(double mx, double my, double mz) {
|
||||
double y = this.locY;
|
||||
|
||||
a(mx, my, mz);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick() {
|
||||
if (npc == null) {
|
||||
@ -341,7 +349,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
a(0, 0, 0);
|
||||
moveWithFallDamage(0, 0, 0);
|
||||
}
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
|
@ -76,7 +76,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private PlayerlistTracker playerlistTracker;
|
||||
private final SkinPacketTracker skinTracker;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -170,7 +169,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
((WorldServer) world).removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -319,13 +318,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
bb *= 0.98F;
|
||||
bd *= 0.98F;
|
||||
be *= 0.9F;
|
||||
e(new Vec3D(this.bb, this.bc, this.bd)); // movement method
|
||||
moveWithFallDamage(new Vec3D(this.bb, this.bc, this.bd)); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(Vec3D vec) {
|
||||
double y = this.locY;
|
||||
|
||||
e(vec);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<?> N() {
|
||||
if (playerlistTracker != null) {
|
||||
@ -345,7 +353,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
e(new Vec3D(0, 0, 0));
|
||||
moveWithFallDamage(new Vec3D(0, 0, 0));
|
||||
}
|
||||
Vec3D mot = getMot();
|
||||
if (Math.abs(mot.getX()) < EPSILON && Math.abs(mot.getY()) < EPSILON && Math.abs(mot.getZ()) < EPSILON) {
|
||||
|
@ -326,13 +326,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
aZ *= 0.98F;
|
||||
bb *= 0.98F;
|
||||
e(new Vec3D(this.aZ, this.ba, this.bb)); // movement method
|
||||
moveWithFallDamage(new Vec3D(this.aZ, this.ba, this.bb)); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(Vec3D vec) {
|
||||
double y = this.locY();
|
||||
|
||||
e(vec);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY() - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playerTick() {
|
||||
if (npc == null) {
|
||||
@ -344,7 +353,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
e(new Vec3D(0, 0, 0));
|
||||
moveWithFallDamage(new Vec3D(0, 0, 0));
|
||||
}
|
||||
Vec3D mot = getMot();
|
||||
if (Math.abs(mot.getX()) < EPSILON && Math.abs(mot.getY()) < EPSILON && Math.abs(mot.getZ()) < EPSILON) {
|
||||
|
@ -348,13 +348,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
aR *= 0.98F;
|
||||
aT *= 0.98F;
|
||||
g(new Vec3D(this.aR, this.aS, this.aT)); // movement method
|
||||
moveWithFallDamage(new Vec3D(this.aR, this.aS, this.aT)); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(Vec3D vec) {
|
||||
double y = this.locY();
|
||||
|
||||
g(vec);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY() - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<?> P() {
|
||||
if (playerlistTracker != null) {
|
||||
@ -374,7 +383,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
g(new Vec3D(0, 0, 0));
|
||||
moveWithFallDamage(new Vec3D(0, 0, 0));
|
||||
}
|
||||
Vec3D mot = getMot();
|
||||
if (Math.abs(mot.getX()) < EPSILON && Math.abs(mot.getY()) < EPSILON && Math.abs(mot.getZ()) < EPSILON) {
|
||||
@ -584,6 +593,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private static final MethodHandle ATTRIBUTE_MAP = NMS.getGetter(AttributeMapBase.class, "d");
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP = NMS.getGetter(AttributeProvider.class, "a");
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFinalSetter(AttributeProvider.class, "a");
|
||||
private static final float EPSILON = 0.005F;
|
||||
private static final float EPSILON = 0.003F;
|
||||
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
travel(Vec3.ZERO);
|
||||
moveWithFallDamage(Vec3.ZERO);
|
||||
}
|
||||
|
||||
Vec3 mot = getDeltaMovement();
|
||||
@ -385,13 +385,21 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
xxa *= 0.98F;
|
||||
zza *= 0.98F;
|
||||
travel(new Vec3(this.xxa, this.yya, this.zza));
|
||||
moveWithFallDamage(new Vec3(this.xxa, this.yya, this.zza));
|
||||
NMS.setHeadYaw(getBukkitEntity(), getYRot());
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(Vec3 vec) {
|
||||
double y = getY();
|
||||
travel(vec);
|
||||
if (!npc.isProtected()) {
|
||||
doCheckFallDamage(getY() - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onClimbable() {
|
||||
if (npc == null || !npc.isFlyable()) {
|
||||
@ -610,7 +618,7 @@ public class EntityHumanNPC extends ServerPlayer implements NPCHolder, Skinnable
|
||||
private static final MethodHandle ATTRIBUTE_PROVIDER_MAP_SETTER = NMS.getFinalSetter(AttributeSupplier.class, "a");
|
||||
private static final MethodHandle ATTRIBUTE_SUPPLIER = NMS.getFirstGetter(AttributeMap.class,
|
||||
AttributeSupplier.class);
|
||||
private static final float EPSILON = 0.005F;
|
||||
private static final float EPSILON = 0.003F;
|
||||
private static final MethodHandle GAMEMODE_SETTING = NMS.getFirstMethodHandle(ServerPlayerGameMode.class, true,
|
||||
GameType.class, GameType.class);
|
||||
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||
|
@ -68,7 +68,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
private final Location packetLocationCache = new Location(null, 0, 0, 0);
|
||||
private final SkinPacketTracker skinTracker;
|
||||
private PlayerlistTrackerEntry trackerEntry;
|
||||
|
||||
private int updateCounter = 0;
|
||||
|
||||
public EntityHumanNPC(MinecraftServer minecraftServer, WorldServer world, GameProfile gameProfile,
|
||||
@ -146,7 +145,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
public void run() {
|
||||
world.removeEntity(EntityHumanNPC.this);
|
||||
}
|
||||
}, 35); // give enough time for death and smoke animation
|
||||
}, 15); // give enough time for death and smoke animation
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -290,7 +289,7 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
if (!navigating && getBukkitEntity() != null
|
||||
&& (!npc.hasTrait(Gravity.class) || npc.getOrAddTrait(Gravity.class).hasGravity())
|
||||
&& Util.isLoaded(getBukkitEntity().getLocation(LOADED_LOCATION))) {
|
||||
g(0, 0);
|
||||
moveWithFallDamage(0, 0);
|
||||
}
|
||||
if (Math.abs(motX) < EPSILON && Math.abs(motY) < EPSILON && Math.abs(motZ) < EPSILON) {
|
||||
motX = motY = motZ = 0;
|
||||
@ -330,13 +329,22 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
aZ *= 0.98F;
|
||||
ba *= 0.98F;
|
||||
bb *= 0.9F;
|
||||
g(aZ, ba); // movement method
|
||||
moveWithFallDamage(aZ, ba); // movement method
|
||||
NMS.setHeadYaw(getBukkitEntity(), yaw);
|
||||
if (jumpTicks > 0) {
|
||||
jumpTicks--;
|
||||
}
|
||||
}
|
||||
|
||||
private void moveWithFallDamage(float mx, float my) {
|
||||
double y = this.locY;
|
||||
|
||||
g(mx, my);
|
||||
if (!npc.isProtected()) {
|
||||
a(this.locY - y, onGround);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMoveDestination(double x, double y, double z, double speed) {
|
||||
controllerMove.a(x, y, z, speed);
|
||||
}
|
||||
@ -509,6 +517,6 @@ public class EntityHumanNPC extends EntityPlayer implements NPCHolder, Skinnable
|
||||
}
|
||||
}
|
||||
|
||||
private static final float EPSILON = 0.005F;
|
||||
private static final float EPSILON = 0.003F;
|
||||
private static final Location LOADED_LOCATION = new Location(null, 0, 0, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user