@@ -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}
0 commit comments