From 22001b293b59a646eee23a9617d3fe77705b9c87 Mon Sep 17 00:00:00 2001 From: Daniel Orr Date: Fri, 19 Jul 2024 16:40:51 +0100 Subject: [PATCH] Teleport -> Passengers --- gradle.properties | 2 +- .../entity/PlayerAttachedTextDisplayEntity.kt | 37 +++++++++++++++---- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index c507a15..b7905be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ kotlin_version=1.9.24 fabric_kotlin_version=1.10.20 # Mod Properties -mod_version=1.1.0 +mod_version=1.1.1 maven_group=net.mcbrawls mod_id=brawls-entities diff --git a/src/main/kotlin/net/mcbrawls/entities/entity/PlayerAttachedTextDisplayEntity.kt b/src/main/kotlin/net/mcbrawls/entities/entity/PlayerAttachedTextDisplayEntity.kt index d28a583..da27b57 100644 --- a/src/main/kotlin/net/mcbrawls/entities/entity/PlayerAttachedTextDisplayEntity.kt +++ b/src/main/kotlin/net/mcbrawls/entities/entity/PlayerAttachedTextDisplayEntity.kt @@ -3,28 +3,30 @@ package net.mcbrawls.entities.entity import dev.andante.audience.player.StandalonePlayerReference import eu.pb4.polymer.core.api.entity.PolymerEntity import net.mcbrawls.entities.entity.PlayerAttachedTextDisplayEntity.TextSupplier +import net.minecraft.entity.Entity import net.minecraft.entity.EntityType import net.minecraft.entity.decoration.DisplayEntity.TextDisplayEntity import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.text.Text -import net.minecraft.util.math.Vec3d +import net.minecraft.util.math.AffineTransformation import net.minecraft.world.World +import org.joml.Vector3f open class PlayerAttachedTextDisplayEntity( /** * The player to be attached to. */ - private val player: StandalonePlayerReference?, + private var player: StandalonePlayerReference?, /** * Provides the text component for this text display. */ - private val textSupplier: TextSupplier, + private var textSupplier: TextSupplier, /** * The offset from the top of the player's hitbox to display the entity. */ - private val positionOffset: Vec3d = DEFAULT_POSITION_OFFSET, + private var positionOffset: Vector3f = DEFAULT_POSITION_OFFSET, type: EntityType<*>, world: World @@ -35,6 +37,10 @@ open class PlayerAttachedTextDisplayEntity( init { setBillboardMode(BillboardMode.CENTER) + + setTransformation( + AffineTransformation(positionOffset, null, null, null) + ) } override fun tick() { @@ -44,14 +50,31 @@ open class PlayerAttachedTextDisplayEntity( if (player == null) { discard() } else { - val position = player.pos.add(0.0, player.height.toDouble(), 0.0).add(positionOffset) - setPosition(position) + // verify same world + if (player.world != world) { + teleport(player.serverWorld, player.x, player.y, player.z, emptySet(), 0.0f, 0.0f) + } + + // verify riding + if (!hasVehicle()) { + startRiding(player, true) + } val text = textSupplier.getText(player, age) setText(text) } } + override fun copyFrom(original: Entity) { + super.copyFrom(original) + + if (original is PlayerAttachedTextDisplayEntity) { + player = original.player + textSupplier = original.textSupplier + positionOffset = original.positionOffset + } + } + override fun getPolymerEntityType(player: ServerPlayerEntity): EntityType<*> { return EntityType.TEXT_DISPLAY } @@ -61,6 +84,6 @@ open class PlayerAttachedTextDisplayEntity( } companion object { - val DEFAULT_POSITION_OFFSET = Vec3d(0.0, 0.5, 0.0) + val DEFAULT_POSITION_OFFSET = Vector3f(0.0f, 0.0f, 0.0f) } }