All work

Open source

Porting PGM's damage tracker to Bedrock for CompMC

For CompMC I built a Minecraft game framework in Java, and ported PGM's damage and death tracker to NukkitX so Bedrock games know who killed whom.

CompMC · Game Developer · 2020 – present

The problem

CompMC runs competitive games, and I built them a multi-module Minecraft game framework in Java with Bed Wars, Sky Wars, Spleef and Parkour on top. For Bedrock players the games run on NukkitX, which has no idea who caused a death. Was it the player who knocked you off the edge, the TNT someone lit, or the fall?

What I built

  1. Trackersremember who caused what
  2. Damagedamager to PhysicalInfo
  3. Resolver chainfirst match wins
  4. Last damagestored per victim
  5. DeathTrackedPlayerDeathEvent

Resolving a death

A sketch of the idea, not the production code.

on EntityDamageEvent(e):
    damager = entity_tracker.resolve(e.damager) ?? block_tracker.resolve(e.damager)
    last_damage[e.victim] = resolve(e.cause, e.victim, damager)

fn resolve(cause, victim, damager):
    if not tracked(victim): return NullDamageInfo        # observers
    for r in [fall, fire, potion, explosion, falling_block, generic]:   # order matters
        if info = r.resolve(cause, victim, damager): return info

on PlayerDeathEvent(e):
    info = last_damage[e.victim] ?? resolve(e.victim.last_damage_cause) ?? Generic(CUSTOM)
    fire(TrackedPlayerDeathEvent(e, e.victim, info, combat_log = is_combat_log(e)))

Why it matters

Kill credit, kill feeds and stats all depend on knowing who actually caused a death, and Bedrock players deserved the same answer Java players got.

Stack

Links