Skip to content

Commit a8969f4

Browse files
committed
Code refactoring.
1 parent ecc7499 commit a8969f4

File tree

21 files changed

+79
-60
lines changed

21 files changed

+79
-60
lines changed

bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/compatibility/mmocore/MMOCoreCompatibility.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,16 @@ class MMOCoreCompatibility : Compatibility {
319319
): Function<HudPlayer, Number> {
320320
val skill = MMOCore.plugin.skillManager.getSkill(args[0]) ?: throw RuntimeException("Unable to find that skill: ${args[0]}")
321321
return Function { p ->
322-
(p.bukkitPlayer.toMMOCore() ?: return@Function 0.0).boundSkills.entries.firstOrNull {
323-
it.value.classSkill.skill.handler.id == skill.handler.id
324-
}?.key ?: 0
322+
val bar = p.bukkitPlayer.inventory.heldItemSlot
323+
var i = 0
324+
for ((index, entry) in (p.bukkitPlayer.toMMOCore() ?: return@Function 0.0).boundSkills.entries.withIndex()) {
325+
if (entry.value.classSkill.skill.handler.id == skill.handler.id) {
326+
i = entry.key
327+
if (index >= bar) i++
328+
break
329+
}
330+
}
331+
i
325332
}
326333
}
327334
},

bootstrap/bukkit/src/main/kotlin/kr/toxicity/hud/bootstrap/bukkit/player/HudPlayerBukkit.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ import org.bukkit.Bukkit
1010
import org.bukkit.boss.BossBar
1111
import org.bukkit.entity.Player
1212
import java.util.*
13-
import kotlin.collections.ArrayList
1413

1514
class HudPlayerBukkit(
1615
private val player: Player,
1716
private val audience: Audience
18-
): HudPlayerImpl() {
17+
) : HudPlayerImpl() {
1918
override fun uuid(): UUID = player.uniqueId
2019
override fun name(): String = player.name
2120
override fun handle(): Any = player

bootstrap/fabric/src/main/kotlin/kr/toxicity/hud/bootstrap/fabric/player/HudPlayerFabric.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ import net.minecraft.server.MinecraftServer
1111
import net.minecraft.server.bossevents.CustomBossEvent
1212
import net.minecraft.server.level.ServerPlayer
1313
import java.util.*
14-
import kotlin.collections.ArrayList
1514

1615
class HudPlayerFabric(
1716
server: MinecraftServer,
1817
private val player: ServerPlayer,
1918
private val audience: Audience
20-
): HudPlayerImpl() {
19+
) : HudPlayerImpl() {
2120

2221
init {
2322
val event = ArrayList<CustomBossEvent>()

bootstrap/velocity/src/main/kotlin/kr/toxicity/hud/bootstrap/velocity/player/HudPlayerVelocity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import java.util.*
1111

1212
class HudPlayerVelocity(
1313
private val player: Player,
14-
): HudPlayerImpl() {
14+
) : HudPlayerImpl() {
1515
override fun uuid(): UUID = player.uniqueId
1616
override fun name(): String = player.username
1717
override fun handle(): Any = player

build.gradle.kts

+30-30
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,6 @@ val supportedVelocityVersions = listOf(
6666
"3.4"
6767
)
6868

69-
val legacyNmsVersion = listOf(
70-
//"v1_17_R1",
71-
//"v1_18_R1",
72-
"v1_18_R2",
73-
"v1_19_R1",
74-
"v1_19_R2",
75-
"v1_19_R3",
76-
"v1_20_R1",
77-
"v1_20_R2",
78-
"v1_20_R3",
79-
).map {
80-
project("nms:$it")
81-
}
82-
val currentNmsVersion = listOf(
83-
"v1_20_R4",
84-
"v1_21_R1",
85-
"v1_21_R2",
86-
).map {
87-
project("nms:$it")
88-
}
89-
90-
val allNmsVersion = legacyNmsVersion + currentNmsVersion
91-
9269
allprojects {
9370
apply(plugin = "java")
9471
apply(plugin = "kotlin")
@@ -158,6 +135,31 @@ subprojects {
158135
}
159136
}
160137

138+
val legacyNmsVersion = listOf(
139+
//"v1_17_R1",
140+
//"v1_18_R1",
141+
"v1_18_R2",
142+
"v1_19_R1",
143+
"v1_19_R2",
144+
"v1_19_R3",
145+
"v1_20_R1",
146+
"v1_20_R2",
147+
"v1_20_R3",
148+
).map {
149+
project("nms:$it")
150+
}.onEach {
151+
it.legacy()
152+
}
153+
154+
val currentNmsVersion = listOf(
155+
"v1_20_R4",
156+
"v1_21_R1",
157+
"v1_21_R2",
158+
).map {
159+
project("nms:$it")
160+
}
161+
162+
val allNmsVersion = legacyNmsVersion + currentNmsVersion
161163

162164
fun Project.dependency(any: Any) = also {
163165
if (any is Collection<*>) {
@@ -238,20 +240,18 @@ fun Project.modrinthPublish(depend: Jar, additionalJar: List<Jar>, loadersList:
238240
}
239241
}
240242

241-
val apiShare = project("api:standard-api").adventure().legacy()
242-
val apiBukkit = project("api:bukkit-api").adventure().bukkit().dependency(apiShare).legacy()
243-
val apiVelocity = project("api:velocity-api").velocity().dependency(apiShare).legacy()
243+
val apiShare = project("api:standard-api").adventure()
244+
val apiBukkit = project("api:bukkit-api").adventure().bukkit().dependency(apiShare)
245+
val apiVelocity = project("api:velocity-api").velocity().dependency(apiShare)
244246
val apiFabric = project("api:fabric-api").adventure().dependency(apiShare)
245247

246248
val api = listOf(
247249
apiShare,
248250
apiBukkit,
249251
apiVelocity,
250252
apiFabric
251-
)
252-
253-
legacyNmsVersion.forEach {
254-
it.legacy()
253+
).onEach {
254+
project -> project.legacy()
255255
}
256256

257257
fun Project.api() = dependency(api)

changelog/1.10.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# BetterHud 1.10
2+
3+
## Fix
4+
- Fix a problem that built core shader has comment.
5+
- Fix mmocore_casting_slot placeholder.
6+
7+
## Add
8+
- Add more uniform value in shaders json.

dist/src/main/kotlin/kr/toxicity/hud/BetterHudImpl.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.util.function.Consumer
2222
import java.util.jar.JarFile
2323

2424
@Suppress("UNUSED")
25-
class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
25+
class BetterHudImpl(val bootstrap: BetterHudBootstrap) : BetterHud {
2626

2727
init {
2828
if (!bootstrap.dataFolder().exists() && !bootstrap.isVelocity) loadAssets("default", bootstrap.dataFolder().apply {
@@ -36,10 +36,8 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
3636
}
3737
}
3838

39-
private var managers: List<BetterHudManager> = emptyList()
40-
41-
fun start() {
42-
managers = listOf(
39+
private val managers: List<BetterHudManager> by lazy {
40+
listOf(
4341
ConfigManagerImpl,
4442
MinecraftManager,
4543
CommandManager,
@@ -61,6 +59,9 @@ class BetterHudImpl(val bootstrap: BetterHudBootstrap): BetterHud {
6159
ShaderManagerImpl,
6260
PlayerManagerImpl,
6361
)
62+
}
63+
64+
fun start() {
6465
managers.forEach {
6566
it.start()
6667
}

dist/src/main/kotlin/kr/toxicity/hud/compass/type/CircleCompass.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CircleCompass(
3030
override val path: String,
3131
private val internalName: String,
3232
section: YamlObject
33-
): CompassImpl {
33+
) : CompassImpl {
3434
companion object {
3535
private val defaultColorEquation = TEquation("255").run {
3636
ColorEquation(

dist/src/main/kotlin/kr/toxicity/hud/image/HudImage.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class HudImage(
1212
val image: List<NamedLoadedImage>,
1313
val type: ImageType,
1414
setting: YamlObject
15-
): HudConfiguration {
15+
) : HudConfiguration {
1616
val conditions = setting.toConditions()
1717
val listener = setting.get("listener")?.asObject()?.let {
1818
ListenerManagerImpl.getListener(it)

dist/src/main/kotlin/kr/toxicity/hud/manager/ShaderManagerImpl.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,13 @@ object ShaderManagerImpl : BetterHudManager, ShaderManager {
187187
if (replaceList.contains(deactivateMatcher.group("name"))) s = deactivateMatcher.replaceAll("")
188188
else return@write
189189
}
190-
if (s.isEmpty()) return@write
190+
if (s.isEmpty() || s.startsWith("//")) return@write
191191
val tagMatcher = tagPattern.matcher(s)
192192
if (tagMatcher.find()) {
193193
val group = tagMatcher.group("name")
194194
(tagBuilders[group]?.invoke() ?: tagSupplier[group])?.let {
195195
it.forEach apply@ { methodString ->
196-
if (methodString.isEmpty()) return@apply
196+
if (methodString.isEmpty() || methodString.startsWith("//")) return@apply
197197
val appendEnter = methodString.first() == '#'
198198
if (appendEnter && (isEmpty() || last() != '\n')) append('\n')
199199
append(methodString.replace(" ", ""))

dist/src/main/kotlin/kr/toxicity/hud/popup/PopupLayout.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ class PopupLayout(
125125
if (hudImage.image.size > 1) hudImage.image.forEach {
126126
val fileName = "$NAME_SPACE_ENCODED:${it.name}"
127127

128-
val height = Math.round(it.image.image.height * target.scale).toInt()
128+
val height = (it.image.image.height * target.scale).roundToInt().toInt()
129129
val scale = height.toDouble() / it.image.image.height
130-
val xOffset = Math.round(it.image.xOffset * scale).toInt()
130+
val xOffset = (it.image.xOffset * scale).roundToInt().toInt()
131131
val ascent = pixel.y
132132
val shaderGroup = ShaderGroup(imageShader, fileName, target.scale, ascent)
133133

@@ -160,7 +160,8 @@ class PopupLayout(
160160
"chars" to jsonArrayOf(char)
161161
))
162162
}
163-
val comp = WidthComponent(Component.text().content(char).font(parent.imageKey), Math.round(it.image.image.width.toDouble() * target.scale).toInt()) + NEGATIVE_ONE_SPACE_COMPONENT
163+
val comp = WidthComponent(Component.text().content(char).font(parent.imageKey), (it.image.image.width.toDouble() * target.scale).roundToInt()
164+
.toInt()) + NEGATIVE_ONE_SPACE_COMPONENT
164165
list.add(comp.toPixelComponent(pixel.x))
165166
}
166167

dist/src/main/kotlin/kr/toxicity/hud/shader/HudShader.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data class HudShader(
99
val outline: Boolean,
1010
val opacity: Double,
1111
val property: Int,
12-
): Comparable<HudShader> {
12+
) : Comparable<HudShader> {
1313
companion object {
1414
private val comparator = Comparator.comparing { s: HudShader ->
1515
s.gui

dist/src/main/kotlin/kr/toxicity/hud/util/Lists.kt

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package kr.toxicity.hud.util
22

33
import java.util.concurrent.CompletableFuture
44
import java.util.concurrent.Executors
5-
import kotlin.collections.ArrayList
65

76
fun <T> List<T>.split(splitSize: Int): List<List<T>> {
87
val result = ArrayList<List<T>>()

dist/src/main/kotlin/kr/toxicity/hud/yaml/YamlArrayImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import java.util.*
88
class YamlArrayImpl(
99
path: String,
1010
private val list: List<*>
11-
): YamlConfigurationImpl(path), YamlArray {
11+
) : YamlConfigurationImpl(path), YamlArray {
1212

1313
@Suppress("UNCHECKED_CAST")
1414
override fun get(): MutableList<Any> = Collections.unmodifiableList(list as MutableList<Any>)

dist/src/main/kotlin/kr/toxicity/hud/yaml/YamlConfigurationImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import kr.toxicity.hud.api.yaml.YamlConfiguration
44

55
abstract class YamlConfigurationImpl(
66
private val path: String,
7-
): YamlConfiguration {
7+
) : YamlConfiguration {
88
override fun path(): String = path
99
override fun equals(other: Any?): Boolean {
1010
if (this === other) return true

dist/src/main/kotlin/kr/toxicity/hud/yaml/YamlElementImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import java.io.Serializable
99
class YamlElementImpl(
1010
path: String,
1111
private val any: Any
12-
): YamlConfigurationImpl(path), YamlElement {
12+
) : YamlConfigurationImpl(path), YamlElement {
1313
override fun get(): Any = any
1414
override fun asString(): String = if (any is Serializable) any.toString() else throw RuntimeException("This is not a string: $any")
1515
override fun asInt(): Int = (any as? Number)?.toInt().ifNull("This is not a int: $any")

dist/src/main/kotlin/kr/toxicity/hud/yaml/YamlObjectImpl.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.util.*
1010
class YamlObjectImpl(
1111
path: String,
1212
private val map: MutableMap<*, *>
13-
): YamlConfigurationImpl(path), YamlObject {
13+
) : YamlConfigurationImpl(path), YamlObject {
1414

1515
override fun save(file: File) {
1616
get().saveToYaml(file)

dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_cutout.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
3030
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
3131
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
32-
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
32+
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
33+
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
3334
]
3435
}

dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_entity_translucent_cull.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"samplers": [
1818
{ "name": "Sampler0" },
19+
{ "name": "Sampler1" },
1920
{ "name": "Sampler2" }
2021
],
2122
"uniforms": [
@@ -28,6 +29,7 @@
2829
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
2930
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
3031
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
31-
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
32+
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
33+
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
3234
]
3335
}

dist/src/main/resources/pack/assets/minecraft/shaders/core/rendertype_item_entity_translucent_cull.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
],
1717
"samplers": [
1818
{ "name": "Sampler0" },
19+
{ "name": "Sampler1" },
1920
{ "name": "Sampler2" }
2021
],
2122
"uniforms": [
@@ -28,6 +29,7 @@
2829
{ "name": "FogEnd", "type": "float", "count": 1, "values": [ 1.0 ] },
2930
{ "name": "FogColor", "type": "float", "count": 4, "values": [ 0.0, 0.0, 0.0, 0.0 ] },
3031
{ "name": "FogShape", "type": "int", "count": 1, "values": [ 0 ] },
31-
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] }
32+
{ "name": "ScreenSize", "type": "float", "count": 2, "values": [ 1.0, 1.0 ] },
33+
{ "name": "GameTime", "type": "float", "count": 1, "values": [ 0.0 ] }
3234
]
3335
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Feb 29 02:18:16 KST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)