Skip to content

Commit

Permalink
fix: optimize client-side tint updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Oct 12, 2024
1 parent 876e892 commit 88a5ae3
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import gay.sylv.legacy_landscape.data_attachment.LegacyAttachments;
import gay.sylv.legacy_landscape.mixin.ClientLevelAccessor;
import gay.sylv.legacy_landscape.networking.client_bound.LegacyChunkPayload;
import net.minecraft.world.level.Level;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.world.level.chunk.LevelChunk;
import net.neoforged.neoforge.network.handling.IPayloadContext;

Expand All @@ -13,15 +14,18 @@ public final class ClientPayloadHandler {
private ClientPayloadHandler() {}

public static void handleLegacyChunkPayload(final LegacyChunkPayload payload, final IPayloadContext context) {
try (Level level = context.player().level()) {
try (ClientLevel level = (ClientLevel) context.player().level()) {
LevelChunk chunk = level.getChunk(payload.chunkPos().x, payload.chunkPos().z);
((ClientLevelAccessor) level).getTintCaches().forEach((colorResolver, blockTintCache) -> blockTintCache.invalidateForChunk(chunk.getPos().x, chunk.getPos().z));
LegacyNetworking.LOGGER.info("{}", payload);
if (payload.isLegacyChunk()) {
chunk.setData(LegacyAttachments.LEGACY_CHUNK, true);
} else {
chunk.removeData(LegacyAttachments.LEGACY_CHUNK);
}
((ClientLevelAccessor) level).getTintCaches().forEach((colorResolver, blockTintCache) -> blockTintCache.invalidateForChunk(chunk.getPos().x, chunk.getPos().z));
for (int y = level.getMinSection(); y < level.getMaxSection(); y++) {
Minecraft.getInstance().levelRenderer.setSectionDirty(chunk.getPos().x, y, chunk.getPos().z);
}
} catch (IOException e) {
LegacyNetworking.LOGGER.error("Failed to handle legacy chunk payload", e);
}
Expand Down

0 comments on commit 88a5ae3

Please sign in to comment.