From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: AlphaKR93 Date: Wed, 27 Sep 2023 22:35:19 +0900 Subject: [PATCH] Ignore useless entity packets diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java index 92ca330bee2f58bde93c8da12a8f5c14e29de540..05342f5fbe5cd62e81e09d3d6743cf47331b54c2 100644 --- a/src/main/java/net/minecraft/server/level/ServerEntity.java +++ b/src/main/java/net/minecraft/server/level/ServerEntity.java @@ -200,6 +200,8 @@ public class ServerEntity { flag4 = true; flag5 = true; } + + if (this.level.plazmaConfig().entity.ignoreUselessPackets && isUselessPacket(packet1)) packet1 = null; // Plazma } if ((this.trackDelta || this.entity.hasImpulse || this.entity instanceof LivingEntity && ((LivingEntity) this.entity).isFallFlying()) && this.tickCount > 0) { @@ -272,6 +274,19 @@ public class ServerEntity { }); } + // Plazma start + private boolean isUselessPacket(@Nullable Packet packet) { + if (!(packet instanceof ClientboundMoveEntityPacket p)) return false; + if (p instanceof ClientboundMoveEntityPacket.Pos) + return p.getXa() == 0 && p.getYa() == 0 && p.getZa() == 0; + if (p instanceof ClientboundMoveEntityPacket.Rot) + return p.getxRot() == 0 && p.getyRot() == 0; + if (p instanceof ClientboundMoveEntityPacket.PosRot) + return p.getXa() == 0 && p.getYa() == 0 && p.getZa() == 0 && p.getxRot() == 0 && p.getyRot() == 0; + return false; + } + // Plazma end + public void removePairing(ServerPlayer player) { this.entity.stopSeenByPlayer(player); player.connection.send(new ClientboundRemoveEntitiesPacket(new int[]{this.entity.getId()})); diff --git a/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java b/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java index 036c0b12553ae203e8c73d44dc2e3d625b812af5..909a74c19501d9440f3d2435b6514d738efcfc05 100644 --- a/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java +++ b/src/main/java/org/plazmamc/plazma/configurations/WorldConfigurations.java @@ -29,6 +29,8 @@ public class WorldConfigurations extends ConfigurationPart { public Entity entity; public class Entity extends ConfigurationPart { + public boolean ignoreUselessPackets = OPTIMIZE; + public Phantom phantom; public class Phantom extends ConfigurationPart {