@@ -3,12 +3,9 @@ package net.mcbrawls.populus
33import com.mojang.authlib.GameProfile
44import com.mojang.authlib.properties.Property
55import eu.pb4.polymer.core.api.entity.PolymerEntity
6- import eu.pb4.polymer.virtualentity.api.ElementHolder
76import eu.pb4.polymer.virtualentity.api.attachment.EntityAttachment
8- import eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement
97import net.minecraft.entity.EntityType
108import net.minecraft.entity.data.DataTracker
11- import net.minecraft.entity.decoration.DisplayEntity
129import net.minecraft.entity.mob.PathAwareEntity
1310import net.minecraft.entity.player.PlayerEntity
1411import net.minecraft.network.packet.Packet
@@ -17,10 +14,8 @@ import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket
1714import net.minecraft.server.network.ServerPlayerEntity
1815import net.minecraft.text.Text
1916import net.minecraft.util.Arm
20- import net.minecraft.util.math.AffineTransformation
2117import net.minecraft.world.GameMode
2218import net.minecraft.world.World
23- import org.joml.Vector3f
2419import xyz.nucleoid.packettweaker.PacketContext
2520import java.util.EnumSet
2621import java.util.function.Consumer
@@ -36,37 +31,28 @@ abstract class AbstractFakePlayerEntity(type: EntityType<out AbstractFakePlayerE
3631 */
3732 open val modelParts: Byte = Byte .MAX_VALUE
3833
39- /* *
40- * The base name tag offset from the passenger position.
41- */
42- open val baseNameTagOffset: Float = 0.2f
43-
44- /* *
45- * The name tag offset for additional lines.
46- */
47- open val additionalNameTagOffset: Float = 0.25f
48-
4934 /* *
5035 * The generated profile name for this fake player.
5136 */
5237 val defaultProfileName: String by lazy { uuid.toString().substring(0 .. < 16 ) }
5338
54- private var nameElementAttachment: EntityAttachment ? = null
39+ var nameHolder: NameTagElementHolder = NameTagElementHolder ()
40+ private set
41+
42+ var nameAttachment: EntityAttachment ? = null
43+ private set
5544
5645 init {
57- refreshNameElements()
46+ nameAttachment = EntityAttachment .ofTicking(nameHolder, this )
47+ refreshNameTag()
5848 }
5949
6050 /* *
6151 * Refreshes attached elements.
6252 */
63- fun refreshNameElements () {
64- nameElementAttachment?.destroy()
65-
66- val elements = createNameAttachmentElement()
67- val holder = ElementHolder ()
68- elements.forEach(holder::addPassengerElement)
69- nameElementAttachment = EntityAttachment .ofTicking(holder, this )
53+ fun refreshNameTag () {
54+ val text = createDisplayNameText()
55+ nameHolder.setText(text)
7056 }
7157
7258 /* *
@@ -77,25 +63,6 @@ abstract class AbstractFakePlayerEntity(type: EntityType<out AbstractFakePlayerE
7763 return emptyList()
7864 }
7965
80- /* *
81- * Creates the attached elements for the player's name tag.
82- * @return null to use default name tag
83- */
84- open fun createNameAttachmentElement (): List <TextDisplayElement > {
85- val components = createDisplayNameText()
86- return components.reversed().mapIndexed { i, text ->
87- val element = TextDisplayElement (text)
88-
89- val transformation = AffineTransformation (Vector3f (0.0f , baseNameTagOffset + (additionalNameTagOffset * i), 0.0f ), null , null , null )
90- element.setTransformation(transformation)
91-
92- element.billboardMode = DisplayEntity .BillboardMode .CENTER
93- element.teleportDuration = 1
94-
95- element
96- }
97- }
98-
9966 /* *
10067 * Creates the player list entry for this player. Necessary for the player entity to spawn.
10168 */
0 commit comments