Apply native-validated landing damage to resident player health

This commit is contained in:
Ludovic Marie
2026-10-07 16:56:23 +02:00
parent 7a0d413b44
commit c82f0ee8be
14 changed files with 2800 additions and 42 deletions
+29 -3
View File
@@ -20,6 +20,29 @@ def vec(values): return list(map(bits, values))
def op(mode, value=None, **extra): return dict(mode=mode, value=value, **extra)
def corpus():
# Real repeated server damage, with explicit clock advancement between hits.
# Clock operations set up elapsed-time state; the enclosing native ticks are
# not executed by this scene harness.
for source in ['fall','stalagmite']:
for absorption in [0,1,4,20]:
for maximum in [1,20,40]:
for gap in [0,1,9,10,11,19,20,21]:
ops=[op('attribute',bits(maximum),name='minecraft:max_health'),op('health',single(maximum)),
op('attribute',bits(20),name='minecraft:max_absorption'),op('absorption',single(absorption))]
for amount in [2,2,1,4,8,25]:
ops.append(op('hurt',single(amount),name='minecraft:'+source))
ops += [op('clock') for _ in range(gap)]
ops += [op('player_tick',vec((0,0,.98)),jumping=True),op('health',single(20)),
op('hurt',single(1),name='minecraft:'+source)]
yield dict(position=vec((25,4,25)),ops=ops)
for source in ['fall','stalagmite']:
for armor in [0,5,20,30]:
for toughness in [0,8,20]:
for amount in [-1,-0.,0.,1e-30,.1,5,20,1e30,float('inf'),float('nan')]:
ops=[op('attribute',bits(armor),name='minecraft:armor'),op('attribute',bits(toughness),name='minecraft:armor_toughness'),
op('attribute',bits(100),name='minecraft:max_health'),op('health',single(100)),
op('hurt',single(amount),name='minecraft:'+source),op('hurt',single(5),name='minecraft:'+source)]
yield dict(position=vec((25,4,25)),ops=ops)
for name,properties in [('pointed_dripstone',{'vertical_direction':'up','thickness':'tip'}),('turtle_egg',{'eggs':'4','hatch':'2'})]:
for seed in range(8):
yield dict(position=vec((25.5,4,25.5)),ops=[op('seed',seed),op('block',name='minecraft:'+name,position=[25,3,25],properties=properties),
@@ -129,7 +152,7 @@ def main():
oracle=lab.ROOT/'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSceneMotionOracle.java'
helpers=[oracle.with_name(name+'.java') for name in ['VanillaSceneCollisionOracle','VanillaRegistryCollisionScanOracle',
'VanillaHeightmapOracle','VanillaCollisionOracle','VanillaBlockStateCodecOracle','VanillaSuffocationOracle',
'VanillaFaceSupportOracle','VanillaEntityAttributeOracle','VanillaBlockLandingOracle','VanillaMovementRegistryOracle']]
'VanillaFaceSupportOracle','VanillaEntityAttributeOracle','VanillaBlockLandingOracle','VanillaMovementRegistryOracle','VanillaDamageSourceOracle']]
sources=[Path(__file__),lab.ROOT/'tools/test_native_client.py',lab.ROOT/'tools/test_rust_parity.py',lab.ROOT/'tools/lab.py',
lab.ROOT/'tools/prepare_native_client.py',oracle,*helpers,lab.ROOT/'Cargo.toml',lab.ROOT/'Cargo.lock',
lab.ROOT/'crates/horizon-client/examples/scene_motion_probe.rs']
@@ -143,9 +166,12 @@ def main():
dependencies=os.pathsep.join(map(str,libraries))
run(['javac','--release',lock['minecraft']['java_major'],'-proc:none','-cp',str(jars['server'])+os.pathsep+dependencies,
'-d',classes,oracle,*helpers],'compile-java')
fixtures=list(corpus());operations=sum(len(f['ops']) for f in fixtures);expected_lines=3*operations+len(fixtures)
fixtures=list(corpus());operations=sum(len(f['ops']) for f in fixtures);expected_lines=4*operations+len(fixtures)
(build/'inputs.txt').write_text(''.join(json.dumps(f,separators=(',',':'))+'\n' for f in fixtures))
input_hash=lab.digest(build/'inputs.txt','sha256')
damage_dir=build/'damage';damage_dir.mkdir(exist_ok=True)
for target, source in [('types.json','damage-types.json'),('tags.json','damage-tags.json')]:
(damage_dir/target).write_bytes((resources/source).read_bytes())
run(['cargo','build','--locked','-p','horizon-client','--example','scene_motion_probe'],'compile-rust')
metadata=json.loads(subprocess.check_output(['cargo','metadata','--locked','--no-deps','--format-version','1'],cwd=lab.ROOT))
binary=Path(metadata['target_directory'])/'debug/examples'/('scene_motion_probe.exe' if os.name=='nt' else 'scene_motion_probe')
@@ -166,7 +192,7 @@ def main():
'java':subprocess.check_output(['java','--version'],text=True).splitlines()[0],'fixtures':len(fixtures),
'operations':operations,'sources_sha256':tested,'resources':resource_hash,'input_sha256':input_hash,
'rust_output_sha256':lab.digest(build/'rust.txt','sha256'),'references':references,
'scope':'Stored PlayerMotion binds resident client chunks and registered attributes/coefficients to air travel, jumping, Entity.move, step resolution, ground/support updates, restitution and speed factors. Repeated native Player.travel/jump/move and actual Player.aiStep / direct LivingEntity.aiStep compare position, velocity, bounds, collision/ground flags, support, climb state, fall-reset field, both sync flags, speed, head yaw, jump trigger and jump delay by exact bits. Prepared-local-input Player.aiStep paths verify speed refresh after movement, with empty inventory and no nearby entities. Dry aiStep includes small-velocity cleanup, input damping, held/released jump timing and server frost-modifier removal. Snapshots also compare all allocated attribute instances, base/cache/dirty state, modifier values/operations/permanence and pending update/sync membership (not JVM identity-dependent iteration order). Dry resident scene, fixed standing dimensions, zero frozen ticks, empty equipment, no interpolation, fluids, vehicles, effects, crouching or other entities. Actual LivingEntity.checkFallDamage, registered Block.fallOn/bounceOn and Player/LivingEntity.causeFallDamage are composed, including float-narrowed fall-distance accumulation, reset, last-climb clearing, safe-fall and damage-multiplier attributes, impulse exemptions and ordered landing particle/sound/statistic/hit-ground/damage requests. Farmland pushes the stored player and replaces actual chunk state; repeated turtle-egg changes preserve hatch. Block state at the landing fixture is compared after every operation. World RNG is a seeded native legacy stream. Health damage, audiovisual playback, block neighbor/drop/block-entity callbacks, movement emission, block-inside and networking remain controlled boundaries; the native hurtServer consumer records requests and returns false. Input preparation has its own client comparison. No full Player.tick, local input lifecycle, nonempty inventory/equipment ticks, full freezing, health/damage lifecycle or full gameplay parity claim.'})
'scope':'Stored PlayerMotion binds resident client chunks and registered attributes/coefficients to air travel, jumping, Entity.move, step resolution, ground/support updates, restitution and speed factors. Repeated native Player.travel/jump/move and actual Player.aiStep / direct LivingEntity.aiStep compare position, velocity, bounds, collision/ground flags, support, climb state, fall-reset field, both sync flags, speed, head yaw, jump trigger and jump delay by exact bits. Prepared-local-input Player.aiStep paths verify the stored speed refresh after movement, with empty inventory and no nearby entities. Travel uses the actual Player.getSpeed movement-attribute query, independently of that stored base-living speed field; both getter and setter execute native bodies. Dry aiStep includes small-velocity cleanup, input damping, held/released jump timing and server frost-modifier removal. Snapshots also compare all allocated attribute instances, base/cache/dirty state, modifier values/operations/permanence and pending update/sync membership (not JVM identity-dependent iteration order). Dry resident scene, fixed standing dimensions, zero frozen ticks, empty equipment, no interpolation, fluids, vehicles, effects, crouching or other entities. Actual LivingEntity.checkFallDamage, registered Block.fallOn/bounceOn and Player/LivingEntity.causeFallDamage are composed, including float-narrowed fall-distance accumulation, reset, last-climb clearing, safe-fall and damage-multiplier attributes, impulse exemptions and ordered landing particle/sound/statistic/hit-ground/damage requests. Farmland pushes the stored player and replaces actual chunk state; repeated turtle-egg changes preserve hatch. Block state at the landing fixture is compared after every operation. World RNG is a seeded native legacy stream. Actual ServerPlayer/Player/LivingEntity hurt dispatch now updates native synchronized health and player absorption, modified armor/toughness reduction, exhaustion, damage cooldown/last-source state and velocity synchronization. Native health storage and dirty flags are compared after every operation. Damage sources use actual decoded/tagged pinned damage registries. ServerPlayer jump statistics and exhaustion are included; dead-or-dying state disables movement input and jumping. Empty equipment/hands/effects, normal difficulty, damage gamerules enabled, loaded client and no spawn-extra fall particles define this scene domain. Ordered health/statistic/combat-record/broadcast/sound/criterion/death requests are compared; criterion argument payloads retain the separate combat gate. Actual health changes are applied, but audiovisual playback, persistent statistics, combat tracker internals, full death/drop/respawn services, block neighbor/drop/block-entity callbacks, movement emission, block-inside and networking remain controlled consumers. Explicit clock operations establish cooldown/hurt-time/game-time state using the two damage-clock phases; the full enclosing native ticks are not invoked by those setup operations. Input preparation has its own client comparison. No full Player.tick, hunger regeneration, local input lifecycle, nonempty inventory/equipment ticks, full freezing, complete death lifecycle or full gameplay parity claim.'})
print(f'Scoped scene motion parity passed: {report}',flush=True)
if __name__=='__main__':main()