Implement disk replacement and chunk postprocessing marks
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare disk columns, optional providers and postprocessing query order."""
|
||||
import itertools
|
||||
import json
|
||||
try:
|
||||
from . import test_simple_block_parity as harness
|
||||
except ImportError:
|
||||
import test_simple_block_parity as harness
|
||||
|
||||
|
||||
def corpus(facts, placement):
|
||||
states = facts['states']; get = lambda name: facts['defaults']['minecraft:' + name]
|
||||
def disk(provider=None, **extra):
|
||||
value = {'type': 'disk', 'state_provider': provider if provider is not None else {'id': 'clay'},
|
||||
'target': {'type': 'true'}, 'radius': 0, 'half_height': 0}
|
||||
value.update(extra); return value
|
||||
def case(definition=None, **extra):
|
||||
value = {'definition': json.dumps(definition if definition is not None else disk(), separators=(',', ':')),
|
||||
'mode': 'feature', 'origin': [0, 64, 0], 'legacy': False, 'seed': 0, 'world_seed': 1,
|
||||
'fail': -1, 'reject': 0, 'brightness': 15, 'fallback': get('stone'), 'states': [], 'repeats': 2}
|
||||
value.update(extra); return value
|
||||
for state in states:
|
||||
yield case(disk(state))
|
||||
for state in range(len(states)):
|
||||
yield case(states=[[0, 65, 0, state], [0, 66, 0, state]])
|
||||
empty = {'type': 'random_block', 'blocks': []}
|
||||
selective = {'type': 'rule_based', 'fallback': {'id': 'clay'}, 'rules': [
|
||||
{'if_true': {'type': 'matching_blocks', 'blocks': 'water'}, 'then': empty}]}
|
||||
providers = [{'id': 'clay'}, empty, selective, {'type': 'random_block', 'blocks': ['clay', 'air', 'water']},
|
||||
{'type': 'rotated', 'state': {'id': 'oak_log'}}, 'horizon:stone']
|
||||
targets = [{'type': 'true'}, {'type': 'not', 'predicate': {'type': 'true'}},
|
||||
{'type': 'matching_blocks', 'blocks': ['stone', 'water']},
|
||||
{'type': 'solid'}, {'type': 'replaceable'}, {'type': 'has_sturdy_face', 'direction': 'up'}]
|
||||
for provider, target, legacy, seed, fail, reject in itertools.product(
|
||||
providers, targets, [False, True], [0, -1, 0x123456789abcdef], [-1, 0, 1, 2, 4, 7, 12], [0, 1, 3]):
|
||||
yield case(disk(provider, target=target, radius={'type': 'uniform', 'min_inclusive': 0, 'max_inclusive': 2}, half_height=2),
|
||||
states=[[0, 65, 0, get('water')], [0, 63, 0, get('air')]], legacy=legacy, seed=seed, fail=fail, reject=reject)
|
||||
# Optional-provider gaps retain the preceding placement flag; failed target
|
||||
# tests reset it. Air above a column stops the two-position postprocessing.
|
||||
for middle, above, fail in itertools.product(['water', 'air', 'stone'], ['air', 'cave_air', 'void_air', 'stone'], [-1, *range(22)]):
|
||||
yield case(disk(selective, target={'type': 'matching_blocks', 'blocks': ['stone', 'water']}, half_height=2),
|
||||
states=[[0, 65, 0, get(middle)], [0, 67, 0, get(above)], [0, 63, 0, get('air')]], fail=fail)
|
||||
for radius, height in itertools.product(range(9), range(5)):
|
||||
yield case(disk(radius=radius, half_height=height), repeats=1)
|
||||
for x, y, z in itertools.product([2147483647, -2147483648], [-64, 319, 2147483647, -2147483648], [2147483647, -2147483648]):
|
||||
for height in [0, 1, 4]:
|
||||
# Bottom overflow can make a native column enormous; interrupt its
|
||||
# first query after comparing the exact traversal prefix.
|
||||
yield case(disk(radius=2, half_height=height), origin=[x,y,z], fail=0 if y == -2147483648 else -1, repeats=1)
|
||||
for origin in [[2147483647,64,0], [0,64,-2147483648]]:
|
||||
yield case(disk(radius=2), origin=origin, fail=0, repeats=1)
|
||||
for key, values in [('state_provider',[None,False,{},'missing']), ('target',[None,False,{}]),
|
||||
('radius',[None,-1,0,8,9,{'type':'uniform','min_inclusive':0,'max_inclusive':9}]),
|
||||
('half_height',[None,-1,0,4,5,False,'1'])]:
|
||||
for value in values:
|
||||
definition=disk();definition[key]=value;yield case(definition)
|
||||
definition=disk();del definition[key];yield case(definition)
|
||||
for legacy, fail, reject in itertools.product([False,True],[-1,0,3,10],[0,3]):
|
||||
placed={'feature':disk(selective,radius=1,half_height=1),'placement':[{'type':'count','count':2},{'type':'in_square'}]}
|
||||
yield case(placed,mode='placed',legacy=legacy,fail=fail,reject=reject)
|
||||
yield case({'type':'overlay','features':[placed,{'feature':'horizon:moss','placement':[]}]},legacy=legacy,fail=fail,reject=reject)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
harness.run(corpus, 'rust-disk-parity', __file__,
|
||||
'Native DiskFeature codec and descending replacement columns, circular inclusive-box traversal, every candidate state, every state above a replacement, all valid radius/half-height constants and bounded integer provider decoding. Optional-provider gaps retain prior placement while rejected targets reset it. Two-block markAboveForPostProcessing reads stop on any air variant; chunk resolution and native ProtoChunk mark calls are traced with ordered failures. Provider draws, repeated mutations, rejected writes, both random modes and overlay/modifier composition are compared. Wrapped finite boxes and failure-terminated pathological prefixes are covered; Rust bounds visits to 2^20. This fixture checks postprocessing call order, not subsequent chunk postprocessing execution. Complete chunk generation and gameplay remain pending.')
|
||||
@@ -88,6 +88,7 @@ def corpus(facts, placement):
|
||||
|
||||
def run(corpus, build_name, source_file, scope):
|
||||
parser=argparse.ArgumentParser(description=__doc__);parser.add_argument('--prepare',action='store_true');args=parser.parse_args()
|
||||
label=build_name.removeprefix('rust-').removesuffix('-parity')
|
||||
build=lab.LOCAL/build_name;build.mkdir(parents=True,exist_ok=True);report_path=build/'report.json';report_path.unlink(missing_ok=True)
|
||||
if args.prepare:lab.prepare()
|
||||
lock,jars,libraries=base.verify_artifacts();oracle=lab.ROOT/'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaSimpleBlockOracle.java'
|
||||
@@ -119,11 +120,11 @@ def run(corpus, build_name, source_file, scope):
|
||||
metadata=json.loads(subprocess.check_output(['cargo','metadata','--no-deps','--format-version','1'],cwd=lab.ROOT,text=True));binary=Path(metadata['target_directory'])/'release/examples'/('simple_block_fixture.exe' if os.name=='nt' else 'simple_block_fixture')
|
||||
run([binary,build],'rust');references=[]
|
||||
for side,jar in jars.items():
|
||||
java(side,side,build);matched=base.compare(build/(side+'.txt'),build/'rust.txt');print(f'{side}: {matched:,} simple-block output lines match Rust',flush=True)
|
||||
java(side,side,build);matched=base.compare(build/(side+'.txt'),build/'rust.txt');print(f'{side}: {matched:,} {label} output lines match Rust',flush=True)
|
||||
references.append({'side':side,'jar_sha256':lab.digest(jar,'sha256'),'output_sha256':lab.digest(build/(side+'.txt'),'sha256'),'matched_output_lines':matched})
|
||||
base.ensure_sources_unchanged(sources,tested_sources);base.ensure_sources_unchanged(fixtures,tested_fixtures)
|
||||
report={'schema':1,'minecraft':lock['minecraft']['version'],'manifest_sha1':lock['minecraft']['manifest_sha1'],'platform':platform.platform(),'java':subprocess.check_output(['java','--version'],text=True).splitlines()[0],'rustc':subprocess.check_output(['rustc','--version'],text=True).strip(),'fixtures':fixture_count,'candidate_states':len(facts['states']),'double_plant_blocks':len(placement['double_plants']),'mossy_carpet_blocks':len(placement['mossy_carpets']),'sources_sha256':tested_sources,'fixtures_sha256':tested_fixtures,'rust_output_sha256':lab.digest(build/'rust.txt','sha256'),'references':references,'scope':scope}
|
||||
lab.write_json(report_path,report);print(f'Scoped simple-block parity passed: {report_path}',flush=True)
|
||||
lab.write_json(report_path,report);print(f'Scoped {label} parity passed: {report_path}',flush=True)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user