From 797e9637d93299dae1f08c22c85cbd47daccd6a3 Mon Sep 17 00:00:00 2001 From: SamB440 Date: Tue, 16 Jul 2024 19:04:33 +0100 Subject: [PATCH] Remove useless stuff in updateAttributes --- .../utils/latency/CompensatedEntities.java | 74 ++++++------------- 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java b/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java index 734ac7650b..3175aa7c92 100644 --- a/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java +++ b/src/main/java/ac/grim/grimac/utils/latency/CompensatedEntities.java @@ -108,72 +108,40 @@ public Integer getPotionLevelForPlayer(PotionType type) { public void updateAttributes(int entityID, List objects) { if (entityID == player.entityID) { + // Check for sprinting attribute. Note that this value can desync: https://bugs.mojang.com/browse/MC-69459 for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) { final Attribute attribute = snapshotWrapper.getAttribute(); - if (attribute == Attributes.GENERIC_MOVEMENT_SPEED) { - boolean found = false; - List modifiers = snapshotWrapper.getModifiers(); - for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) { - final ResourceLocation name = modifier.getName(); - if (name.getKey().equals(SPRINTING_MODIFIER_UUID.toString()) || name.getKey().equals("sprinting")) { - found = true; - break; - } + if (attribute != Attributes.GENERIC_MOVEMENT_SPEED) continue; + + boolean found = false; + List modifiers = snapshotWrapper.getModifiers(); + for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) { + final ResourceLocation name = modifier.getName(); + if (name.getKey().equals(SPRINTING_MODIFIER_UUID.toString()) || name.getKey().equals("sprinting")) { + found = true; + break; } - - // The server can set the player's sprinting attribute - hasSprintingAttributeEnabled = found; - player.compensatedEntities.getSelf().getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper); - continue; - } - - final Optional valuedAttribute = player.compensatedEntities.getSelf().getAttribute(attribute); - if (!valuedAttribute.isPresent()) { - // Not an attribute we want to track - continue; } - valuedAttribute.get().with(snapshotWrapper); + // The server can set the player's sprinting attribute + hasSprintingAttributeEnabled = found; + break; } - return; } PacketEntity entity = player.compensatedEntities.getEntity(entityID); if (entity == null) return; - if (player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_5)) { - for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) { - final Attribute attribute = snapshotWrapper.getAttribute(); - final Optional valuedAttribute = entity.getAttribute(attribute); - if (!valuedAttribute.isPresent()) { - // Not an attribute we want to track - continue; - } - - valuedAttribute.get().with(snapshotWrapper); - } - } - - if (entity instanceof PacketEntityHorse) { - for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) { - if (snapshotWrapper.getAttribute() == null) continue; - if (snapshotWrapper.getKey().toUpperCase().contains("MOVEMENT")) { - entity.getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper); - } - - if (snapshotWrapper.getKey().toUpperCase().contains("JUMP")) { - entity.getAttribute(Attributes.GENERIC_JUMP_STRENGTH).get().with(snapshotWrapper); - } + for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) { + final Attribute attribute = snapshotWrapper.getAttribute(); + if (attribute == null) continue; // TODO: Warn if this happens? Either modded server or bug in packetevents. + final Optional valuedAttribute = entity.getAttribute(attribute); + if (!valuedAttribute.isPresent()) { + // Not an attribute we want to track + continue; } - } - if (entity instanceof PacketEntityRideable) { - for (WrapperPlayServerUpdateAttributes.Property snapshotWrapper : objects) { - if (snapshotWrapper.getAttribute() == null) continue; - if (snapshotWrapper.getKey().toUpperCase().contains("MOVEMENT")) { - entity.getAttribute(Attributes.GENERIC_MOVEMENT_SPEED).get().with(snapshotWrapper); - } - } + valuedAttribute.get().with(snapshotWrapper); } }