Skip to content

Commit 888aa79

Browse files
committed
feat: better log custom names and hotbar messages
1 parent f66a104 commit 888aa79

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎src/main/kotlin/openshock/integrations/minecraft/ConfigScreen.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import openshock.integrations.minecraft.api.Shocker
1313
import openshock.integrations.minecraft.api.ShockerCatalog
1414
import openshock.integrations.minecraft.config.AccountConfig
1515
import openshock.integrations.minecraft.config.DamageCategory
16+
import openshock.integrations.minecraft.config.DamageFilter
1617
import openshock.integrations.minecraft.config.DamageFilterMode
1718
import openshock.integrations.minecraft.config.DamageShockMode
1819
import openshock.integrations.minecraft.config.ShockCraftConfig
@@ -363,7 +364,7 @@ object ConfigScreen {
363364

364365
val typeOptions = available.map { id ->
365366
Option.createBuilder<Boolean>()
366-
.name(Component.literal(id.removePrefix("minecraft:")))
367+
.name(Component.literal(DamageFilter.shortName(id)))
367368
.description(OptionDescription.of(Component.literal(id)))
368369
.controller { TickBoxControllerBuilder.create(it) }
369370
.available(byTypeAvailable)

‎src/main/kotlin/openshock/integrations/minecraft/ShockCraft.kt‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,29 @@ object ShockCraft {
4545
var lastTickXpLevel: Int = 0
4646

4747
/**
48-
* A human-readable label for what hurt us, used as the OpenShock control name.
48+
* What a shock is sent under: who hurt us and how, e.g. `Zombie (mob_attack)`. It becomes the
49+
* OpenShock control name and, with the action bar switched on, what you read on screen.
50+
*
51+
* Both halves earn their place - "Zombie" alone does not say whether that was a hit or its
52+
* arrow, and a bare type does not say who threw it. The type is spelled the way the config
53+
* screen lists it, so a name you see here can be found in the Exact Damage Types picker.
4954
*
5055
* The server only sends a causing/direct entity when something actually attacked you, so
51-
* environmental damage (fall, lava, drowning, fire, cactus, ...) has neither. In that case fall
52-
* back to the damage type id, which is what vanilla names the death message after.
56+
* environmental damage (fall, lava, drowning, fire, cactus, ...) has neither and is left as
57+
* the type on its own.
5358
*/
54-
val DamageSource?.attackerName: String
59+
val DamageSource?.controlName: String
5560
get() {
5661
if (this == null) return "Unknown"
62+
5763
// getEntity() is the mob/player behind it, getDirectEntity() the projectile it used.
58-
val attacker = this.entity ?: this.directEntity
59-
return attacker?.name?.string ?: this.msgId
64+
val attacker = (this.entity ?: this.directEntity)?.name?.string
65+
66+
// msgId is the fallback for a hit whose type never reached the client: it is what
67+
// vanilla names the death message after, so it still reads like something.
68+
val type = DamageFilter.typeIdOf(this)?.let(DamageFilter::shortName) ?: this.msgId
69+
70+
return if (attacker == null) type else "$attacker ($type)"
6071
}
6172

6273
private fun reset() {
@@ -188,7 +199,7 @@ object ShockCraft {
188199
ControlType.Shock,
189200
config.onDeathIntensity,
190201
config.onDeathDuration,
191-
player.lastDamageSource.attackerName,
202+
player.lastDamageSource.controlName,
192203
)
193204
}
194205

@@ -246,7 +257,7 @@ object ShockCraft {
246257
ControlType.Shock,
247258
intensity,
248259
duration,
249-
player.lastDamageSource.attackerName,
260+
player.lastDamageSource.controlName,
250261
)
251262
}
252263
}

‎src/main/kotlin/openshock/integrations/minecraft/config/DamageFilter.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ object DamageFilter {
2828

2929
/** What to call a hit in the log: its exact type when we know it, its bucket otherwise. */
3030
fun describe(source: DamageSource?): String = typeIdOf(source) ?: DamageCategory.of(source).name
31+
32+
/**
33+
* A type id the way the config screen labels it: vanilla without its namespace, everything
34+
* else in full so a modded type stays unambiguous.
35+
*
36+
* Shared with the shock name, so what you read on screen matches what you tick in the picker.
37+
*/
38+
fun shortName(typeId: String): String = typeId.removePrefix("minecraft:")
3139
}

0 commit comments

Comments
 (0)