Skip to content

Commit

Permalink
Teleport -> Passengers
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Jul 19, 2024
1 parent 729160c commit 22001b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,6 +37,10 @@ open class PlayerAttachedTextDisplayEntity(

init {
setBillboardMode(BillboardMode.CENTER)

setTransformation(
AffineTransformation(positionOffset, null, null, null)
)
}

override fun tick() {
Expand All @@ -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
}
Expand All @@ -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)
}
}

0 comments on commit 22001b2

Please sign in to comment.