Skip to content

Commit

Permalink
Fix data consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 21, 2024
1 parent aae3811 commit 69955b0
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void tick(BotConnection connection) {

var previousYRot = clientEntity.yRot();
clientEntity.lookAt(RotationOrigin.EYES, targetMiddleBlock);
clientEntity.xRot(0);
clientEntity.setXRot(0);
var newYRot = clientEntity.yRot();

var yRotDifference = Math.abs(MathHelper.wrapDegrees(newYRot - previousYRot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void tick(BotConnection connection) {

var previousYRot = clientEntity.yRot();
clientEntity.lookAt(RotationOrigin.EYES, targetMiddleBlock);
clientEntity.xRot(0);
clientEntity.setXRot(0);
var newYRot = clientEntity.yRot();

var yRotDifference = Math.abs(MathHelper.wrapDegrees(newYRot - previousYRot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,8 @@ public void packetSent(Session botSession, Packet packet) {
lastZ = posRot.getZ();

clientEntity.setPos(posRot.getX(), posRot.getY(), posRot.getZ());
clientEntity.yRot(posRot.getYaw());
clientEntity.xRot(posRot.getPitch());
clientEntity.setYRot(posRot.getYaw());
clientEntity.setXRot(posRot.getPitch());
}
case ServerboundMovePlayerPosPacket pos -> {
lastX = pos.getX();
Expand All @@ -967,8 +967,8 @@ public void packetSent(Session botSession, Packet packet) {
clientEntity.setPos(pos.getX(), pos.getY(), pos.getZ());
}
case ServerboundMovePlayerRotPacket rot -> {
clientEntity.yRot(rot.getYaw());
clientEntity.xRot(rot.getPitch());
clientEntity.setYRot(rot.getYaw());
clientEntity.setXRot(rot.getPitch());
}
case ServerboundAcceptTeleportationPacket teleportationPacket -> {
// This was a forced teleport, the server should not know about it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public void onPosition(ClientboundPlayerPositionPacket packet) {

@EventHandler
public void onRotation(ClientboundPlayerRotationPacket packet) {
localPlayer.setRotation(
localPlayer.setRot(
packet.getYRot(),
packet.getXRot()
);
Expand Down Expand Up @@ -940,7 +940,7 @@ public void onEntityPos(ClientboundMoveEntityPosPacket packet) {
}

state.addPos(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ());
state.onGround(packet.isOnGround());
state.setOnGround(packet.isOnGround());
}

@EventHandler
Expand All @@ -952,8 +952,8 @@ public void onEntityRot(ClientboundMoveEntityRotPacket packet) {
return;
}

state.setRotation(packet.getYaw(), packet.getPitch());
state.onGround(packet.isOnGround());
state.setRot(packet.getYaw(), packet.getPitch());
state.setOnGround(packet.isOnGround());
}

@EventHandler
Expand All @@ -979,8 +979,8 @@ public void onEntityPosRot(ClientboundMoveEntityPosRotPacket packet) {
}

state.addPos(packet.getMoveX(), packet.getMoveY(), packet.getMoveZ());
state.setRotation(packet.getYaw(), packet.getPitch());
state.onGround(packet.isOnGround());
state.setRot(packet.getYaw(), packet.getPitch());
state.setOnGround(packet.isOnGround());
}

@EventHandler
Expand All @@ -998,7 +998,7 @@ public void onEntityTeleport(ClientboundTeleportEntityPacket packet) {
packet.getYRot(),
packet.getXRot()
), packet.getRelatives()));
state.onGround(packet.isOnGround());
state.setOnGround(packet.isOnGround());
}

@EventHandler
Expand All @@ -1016,7 +1016,7 @@ public void onEntityPositionSync(ClientboundEntityPositionSyncPacket packet) {
packet.getYRot(),
packet.getXRot()
));
state.onGround(packet.isOnGround());
state.setOnGround(packet.isOnGround());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@

@Slf4j
@Getter
@Setter
public abstract class Entity {
protected static final int FLAG_ONFIRE = 0;
protected static final int FLAG_GLOWING = 6;
Expand All @@ -67,9 +66,13 @@ public abstract class Entity {
protected final EntityType entityType;
protected final EntityMetadataState metadataState;
protected float fallDistance;
@Setter
protected UUID uuid;
@Setter
protected ObjectData data;
@Setter
protected int entityId;
@Setter
protected Level level;
protected BlockState inBlockState = null;
protected boolean firstTick = true;
Expand Down Expand Up @@ -125,7 +128,7 @@ public void fromAddEntityPacket(ClientboundAddEntityPacket packet) {
data(packet.getData());
setPos(packet.getX(), packet.getY(), packet.getZ());
setHeadRotation(packet.getHeadYaw());
setRotation(packet.getYaw(), packet.getPitch());
setRot(packet.getYaw(), packet.getPitch());
setDeltaMovement(packet.getMotionX(), packet.getMotionY(), packet.getMotionZ());
}

Expand All @@ -136,7 +139,7 @@ public EntityMovement toMovement() {
public void setFrom(EntityMovement entityMovement) {
setPos(entityMovement.pos());
setDeltaMovement(entityMovement.deltaMovement());
setRotation(entityMovement.yRot(), entityMovement.xRot());
setRot(entityMovement.yRot(), entityMovement.xRot());
}

public double x() {
Expand Down Expand Up @@ -233,9 +236,25 @@ public final void setBoundingBox(AABB bb) {
this.bb = bb;
}

public void setRotation(float yRot, float xRot) {
this.yRot = yRot;
this.xRot = xRot;
public void setRot(float yRot, float xRot) {
this.setYRot(yRot % 360.0F);
this.setXRot(xRot % 360.0F);
}

public void setYRot(float yRot) {
if (!Float.isFinite(yRot)) {
log.warn("Invalid entity y rotation: {}, discarding.", yRot);
} else {
this.yRot = yRot;
}
}

public void setXRot(float xRot) {
if (!Float.isFinite(xRot)) {
log.warn("Invalid entity x rotation: {}, discarding.", xRot);
} else {
this.xRot = Math.clamp(xRot % 360.0F, -90.0F, 90.0F);
}
}

public void setHeadRotation(float headYRot) {
Expand Down Expand Up @@ -608,7 +627,6 @@ public boolean updateFluidHeightAndDoFluidPushing(TagKey<FluidType> fluidTag, do
height = Math.max(f - lv.minY, height);
if (pushedByFluid) {
var flowDirection = lv4.getFlow(this.level(), lv3);
System.out.println(flowDirection);
if (height < 0.4) {
flowDirection = flowDirection.mul(height);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void tick() {
}

if (this.isSleeping()) {
this.xRot(0.0F);
this.setXRot(0.0F);
}

var currentScale = this.getScale();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Player(Level level, GameProfile gameProfile) {
public void tick() {
this.noPhysics = this.isSpectator();
if (this.isSpectator()) {
this.onGround(false);
this.setOnGround(false);
}

this.wasUnderwater = this.isEyeInFluid(FluidTags.WATER);
Expand Down

0 comments on commit 69955b0

Please sign in to comment.