From 8bdb7f97de61e7cab0cc175c71e0f964c4bdd2c9 Mon Sep 17 00:00:00 2001 From: sylv256 Date: Tue, 12 Nov 2024 17:35:45 -0500 Subject: [PATCH] fix: Various Evanescence synchronization issues. --- gradle.properties | 2 +- .../effect/EvanescenceEffect.java | 17 ++++++++++------- .../mixin/Mixin_LivingEntity.java | 4 +--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6b90585..52b8bdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ mod_name=Legacy Landscape # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=EUPL-1.2 # The mod version. See https://semver.org/ -mod_version=0.7.1+1.21.1 +mod_version=0.7.2+1.21.1 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/gay/sylv/legacy_landscape/effect/EvanescenceEffect.java b/src/main/java/gay/sylv/legacy_landscape/effect/EvanescenceEffect.java index 642d500..d893720 100644 --- a/src/main/java/gay/sylv/legacy_landscape/effect/EvanescenceEffect.java +++ b/src/main/java/gay/sylv/legacy_landscape/effect/EvanescenceEffect.java @@ -1,12 +1,10 @@ package gay.sylv.legacy_landscape.effect; import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments; -import gay.sylv.legacy_landscape.entity.SilentLivingEntity; import gay.sylv.legacy_landscape.mixin.Accessor_ChunkMap; import gay.sylv.legacy_landscape.mixin.Accessor_TrackedEntity; import gay.sylv.legacy_landscape.util.Maths; import net.minecraft.core.particles.ParticleOptions; -import net.minecraft.network.protocol.game.ClientboundAddEntityPacket; import net.minecraft.network.protocol.game.ClientboundRemoveMobEffectPacket; import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; import net.minecraft.server.level.ChunkMap; @@ -59,6 +57,8 @@ public void onEffectAdded(@NotNull LivingEntity livingEntity, int amplifier) { ServerPlayer player = connection.getPlayer(); if (!player.hasData(LegacyAttachments.OMNISCIENT)) { ((Accessor_TrackedEntity) trackedEntity).getServerEntity().removePairing(player); + } else { + sendActiveEffect(livingEntity, connection); } }); }); @@ -129,16 +129,19 @@ private static void onRemoved(LivingEntity entity) { trackedEntity.updatePlayers((List) entity.level().players()); ((Accessor_TrackedEntity) trackedEntity).getSeenBy() .forEach(connection -> { - connection.send(new ClientboundAddEntityPacket(entity, ((Accessor_TrackedEntity) trackedEntity).getServerEntity())); - if (connection.getPlayer().hasData(LegacyAttachments.OMNISCIENT)) { + ServerPlayer player = connection.getPlayer(); + if (player.hasData(LegacyAttachments.OMNISCIENT)) { removeInactiveEffect(entity, connection); + } else { + pairEntity(player, trackedEntity); } }); }); } + } - // Make entity no longer silent. - ((SilentLivingEntity) entity).legacy_landscape$setSilent(false); + private static void pairEntity(ServerPlayer player, ChunkMap.TrackedEntity trackedEntity) { + ((Accessor_TrackedEntity) trackedEntity).getServerEntity().addPairing(player); } private static void showForPlayer(LivingEntity entity, ServerPlayer player) { @@ -153,7 +156,7 @@ private static void showForPlayer(LivingEntity entity, ServerPlayer player) { // Tell player to track this entity again. trackedEntity.updatePlayers(List.of(player)); ((Accessor_TrackedEntity) trackedEntity).getSeenBy() - .forEach(connection -> connection.send(new ClientboundAddEntityPacket(entity, ((Accessor_TrackedEntity) trackedEntity).getServerEntity()))); + .forEach(connection -> pairEntity(player, trackedEntity)); sendActiveEffect(entity, player.connection); }); } diff --git a/src/main/java/gay/sylv/legacy_landscape/mixin/Mixin_LivingEntity.java b/src/main/java/gay/sylv/legacy_landscape/mixin/Mixin_LivingEntity.java index b32ccf9..f00db6d 100644 --- a/src/main/java/gay/sylv/legacy_landscape/mixin/Mixin_LivingEntity.java +++ b/src/main/java/gay/sylv/legacy_landscape/mixin/Mixin_LivingEntity.java @@ -32,9 +32,7 @@ private Mixin_LivingEntity(EntityType entityType, Level level) { at = @At("HEAD") ) private void silenceIfEvanescent(CallbackInfo ci) { - if (this.hasEffect(LegacyEffects.EVANESCENCE) && !this.legacy_landscape$isSilent()) { - this.legacy_landscape$setSilent(true); - } + this.legacy_landscape$setSilent(this.hasEffect(LegacyEffects.EVANESCENCE)); } @Override