From 20ea3e8723a2c6f11828b24cb2eba6b5d8a68f3c Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 22 Jun 2024 13:21:21 +0800 Subject: [PATCH] Fix players not jumping in newer minecraft versions --- .../nms/v1_16_R3/util/EntityMoveControl.java | 1 - .../nms/v1_17_R1/util/EntityMoveControl.java | 32 ++++++++++++------- .../nms/v1_17_R1/util/NMSImpl.java | 3 ++ .../nms/v1_18_R2/util/EntityMoveControl.java | 29 +++++++++++------ .../nms/v1_18_R2/util/NMSImpl.java | 7 +++- .../nms/v1_19_R3/util/EntityMoveControl.java | 29 +++++++++++------ .../nms/v1_19_R3/util/NMSImpl.java | 10 +++--- .../nms/v1_20_R4/util/EntityMoveControl.java | 29 +++++++++++------ .../nms/v1_20_R4/util/NMSImpl.java | 10 +++--- .../nms/v1_21_R1/util/EntityMoveControl.java | 29 +++++++++++------ .../nms/v1_21_R1/util/NMSImpl.java | 10 +++--- .../v1_8_R3/util/PlayerControllerMove.java | 9 ++---- 12 files changed, 125 insertions(+), 73 deletions(-) diff --git a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/EntityMoveControl.java b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/EntityMoveControl.java index 945d477c6..fc58a25fe 100644 --- a/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/EntityMoveControl.java +++ b/v1_16_R3/src/main/java/net/citizensnpcs/nms/v1_16_R3/util/EntityMoveControl.java @@ -3,7 +3,6 @@ package net.citizensnpcs.nms.v1_16_R3.util; import java.util.Random; import net.citizensnpcs.util.NMS; -import net.minecraft.server.v1_16_R3.AttributeModifiable; import net.minecraft.server.v1_16_R3.ControllerMove; import net.minecraft.server.v1_16_R3.EntityInsentient; import net.minecraft.server.v1_16_R3.EntityLiving; diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/EntityMoveControl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/EntityMoveControl.java index 17d0e9177..df2895200 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/EntityMoveControl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/EntityMoveControl.java @@ -3,6 +3,9 @@ package net.citizensnpcs.nms.v1_17_R1.util; import java.util.Random; import net.citizensnpcs.util.NMS; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction.Axis; +import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -10,6 +13,8 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; public class EntityMoveControl extends MoveControl { protected LivingEntity entity; @@ -94,27 +99,32 @@ public class EntityMoveControl extends MoveControl { 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; + double dXYZ = Math.sqrt(dX * dX + dY * dY + dZ * dZ); + if (dXYZ < 2.500000277905201E-7) { + // 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()); + float f = (float) Math.toDegrees(Mth.atan2(dZ, dX)) - 90.0F; + entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); + NMS.setHeadYaw(entity.getBukkitEntity(), entity.getYRot()); } - this.entity.zza = (float) (this.speed * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); + this.entity.zza = (float) (this.speed * entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); 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); + return; + } + BlockPos pos = entity.blockPosition(); + BlockState bs = entity.level.getBlockState(pos); + VoxelShape vs = bs.getCollisionShape(entity.level, pos); + if (dY >= entity.maxUpStep && dXZ < Math.max(1.0F, entity.getBbWidth()) + || !vs.isEmpty() && entity.getY() < vs.max(Axis.Y) + pos.getY() && !bs.is(BlockTags.DOORS) + && !bs.is(BlockTags.FENCES)) { + NMS.setShouldJump(entity.getBukkitEntity()); } } } diff --git a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java index 5c7d99492..7707688e4 100644 --- a/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java +++ b/v1_17_R1/src/main/java/net/citizensnpcs/nms/v1_17_R1/util/NMSImpl.java @@ -1512,6 +1512,9 @@ public class NMSImpl implements NMSBridge { if (ai != null) { ai.getJumpControl().jump(); } + if (handle instanceof LivingEntity) { + ((LivingEntity) handle).setJumping(true); + } } @Override diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/EntityMoveControl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/EntityMoveControl.java index 7d554d50a..0da2853dc 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/EntityMoveControl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/EntityMoveControl.java @@ -3,6 +3,9 @@ package net.citizensnpcs.nms.v1_18_R2.util; import java.util.Random; import net.citizensnpcs.util.NMS; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction.Axis; +import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -10,6 +13,8 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; public class EntityMoveControl extends MoveControl { protected LivingEntity entity; @@ -94,26 +99,32 @@ public class EntityMoveControl extends MoveControl { 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) + double dXYZ = Math.sqrt(dX * dX + dY * dY + dZ * dZ); + if (dXYZ < 2.500000277905201E-7) { // 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()); + entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); + NMS.setHeadYaw(entity.getBukkitEntity(), entity.getYRot()); } - this.entity.zza = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); + this.entity.zza = (float) (this.speedMod * entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); 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); + return; + } + BlockPos pos = entity.blockPosition(); + BlockState bs = entity.level.getBlockState(pos); + VoxelShape vs = bs.getCollisionShape(entity.level, pos); + if (dY >= entity.maxUpStep && dXZ < Math.max(1.0F, entity.getBbWidth()) + || !vs.isEmpty() && entity.getY() < vs.max(Axis.Y) + pos.getY() && !bs.is(BlockTags.DOORS) + && !bs.is(BlockTags.FENCES)) { + NMS.setShouldJump(entity.getBukkitEntity()); } } } diff --git a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java index c2c134aeb..6991a25f8 100644 --- a/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java +++ b/v1_18_R2/src/main/java/net/citizensnpcs/nms/v1_18_R2/util/NMSImpl.java @@ -1519,7 +1519,12 @@ public class NMSImpl implements NMSBridge { if (handle == null) return; MobAI ai = MobAI.from(handle); - ai.getJumpControl().jump(); + if (ai != null) { + ai.getJumpControl().jump(); + } + if (handle instanceof LivingEntity) { + ((LivingEntity) handle).setJumping(true); + } } @Override diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/EntityMoveControl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/EntityMoveControl.java index d9172f195..049f1b639 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/EntityMoveControl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/EntityMoveControl.java @@ -3,6 +3,9 @@ package net.citizensnpcs.nms.v1_19_R3.util; import java.util.Random; import net.citizensnpcs.util.NMS; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction.Axis; +import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -10,6 +13,8 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; public class EntityMoveControl extends MoveControl { protected LivingEntity entity; @@ -94,26 +99,32 @@ public class EntityMoveControl extends MoveControl { 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) + double dXYZ = Math.sqrt(dX * dX + dY * dY + dZ * dZ); + if (dXYZ < 2.500000277905201E-7) { // 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()); + entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); + NMS.setHeadYaw(entity.getBukkitEntity(), entity.getYRot()); } - this.entity.zza = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); + this.entity.zza = (float) (this.speedMod * entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); 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); + return; + } + BlockPos pos = entity.blockPosition(); + BlockState bs = entity.level.getBlockState(pos); + VoxelShape vs = bs.getCollisionShape(entity.level, pos); + if (dY >= entity.maxUpStep() && dXZ < Math.max(1.0F, entity.getBbWidth()) + || !vs.isEmpty() && entity.getY() < vs.max(Axis.Y) + pos.getY() && !bs.is(BlockTags.DOORS) + && !bs.is(BlockTags.FENCES)) { + NMS.setShouldJump(entity.getBukkitEntity()); } } } diff --git a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java index 9ce9f8742..a28e9e9cb 100644 --- a/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java +++ b/v1_19_R3/src/main/java/net/citizensnpcs/nms/v1_19_R3/util/NMSImpl.java @@ -308,7 +308,6 @@ import net.minecraft.world.entity.ai.attributes.AttributeMap; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.FlyingMoveControl; -import net.minecraft.world.entity.ai.control.JumpControl; import net.minecraft.world.entity.ai.control.LookControl; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.ai.goal.GoalSelector; @@ -1663,10 +1662,11 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); if (handle == null) return; - if (handle instanceof Mob) { - JumpControl controller = ((Mob) handle).getJumpControl(); - controller.jump(); - } else { + MobAI ai = MobAI.from(handle); + if (ai != null) { + ai.getJumpControl().jump(); + } + if (handle instanceof LivingEntity) { ((LivingEntity) handle).setJumping(true); } } diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/EntityMoveControl.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/EntityMoveControl.java index 9c1689bf4..228a05e40 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/EntityMoveControl.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/EntityMoveControl.java @@ -3,6 +3,9 @@ package net.citizensnpcs.nms.v1_20_R4.util; import java.util.Random; import net.citizensnpcs.util.NMS; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction.Axis; +import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -10,6 +13,8 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; public class EntityMoveControl extends MoveControl { protected LivingEntity entity; @@ -92,27 +97,31 @@ public class EntityMoveControl extends MoveControl { 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) + double dXYZ = Math.sqrt(dX * dX + dY * dY + dZ * dZ); + if (dXYZ < 2.500000277905201E-7) { // 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()); + entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); + NMS.setHeadYaw(entity.getBukkitEntity(), entity.getYRot()); } - this.entity.zza = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); + this.entity.zza = (float) (this.speedMod * entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); 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); + return; + } + BlockPos pos = entity.blockPosition(); + BlockState bs = entity.level().getBlockState(pos); + VoxelShape vs = bs.getCollisionShape(entity.level(), pos); + if (dY >= entity.maxUpStep() && dXZ < Math.max(1.0F, entity.getBbWidth()) || !vs.isEmpty() + && entity.getY() < vs.max(Axis.Y) + pos.getY() && !bs.is(BlockTags.DOORS) && !bs.is(BlockTags.FENCES)) { + NMS.setShouldJump(entity.getBukkitEntity()); } } } \ No newline at end of file diff --git a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java index 1974f9492..89c99756a 100644 --- a/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java +++ b/v1_20_R4/src/main/java/net/citizensnpcs/nms/v1_20_R4/util/NMSImpl.java @@ -305,7 +305,6 @@ import net.minecraft.world.entity.ai.attributes.AttributeMap; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.FlyingMoveControl; -import net.minecraft.world.entity.ai.control.JumpControl; import net.minecraft.world.entity.ai.control.LookControl; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.ai.goal.GoalSelector; @@ -1662,10 +1661,11 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); if (handle == null) return; - if (handle instanceof Mob) { - JumpControl controller = ((Mob) handle).getJumpControl(); - controller.jump(); - } else { + MobAI ai = MobAI.from(handle); + if (ai != null) { + ai.getJumpControl().jump(); + } + if (handle instanceof LivingEntity) { ((LivingEntity) handle).setJumping(true); } } diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EntityMoveControl.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EntityMoveControl.java index 1c76137a7..f076811a8 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EntityMoveControl.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/EntityMoveControl.java @@ -3,6 +3,9 @@ package net.citizensnpcs.nms.v1_21_R1.util; import java.util.Random; import net.citizensnpcs.util.NMS; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction.Axis; +import net.minecraft.tags.BlockTags; import net.minecraft.util.Mth; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -10,6 +13,8 @@ import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.monster.Slime; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.shapes.VoxelShape; public class EntityMoveControl extends MoveControl { protected LivingEntity entity; @@ -92,27 +97,31 @@ public class EntityMoveControl extends MoveControl { 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) + double dXYZ = Math.sqrt(dX * dX + dY * dY + dZ * dZ); + if (dXYZ < 2.500000277905201E-7) { // 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()); + entity.setYRot(rotlerp(this.entity.getYRot(), f, 90.0F)); + NMS.setHeadYaw(entity.getBukkitEntity(), entity.getYRot()); } - this.entity.zza = (float) (this.speedMod * this.entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); + this.entity.zza = (float) (this.speedMod * entity.getAttribute(Attributes.MOVEMENT_SPEED).getValue()); 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); + return; + } + BlockPos pos = entity.blockPosition(); + BlockState bs = entity.level().getBlockState(pos); + VoxelShape vs = bs.getCollisionShape(entity.level(), pos); + if (dY >= entity.maxUpStep() && dXZ < Math.max(1.0F, entity.getBbWidth()) || !vs.isEmpty() + && entity.getY() < vs.max(Axis.Y) + pos.getY() && !bs.is(BlockTags.DOORS) && !bs.is(BlockTags.FENCES)) { + NMS.setShouldJump(entity.getBukkitEntity()); } } } \ No newline at end of file diff --git a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java index 64e3fbb81..d2f56acb1 100644 --- a/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java +++ b/v1_21_R1/src/main/java/net/citizensnpcs/nms/v1_21_R1/util/NMSImpl.java @@ -306,7 +306,6 @@ import net.minecraft.world.entity.ai.attributes.AttributeMap; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.control.FlyingMoveControl; -import net.minecraft.world.entity.ai.control.JumpControl; import net.minecraft.world.entity.ai.control.LookControl; import net.minecraft.world.entity.ai.control.MoveControl; import net.minecraft.world.entity.ai.goal.GoalSelector; @@ -1641,10 +1640,11 @@ public class NMSImpl implements NMSBridge { Entity handle = getHandle(entity); if (handle == null) return; - if (handle instanceof Mob) { - JumpControl controller = ((Mob) handle).getJumpControl(); - controller.jump(); - } else { + MobAI ai = MobAI.from(handle); + if (ai != null) { + ai.getJumpControl().jump(); + } + if (handle instanceof LivingEntity) { ((LivingEntity) handle).setJumping(true); } } diff --git a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java index a085518e8..a44c4e87b 100644 --- a/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java +++ b/v1_8_R3/src/main/java/net/citizensnpcs/nms/v1_8_R3/util/PlayerControllerMove.java @@ -2,7 +2,6 @@ package net.citizensnpcs.nms.v1_8_R3.util; import java.util.Random; -import net.citizensnpcs.nms.v1_8_R3.entity.EntityHumanNPC; import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_8_R3.ControllerMove; import net.minecraft.server.v1_8_R3.EntityInsentient; @@ -86,12 +85,8 @@ public class PlayerControllerMove extends ControllerMove { 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 { - ((EntityInsentient) this.a).getControllerJump().a(); - } + } else if (dY > NMS.getStepHeight(a.getBukkitEntity()) && dXZ < 0.4D) { + NMS.setShouldJump(a.getBukkitEntity()); } }