Skip to content

Commit

Permalink
fix: Various Evanescence synchronization issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Nov 12, 2024
1 parent 356935f commit 8bdb7f9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
});
});
Expand Down Expand Up @@ -129,16 +129,19 @@ private static void onRemoved(LivingEntity entity) {
trackedEntity.updatePlayers((List<ServerPlayer>) 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) {
Expand All @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bdb7f9

Please sign in to comment.