Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for plugins that use display entities as nametag #5157

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@

package org.geysermc.geyser.entity.type;

import lombok.Getter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.UUID;

// Note: 1.19.4 requires that the billboard is set to something in order to show, on Java Edition
@Getter
public class TextDisplayEntity extends DisplayBaseEntity {

private int lines;

public TextDisplayEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position.add(0, definition.offset(), 0), motion, yaw, pitch, headYaw);
}
Expand All @@ -61,5 +69,14 @@ protected void initializeMetadata() {

public void setText(EntityMetadata<Component, ?> entityMetadata) {
this.dirtyMetadata.put(EntityDataTypes.NAME, MessageTranslator.convertMessage(entityMetadata.getValue()));
calculateLines(entityMetadata.getValue());
}

private void calculateLines(@Nullable Component text) {
if (text == null) {
lines = 0;
return;
alexdev03 marked this conversation as resolved.
Show resolved Hide resolved
}
lines = PlainTextComponentSerializer.plainText().serialize(text).split("\n").length;
}
}
12 changes: 12 additions & 0 deletions core/src/main/java/org/geysermc/geyser/util/EntityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ public static void updateMountOffset(Entity passenger, Entity mount, boolean rid
zOffset = displayTranslation.getZ();
}
}
case PLAYER -> {
alexdev03 marked this conversation as resolved.
Show resolved Hide resolved
if (passenger instanceof TextDisplayEntity textDisplay) {
Vector3f displayTranslation = textDisplay.getTranslation();
int lines = textDisplay.getLines();
if (displayTranslation != null && lines != 0) {
float multiplier = (float) Math.max(0.22f, 0.45f - (0.06f * Math.floor((lines - 4) / 2f)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get some info on what all these numbers are?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some tests with multiple lines, then I gave an ai those tests and it gave me a function that follows a pattern based on the number of lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get this info verified?
And I think that it'd also be nice that we assert the behaviour by adding some tests for it

xOffset = displayTranslation.getX();
yOffset = displayTranslation.getY() + multiplier * lines;
zOffset = displayTranslation.getZ();
}
}
}
}
if (mount instanceof ChestBoatEntity) {
xOffset = 0.15F;
Expand Down