Skip to content

Commit

Permalink
3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Dec 31, 2024
1 parent f4381a7 commit 744d528
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 167 deletions.
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
`java-library`
kotlin("jvm") version "2.1.0"
id("io.github.goooler.shadow") version "8.1.8"
id("io.papermc.paperweight.userdev") version "2.0.0-beta.8" apply false
id("io.papermc.paperweight.userdev") version "2.0.0-beta.10" apply false
id("xyz.jpenilla.run-paper") version "2.3.1"
id("org.jetbrains.dokka") version "1.9.20" //TODO set this to 2.0.0 when stable version is released.
}
Expand All @@ -17,7 +17,7 @@ allprojects {
apply(plugin = "kotlin")
apply(plugin = "org.jetbrains.dokka")
group = "kr.toxicity.healthbar"
version = "3.7.4"
version = "3.8"
repositories {
mavenCentral()
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down Expand Up @@ -85,7 +85,7 @@ val dist = getApiDependencyProject("dist").spigot()
.dependency("net.citizensnpcs:citizens-main:2.0.37-SNAPSHOT")
.dependency("com.github.SkriptLang:Skript:2.9.5")
.dependency("com.nexomc:nexo:0.7.0")
.dependency("io.th0rgal:oraxen:1.186.0")
.dependency("io.th0rgal:oraxen:1.186.1")
.also {
it.tasks.processResources {
filteringCharset = Charsets.UTF_8.name()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,15 @@ enum class PluginConfiguration(
val exists = file.exists()
if (!exists) PLUGIN.saveResource(dir, false)
val yaml = file.toYaml()
val version = yaml.getString("plugin-version") ?: "unknown"
if (exists && PLUGIN.description.version != version) {
warn(
"Old configuration version found: $dir in $version",
"Configuration will be automatically updated."
)
val newYaml = PLUGIN.getResource(dir).ifNull("Resource '$dir' not found.").toYaml()
yaml.getKeys(true).forEach {
if (!newYaml.contains(it)) yaml.set(it, null)
}
newYaml.getKeys(true).forEach {
if (!yaml.contains(it)) {
yaml.set(it, newYaml.get(it))
yaml.setComments(it ,newYaml.getComments(it))
yaml.setInlineComments(it, newYaml.getComments(it))
}
val newYaml = PLUGIN.getResource(dir).ifNull("Resource '$dir' not found.").toYaml()
yaml.getKeys(true).forEach {
if (!newYaml.contains(it)) yaml.set(it, null)
}
newYaml.getKeys(true).forEach {
if (!yaml.contains(it)) {
yaml.set(it, newYaml.get(it))
yaml.setComments(it ,newYaml.getComments(it))
yaml.setInlineComments(it, newYaml.getComments(it))
}
}
yaml.set("plugin-version", PLUGIN.description.version)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ImageLayoutImpl(
override fun listener(): HealthBarListener = listener
override fun duration(): Int = duration

fun build(resource: PackResource, max: Int, count: Int, jsonArray: JsonArray) {
fun build(resource: PackResource, count: Int, jsonArray: JsonArray) {
val componentMap = HashMap<BitmapData, WidthComponent>()
image.images().forEach {
val list = ArrayList<PixelComponent>()
Expand All @@ -49,7 +49,7 @@ class ImageLayoutImpl(
val newHeight = (it.image.image.height.toDouble() * scale()).roundToInt()
val div = newHeight.toDouble() / it.image.image.height.toDouble()
for (i in 0..<count) {
val y = y() + groupY() * i + max
val y = y() + groupY() * i
list.add(componentMap.computeIfAbsent(BitmapData(dir, y, newHeight)) { _ ->
val component = parent.index++.parseChar()
jsonArray.add(JsonObject().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import com.google.gson.JsonObject
import kr.toxicity.healthbar.api.layout.ImageLayout
import kr.toxicity.healthbar.api.layout.LayoutGroup
import kr.toxicity.healthbar.api.layout.TextLayout
import kr.toxicity.healthbar.manager.ConfigManagerImpl
import kr.toxicity.healthbar.manager.EncodeManager
import kr.toxicity.healthbar.pack.PackResource
import kr.toxicity.healthbar.util.*
import net.kyori.adventure.key.Key
import org.bukkit.configuration.ConfigurationSection
import kotlin.math.max
import kotlin.math.min

class LayoutGroupImpl(
private val path: String,
Expand Down Expand Up @@ -51,32 +48,19 @@ class LayoutGroupImpl(
)
}
}
val min get() = if (ConfigManagerImpl.useCoreShaders()) 0 else min(
-max(
images.maxOfOrNull {
it.y() - (it.image().images().maxOfOrNull { image ->
image.image.image.height
} ?: 0)
} ?: 0,
texts.maxOfOrNull {
it.y() - it.height()
} ?: 0
),
0
)

fun build(resource: PackResource, min: Int, count: Int) {
fun build(resource: PackResource, count: Int) {
val json = JsonArray()
images.forEach {
it.build(resource, min, count, json)
it.build(resource, count, json)
}
resource.font.add("$encodedName.json") {
JsonObject().apply {
add("providers", json)
}.save()
}
texts.forEach {
it.build(resource, min, count)
it.build(resource, count)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TextLayoutImpl(
val x: Int,
)

fun build(resource: PackResource, max: Int, count: Int) {
fun build(resource: PackResource, count: Int) {
val dataList = ArrayList<JsonData>()
val fileParent = "${parent.name}/text/${layer()}"
text.bitmap().forEachIndexed { index, textBitmap ->
Expand All @@ -83,7 +83,7 @@ class TextLayoutImpl(

val map = HashMap<BitmapData, WidthKey>()
for (i in 0..<count) {
val y = y() + groupY() * i + max
val y = y() + groupY() * i
val keyName = encodeKey(EncodeManager.EncodeNamespace.FONT, "${parent.name}/$name/${i + 1}")
keys.add(map.computeIfAbsent(BitmapData(keyName, y, height)) {
resource.font.add("$keyName.json") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,16 @@ object LayoutManagerImpl : LayoutManager, BetterHealthBerManager {
}
}
}
val min = layoutMap.minOfOrNull {
it.value.min
} ?: 0
layoutMap.forEach {
it.value.group()?.let { group ->
groupData.computeIfAbsent(group) {
Collections.synchronizedSet(HashSet())
}.add(it.value)
} ?: it.value.build(resource, min, 1)
} ?: it.value.build(resource, 1)
}
groupData.values.forEach {
it.forEach { group ->
group.build(resource, min, it.size)
group.build(resource, it.size)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package kr.toxicity.healthbar.util

import kr.toxicity.healthbar.api.component.PixelComponent
import kr.toxicity.healthbar.api.component.WidthComponent
import kr.toxicity.healthbar.manager.ConfigManagerImpl
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.TextDecoration
import net.kyori.adventure.text.minimessage.MiniMessage
Expand Down Expand Up @@ -53,7 +52,7 @@ val EMPTY_WIDTH_COMPONENT
val EMPTY_PIXEL_COMPONENT
get() = PixelComponent(0, EMPTY_WIDTH_COMPONENT)

fun Int.toAscent() = if (ConfigManagerImpl.useCoreShaders()) this - 8192 else this
fun Int.toAscent() = this - 8192
fun Int.toHeight() = apply {
if (this > 256) throw RuntimeException("Too large height: $this > 256")
if (this < 0) throw RuntimeException("Too low height: $this < 0")
Expand Down
6 changes: 5 additions & 1 deletion dist/src/main/kotlin/kr/toxicity/healthbar/util/Entities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ fun HealthBarCreateEvent.toEntityLocation(): Location {
}
}
}

private const val HEIGHT = 8192.0 / 40.0

fun HealthBarCreateEvent.createEntity(component: WidthComponent, layer: Int = 0): VirtualTextDisplay {
return PLUGIN.nms().createTextDisplay(player.player(), toEntityLocation(), component.component.build()).apply {
shadowRadius(healthBar.shadowRadius())
shadowStrength(healthBar.shadowStrength())
val scale = healthBar.scale()
val multiplier = -(1 - scale.y) * HEIGHT
transformation(
Vector(0.0, if (ConfigManagerImpl.useCoreShaders()) -(1 - scale.y) * 8192 / 40 else 0.0, layer.toDouble() / 4000),
Vector(0.0, if (ConfigManagerImpl.useCoreShaders()) -multiplier else HEIGHT + multiplier, layer.toDouble() / 4000),
scale
)
}
Expand Down
3 changes: 2 additions & 1 deletion dist/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ shaders:
text.vsh: true
text.fsh: true
use-core-shaders: true
show-me-healthbar: true
show-me-healthbar: true
resource-pack-obfuscation: false
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +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
import kotlin.math.*

@Suppress("UNUSED")
class NMSImpl : NMS {
Expand Down Expand Up @@ -327,6 +324,7 @@ class NMSImpl : NMS {
private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
fun Double.square() = this * this
entity?.let { e ->
if (!e.canSee()) 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 @@ -359,24 +357,30 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
return getLevelGetter().all
.asSequence()
.mapNotNull {
it as? LivingEntity
}
.filter {
it !== serverPlayer
}
.toList()
}

private fun net.minecraft.world.entity.Entity.canSee(): Boolean {
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.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)
val x = this.z - serverPlayer.z
val y = this.y - serverPlayer.y
val z = -(this.x - serverPlayer.x)

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
}
val dy = abs(atan2(y, abs(cos(playerYaw) * x - sin(playerYaw) * z)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
return (dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ class NMSImpl : NMS {
private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
fun Double.square() = this * this
entity?.let { e ->
if (!e.canSee()) 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 @@ -365,24 +366,30 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
return getLevelGetter().all
.asSequence()
.mapNotNull {
it as? LivingEntity
}
.filter {
it !== serverPlayer
}
.toList()
}

private fun net.minecraft.world.entity.Entity.canSee(): Boolean {
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.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)
val x = this.z - serverPlayer.z
val y = this.y - serverPlayer.y
val z = -(this.x - serverPlayer.x)

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
}
val dy = abs(atan2(y, abs(x)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
return (dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)
}

@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +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
import kotlin.math.*

@Suppress("UNUSED")
class NMSImpl : NMS {
Expand Down Expand Up @@ -329,6 +326,7 @@ class NMSImpl : NMS {
private fun show(handle: Any, trigger: HealthBarTriggerType, entity: net.minecraft.world.entity.Entity?) {
fun Double.square() = this * this
entity?.let { e ->
if (!e.canSee()) 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,24 +359,30 @@ class NMSImpl : NMS {
}
}
private fun getViewedEntity(): List<LivingEntity> {
return getLevelGetter().all
.asSequence()
.mapNotNull {
it as? LivingEntity
}
.filter {
it !== serverPlayer
}
.toList()
}

private fun net.minecraft.world.entity.Entity.canSee(): Boolean {
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.z - serverPlayer.z
val y = it.y - serverPlayer.y
val z = -(it.x - serverPlayer.x)
val x = this.z - serverPlayer.z
val y = this.y - serverPlayer.y
val z = -(this.x - serverPlayer.x)

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
}
val dy = abs(atan2(y, abs(cos(playerYaw) * x - sin(playerYaw) * z)) - playerPitch)
val dz = abs(atan2(z, x) - playerYaw)
return (dy <= degree || dy >= 2 * PI - degree) && (dz <= degree || dz >= 2 * PI - degree)
}

@Suppress("UNCHECKED_CAST")
Expand Down
Loading

0 comments on commit 744d528

Please sign in to comment.