Commit d3eed475 by Jonathan Thomas

Clear client ChatDataManager when a client joins or disconnects from a world

parent aa6a8087
Pipeline #11654 passed with stage
in 26 seconds
...@@ -2,6 +2,7 @@ package com.owlmaddie; ...@@ -2,6 +2,7 @@ package com.owlmaddie;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
...@@ -36,9 +37,23 @@ public class ClientInit implements ClientModInitializer { ...@@ -36,9 +37,23 @@ public class ClientInit implements ClientModInitializer {
public void onInitializeClient() { public void onInitializeClient() {
ClickHandler.register(); ClickHandler.register();
// Register an event callback to render text bubbles
WorldRenderEvents.LAST.register((context) -> { WorldRenderEvents.LAST.register((context) -> {
drawTextAboveEntities(context, context.tickDelta()); drawTextAboveEntities(context, context.tickDelta());
}); });
// Register an event callback for when the client disconnects from a server or changes worlds
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
// Clear or reset the ChatDataManager
ChatDataManager.getClientInstance().clearData();
});
// Register an event callback for when the player joins a server or world
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
// Possibly re-initialize or prepare the ChatDataManager for the new session
ChatDataManager.getClientInstance().clearData();
});
} }
public void drawTextBubbleBackground(MatrixStack matrices, Entity entity, float x, float y, float width, float height) { public void drawTextBubbleBackground(MatrixStack matrices, Entity entity, float x, float y, float width, float height) {
......
...@@ -85,6 +85,11 @@ public class ChatDataManager { ...@@ -85,6 +85,11 @@ public class ChatDataManager {
} }
} }
public void clearData() {
// Clear the chat data for the previous session
entityChatDataMap.clear();
}
private ChatDataManager() { private ChatDataManager() {
entityChatDataMap = new HashMap<>(); entityChatDataMap = new HashMap<>();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment