From da98acc3cd01aac7e6d7f3ad6845b6471e7940df Mon Sep 17 00:00:00 2001 From: thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:10:14 -0800 Subject: [PATCH] Avoid sending duplicate visual updates to the client --- .../exdeorum/network/VisualUpdateTracker.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateTracker.java b/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateTracker.java index f515c317..b4f8635d 100644 --- a/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateTracker.java +++ b/src/main/java/thedarkcolour/exdeorum/network/VisualUpdateTracker.java @@ -23,26 +23,24 @@ import net.minecraft.world.level.chunk.LevelChunk; import net.minecraftforge.network.PacketDistributor; import thedarkcolour.exdeorum.blockentity.EBlockEntity; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; +import java.util.*; // Syncs certain block entity data to the client for visual purposes // Since some block entities might change their data multiple times a tick, this class keeps track of // whether a block entity has updated and then pushes out the changes once at the end of each tick. public class VisualUpdateTracker { // WeakHashMap is faster than Guava mapmaker - private static final Map> UPDATES = new WeakHashMap<>(); + // Use sets to avoid duplicate updates + private static final Map> UPDATES = new WeakHashMap<>(); public static void sendVisualUpdate(EBlockEntity blockEntity) { var level = blockEntity.getLevel(); if (level != null && !level.isClientSide) { var dimension = level.getChunkAt(blockEntity.getBlockPos()); - List updatesList; + Set updatesList; if (!UPDATES.containsKey(dimension)) { - UPDATES.put(dimension, updatesList = new ArrayList<>()); + UPDATES.put(dimension, updatesList = new HashSet<>()); } else { updatesList = UPDATES.get(dimension); }