Skip to content

Commit

Permalink
Support BetterModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 27, 2024
1 parent 34c8bcd commit 7f6639c
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import kr.toxicity.healthbar.api.bedrock.BedrockAdapter;
import kr.toxicity.healthbar.api.manager.*;
import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter;
import kr.toxicity.healthbar.api.modelengine.ModelAdapter;
import kr.toxicity.healthbar.api.nms.NMS;
import kr.toxicity.healthbar.api.plugin.ReloadState;
import kr.toxicity.healthbar.api.scheduler.WrappedScheduler;
Expand Down Expand Up @@ -37,7 +37,7 @@ public final void onLoad() {
public abstract boolean isPaper();
public abstract boolean isFolia();
public abstract @NotNull WrappedScheduler scheduler();
public abstract @NotNull ModelEngineAdapter modelEngine();
public abstract @NotNull ModelAdapter modelAdapter();
public abstract @NotNull BedrockAdapter bedrock();
public abstract @NotNull MiniMessage miniMessage();
public abstract @NotNull BukkitAudiences audiences();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.jetbrains.annotations.Nullable;

@FunctionalInterface
public interface ModelEngineAdapter {
ModelEngineAdapter NONE = e -> null;
public interface ModelAdapter {
ModelAdapter NONE = e -> null;
@Nullable
Double height(@NotNull Entity entity);
}
11 changes: 6 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ allprojects {
apply(plugin = "kotlin")
apply(plugin = "org.jetbrains.dokka")
group = "kr.toxicity.healthbar"
version = "3.7.3"
version = "3.7.4"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down Expand Up @@ -81,9 +81,10 @@ val dist = getApiDependencyProject("dist").spigot()
.dependency("com.alessiodp.parties:parties-bukkit:3.2.16")
.dependency("io.github.toxicity188:BetterHud-standard-api:1.11.1")
.dependency("io.github.toxicity188:BetterHud-bukkit-api:1.11.1")
.dependency("net.citizensnpcs:citizens-main:2.0.35-SNAPSHOT")
.dependency("io.github.toxicity188:BetterModel:1.1")
.dependency("net.citizensnpcs:citizens-main:2.0.37-SNAPSHOT")
.dependency("com.github.SkriptLang:Skript:2.9.5")
.dependency("com.nexomc:nexo:0.4.0")
.dependency("com.nexomc:nexo:0.7.0")
.dependency("io.th0rgal:oraxen:1.186.0")
.also {
it.tasks.processResources {
Expand Down Expand Up @@ -162,10 +163,10 @@ tasks {
finalizedBy(shadowJar)
}
runServer {
version("1.21.1") //TODO set this to 'minecraft' when other plugins support the latest version.
version(minecraft)
pluginJars(fileTree("plugins"))
downloadPlugins {
hangar("BetterHud", "1.11.1")
hangar("BetterHud", "1.11.2.348")
hangar("PlaceholderAPI", "2.11.6")
hangar("Skript", "2.9.5")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kr.toxicity.healthbar
import kr.toxicity.healthbar.api.BetterHealthBar
import kr.toxicity.healthbar.api.bedrock.BedrockAdapter
import kr.toxicity.healthbar.api.manager.*
import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter
import kr.toxicity.healthbar.api.modelengine.ModelAdapter
import kr.toxicity.healthbar.api.nms.NMS
import kr.toxicity.healthbar.api.pack.PackType
import kr.toxicity.healthbar.api.plugin.ReloadState
Expand All @@ -21,6 +21,7 @@ import kr.toxicity.healthbar.scheduler.StandardScheduler
import kr.toxicity.healthbar.util.*
import kr.toxicity.healthbar.version.MinecraftVersion
import kr.toxicity.healthbar.version.ModelEngineVersion
import kr.toxicity.model.api.tracker.EntityTracker
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.event.ClickEvent
Expand Down Expand Up @@ -52,7 +53,7 @@ class BetterHealthBarImpl : BetterHealthBar() {
true
}.getOrDefault(false)
private var bedrock = BedrockAdapter.NONE
private var modelEngine = ModelEngineAdapter.NONE
private var model = ModelAdapter.NONE
private lateinit var nms: NMS
private lateinit var audiences: BukkitAudiences
private val scheduler = if (isFolia) FoliaScheduler() else StandardScheduler()
Expand Down Expand Up @@ -98,9 +99,13 @@ class BetterHealthBarImpl : BetterHealthBar() {
manager.getPlugin("ModelEngine")?.let {
runWithHandleException("Failed to load ModelEngine support.") {
val version = ModelEngineVersion(it.description.version)
modelEngine = if (version >= ModelEngineVersion.version_4_0_0) CurrentModelEngineAdapter() else LegacyModelEngineAdapter()
model = if (version >= ModelEngineVersion.version_4_0_0) CurrentModelEngineAdapter() else LegacyModelEngineAdapter()
log.add("ModelEngine support enabled: $version")
}
} ?: run {
if (manager.isPluginEnabled("BetterModel")) model = ModelAdapter {
EntityTracker.tracker(it.uniqueId)?.height()
}
}
if (manager.isPluginEnabled("Geyser-Spigot")) {
log.add("Geyser support enabled.")
Expand Down Expand Up @@ -200,7 +205,7 @@ class BetterHealthBarImpl : BetterHealthBar() {
override fun onReload(): Boolean = onReload
override fun bedrock(): BedrockAdapter = bedrock
override fun miniMessage(): MiniMessage = MINI_MESSAGE
override fun modelEngine(): ModelEngineAdapter = modelEngine
override fun modelAdapter(): ModelAdapter = model
override fun scheduler(): WrappedScheduler = scheduler
override fun nms(): NMS = nms
override fun isFolia(): Boolean = isFolia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ val ATTRIBUTE_ARMOR = Registry.ATTRIBUTE.get(NamespacedKey.minecraft(if (Minecra

fun HealthBarCreateEvent.toEntityLocation(): Location {
return entity.entity().location.apply {
y += (PLUGIN.modelEngine().height(entity.entity()) ?: entity.entity().eyeHeight) + ConfigManagerImpl.defaultHeight()
y += (PLUGIN.modelAdapter().height(entity.entity()) ?: entity.entity().eyeHeight) + ConfigManagerImpl.defaultHeight()
entity.mob()?.let {
y += it.configuration().height()
}
Expand Down
1 change: 1 addition & 0 deletions dist/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ libraries:
- "net.kyori:adventure-platform-bukkit:${platform}"
softdepend:
- BetterHud
- BetterModel
- ModelEngine
- MythicMobs
- PlaceholderAPI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kr.toxicity.healthbar.modelengine

import com.ticxo.modelengine.api.ModelEngineAPI
import com.ticxo.modelengine.api.generator.blueprint.BlueprintBone
import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter
import kr.toxicity.healthbar.api.modelengine.ModelAdapter
import net.jodah.expiringmap.ExpirationPolicy
import net.jodah.expiringmap.ExpiringMap
import org.bukkit.entity.Entity
import java.util.concurrent.TimeUnit

class CurrentModelEngineAdapter : ModelEngineAdapter {
class CurrentModelEngineAdapter : ModelAdapter {

private val blueprintCache = ExpiringMap.builder()
.maxSize(256)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kr.toxicity.healthbar.modelengine

import com.ticxo.modelengine.api.ModelEngineAPI
import com.ticxo.modelengine.api.generator.model.BlueprintBone
import kr.toxicity.healthbar.api.modelengine.ModelEngineAdapter
import kr.toxicity.healthbar.api.modelengine.ModelAdapter
import net.jodah.expiringmap.ExpirationPolicy
import net.jodah.expiringmap.ExpiringMap
import org.bukkit.entity.Entity
import java.util.concurrent.TimeUnit

class LegacyModelEngineAdapter : ModelEngineAdapter {
class LegacyModelEngineAdapter : ModelAdapter {

private val blueprintCache = ExpiringMap.builder()
.maxSize(256)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.bukkit.util.Vector
import org.joml.Vector3f
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.sqrt
Expand Down Expand Up @@ -324,12 +325,9 @@ class NMSImpl : NMS {
}

private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z
fun Double.square() = this * this
entity?.let { e ->
if (sqrt((playerX - e.x).square() + (playerY - e.y).square() + (playerZ - e.z).square()) > plugin.configManager().lookDistance()) return
if (sqrt((serverPlayer.x - e.x).square() + (serverPlayer.y - e.y).square() + (serverPlayer.z - e.z).square()) > plugin.configManager().lookDistance()) return
val set = HashSet(plugin.healthBarManager().allHealthBars().filter {
it.isDefault && it.triggers().contains(trigger)
})
Expand Down Expand Up @@ -361,25 +359,21 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z

var yaw = serverPlayer.yHeadRot.toDouble()
if (yaw < 90) yaw += 90
else yaw = -(360 - (yaw + 90))
val playerYaw = Math.toRadians(yaw)
val playerYaw = Math.toRadians(serverPlayer.yRot.toDouble())
val playerPitch = Math.toRadians(-serverPlayer.xRot.toDouble())

val degree = plugin.configManager().lookDegree()

return getLevelGetter().all.mapNotNull {
if (it is LivingEntity && it !== serverPlayer) {
val x = it.x
val y = it.y
val z = it.z
val x = it.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)

if (abs(atan2(y - playerY, abs(x - playerX)) - playerPitch) <= degree && abs(atan2(z - playerZ, x - playerX) - playerYaw) <= degree) it
val dy = abs(atan2(y, abs(x)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
if ((dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)) it
else null
} else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.bukkit.util.Vector
import org.joml.Vector3f
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.sqrt
Expand Down Expand Up @@ -330,12 +331,9 @@ class NMSImpl : NMS {
}

private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z
fun Double.square() = this * this
entity?.let { e ->
if (sqrt((playerX - e.x).square() + (playerY - e.y).square() + (playerZ - e.z).square()) > plugin.configManager().lookDistance()) return
if (sqrt((serverPlayer.x - e.x).square() + (serverPlayer.y - e.y).square() + (serverPlayer.z - e.z).square()) > plugin.configManager().lookDistance()) return
val set = HashSet(plugin.healthBarManager().allHealthBars().filter {
it.isDefault && it.triggers().contains(trigger)
})
Expand Down Expand Up @@ -367,25 +365,21 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z

var yaw = serverPlayer.yHeadRot.toDouble()
if (yaw < 90) yaw += 90
else yaw = -(360 - (yaw + 90))
val playerYaw = Math.toRadians(yaw)
val playerYaw = Math.toRadians(serverPlayer.yRot.toDouble())
val playerPitch = Math.toRadians(-serverPlayer.xRot.toDouble())

val degree = plugin.configManager().lookDegree()

return getLevelGetter().all.mapNotNull {
if (it is LivingEntity && it !== serverPlayer) {
val x = it.x
val y = it.y
val z = it.z
val x = it.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)

if (abs(atan2(y - playerY, abs(x - playerX)) - playerPitch) <= degree && abs(atan2(z - playerZ, x - playerX) - playerYaw) <= degree) it
val dy = abs(atan2(y, abs(x)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
if ((dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)) it
else null
} else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.bukkit.util.Vector
import org.joml.Vector3f
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.sqrt
Expand Down Expand Up @@ -326,12 +327,9 @@ class NMSImpl : NMS {
}

private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z
fun Double.square() = this * this
entity?.let { e ->
if (sqrt((playerX - e.x).square() + (playerY - e.y).square() + (playerZ - e.z).square()) > plugin.configManager().lookDistance()) return
if (sqrt((serverPlayer.x - e.x).square() + (serverPlayer.y - e.y).square() + (serverPlayer.z - e.z).square()) > plugin.configManager().lookDistance()) return
val set = HashSet(plugin.healthBarManager().allHealthBars().filter {
it.isDefault && it.triggers().contains(trigger)
})
Expand Down Expand Up @@ -363,25 +361,21 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z

var yaw = serverPlayer.yHeadRot.toDouble()
if (yaw < 90) yaw += 90
else yaw = -(360 - (yaw + 90))
val playerYaw = Math.toRadians(yaw)
val playerYaw = Math.toRadians(serverPlayer.yRot.toDouble())
val playerPitch = Math.toRadians(-serverPlayer.xRot.toDouble())

val degree = plugin.configManager().lookDegree()

return getLevelGetter().all.mapNotNull {
if (it is LivingEntity && it !== serverPlayer) {
val x = it.x
val y = it.y
val z = it.z
val x = it.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)

if (abs(atan2(y - playerY, abs(x - playerX)) - playerPitch) <= degree && abs(atan2(z - playerZ, x - playerX) - playerYaw) <= degree) it
val dy = abs(atan2(y, abs(x)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
if ((dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)) it
else null
} else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import org.bukkit.util.Vector
import org.joml.Vector3f
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.PI
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.sqrt
Expand Down Expand Up @@ -326,12 +327,9 @@ class NMSImpl : NMS {
}

private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z
fun Double.square() = this * this
entity?.let { e ->
if (sqrt((playerX - e.x).square() + (playerY - e.y).square() + (playerZ - e.z).square()) > plugin.configManager().lookDistance()) return
if (sqrt((serverPlayer.x - e.x).square() + (serverPlayer.y - e.y).square() + (serverPlayer.z - e.z).square()) > plugin.configManager().lookDistance()) return
val set = HashSet(plugin.healthBarManager().allHealthBars().filter {
it.isDefault && it.triggers().contains(trigger)
})
Expand Down Expand Up @@ -363,25 +361,21 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
val playerX = serverPlayer.x
val playerY = serverPlayer.y
val playerZ = serverPlayer.z

var yaw = serverPlayer.yHeadRot.toDouble()
if (yaw < 90) yaw += 90
else yaw = -(360 - (yaw + 90))
val playerYaw = Math.toRadians(yaw)
val playerYaw = Math.toRadians(serverPlayer.yRot.toDouble())
val playerPitch = Math.toRadians(-serverPlayer.xRot.toDouble())

val degree = plugin.configManager().lookDegree()

return getLevelGetter().all.mapNotNull {
if (it is LivingEntity && it !== serverPlayer) {
val x = it.x
val y = it.y
val z = it.z
val x = it.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)

if (abs(atan2(y - playerY, abs(x - playerX)) - playerPitch) <= degree && abs(atan2(z - playerZ, x - playerX) - playerYaw) <= degree) it
val dy = abs(atan2(y, abs(x)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
if ((dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)) it
else null
} else null
}
Expand Down
Loading

0 comments on commit 7f6639c

Please sign in to comment.