diff --git a/CHANGELOG.md b/CHANGELOG.md index 508f3f725..53fc8e803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ Unless otherwise specified, any version comparison below is the comparison of se - (API) Introduced `EntityBaseComponent#computeLiquidMotion` method to control whether an entity has liquid motion. - (API) Introduced `EntityDamageComponent#hasDrowningDamage` method to control whether an entity has drowning damage. - Added liquid motion for water and lava. Now entity will be moved by liquid flow if it is in the liquid. +- Pos sent by the client will only be handled when the pos is changed, as `PlayerAuthInputPacket` is sent every tick but + the player may not move every tick. ### Changed @@ -34,6 +36,8 @@ Unless otherwise specified, any version comparison below is the comparison of se touched by users. - Introduced tag name constants for where a large number of NBT saving and reading are involved. This improved the maintainability of the project. +- Introduced better names for some of the fields in `PlayerAuthInputPacketProcessor`, this improved the readability of + the code. ### Fixed diff --git a/server/src/main/java/org/allaymc/server/network/processor/impl/ingame/PlayerAuthInputPacketProcessor.java b/server/src/main/java/org/allaymc/server/network/processor/impl/ingame/PlayerAuthInputPacketProcessor.java index bc4ae296a..de769127a 100644 --- a/server/src/main/java/org/allaymc/server/network/processor/impl/ingame/PlayerAuthInputPacketProcessor.java +++ b/server/src/main/java/org/allaymc/server/network/processor/impl/ingame/PlayerAuthInputPacketProcessor.java @@ -34,23 +34,25 @@ @Slf4j public class PlayerAuthInputPacketProcessor extends PacketProcessor { - // Since block actions are processed asynchronously, a tolerance of 3 ticks is normal // TODO: Accurate breaking time calculations when player keeping jumping // The current implementation will work fine in most cases // But it doesn't work out the same breaking time as the client when player keep jumping // It is hard for us to calculate the exact breaking time when player keep jumping protected static final int BLOCK_BREAKING_TIME_FAULT_TOLERANCE = Integer.MAX_VALUE; - protected int breakBlockX = Integer.MAX_VALUE; - protected int breakBlockY = Integer.MAX_VALUE; - protected int breakBlockZ = Integer.MAX_VALUE; + protected int blockToBreakX = Integer.MAX_VALUE; + protected int blockToBreakY = Integer.MAX_VALUE; + protected int blockToBreakZ = Integer.MAX_VALUE; - protected int breakFaceId; - protected BlockState breakBlock; + protected int faceToBreak; + protected BlockState blockToBreak; - protected long startBreakTime; // Ticks - protected double needBreakTime; // Seconds - protected double stopBreakTime; // Ticks + // Ticks + protected long startBreakingTime; + // Seconds + protected double timeNeededToBreak; + // Ticks + protected double stopBreakingTime; private static boolean isInvalidGameType(EntityPlayer player) { return player.getGameType() == GameType.CREATIVE || @@ -96,7 +98,7 @@ protected void handleBlockAction(EntityPlayer player, List inputData) { @@ -292,8 +294,10 @@ public PacketSignal handleAsync(EntityPlayer player, PlayerAuthInputPacket packe return PacketSignal.HANDLED; } - // The pos which client sends to the server is higher than the actual coordinates (one base offset) - handleMovement(player, packet.getPosition().sub(0, player.getBaseOffset(), 0), packet.getRotation()); + if (isLocationChanged(player, packet.getPosition(), packet.getRotation())) { + // The pos which client sends to the server is higher than the actual coordinates (one base offset) + handleMovement(player, packet.getPosition().sub(0, player.getBaseOffset(), 0), packet.getRotation()); + } handleBlockAction(player, packet.getPlayerActions(), receiveTime); if (isBreakingBlock()) { sendBreakingPracticeAndTime(player, receiveTime); @@ -314,6 +318,13 @@ protected boolean validateClientLocation(EntityPlayer player, Vector3f pos, Vect return valid; } + protected boolean isLocationChanged(EntityPlayer player, Vector3f pos, Vector3f rot) { + // The PlayerAuthInput packet is sent every tick, so don't do anything if the position and rotation were unchanged. + var location = player.getLocation(); + return Float.compare(location.x(), pos.getX()) != 0 || Float.compare(location.y() + player.getBaseOffset(), pos.getY()) != 0 || Float.compare(location.z(), pos.getZ()) != 0 || + Double.compare(location.pitch(), rot.getX()) != 0 || Double.compare(location.yaw(), rot.getY()) != 0 || Double.compare(location.headYaw(), rot.getZ()) != 0; + } + protected void handleSingleItemStackRequest(EntityPlayer player, ItemStackRequest request, long receiveTime) { // We had no idea why the client still use PlayerAuthInputPacket to hold ItemStackRequest // Instead of using ItemStackRequestPacket