Commit d0d00512 by Jonathan Thomas

Draw bubble over Ender Dragon's head, and update click detection to use same calculation

parent 991ad1d3
Pipeline #11977 passed with stage
in 19 seconds
......@@ -14,6 +14,8 @@ 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.util.Identifier;
import net.minecraft.util.math.Box;
......@@ -22,6 +24,8 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.joml.Matrix4f;
import org.joml.Quaternionf;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.stream.Collectors;
......@@ -31,6 +35,7 @@ import java.util.stream.Collectors;
* text, friendship status, and other UI-related rendering code.
*/
public class BubbleRenderer {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
protected static TextureLoader textures = new TextureLoader();
public static int DISPLAY_NUM_LINES = 3;
public static int DISPLAY_PADDING = 2;
......@@ -259,16 +264,34 @@ public class BubbleRenderer {
MathHelper.lerp(partialTicks, entity.prevZ, entity.getPos().z)
);
// Calculate the forward offset based on the entity's yaw
float entityYawRadians = (float) Math.toRadians(entity.getYaw(partialTicks));
Vec3d forwardOffset = new Vec3d(-Math.sin(entityYawRadians), 0.0, Math.cos(entityYawRadians));
// Calculate the forward offset based on the entity's yaw, scaled to 80% towards the front edge
Vec3d scaledForwardOffset = forwardOffset.multiply(entity.getWidth() / 2.0 * 0.8);
// Calculate the position of the chat bubble: above the head and 80% towards the front
Vec3d bubblePosition = interpolatedEntityPos.add(scaledForwardOffset)
.add(0, entityHeight + paddingAboveEntity, 0);
// Determine the chat bubble position
Vec3d bubblePosition;
if (entity instanceof EnderDragonEntity) {
// Ender dragons a unique, and we must use the Head for position
EnderDragonEntity dragon = (EnderDragonEntity) entity;
EnderDragonPart head = dragon.head;
// Interpolate the head position
Vec3d headPos = new Vec3d(
MathHelper.lerp(partialTicks, head.prevX, head.getX()),
MathHelper.lerp(partialTicks, head.prevY, head.getY()),
MathHelper.lerp(partialTicks, head.prevZ, head.getZ())
);
// Just use the head's interpolated position directly
bubblePosition = headPos.add(0, entityHeight + paddingAboveEntity, 0);
} else {
// Calculate the forward offset based on the entity's yaw
float entityYawRadians = (float) Math.toRadians(entity.getYaw(partialTicks));
Vec3d forwardOffset = new Vec3d(-Math.sin(entityYawRadians), 0.0, Math.cos(entityYawRadians));
// Calculate the forward offset based on the entity's yaw, scaled to 80% towards the front edge
Vec3d scaledForwardOffset = forwardOffset.multiply(entity.getWidth() / 2.0 * 0.8);
// Calculate the position of the chat bubble: above the head and 80% towards the front
bubblePosition = interpolatedEntityPos.add(scaledForwardOffset)
.add(0, entityHeight + paddingAboveEntity, 0);
}
// Translate to the chat bubble's position
matrices.translate(bubblePosition.x - interpolatedCameraPos.x,
......
......@@ -15,6 +15,7 @@ import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.Camera;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.boss.dragon.EnderDragonEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.math.Box;
......@@ -172,8 +173,21 @@ public class ClickHandler {
Vec3d forwardOffset = new Vec3d(-Math.sin(entityYawRadians), 0.0, Math.cos(entityYawRadians)).multiply(entity.getWidth() / 2.0 * 0.8);
double paddingAboveEntity = 0.4D;
Vec3d entityPos = entity.getPos();
Vec3d iconCenter = entityPos.add(forwardOffset).add(0, entityHeight + paddingAboveEntity, 0);
Vec3d iconCenter;
// Determine the chat bubble position
if (entity instanceof EnderDragonEntity) {
// Ender dragons a unique, and we must use the Head for position
EnderDragonEntity dragon = (EnderDragonEntity) entity;
Vec3d headPos = dragon.head.getPos();
// Just use the head's interpolated position directly
iconCenter = headPos.add(0, entityHeight + paddingAboveEntity, 0);
} else {
// Calculate the position of the chat bubble: above the head and 80% towards the front
Vec3d entityPos = entity.getPos();
iconCenter = entityPos.add(forwardOffset).add(0, entityHeight + paddingAboveEntity, 0);
}
// Define a bounding box that accurately represents the text bubble
double bubbleRadius = 1D; // Determine the radius or size of the text bubble
......
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