Commit 874d53ba by Jonathan Thomas

- New class to track the render details of all chat bubbles (height, width, rotation, etc...)

- Integrated this BubbleLocationManager into the ClickHandler, which fixes lots of issues and removes lots of duplicate code
- Rotate (yaw/pitch) of click handler geometry, so it matches exactly with the rendering locations/rotations.
parent 4faa7d0b
Pipeline #11986 passed with stage
in 20 seconds
package com.owlmaddie.ui;
import net.minecraft.util.math.Vec3d;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
/**
* The {@code BubbleLocationManager} class is used to keep track of the currently rendered chat bubbles,
* to simplify click handling of nearby chat bubbles. This data includes the exact location of the chat
* bubbles, and their rotations (pitch, yaw).
*/
public class BubbleLocationManager {
private static final Map<UUID, BubbleData> bubbleDataMap = new ConcurrentHashMap<>();
public static void updateBubbleData(UUID entityId, Vec3d position, double width, double height, double yaw, double pitch) {
bubbleDataMap.put(entityId, new BubbleData(position, width, height, yaw, pitch));
}
public static BubbleData getBubbleData(UUID entityId) {
return bubbleDataMap.get(entityId);
}
public static class BubbleData {
public final Vec3d position;
public final double width;
public final double height;
public final double yaw;
public final double pitch;
public BubbleData(Vec3d position, double width, double height, double yaw, double pitch) {
this.position = position;
this.width = width;
this.height = height;
this.yaw = yaw;
this.pitch = pitch;
}
}
public static void performCleanup(List<UUID> activeEntityIds) {
// Retain only entries for active entities
bubbleDataMap.keySet().retainAll(activeEntityIds);
}
public static Map<UUID, BubbleData> getAllBubbleData() {
return Collections.unmodifiableMap(bubbleDataMap);
}
}
...@@ -28,6 +28,7 @@ import org.slf4j.Logger; ...@@ -28,6 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -342,6 +343,10 @@ public class BubbleRenderer { ...@@ -342,6 +343,10 @@ public class BubbleRenderer {
float minTextHeight = (DISPLAY_NUM_LINES * (fontRenderer.fontHeight + lineSpacing)) + (DISPLAY_PADDING * 2); float minTextHeight = (DISPLAY_NUM_LINES * (fontRenderer.fontHeight + lineSpacing)) + (DISPLAY_PADDING * 2);
scaledTextHeight = Math.max(scaledTextHeight, minTextHeight); scaledTextHeight = Math.max(scaledTextHeight, minTextHeight);
// Update Bubble Data for Click Handling using UUID (account for scaling)
BubbleLocationManager.updateBubbleData(entity.getUuid(), bubblePosition,
128F / (1 / 0.02F), (scaledTextHeight + 25F) / (1 / 0.02F), yaw, pitch);
// Scale down before rendering textures (otherwise font is huge) // Scale down before rendering textures (otherwise font is huge)
matrices.scale(-0.02F, -0.02F, 0.02F); matrices.scale(-0.02F, -0.02F, 0.02F);
...@@ -391,5 +396,13 @@ public class BubbleRenderer { ...@@ -391,5 +396,13 @@ public class BubbleRenderer {
// Pop the matrix to return to the original state. // Pop the matrix to return to the original state.
matrices.pop(); matrices.pop();
} }
// Get list of Entity UUIDs with chat bubbles rendered
List<UUID> activeEntityUUIDs = nearbyCreatures.stream()
.map(Entity::getUuid)
.collect(Collectors.toList());
// Purge entities that were not rendered
BubbleLocationManager.performCleanup(activeEntityUUIDs);
} }
} }
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