Commit 458845e4 by Jonathan Thomas

- Adding playerId UUID into entityChatData, so we can know what user interacted with the entity.

- Broadcast this new playerId along with the chatData
parent a2ed5ee5
Pipeline #11991 passed with stage
in 25 seconds
......@@ -13,10 +13,10 @@ import net.minecraft.client.render.*;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.boss.dragon.EnderDragonPart;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
......@@ -132,7 +132,7 @@ public class BubbleRenderer {
RenderSystem.disableDepthTest();
}
private static void drawEntityIcon(MatrixStack matrices, MobEntity entity, float x, float y, float width, float height) {
private static void drawEntityIcon(MatrixStack matrices, Entity entity, float x, float y, float width, float height) {
// Get entity renderer
EntityRenderer renderer = EntityRendererAccessor.getEntityRenderer(entity);
String entity_icon_path = renderer.getTexture(entity).getPath();
......@@ -184,7 +184,7 @@ public class BubbleRenderer {
}
}
private static void drawEntityName(MobEntity entity, Matrix4f matrix, VertexConsumerProvider immediate,
private static void drawEntityName(Entity entity, Matrix4f matrix, VertexConsumerProvider immediate,
int fullBright, float yOffset) {
TextRenderer fontRenderer = MinecraftClient.getInstance().textRenderer;
......@@ -204,6 +204,10 @@ public class BubbleRenderer {
}
public static void drawTextAboveEntities(WorldRenderContext context, long tick, float partialTicks) {
// Access the Minecraft client instance
MinecraftClient client = MinecraftClient.getInstance();
PlayerEntity player = client.player;
Camera camera = context.camera();
Entity cameraEntity = camera.getFocusedEntity();
if (cameraEntity == null) return;
......@@ -227,14 +231,15 @@ public class BubbleRenderer {
// Get all entities
List<Entity> nearbyEntities = world.getOtherEntities(null, area);
// Filter MobEntity/Living entities
List<MobEntity> nearbyCreatures = nearbyEntities.stream()
.filter(entity -> entity instanceof MobEntity)
.map(entity -> (MobEntity) entity)
// Filter to include only MobEntity & PlayerEntity but exclude the current player and any entities with passengers
List<Entity> relevantEntities = nearbyEntities.stream()
.filter(entity -> (entity instanceof MobEntity || entity instanceof PlayerEntity))
.filter(entity -> !entity.getUuid().equals(player.getUuid())) // Exclude current player by UUID
.filter(entity -> !entity.hasPassengers()) // Exclude entities with passengers
.collect(Collectors.toList());
for (MobEntity entity : nearbyCreatures) {
if (entity.getType() == EntityType.PLAYER || entity.hasPassengers()) {
for (Entity entity : relevantEntities) {
if (entity.hasPassengers()) {
// Skip
continue;
}
......@@ -401,7 +406,7 @@ public class BubbleRenderer {
}
// Get list of Entity UUIDs with chat bubbles rendered
List<UUID> activeEntityUUIDs = nearbyCreatures.stream()
List<UUID> activeEntityUUIDs = relevantEntities.stream()
.map(Entity::getUuid)
.collect(Collectors.toList());
......
......@@ -57,6 +57,7 @@ public class ClickHandler {
ClientPlayNetworking.registerGlobalReceiver(ModInit.PACKET_S2C_MESSAGE, (client, handler, buffer, responseSender) -> {
// Read the data from the server packet
UUID entityId = UUID.fromString(buffer.readString());
UUID playerId = UUID.fromString(buffer.readString());
String message = buffer.readString(32767);
int line = buffer.readInt();
String status_name = buffer.readString(32767);
......@@ -69,6 +70,7 @@ public class ClickHandler {
if (entity != null) {
ChatDataManager chatDataManager = ChatDataManager.getClientInstance();
ChatDataManager.EntityChatData chatData = chatDataManager.getOrCreateChatData(entity.getUuidAsString());
chatData.playerId = playerId.toString();
if (!message.isEmpty()) {
chatData.currentMessage = message;
}
......
package com.owlmaddie.utils;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.Entity;
/**
* The {@code EntityHeightMap} class returns an adjusted entity height (which fixes certain MobEntity's with
* unusually tall heights)
*/
public class EntityHeights {
public static float getAdjustedEntityHeight(MobEntity entity) {
public static float getAdjustedEntityHeight(Entity entity) {
// Get entity height (adjust for specific classes)
float entityHeight = entity.getHeight();
if (entity instanceof EnderDragonEntity) {
......
......@@ -275,7 +275,8 @@ public class ModInit implements ModInitializer {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
// Write the entity's chat updated data
buffer.writeString(entity.getUuidAsString());
buffer.writeString(chatData.entityId);
buffer.writeString(chatData.playerId);
buffer.writeString(chatData.currentMessage);
buffer.writeInt(chatData.currentLineNumber);
buffer.writeString(chatData.status.toString());
......
......@@ -72,6 +72,7 @@ public class ChatDataManager {
// Inner class to hold entity-specific data
public static class EntityChatData {
public String entityId;
public String playerId;
public String currentMessage;
public int currentLineNumber;
public ChatStatus status;
......@@ -82,6 +83,7 @@ public class ChatDataManager {
public EntityChatData(String entityId) {
this.entityId = entityId;
this.playerId = null;
this.currentMessage = "";
this.currentLineNumber = 0;
this.previousMessages = new ArrayList<>();
......@@ -196,7 +198,7 @@ public class ChatDataManager {
public void generateMessage(ServerPlayerEntity player, String systemPrompt, String userMessage) {
this.status = ChatStatus.PENDING;
// Add USER Message
this.addMessage(userMessage, ChatSender.USER);
this.addMessage(userMessage, ChatSender.USER, player.getUuidAsString());
// Add PLAYER context information
Map<String, String> contextData = getPlayerContext(player);
......@@ -210,7 +212,7 @@ public class ChatDataManager {
// Add NEW CHARACTER sheet & greeting
this.characterSheet = output_message;
String shortGreeting = getCharacterProp("short greeting");
this.addMessage(shortGreeting.replace("\n", " "), ChatSender.ASSISTANT);
this.addMessage(shortGreeting.replace("\n", " "), ChatSender.ASSISTANT, player.getUuidAsString());
} else if (output_message != null && systemPrompt == "system-chat") {
// Chat Message: Parse message for behaviors
......@@ -272,7 +274,7 @@ public class ChatDataManager {
}
// Add ASSISTANT message to history
this.addMessage(result.getOriginalMessage(), ChatSender.ASSISTANT);
this.addMessage(result.getOriginalMessage(), ChatSender.ASSISTANT, player.getUuidAsString());
// Get cleaned message (i.e. no <BEHAVIOR> strings)
String cleanedMessage = result.getCleanedMessage();
......@@ -285,7 +287,7 @@ public class ChatDataManager {
} else {
// Error / No Chat Message (Failure)
String randomErrorMessage = ParsedMessage.getRandomErrorMessage();
this.addMessage(randomErrorMessage, ChatSender.ASSISTANT);
this.addMessage(randomErrorMessage, ChatSender.ASSISTANT, player.getUuidAsString());
// Clear history (if no character sheet was generated)
if (characterSheet.isEmpty()) {
......@@ -299,7 +301,7 @@ public class ChatDataManager {
}
// Add a message to the history and update the current message
public void addMessage(String message, ChatSender messageSender) {
public void addMessage(String message, ChatSender messageSender, String playerId) {
// Add message to history
previousMessages.add(new ChatMessage(message, messageSender));
......@@ -314,6 +316,7 @@ public class ChatDataManager {
status = ChatStatus.PENDING;
}
sender = messageSender;
this.playerId = playerId;
// Broadcast to all players
ModInit.BroadcastPacketMessage(this);
......
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