mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-20 15:39:31 +00:00
Added preliminary client-side display name support (will merge into eco)
This commit is contained in:
@@ -16,9 +16,8 @@ base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
project(":eco-core").dependencyProject.subprojects {
|
implementation(project(":eco-core:core-plugin"))
|
||||||
implementation(this)
|
implementation(project(path = ":eco-core:core-nms:v1_20_R1", configuration = "reobf"))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
|
|||||||
12
eco-core/core-nms/build.gradle.kts
Normal file
12
eco-core/core-nms/build.gradle.kts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
plugins {
|
||||||
|
id("io.papermc.paperweight.userdev") version "1.5.3" apply false
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.willfp"
|
||||||
|
version = rootProject.version
|
||||||
|
|
||||||
|
subprojects {
|
||||||
|
dependencies {
|
||||||
|
compileOnly(project(":eco-core:core-plugin"))
|
||||||
|
}
|
||||||
|
}
|
||||||
10
eco-core/core-nms/v1_20_R1/build.gradle.kts
Normal file
10
eco-core/core-nms/v1_20_R1/build.gradle.kts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
plugins {
|
||||||
|
id("io.papermc.paperweight.userdev")
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "com.willfp"
|
||||||
|
version = rootProject.version
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT")
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.willfp.ecomobs.nms.v1_20_R1
|
||||||
|
|
||||||
|
import com.willfp.eco.core.packet.Packet
|
||||||
|
import com.willfp.eco.core.packet.sendPacket
|
||||||
|
import com.willfp.ecomobs.name.DisplayNameProxy
|
||||||
|
import io.papermc.paper.adventure.PaperAdventure
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket
|
||||||
|
import net.minecraft.network.syncher.EntityDataAccessor
|
||||||
|
import net.minecraft.network.syncher.SynchedEntityData
|
||||||
|
import net.minecraft.world.entity.Entity
|
||||||
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftMob
|
||||||
|
import org.bukkit.entity.Mob
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
import java.util.Optional
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
class DisplayName : DisplayNameProxy {
|
||||||
|
private val displayNameAccessor = Entity::class.java
|
||||||
|
.declaredFields
|
||||||
|
.filter { it.type == EntityDataAccessor::class.java }
|
||||||
|
.toList()[2]
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
.get(null) as EntityDataAccessor<Optional<net.minecraft.network.chat.Component>>
|
||||||
|
|
||||||
|
private val customNameVisibleAccessor = Entity::class.java
|
||||||
|
.declaredFields
|
||||||
|
.filter { it.type == EntityDataAccessor::class.java }
|
||||||
|
.toList()[3]
|
||||||
|
.apply { isAccessible = true }
|
||||||
|
.get(null) as EntityDataAccessor<Boolean>
|
||||||
|
|
||||||
|
override fun setDisplayName(mob: Mob, player: Player, displayName: Component, visible: Boolean) {
|
||||||
|
if (mob !is CraftMob) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val nmsComponent = PaperAdventure.asVanilla(displayName)
|
||||||
|
?: throw IllegalStateException("Display name component is null!")
|
||||||
|
|
||||||
|
val nmsEntity = mob.handle
|
||||||
|
nmsEntity.isCustomNameVisible
|
||||||
|
val entityData = SynchedEntityData(nmsEntity)
|
||||||
|
|
||||||
|
entityData.forceSet(displayNameAccessor, Optional.of(nmsComponent))
|
||||||
|
entityData.forceSet(customNameVisibleAccessor, visible)
|
||||||
|
|
||||||
|
val packet = ClientboundSetEntityDataPacket(
|
||||||
|
nmsEntity.id,
|
||||||
|
entityData.packDirty() ?: throw IllegalStateException("No packed entity data")
|
||||||
|
)
|
||||||
|
|
||||||
|
player.sendPacket(Packet(packet))
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> SynchedEntityData.forceSet(
|
||||||
|
accessor: EntityDataAccessor<T>,
|
||||||
|
value: T
|
||||||
|
) {
|
||||||
|
if (!this.hasItem(accessor)) {
|
||||||
|
this.define(accessor, value)
|
||||||
|
}
|
||||||
|
this[accessor] = value
|
||||||
|
this.markDirty(accessor)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ group = "com.willfp"
|
|||||||
version = rootProject.version
|
version = rootProject.version
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("io.papermc.paper:paper-api:1.19.3-R0.1-SNAPSHOT")
|
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
|
||||||
compileOnly("com.github.lokka30:LevelledMobs:3.1.4")
|
compileOnly("com.github.lokka30:LevelledMobs:3.1.4")
|
||||||
compileOnly("com.ticxo.modelengine:api:R3.1.8")
|
compileOnly("com.ticxo.modelengine:api:R3.1.8")
|
||||||
compileOnly("LibsDisguises:LibsDisguises:10.0.38")
|
compileOnly("LibsDisguises:LibsDisguises:10.0.38")
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.willfp.ecomobs.name
|
||||||
|
|
||||||
|
import com.willfp.eco.util.toComponent
|
||||||
|
import com.willfp.ecomobs.plugin
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import org.bukkit.entity.Mob
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
|
interface DisplayNameProxy {
|
||||||
|
fun setDisplayName(mob: Mob, player: Player, displayName: Component, visible: Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Mob.setClientDisplayName(player: Player, name: String, visible: Boolean) =
|
||||||
|
plugin.getProxy(DisplayNameProxy::class.java).setDisplayName(this, player, name.toComponent(), visible)
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package com.willfp.ecomobs.tick
|
package com.willfp.ecomobs.tick
|
||||||
|
|
||||||
import com.willfp.ecomobs.mob.LivingMob
|
import com.willfp.ecomobs.mob.LivingMob
|
||||||
|
import com.willfp.ecomobs.name.setClientDisplayName
|
||||||
|
import org.bukkit.entity.Player
|
||||||
|
|
||||||
class TickHandlerDisplayName: TickHandler {
|
class TickHandlerDisplayName : TickHandler {
|
||||||
override fun tick(mob: LivingMob, tick: Int) {
|
override fun tick(mob: LivingMob, tick: Int) {
|
||||||
if (tick % 5 != 0) {
|
if (tick % 5 != 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
mob.entity.getNearbyEntities(20.0, 20.0, 20.0)
|
||||||
mob.entity.customName = mob.displayName
|
.filterIsInstance<Player>()
|
||||||
|
.forEach { mob.entity.setClientDisplayName(it, mob.displayName, false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ options:
|
|||||||
resource-id: 525
|
resource-id: 525
|
||||||
bstats-id: 10635
|
bstats-id: 10635
|
||||||
color: "&9"
|
color: "&9"
|
||||||
|
proxy-package: "com.willfp.ecomobs.nms"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ pluginManagement {
|
|||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven("https://repo.jpenilla.xyz/snapshots/")
|
maven("https://repo.jpenilla.xyz/snapshots/")
|
||||||
maven("https://repo.auxilor.io/repository/maven-public/")
|
maven("https://repo.auxilor.io/repository/maven-public/")
|
||||||
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,3 +13,5 @@ rootProject.name = "EcoMobs"
|
|||||||
// Core
|
// Core
|
||||||
include(":eco-core")
|
include(":eco-core")
|
||||||
include(":eco-core:core-plugin")
|
include(":eco-core:core-plugin")
|
||||||
|
include(":eco-core:core-nms")
|
||||||
|
include(":eco-core:core-nms:v1_20_R1")
|
||||||
|
|||||||
Reference in New Issue
Block a user