Properly forward slime jump to move controller in 1.17+

This commit is contained in:
fullwall 2023-10-23 18:32:34 +08:00
parent 8efde00530
commit 1fa3b22c57
13 changed files with 103 additions and 179 deletions

View File

@ -86,9 +86,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.l(movement);
this.a.bg = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().a();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
@ -114,16 +116,5 @@ public class PlayerControllerMove extends ControllerMove {
@Override
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
return thi
}

View File

@ -88,9 +88,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.l(movement);
this.a.bf = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().a();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
@ -118,14 +120,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -51,9 +51,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.k(movement);
this.a.bg = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().a();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
@ -118,14 +120,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -53,9 +53,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.o(movement);
this.a.bj = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().a();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
@ -120,14 +122,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -52,9 +52,11 @@ public class PlayerControllerMove extends ControllerMove {
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();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().jump();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().jump();
} else {
@ -119,14 +121,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -52,9 +52,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.o(movement);
this.a.bb = movement;
if (shouldSlimeJump() || ((d2 >= NMS.getStepHeight(a.getBukkitEntity())) && (d0 * d0 + d1 * d1 < 1.0D))) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().jump();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().jump();
} else {
@ -119,14 +121,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -53,9 +53,13 @@ public class EntityMoveControl extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.q(movement);
this.a.aT = movement;
if (shouldSlimeJump() || (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D)) {
this.h = cg();
this.h /= 3;
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
if (((EntitySlime) a).isAggressive()) {
this.h /= 3;
}
ai.getJumpControl().jump();
} else if (d2 >= NMS.getStepHeight(a.getBukkitEntity()) && (d0 * d0 + d1 * d1) < 1.0D) {
ai.getJumpControl().jump();
}
}
@ -116,14 +120,4 @@ public class EntityMoveControl extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}

View File

@ -86,16 +86,6 @@ public class EntityMoveControl extends MoveControl {
this.moving = true;
}
private boolean shouldJump() {
if (!(this.entity instanceof Slime)) {
return false;
}
if (this.jumpTicks-- <= 0) {
return true;
}
return false;
}
@Override
public void tick() {
this.entity.zza = 0;
@ -109,18 +99,27 @@ public class EntityMoveControl extends MoveControl {
this.entity.zza = 0.0F;
return;
}
if (dXZ > 0.4) {
float f = (float) (Mth.atan2(dZ, dX) * 57.2957763671875D) - 90.0F;
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
AttributeInstance speed = this.entity.getAttribute(Attributes.MOVEMENT_SPEED);
float movement = (float) (this.speed * speed.getValue());
this.entity.setSpeed(movement);
this.entity.zza = movement;
if (shouldJump() || (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 1.0D)) {
this.jumpTicks = jumpTicks();
this.jumpTicks /= 3;
if (entity instanceof Slime && jumpTicks-- <= 0) {
this.jumpTicks = new Random().nextInt(20) + 10;
if (((Slime) entity).isAggressive()) {
this.jumpTicks /= 3;
}
((Slime) entity).getJumpControl().jump();
} else if (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D) {
if (entity instanceof Mob) {
((Mob) entity).getJumpControl().jump();
}
entity.setJumping(true);
}
}

View File

@ -85,16 +85,6 @@ public class EntityMoveControl extends MoveControl {
this.moving = true;
}
private boolean shouldJump() {
if (!(this.entity instanceof Slime)) {
return false;
}
if (this.jumpTicks-- <= 0) {
return true;
}
return false;
}
@Override
public void tick() {
this.entity.zza = 0;
@ -116,9 +106,16 @@ public class EntityMoveControl extends MoveControl {
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement);
this.entity.zza = movement;
if (shouldJump() || (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D)) {
this.jumpTicks = jumpTicks();
this.jumpTicks /= 3;
if (entity instanceof Slime && jumpTicks-- <= 0) {
this.jumpTicks = new Random().nextInt(20) + 10;
if (((Slime) entity).isAggressive()) {
this.jumpTicks /= 3;
}
((Slime) entity).getJumpControl().jump();
} else if (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D) {
if (entity instanceof Mob) {
((Mob) entity).getJumpControl().jump();
}
entity.setJumping(true);
}
}

View File

@ -85,16 +85,6 @@ public class EntityMoveControl extends MoveControl {
this.moving = true;
}
private boolean shouldJump() {
if (!(this.entity instanceof Slime))
return false;
if (this.jumpTicks-- <= 0)
return true;
return false;
}
@Override
public void tick() {
this.entity.zza = 0;
@ -116,9 +106,16 @@ public class EntityMoveControl extends MoveControl {
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement);
this.entity.zza = movement;
if (shouldJump() || (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D)) {
this.jumpTicks = jumpTicks();
this.jumpTicks /= 3;
if (entity instanceof Slime && jumpTicks-- <= 0) {
this.jumpTicks = new Random().nextInt(20) + 10;
if (((Slime) entity).isAggressive()) {
this.jumpTicks /= 3;
}
((Slime) entity).getJumpControl().jump();
} else if (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D) {
if (entity instanceof Mob) {
((Mob) entity).getJumpControl().jump();
}
entity.setJumping(true);
}
}

View File

@ -16,7 +16,6 @@ import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.util.NMS;
import net.citizensnpcs.util.Util;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent;
@ -48,7 +47,6 @@ public class SlimeController extends MobEntityController {
public static class EntitySlimeNPC extends Slime implements NPCHolder {
private final CitizensNPC npc;
private MoveControl oldMoveController;
public EntitySlimeNPC(EntityType<? extends Slime> types, Level level) {
@ -67,17 +65,17 @@ public class SlimeController extends MobEntityController {
@Override
protected boolean canRide(Entity entity) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart)) {
if (npc != null && (entity instanceof Boat || entity instanceof AbstractMinecart))
return !npc.isProtected();
}
return super.canRide(entity);
}
@Override
public boolean causeFallDamage(float f, float f1, DamageSource damagesource) {
if (npc == null || !npc.isFlyable()) {
if (npc == null || !npc.isFlyable())
return super.causeFallDamage(f, f1, damagesource);
}
return false;
}

View File

@ -54,10 +54,6 @@ public class EntityMoveControl extends MoveControl {
return this.moving;
}
protected int jumpTicks() {
return new Random().nextInt(20) + 10;
}
@Override
protected float rotlerp(float f, float f1, float f2) {
float f3 = Mth.wrapDegrees(f1 - f);
@ -85,42 +81,42 @@ public class EntityMoveControl extends MoveControl {
this.moving = true;
}
private boolean shouldJump() {
if (!(this.entity instanceof Slime))
return false;
if (this.jumpTicks-- <= 0)
return true;
return false;
}
@Override
public void tick() {
this.entity.zza = 0;
if (this.moving) {
this.moving = false;
double dX = this.tx - this.entity.getX();
double dZ = this.tz - this.entity.getZ();
double dY = this.ty - this.entity.getY();
double dXZ = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1.0 && dXZ < 0.01) {
// this.entity.zza = 0.0F;
return;
}
if (dXZ > 0.4) {
float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F;
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement);
this.entity.zza = movement;
if (shouldJump() || (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D)) {
this.jumpTicks = jumpTicks();
if (!this.moving)
return;
this.moving = false;
double dX = this.tx - this.entity.getX();
double dZ = this.tz - this.entity.getZ();
double dY = this.ty - this.entity.getY();
double dXZ = Math.sqrt(dX * dX + dZ * dZ);
if (Math.abs(dY) < 1.0 && dXZ < 0.01) {
// this.entity.zza = 0.0F;
return;
}
if (dXZ > 0.4) {
float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F;
this.entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F));
NMS.setHeadYaw(entity.getBukkitEntity(), this.entity.getYRot());
}
float movement = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue());
this.entity.setSpeed(movement);
this.entity.zza = movement;
if (entity instanceof Slime && jumpTicks-- <= 0) {
this.jumpTicks = new Random().nextInt(20) + 10;
if (((Slime) entity).isAggressive()) {
this.jumpTicks /= 3;
entity.setJumping(true);
}
((Slime) entity).getJumpControl().jump();
} else if (dY >= NMS.getStepHeight(entity.getBukkitEntity()) && dXZ < 0.4D) {
if (entity instanceof Mob) {
((Mob) entity).getJumpControl().jump();
}
entity.setJumping(true);
}
}
}

View File

@ -86,9 +86,11 @@ public class PlayerControllerMove extends ControllerMove {
float movement = (float) (this.e * speed.getValue());
this.a.k(movement);
this.a.ba = movement;
if (shouldSlimeJump() || ((dY >= NMS.getStepHeight(a.getBukkitEntity())) && dXZ < 0.4)) {
this.h = cg();
if (a instanceof EntitySlime && h-- <= 0) {
this.h = new Random().nextInt(20) + 10;
this.h /= 3;
((EntityInsentient) this.a).getControllerJump().a();
} else if (dY >= NMS.getStepHeight(a.getBukkitEntity()) && (dXZ) < 0.4D) {
if (this.a instanceof EntityHumanNPC) {
((EntityHumanNPC) this.a).getControllerJump().a();
} else {
@ -115,14 +117,4 @@ public class PlayerControllerMove extends ControllerMove {
public double f() {
return this.d;
}
private boolean shouldSlimeJump() {
if (!(this.a instanceof EntitySlime)) {
return false;
}
if (this.h-- <= 0) {
return true;
}
return false;
}
}