From 1ad02edb01dc048729ce9cb3b32494b8faba727b Mon Sep 17 00:00:00 2001 From: MattMX <39436418+Matt-MX@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:35:48 +0000 Subject: [PATCH] Update README.md --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 822ba1a..6a5d0c7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Replace your players' boring old name tags with customizable ones based on -text displays! +text displays! (Thanks to [EntityLib](https://github.com/Tofaa2/EntityLib)!)
@@ -71,6 +71,59 @@ class MyCustomListener implements Listener {
```
+Kotlin example
+
+Here is a brief example of Kotlin usage, and shows that you can use the nametags on entities other than just Players!
+
+In this example, a dropped item will display a timer of 4 seconds before it is removed from the world, with a timer above it!
+
+```kt
+@EventHandler
+fun onItemSpawn(event: ItemSpawnEvent) = event.apply {
+ entity.isPersistent = false
+
+ // Armour and tools should take longer to despawn
+ val ticksTillRemove = 80 // 4 seconds
+
+ val nameTagEntity = NameTags.getInstance()
+ .entityManager
+ .getOrCreateNameTagEntity(entity)
+
+ nameTagEntity.modify { meta ->
+ meta.isShadow = true
+ meta.viewRange = 90f
+ meta.backgroundColor = NameTags.TRANSPARENT
+ meta.translation = Vector3f(0f, 0.45f, 0f)
+ meta.billboardConstraints = AbstractDisplayMeta.BillboardConstraints.VERTICAL
+ meta.textOpacity = (-180).toByte()
+ }
+
+ var counter = ticksTillRemove / 20L
+ val update = runAsyncRepeat(20) {
+ counter--
+ nameTagEntity.modify { meta ->
+ meta.text = Component.text(counter.toString()).color(NamedTextColor.RED)
+ }
+ }
+
+ runSyncLater(ticksTillRemove) {
+ update?.cancel()
+
+ NameTags.getInstance()
+ .entityManager
+ .removeEntity(entity)
+ ?.destroy()
+
+ if (entity.isValid) {
+ entity.remove()
+ }
+ }
+}
+```
+
+