Skip to content

Commit

Permalink
Fix players not jumping in newer minecraft versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jun 22, 2024
1 parent ee9c67f commit 20ea3e8
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;
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;
Expand Down Expand Up @@ -94,27 +99,32 @@ public void tick() {
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,9 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
if (ai != null) {
ai.getJumpControl().jump();
}
if (handle instanceof LivingEntity) {
((LivingEntity) handle).setJumping(true);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;
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;
Expand Down Expand Up @@ -94,26 +99,32 @@ public void tick() {
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,12 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;
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;
Expand Down Expand Up @@ -94,26 +99,32 @@ public void tick() {
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@
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;
Expand Down Expand Up @@ -1663,10 +1662,11 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;
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;
Expand Down Expand Up @@ -92,27 +97,31 @@ public void tick() {
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@
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;
Expand Down Expand Up @@ -1662,10 +1661,11 @@ public void setShouldJump(org.bukkit.entity.Entity entity) {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
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;
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;
Expand Down Expand Up @@ -92,27 +97,31 @@ public void tick() {
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());
}
}
}
Loading

0 comments on commit 20ea3e8

Please sign in to comment.