Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
CreatureChat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Public
CreatureChat
Commits
d0d00512
Commit
d0d00512
authored
Apr 12, 2024
by
Jonathan Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
12 deletions
+49
-12
BubbleRenderer.java
src/client/java/com/owlmaddie/ui/BubbleRenderer.java
+33
-10
ClickHandler.java
src/client/java/com/owlmaddie/ui/ClickHandler.java
+16
-2
No files found.
src/client/java/com/owlmaddie/ui/BubbleRenderer.java
View file @
d0d00512
...
...
@@ -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
,
...
...
src/client/java/com/owlmaddie/ui/ClickHandler.java
View file @
d0d00512
...
...
@@ -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.4
D
;
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
=
1
D
;
// Determine the radius or size of the text bubble
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment