Merge branch 'main' into worktree-agent-a3f604d3c8055fe6e
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Shared driver of the block update / random tick / redstone differential harnesses.
|
||||
|
||||
Cases are JSON lines understood by `VanillaBlockUpdateOracle` (vanilla block code
|
||||
over a map-backed headless ServerLevel) and `block_update_fixture` (the Rust
|
||||
`Behaviours` over the same kind of level). Both print one result block per case
|
||||
(state changes, pending scheduled ticks, side-effect log, RNG fingerprint); this
|
||||
module generates cases, runs both sides and reports differing cases grouped by
|
||||
the block under test.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import subprocess
|
||||
try:
|
||||
from . import lab, test_rust_parity as base
|
||||
except ImportError:
|
||||
import lab
|
||||
import test_rust_parity as base
|
||||
|
||||
NEIGHBOUR_PALETTE = [
|
||||
'stone', 'dirt', 'grass_block', 'water', 'lava', 'sand', 'oak_log', 'oak_planks', 'farmland', 'snow', 'snow_block',
|
||||
'ice', 'packed_ice', 'soul_sand', 'netherrack', 'mycelium', 'podzol', 'gravel', 'glass', 'oak_leaves', 'fire',
|
||||
'redstone_block', 'redstone_wire', 'redstone_torch', 'torch', 'lever', 'iron_block', 'magma_block', 'bedrock',
|
||||
'cobblestone', 'obsidian', 'tnt', 'oak_slab', 'oak_stairs', 'hopper', 'bamboo', 'cactus', 'sugar_cane', 'kelp',
|
||||
'seagrass', 'vine', 'moss_block', 'dripstone_block', 'amethyst_block', 'calcite', 'clay', 'coarse_dirt', 'rooted_dirt',
|
||||
]
|
||||
|
||||
DIRS = [(0, -1, 0), (0, 1, 0), (0, 0, -1), (0, 0, 1), (-1, 0, 0), (1, 0, 0)]
|
||||
|
||||
|
||||
class Facts:
|
||||
def __init__(self, resources):
|
||||
facts = json.loads((resources / 'facts.json').read_text())
|
||||
self.states = facts['states']
|
||||
self.defaults = facts['defaults']
|
||||
self.by_block = {}
|
||||
for index, state in enumerate(self.states):
|
||||
self.by_block.setdefault(state[0], []).append(index)
|
||||
self.palette = [name for name in ('minecraft:' + n for n in NEIGHBOUR_PALETTE) if name in self.by_block]
|
||||
self.names = list(self.by_block)
|
||||
|
||||
def describe(self, index):
|
||||
return self.states[index][3].replace('Block{', '').replace('}', '', 1)
|
||||
|
||||
def neighbour(self, rng, own):
|
||||
roll = rng.random()
|
||||
if roll < 0.30:
|
||||
return rng.choice(self.by_block[rng.choice(self.palette)])
|
||||
if roll < 0.45:
|
||||
return rng.choice(self.by_block[self.states[own][0]])
|
||||
if roll < 0.60:
|
||||
return rng.choice(self.by_block[rng.choice(self.names)])
|
||||
return None
|
||||
|
||||
def cells(self, rng, origin_state, density=0.55, face_density=0.8, extent=2):
|
||||
cells = [[0, 0, 0, origin_state]]
|
||||
for x in range(-extent, extent + 1):
|
||||
for y in range(-extent, extent + 1):
|
||||
for z in range(-extent, extent + 1):
|
||||
if (x, y, z) == (0, 0, 0):
|
||||
continue
|
||||
face = abs(x) + abs(y) + abs(z) == 1
|
||||
if rng.random() > (face_density if face else density):
|
||||
continue
|
||||
state = self.neighbour(rng, origin_state)
|
||||
if state is not None:
|
||||
cells.append([x, y, z, state])
|
||||
return cells
|
||||
|
||||
|
||||
def environment(rng):
|
||||
case = {'seed': rng.randrange(1 << 40), 'time': rng.randrange(0, 100000)}
|
||||
roll = rng.random()
|
||||
if roll < 0.5:
|
||||
case['light'] = [15, 0]
|
||||
elif roll < 0.7:
|
||||
case['light'] = [0, 0]
|
||||
elif roll < 0.85:
|
||||
case['light'] = [rng.randrange(16), rng.randrange(16)]
|
||||
else:
|
||||
case['light'] = [15, 15]
|
||||
if rng.random() < 0.1:
|
||||
case['raining'] = True
|
||||
case['thundering'] = rng.random() < 0.3
|
||||
return case
|
||||
|
||||
|
||||
def put(cells, pos, state):
|
||||
for cell in cells:
|
||||
if cell[:3] == list(pos):
|
||||
cell[3] = state
|
||||
return
|
||||
cells.append([*pos, state])
|
||||
|
||||
|
||||
def argument_parser(description):
|
||||
parser = argparse.ArgumentParser(description=description)
|
||||
parser.add_argument('--count', type=int, default=40000, help='cases to generate')
|
||||
parser.add_argument('--seed', type=int, default=1)
|
||||
parser.add_argument('--only', help='substring of the block name under test')
|
||||
parser.add_argument('--show', type=int, default=1, help='examples printed per block')
|
||||
parser.add_argument('--events', action='store_true', help='compare side-effect logs too (default: states, ticks, rng and events)')
|
||||
parser.add_argument('--ignore', default='', help='comma separated line prefixes to ignore when comparing (e.g. S,G)')
|
||||
return parser
|
||||
|
||||
|
||||
def blocks_of(facts):
|
||||
return facts.names
|
||||
|
||||
|
||||
def run(command, **kwargs):
|
||||
done = subprocess.run(command, capture_output=True, text=True, **kwargs)
|
||||
if done.returncode:
|
||||
print((done.stdout + done.stderr)[-3000:])
|
||||
raise SystemExit(f'{command[0]} failed')
|
||||
return done
|
||||
|
||||
|
||||
def execute(name, cases, args, facts, origin_of=None):
|
||||
"""Run `cases` on both sides; print a report and return the number of differing cases."""
|
||||
lock, jars, libraries = base.verify_artifacts()
|
||||
resources = lab.LOCAL / 'horizon-client' / lock['minecraft']['version']
|
||||
work = lab.LOCAL / name
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
(work / 'cases.jsonl').write_text(''.join(json.dumps(case) + '\n' for case in cases))
|
||||
classes = work / 'classes'
|
||||
classes.mkdir(exist_ok=True)
|
||||
dependencies = os.pathsep.join(map(str, [jars['server'], *libraries]))
|
||||
java_root = lab.ROOT / 'mods/horizon/src/test/java'
|
||||
run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none', '-sourcepath', str(java_root), '-nowarn',
|
||||
'-cp', dependencies, '-d', str(classes), str(java_root / 'dev/horizonlab/parity/VanillaBlockUpdateOracle.java')])
|
||||
run(['java', '-Xmx2G', '-cp', str(classes) + os.pathsep + dependencies, 'dev.horizonlab.parity.VanillaBlockUpdateOracle',
|
||||
str(resources), str(work / 'cases.jsonl'), str(work / 'native.txt')])
|
||||
run(['cargo', 'run', '-q', '--release', '-p', 'horizon-world', '--example', 'block_update_fixture', '--',
|
||||
str(resources), str(work / 'cases.jsonl'), str(work / 'rust.txt')], cwd=lab.ROOT, env={**os.environ, 'CARGO_BUILD_JOBS': '3'})
|
||||
ignore = tuple(prefix + ' ' for prefix in args.ignore.split(',') if prefix)
|
||||
native = split_cases((work / 'native.txt').read_text(), ignore)
|
||||
rust = split_cases((work / 'rust.txt').read_text(), ignore)
|
||||
assert len(native) == len(rust) == len(cases), (len(native), len(rust), len(cases))
|
||||
groups = {}
|
||||
errors = {}
|
||||
for case, a, b in zip(cases, native, rust):
|
||||
if a and a[0].startswith('error'):
|
||||
errors.setdefault(a[0], []).append(case)
|
||||
continue
|
||||
if a != b:
|
||||
groups.setdefault(origin_name(case, facts), []).append((case, a, b))
|
||||
total = sum(len(v) for v in groups.values())
|
||||
for kind, entries in sorted(errors.items(), key=lambda entry: -len(entry[1])):
|
||||
print(f'oracle error x{len(entries)}: {kind} (e.g. {facts.describe(entries[0]["cells"][0][3])})')
|
||||
for block, entries in sorted(groups.items(), key=lambda entry: -len(entry[1])):
|
||||
print(f'{block}: {len(entries)} differing')
|
||||
for case, a, b in entries[:args.show]:
|
||||
print(' case ' + describe_case(case, facts))
|
||||
print(' native ' + ' | '.join(a))
|
||||
print(' rust ' + ' | '.join(b))
|
||||
skipped = sum(len(v) for v in errors.values())
|
||||
print(f'{len(cases) - total - skipped}/{len(cases) - skipped} cases match ({skipped} oracle errors)')
|
||||
(work / 'differences.json').write_text(json.dumps({k: [[c, a, b] for c, a, b in v[:5]] for k, v in groups.items()}))
|
||||
return total
|
||||
|
||||
|
||||
def split_cases(text, ignore):
|
||||
out = []
|
||||
for block in text.split('case ')[1:]:
|
||||
lines = block.splitlines()[1:]
|
||||
out.append([line for line in lines if not line.startswith(ignore)] if ignore else lines)
|
||||
return out
|
||||
|
||||
|
||||
def origin_name(case, facts):
|
||||
pos = case.get('pos', [0, 0, 0])
|
||||
for cell in case['cells']:
|
||||
if cell[:3] == pos:
|
||||
return facts.states[cell[3]][0]
|
||||
return 'minecraft:air'
|
||||
|
||||
|
||||
def describe_case(case, facts):
|
||||
pos = case.get('pos', [0, 0, 0])
|
||||
parts = [case['mode'], facts.describe(next(c[3] for c in case['cells'] if c[:3] == pos))]
|
||||
if case['mode'] == 'shape':
|
||||
parts.append(f'dir={case["dir"]} neighbor={facts.describe(case["neighbor"])}')
|
||||
if case['mode'] == 'neighbor':
|
||||
parts.append(f'from={case["from"]}')
|
||||
if case.get('light') not in (None, [15, 0]):
|
||||
parts.append(f'light={case["light"]}')
|
||||
if case.get('raining'):
|
||||
parts.append('raining')
|
||||
near = []
|
||||
for dx, dy, dz in DIRS:
|
||||
at = [pos[0] + dx, pos[1] + dy, pos[2] + dz]
|
||||
state = next((c[3] for c in case['cells'] if c[:3] == at), None)
|
||||
near.append('air' if state is None else facts.describe(state))
|
||||
parts.append('faces=' + ';'.join(near))
|
||||
return ' '.join(parts) + f' seed={case["seed"]} time={case.get("time")}'
|
||||
|
||||
|
||||
def load_facts():
|
||||
lock, _, _ = base.verify_artifacts()
|
||||
return Facts(lab.LOCAL / 'horizon-client' / lock['minecraft']['version'])
|
||||
|
||||
|
||||
def state_pool(facts, only):
|
||||
return [i for i, s in enumerate(facts.states) if not only or only in s[0]]
|
||||
|
||||
|
||||
def finish(differing):
|
||||
raise SystemExit(1 if differing else 0)
|
||||
@@ -0,0 +1,545 @@
|
||||
"""Command corpus for tools/test_command_parse_parity.py.
|
||||
|
||||
The corpus walks vanilla's exported command tree. For every executable path it
|
||||
emits the valid command (sample values per argument type), every token-boundary
|
||||
prefix (completion suggestions), mutations that replace one argument by a bad
|
||||
sample of its type (error message and cursor), a truncated last argument and a
|
||||
trailing-garbage variant. Hand-written extra commands cover selectors, NBT
|
||||
paths, coordinates, ranges and the other parsers in more depth.
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
SELECTORS = [
|
||||
'@s', '@a', '@e', '@p', '@r', '@n', 'Player', 'Steve', 'some_name', '00000000-0000-0000-0000-000000000001',
|
||||
'@a[distance=..5]', '@e[distance=1..5]', '@e[distance=2]', '@e[type=minecraft:pig,limit=1,sort=nearest]', '@e[type=!zombie]',
|
||||
'@e[type=#minecraft:skeletons]', '@e[tag=a,tag=!b]', '@e[tag=]', '@e[tag=!]', '@e[team=red]', '@e[team=!red]', '@e[team=]',
|
||||
'@e[scores={kills=1..}]', '@e[scores={kills=1,health=..5}]', '@e[nbt={Invulnerable:1b}]', '@e[nbt=!{Invulnerable:1b}]',
|
||||
'@e[x=1,y=2,z=3,dx=4,dy=5,dz=6]', '@e[x=1.5]', '@e[level=5..10]', '@e[level=3]', '@a[gamemode=survival]', '@a[gamemode=!creative]',
|
||||
'@e[name="Bob"]', '@e[name=Bob]', '@e[name=!Bob]', '@e[advancements={minecraft:story/root=true}]',
|
||||
'@e[advancements={minecraft:story/root={a=true}}]', '@e[predicate=minecraft:foo]', '@e[predicate=!minecraft:foo]',
|
||||
'@e[x_rotation=..0]', '@e[y_rotation=90..180]', '@e[x_rotation=0]', '@e[limit=0]', '@e[limit=3]', '@e[sort=random]',
|
||||
'@e[sort=furthest]', '@e[sort=arbitrary]', '@e[type=player]', '@a[type=player]', '@e[distance=..5,limit=1]', '@e[ ]',
|
||||
'@e[ type = pig ]', '@e[type=pig , limit=2]', '@e[type=pig,]', '@e[,]', '@a[ name = "x" ]',
|
||||
'@a[scores={}]', '@a[advancements={}]', '@e[nbt={}]', '@e[nbt={a:1,b:[1,2]}]',
|
||||
'@e[x=1,x=2]', '@e[limit=1,limit=2]', '@s[type=pig]', '@e[type=pig,type=cow]', '@e[type=!pig,type=!cow]',
|
||||
'@e[distance=..5,distance=1..]', '@e[sort=nearest,sort=random]', '@e[gamemode=survival,gamemode=creative]',
|
||||
]
|
||||
BAD_SELECTORS = [
|
||||
'@x', '@', '@E', '@e[', '@e[]', '@e[distance=-1]', '@e[distance=..-1]', '@e[unknown=1]', '@e[limit=a]', '@e[limit=-1]',
|
||||
'@e[type=pig', '@e[type=minecraft:nope]', '@e[type=nope]', '@e[type=#nope]', '@e[sort=bad]', '@e[gamemode=bad]',
|
||||
'@e[nbt={]', '@e[nbt=]', '@e[scores={a=}]', '@e[scores={a=x}]', '@e[scores={a}]', '@e[scores={a=1', '@e[scores=1]',
|
||||
'@e[advancements={a=}]', '@e[advancements={nope=true}]', '@e[advancements={minecraft:story/root=maybe}]',
|
||||
'@e[level=a]', '@e[level=-1..]', '@e[x=]', '@e[x=a]', '@e[dx=a]', '@e[x_rotation=a]', '@e[name=]', '@e[name="x]',
|
||||
'@e[team]', '@e[tag]', '@e[limit]', '@e[=1]', '@e[a=1]', '@e[type=pig,]x', '@e[type=pig]x', '@e [type=pig]',
|
||||
'@e[predicate=]', '@e[predicate=minecraft:]', '@e[predicate=Bad]', '@e[type=Bad]', '@e[gamemode=]', '@e[sort=]',
|
||||
'@e[distance=..]', '@e[distance=1..a]', '@e[level=..]', '@e[nbt={a:}]', '@e[nbt=1]', '@a[limit=0]',
|
||||
'@e[nbt={a:1}', '@e[type=pig,type=!pig]', '@e[type=!pig,type=pig]', '@p[type=zombie]', '@a[type=zombie]', '@r[type=!player]',
|
||||
'@e[scores={kills=1..}', '@e[tag=a b]', '"Bob', '@e[type="pig"]', '@e[type=\'pig\']', '@s[', '@s]', '@e{}',
|
||||
'Bad Name', 'x'.ljust(17, 'y'), '\u00e9', '00000000-0000-0000-0000-00000000000g', '00000000-0000-0000-0000-00000000000',
|
||||
]
|
||||
COMPONENTS = [
|
||||
'"text"', '{"text":"hi"}', '[{"text":"a"},"b"]', '{"translate":"chat.type.text","with":["a","b"]}',
|
||||
'{"text":"x","color":"red","bold":true}', 'true', '12', '1.5', '{"selector":"@a"}', '{"selector":"@a","separator":", "}',
|
||||
'{"score":{"name":"@s","objective":"kills"}}', '{"nbt":"foo","entity":"@s"}', '{"nbt":"foo","block":"0 0 0"}',
|
||||
'{"nbt":"foo","storage":"a:b","interpret":true}', '{"keybind":"key.jump"}', "'single'", '{text:"snbt"}', '{text:"a",extra:["b",{text:"c"}]}',
|
||||
'{"text":"x","hover_event":{"action":"show_text","value":"y"}}', '{"text":"x","click_event":{"action":"open_url","url":"https://a.b"}}',
|
||||
'{"text":"x","click_event":{"action":"run_command","command":"/help"}}', '{"text":"x","font":"minecraft:uniform"}',
|
||||
'{"text":"x","color":"#ff00ff"}', '{"text":"x","shadow_color":-1}', '{"text":"x","insertion":"y"}', '[]', '[1,2]', '""', '{}',
|
||||
'{"type":"text","text":"x"}', '{"type":"translatable","translate":"x"}', '{"translate":"x","fallback":"y"}',
|
||||
'{"object":"atlas","sprite":"item/porkchop"}', '{"object":"player","player":{"name":"Notch"}}',
|
||||
'{text:"x",color:red}', '"a\\nb"', '{"text":"a","italic":false,"underlined":true,"strikethrough":false,"obfuscated":false}',
|
||||
]
|
||||
BAD_COMPONENTS = [
|
||||
'{"text":', '{"text":"x",}', '{"color":"nope","text":"x"}', '{"translate":}', '[', '{"text":"x","extra":5}', '{"unknown":1}',
|
||||
'{"text":"x"} y', '"unterminated', "{'a':1}", '{"text":1,"color":}', '{"selector":"@x"}', '{"nbt":"a"}',
|
||||
'{"score":{"name":"@s"}}', '{"keybind":5}', '{"text":"x","click_event":{"action":"nope"}}', '{"text":"x","bold":"maybe"}',
|
||||
'{"translate":"x","with":5}', '{"text":"x","color":"#gggggg"}', '{"text":"x","hover_event":{"action":"show_text"}}', 'nope',
|
||||
'{"text":"x","font":"Bad Font"}', '{"nbt":"a","entity":"@x"}', '{"type":"nope"}', '[{"text":"a"},', '{"text":"a"', '}',
|
||||
]
|
||||
NBT_COMPOUNDS = [
|
||||
'{}', '{a:1}', '{a:1b,b:"x",c:[1,2,3]}', '{a:{b:{c:1}}}', '{"quoted key":1}', "{'single':1}", '{a:[I;1,2,3]}', '{a:[B;1b,2b]}',
|
||||
'{a:[L;1L,2L]}', '{a:1.5f,b:2d,c:3L,d:4s}', '{a:1,}', '{ a : 1 }', '{a:true,b:false}', '{a:1.5e3}', '{a:0x10}', '{a:0b101}',
|
||||
'{a:-1b}', '{a:+1}', '{a:"\\n"}', '{a:[]}', '{a:[{}]}', '{a:[[1],[2]]}', '{a:1_000}', '{a:bare}', '{a:.5}', '{a:5.}',
|
||||
'{a:1,a:2}', '{a:[I;]}', '{a:[B;]}', '{a:1f}', '{a:1F}', '{a:1D}', '{a:NaN}', '{a:Infinity}', '{a:"\\u00e9"}',
|
||||
]
|
||||
BAD_NBT_COMPOUNDS = [
|
||||
'{', '{a:}', '{a:1', '{a 1}', '{a:[I;1b]}', '{a:[1,"x"]}', '{a:1,,}', '{,}', '{:1}', '{a:[B;1]}', '[]', '1', '"x"',
|
||||
'{a:"unterminated}', '{a:[}', '{a:1b2}', '{a:300b}', '{a:99999999999}', '{a:[I;1.5]}', '{a:1 b:2}', '{a:{}', '{a:1}x',
|
||||
'{"":1}', '{a:\\}', '{a:"\\x"}', '{a:0x}', '{a:1.2.3}', '{a:--1}',
|
||||
]
|
||||
NBT_TAGS = ['1', '1b', '"str"', '[1,2]', '{a:1}', 'true', '1.5', '[B;1b]', '1s', '1L', '1.5f', '2d', "'x'", 'bare', '[]', '[I;1]', '0', '-1']
|
||||
BAD_NBT_TAGS = ['', '[', '{', '"x', '[1,"a"]', '1b2', '[B;1', '1.5.5', '[I;1b]', '1,', '{a}', ']']
|
||||
NBT_PATHS = [
|
||||
'foo', 'foo.bar', 'foo[0]', 'foo[]', 'foo[{a:1}]', '{a:1}', 'foo{a:1}', '"quoted key".x', 'a.b[2].c', '[0]', 'foo[-1]', 'a[0][1]',
|
||||
'a[0].b', 'a{b:1}.c', '"a b"', "'a b'", 'a.b.c.d', '{}', 'a[{}]', 'a[ 0 ]', 'a.', 'Items[{Slot:0b}].id', 'a[{b:{c:1}}]',
|
||||
'_x', 'A1', '1a', 'a-b', 'a:b', 'a/b', 'a+b', '\u00e9',
|
||||
]
|
||||
BAD_NBT_PATHS = ['.', 'foo.', 'foo[', 'foo[a]', 'foo..bar', '{a:', 'foo[{a:1}', '[]foo', 'foo[0', 'foo]', 'foo[1.5]', 'foo[-]', '"foo', 'foo."bar', 'a{', '{a:1}{b:2}', 'a.{b:1}', '[{a:1}]x']
|
||||
BLOCK_POS = ['0 64 0', '~ ~ ~', '~1 ~-2 ~3', '^ ^ ^1', '1 2 3', '~.5 ~ ~', '-1 -2 -3', '1.5 2 3', '~1.5 ~ ~', '^1.5 ^ ^', '0 0 0', '+1 +2 +3', '.5 1 1', '1e2 2 3']
|
||||
BAD_BLOCK_POS = ['0 64', '~ ~', '^ ^ 1', '~1 ^2 3', 'a b c', '1 2', '~ a ~', '^ ~ ^', '1 2 ^', '99999999999 0 0', '~a ~ ~', '~ ~ ~x', '^1 ^2', '~-', '- 0 0']
|
||||
VEC3 = ['0 64 0', '~ ~ ~', '1.5 2.5 -3.5', '^1 ^ ^-2', '.5 .5 .5', '1 2 3', '~0.5 ~ ~', '-0 0 0', '1e3 0 0', '+1 0 0', '1.5e-3 0 0']
|
||||
BAD_VEC3 = ['1 2', '^ ~ ~', '~a ~ ~', '1.5 2', 'a b c', '~ ~', 'NaN 0 0', '1 2 ^', '0 0 0x', '1.2.3 0 0', '~- 0 0']
|
||||
VEC2 = ['0 0', '~ ~', '1.5 -2', '~1 ~-1', '1 2']
|
||||
BAD_VEC2 = ['1', '~ a', '^ ^', '1 ^', 'a b', '~ ~ ~']
|
||||
COLUMN_POS = ['0 0', '~ ~', '~3 ~-4', '1 2', '-5 7']
|
||||
BAD_COLUMN_POS = ['0', '~ ^', 'a b', '1.5 2', '^ ^', '0 0 0']
|
||||
ROTATION = ['0 0', '~ ~', '90 -45', '~10 ~-5', '1.5 2.5', '-180 180', '^ ^']
|
||||
BAD_ROTATION = ['^ ^', 'a b', '0', '~ a', '1 2 3']
|
||||
INT_RANGES = ['1', '1..5', '..5', '1..', '0..0', '-5..-1', '-5..5', '5..5', '+1', '1..+5', '0']
|
||||
BAD_INT_RANGES = ['..', '1...5', 'a', '5..1', '1..a', '1.5', '1..5..6', '-', '..-', ' ', '99999999999', '1..99999999999']
|
||||
FLOAT_RANGES = ['1', '1.5', '1..5', '..5.5', '0.1..', '-1.5..2.5', '.5', '5.', '1..1', '1.5..1.5', '..0', '0..']
|
||||
BAD_FLOAT_RANGES = ['..', 'a', '1.5.5', '5..1', '1..a', '1...2', '1e5', '-', '..-', '2..1.5']
|
||||
TIMES = ['1', '1d', '1s', '1t', '0.5d', '2.5s', '100', '1.5t', '0', '0d', '3600', '24000', '1e2']
|
||||
BAD_TIMES = ['1x', 'abc', '-1', '1.5.5s', '1 s', 'd', '99999999999', '1e', '.d', '-1t', '0.5t', '2147483648']
|
||||
RESOURCE_LOCATIONS = ['minecraft:stone', 'stone', 'foo:bar', 'a/b', 'foo:bar/baz', 'foo.bar:a-b_c', 'a_b', '.', 'minecraft:']
|
||||
BAD_RESOURCE_LOCATIONS = ['Stone', 'foo:Bar', 'a b', ':x', 'minecraft::x', 'a:b:c', 'foo:bar$', '\u00e9', '@a', '#a']
|
||||
ITEM_STACKS = [
|
||||
'minecraft:stone', 'stone', 'minecraft:diamond_sword[damage=5]', 'minecraft:stone[]', 'minecraft:stone[minecraft:custom_name="x"]',
|
||||
'minecraft:stone[!damage]', 'minecraft:diamond_sword[damage=5,max_damage=10]', 'minecraft:stone[count=1]', 'minecraft:stone[ ]',
|
||||
'minecraft:stone[custom_name={"text":"x"}]', 'minecraft:stone[lore=["a","b"]]', 'minecraft:stone[enchantments={"minecraft:sharpness":1}]',
|
||||
'minecraft:stone[custom_data={a:1}]', 'minecraft:stone[unbreakable={}]', 'minecraft:stone[max_stack_size=1]', 'minecraft:stone[rarity=epic]',
|
||||
'minecraft:stone[!damage,!max_damage]', 'minecraft:stone[damage=5,!max_damage]', 'minecraft:player_head[profile="Notch"]', 'minecraft:stone[ damage = 5 ]',
|
||||
'minecraft:stone[repair_cost=0]', 'minecraft:stone[item_name="x"]', 'minecraft:stone[tooltip_display={hide_tooltip:true}]',
|
||||
]
|
||||
BAD_ITEM_STACKS = [
|
||||
'minecraft:nope', 'nope', 'minecraft:stone[', 'minecraft:stone[damage]', 'minecraft:stone[damage=x]', 'minecraft:stone[nope=1]',
|
||||
'minecraft:stone[damage=5,damage=6]', 'minecraft:stone{a:1}', 'minecraft:stone[!nope]', 'minecraft:stone[damage=5', 'minecraft:stone[damage=5,]',
|
||||
'minecraft:stone[=5]', 'minecraft:stone[!]', 'minecraft:stone[!damage=5]', 'minecraft:stone]', 'Minecraft:stone', 'minecraft:stone[damage=-5]',
|
||||
'minecraft:stone[damage=5,!damage]', 'minecraft:stone[max_stack_size=0]', 'minecraft:stone[max_stack_size=100]', 'minecraft:stone[rarity=nope]',
|
||||
'minecraft:stone[custom_name={"text":}]', 'minecraft:stone[enchantments=1]', '#minecraft:logs', '*', 'minecraft:stone[unknown:thing=1]',
|
||||
]
|
||||
ITEM_PREDICATES = [
|
||||
'minecraft:stone', 'stone', '*', '#minecraft:planks', '#planks', 'minecraft:stone[damage=5]', 'minecraft:stone[!damage]', 'stone[count=1]',
|
||||
'stone[count~1]', 'stone[damage|max_damage=5]', 'stone[damage~5]', 'stone[count={min:1}]', 'stone[custom_data~{a:1}]', '*[damage=5]',
|
||||
'#minecraft:planks[damage=5]', 'stone[enchantments~[{enchantments:"minecraft:sharpness"}]]', 'stone[enchantments~[{levels:{min:1}}]]',
|
||||
'stone[damage|count=1]', 'stone[count=1|damage=2]', 'stone[(count=1|damage=2),!max_damage]', 'stone[damage={durability:5}]',
|
||||
]
|
||||
BAD_ITEM_PREDICATES = [
|
||||
'minecraft:nope', '#nope', '#', 'stone[', 'stone[damage=x]', 'stone[nope=1]', 'stone[nope~1]', 'stone[count~]', 'stone[!nope]', 'stone[damage|]',
|
||||
'stone[|damage]', 'stone[damage||count]', '*[', '*x', 'stone[damage=5,damage=6]', 'stone[damage=1 count=2]', 'stone[count=1,]', 'stone[ ]x',
|
||||
'stone[count~a]', 'stone[(damage=1]', 'stone[damage=1)]',
|
||||
]
|
||||
BLOCK_STATES = [
|
||||
'minecraft:stone', 'stone', 'oak_stairs[facing=north]', 'oak_stairs[facing=north,half=top]', 'minecraft:chest{Items:[]}', 'stone{}', 'oak_stairs[]',
|
||||
'oak_stairs[ ]', 'oak_stairs[ facing = north ]', 'minecraft:chest[facing=west]{Items:[]}', 'oak_stairs[waterlogged=true,shape=straight]',
|
||||
'minecraft:oak_stairs[half=bottom,facing=south,shape=inner_left,waterlogged=false]', 'redstone_wire[north=side]', 'sculk_sensor[power=15]', 'cake[bites=0]',
|
||||
]
|
||||
BAD_BLOCK_STATES = [
|
||||
'minecraft:nope', 'oak_stairs[', 'oak_stairs[facing=up]', 'oak_stairs[nope=1]', 'oak_stairs[facing]', 'oak_stairs[facing=north,facing=south]', 'oak_stairs[facing=]',
|
||||
'oak_stairs[=north]', 'oak_stairs[facing=north', 'oak_stairs[facing=north,]', 'oak_stairs[facing=north]x', 'oak_stairs{', 'stone[a=b]', 'oak_stairs[facing=north]{}x',
|
||||
'oak_stairs]', '#minecraft:logs', 'oak_stairs[facing=North]', 'cake[bites=99]', 'minecraft:chest{', 'Minecraft:stone', 'stone{a:}',
|
||||
]
|
||||
BLOCK_PREDICATES = BLOCK_STATES + ['#minecraft:logs', '#minecraft:logs[axis=y]', '#logs', '#minecraft:logs{}', '#minecraft:logs[nope=1]']
|
||||
BAD_BLOCK_PREDICATES = BAD_BLOCK_STATES[:-1] + ['#nope', '#', '#minecraft:logs[', '#minecraft:logs[axis=]', '#minecraft:logs[axis]', '#minecraft:logs[axis=y,axis=x]', '#minecraft:logs[axis=q]']
|
||||
PARTICLES = [
|
||||
'flame', 'minecraft:flame', 'minecraft:dust{color:[1.0,0.0,0.0],scale:1.0}', 'minecraft:dust{color:16711680,scale:1.0}', 'minecraft:block{block_state:"minecraft:stone"}',
|
||||
'minecraft:block{block_state:{Name:"minecraft:stone"}}', 'minecraft:entity_effect{color:[1.0,0.0,0.0,1.0]}', 'minecraft:item{item:"minecraft:stick"}',
|
||||
'minecraft:item{item:{id:"minecraft:stick",count:1}}', 'minecraft:sculk_charge{roll:0.5}', 'minecraft:shriek{delay:5}', 'minecraft:dragon_breath{power:1.0}',
|
||||
'minecraft:trail{target:[0.0,0.0,0.0],color:16777215,duration:5}', 'minecraft:vibration{destination:{type:"block",pos:[0,0,0]},arrival_in_ticks:5}',
|
||||
'minecraft:dust_color_transition{from_color:[1.0,0.0,0.0],to_color:[0.0,0.0,1.0],scale:1.0}', 'minecraft:flame{}',
|
||||
]
|
||||
BAD_PARTICLES = ['nope', 'minecraft:dust', 'minecraft:dust{', 'minecraft:flame{a:1}x', 'minecraft:block', 'minecraft:block{}', 'minecraft:dust{color:1}', 'Flame', 'minecraft:']
|
||||
ITEM_SLOTS = [
|
||||
'container.0', 'weapon.mainhand', 'weapon.offhand', 'armor.head', 'armor.chest', 'armor.legs', 'armor.feet', 'hotbar.3', 'enderchest.26', 'villager.0',
|
||||
'horse.chest.4', 'player.cursor', 'contents', 'inventory.5', 'saddle', 'horse.armor', 'player.crafting.0', 'container.53', 'hotbar.8', 'weapon', 'armor.body',
|
||||
]
|
||||
BAD_ITEM_SLOTS = ['container.54', 'nope', 'container.a', 'armor.', 'hotbar.9', 'container.-1', 'container', 'container.0.0', '', 'weapon.', 'armor.nope', 'enderchest.27']
|
||||
HEX_COLORS = ['ff0000', '#ff0000', '00ff00', 'FFFFFF', '000000', '#abc']
|
||||
BAD_HEX_COLORS = ['ff00', 'gggggg', '##ff0000', '1234567', '#', '-1']
|
||||
MESSAGES = ['hello', '@a hello @p', 'hi @e[type=pig] there', 'two spaces', '@s', 'a @r b @n c', 'x @e[', '@a[x=1]', '@a[limit=0] hi', 'hello world @', '@x hello', '@e[type=nope]']
|
||||
BAD_MESSAGES = ['@e[', 'hello @x', '@e[type=nope] x']
|
||||
OBJECTIVE_CRITERIA = ['dummy', 'trigger', 'health', 'minecraft.killed:minecraft.pig', 'minecraft.custom:minecraft.jump', 'teamkill.red', 'killedByTeam.blue',
|
||||
'level', 'food', 'air', 'armor', 'xp', 'deathCount', 'playerKillCount', 'totalKillCount', 'minecraft.mined:minecraft.stone',
|
||||
'minecraft.broken:minecraft.stone', 'minecraft.crafted:minecraft.stone', 'minecraft.used:minecraft.stone',
|
||||
'minecraft.picked_up:minecraft.stone', 'minecraft.dropped:minecraft.stone', 'minecraft.killed_by:minecraft.pig', 'teamkill.', 'killedByTeam.blue']
|
||||
BAD_OBJECTIVE_CRITERIA = ['bad', 'minecraft.killed:', 'minecraft.killed:minecraft.nope', 'minecraft.custom:nope', 'teamkill.nocolor', 'minecraft.nope:minecraft.pig', '', 'DUMMY', 'minecraft.killed']
|
||||
OPERATIONS = ['=', '+=', '-=', '*=', '/=', '%=', '<', '>', '><']
|
||||
BAD_OPERATIONS = ['==', '=+', 'x', '=-', '<>', '+', '<=']
|
||||
SCOREBOARD_SLOTS = ['sidebar', 'list', 'below_name', 'sidebar.team.red', 'sidebar.team.light_purple', 'sidebar.team.blue']
|
||||
BAD_SCOREBOARD_SLOTS = ['foo', 'sidebar.team', 'sidebar.team.nocolor', 'sidebar.', 'Sidebar', 'sidebar.team.']
|
||||
SCORE_HOLDERS = ['Player', '@s', '@e[type=pig]', '*', '#total', '@a[tag=x]', 'fake', 'Steve', '@p', '@e[limit=1]', 'a b']
|
||||
BAD_SCORE_HOLDERS = ['@x', '@e[', '@e[type=nope]', '@a[limit=-1]']
|
||||
UUIDS = ['00000000-0000-0000-0000-000000000001', '123e4567-e89b-12d3-a456-426614174000', '1-2-3-4-5', 'FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF']
|
||||
BAD_UUIDS = ['nope', '1234', '00000000-0000-0000-0000', 'g-2-3-4-5', '-', '00000000-0000-0000-0000-0000000000000000000']
|
||||
SWIZZLES = ['x', 'xy', 'xyz', 'zx', 'yz', 'zyx']
|
||||
BAD_SWIZZLES = ['xx', 'a', 'xyzx', 'xa', 'X', '']
|
||||
STYLES = ['{"color":"red"}', '{"bold":true,"italic":false}', '{}', '{color:red}', '{"color":"#ff0000"}', '{"font":"minecraft:uniform"}', '{"underlined":true,"strikethrough":true,"obfuscated":true}']
|
||||
BAD_STYLES = ['{"color":"x"}', 'red', '{', '"x"', '{"bold":"x"}', '{"color":}', '[]', '{"text":"x"}']
|
||||
CONTEXT_INTS = ['1', '5', '0', '-1', '{type:"minecraft:uniform",min_inclusive:1,max_inclusive:5}', '{type:"minecraft:constant",value:3}', '{"type":"minecraft:uniform","min":1,"max":5}',
|
||||
'{type:"minecraft:binomial",n:5,p:0.5}', '{min:1,max:5}', '[1,2]', '"x"']
|
||||
BAD_CONTEXT_INTS = ['{', 'x', '{type:"minecraft:nope"}', '{type:"minecraft:uniform"}', '1.5', '{min:5}', '[1', '']
|
||||
CONTEXT_FLOATS = ['1', '1.5', '0', '-1.5', '{type:"minecraft:uniform",min_inclusive:1,max_inclusive:5}', '{type:"minecraft:constant",value:3}', '{min:1,max:5}']
|
||||
BAD_CONTEXT_FLOATS = ['{', 'x', '{type:"minecraft:nope"}', '{min:5}', '']
|
||||
SLOT_SOURCES = ['container.0', 'weapon.mainhand', '{type:"minecraft:slot_range",slots:"container.*"}', '{source:"minecraft:this"}', 'armor.*', 'hotbar.*', 'container.*']
|
||||
BAD_SLOT_SOURCES = ['{', 'nope', '{type:"minecraft:nope"}', 'container.', '']
|
||||
ENTITY_ANCHORS = ['feet', 'eyes']
|
||||
BAD_ENTITY_ANCHORS = ['head', 'Eyes', '']
|
||||
HEIGHTMAPS = ['world_surface', 'motion_blocking', 'motion_blocking_no_leaves', 'ocean_floor']
|
||||
BAD_HEIGHTMAPS = ['x', 'surface', 'WORLD_SURFACE']
|
||||
GAMEMODES = ['survival', 'creative', 'adventure', 'spectator']
|
||||
BAD_GAMEMODES = ['x', 'Survival', '0', 's', 'survival ']
|
||||
MIRRORS = ['none', 'left_right', 'front_back']
|
||||
BAD_MIRRORS = ['x', 'both', 'LEFT_RIGHT']
|
||||
ROTATIONS = ['none', 'clockwise_90', '180', 'counterclockwise_90']
|
||||
BAD_ROTATIONS = ['90', 'x', 'clockwise']
|
||||
SWINGS = ['mainhand', 'offhand']
|
||||
BAD_SWINGS = ['x', 'main_hand', '']
|
||||
TEAM_COLORS = ['red', 'blue', 'reset', 'white', 'light_purple', 'dark_aqua', 'black']
|
||||
BAD_TEAM_COLORS = ['nope', 'Red', 'bold', 'italic']
|
||||
DIMENSIONS = ['minecraft:overworld', 'overworld', 'the_nether', 'minecraft:the_end']
|
||||
BAD_DIMENSIONS = ['minecraft:nope', 'nope', 'Bad']
|
||||
FUNCTIONS = ['foo:bar', '#foo:bar', 'minecraft:x/y', 'foo']
|
||||
BAD_FUNCTIONS = ['#', 'Foo:bar', '#Foo:bar', 'foo:']
|
||||
GAME_PROFILES = ['Player', '@a', '@p', 'Steve', '00000000-0000-0000-0000-000000000001', '@s', 'Alex', 'unknown_name']
|
||||
BAD_GAME_PROFILES = ['@x', '@e[', '@a[limit=-1]']
|
||||
DIALOGS = ['{type:"minecraft:notice",title:"x"}', 'minecraft:server_links', 'foo:bar']
|
||||
BAD_DIALOGS = ['{', '{type:"minecraft:nope"}', 'Bad']
|
||||
BOOLS = ['true', 'false']
|
||||
BAD_BOOLS = ['maybe', 'TRUE', '1', 'tru', 'True', 'truee']
|
||||
|
||||
|
||||
def sha(text):
|
||||
return int(hashlib.sha1(text.encode()).hexdigest()[:8], 16)
|
||||
|
||||
|
||||
def int_samples(props):
|
||||
lo = props.get('min', -2147483648) if props else -2147483648
|
||||
hi = props.get('max', 2147483647) if props else 2147483647
|
||||
cands = [v for v in (0, 1, 5, 10, 100, 1000, -1, -10) if lo <= v <= hi]
|
||||
if not cands:
|
||||
cands = [lo]
|
||||
bad = ['abc', '1.5', '99999999999', '-99999999999', '1e3', '-', '+', '--1', '0x10', '1 ', '2147483648', '-2147483649']
|
||||
if lo > -2147483648:
|
||||
bad.append(str(lo - 1))
|
||||
if hi < 2147483647:
|
||||
bad.append(str(hi + 1))
|
||||
return [str(c) for c in cands], bad
|
||||
|
||||
|
||||
def double_samples(props, long_like=False):
|
||||
lo = props.get('min', -1e308) if props else -1e308
|
||||
hi = props.get('max', 1e308) if props else 1e308
|
||||
cands = [v for v in ('0', '1', '1.5', '-2.25', '10', '0.5', '100', '.5', '5.') if lo <= float(v) <= hi]
|
||||
if not cands:
|
||||
cands = [str(lo)]
|
||||
bad = ['abc', '1.2.3', 'NaN', '1e', '-', '--1', '1,5', '+', '.', 'infinity']
|
||||
if lo > -1e308:
|
||||
bad.append(repr(lo - 1))
|
||||
if hi < 1e308:
|
||||
bad.append(repr(hi + 1))
|
||||
return cands, bad
|
||||
|
||||
|
||||
def registry_samples(registries, registry, allow_tag, allow_inline=False):
|
||||
entry = registries.get('by_registry', {}).get(registry, {'ids': [], 'tags': []})
|
||||
ids = entry['ids']
|
||||
valid = []
|
||||
if ids:
|
||||
valid += [ids[0], ids[len(ids) // 2], ids[-1].split(':', 1)[-1] if ids[-1].startswith('minecraft:') else ids[-1]]
|
||||
else:
|
||||
valid += ['minecraft:thing']
|
||||
if allow_tag and entry['tags']:
|
||||
valid.append('#' + entry['tags'][0])
|
||||
bad = ['minecraft:nonexistent_thing', 'Bad Id', 'minecraft:']
|
||||
if allow_tag:
|
||||
bad += ['#minecraft:nonexistent_tag', '#']
|
||||
return valid, bad
|
||||
|
||||
|
||||
def pools(parser, props, registries):
|
||||
"""(valid samples, bad samples) for one argument node."""
|
||||
props = props or {}
|
||||
if parser == 'brigadier:bool':
|
||||
return BOOLS, BAD_BOOLS
|
||||
if parser == 'brigadier:integer' or parser == 'brigadier:long':
|
||||
return int_samples(props)
|
||||
if parser in ('brigadier:double', 'brigadier:float'):
|
||||
return double_samples(props)
|
||||
if parser == 'brigadier:string':
|
||||
kind = props.get('type', 'word')
|
||||
if kind == 'greedy':
|
||||
return ['hello world', 'a', '@a x', '"q" r', ''], []
|
||||
if kind == 'phrase':
|
||||
return ['word', '"quoted phrase"', '"esc\\"aped"', '"a\\\\b"', "'single'"], ['"unterminated', '"bad\\escape"', '"x\\']
|
||||
return ['word', 'a.b-c_d+e', 'a1'], []
|
||||
if parser == 'minecraft:block_pos':
|
||||
return BLOCK_POS, BAD_BLOCK_POS
|
||||
if parser == 'minecraft:vec3':
|
||||
return VEC3, BAD_VEC3
|
||||
if parser == 'minecraft:vec2':
|
||||
return VEC2, BAD_VEC2
|
||||
if parser == 'minecraft:column_pos':
|
||||
return COLUMN_POS, BAD_COLUMN_POS
|
||||
if parser == 'minecraft:rotation':
|
||||
return ROTATION, BAD_ROTATION
|
||||
if parser == 'minecraft:entity':
|
||||
return SELECTORS, BAD_SELECTORS
|
||||
if parser == 'minecraft:score_holder':
|
||||
return SCORE_HOLDERS, BAD_SCORE_HOLDERS
|
||||
if parser == 'minecraft:game_profile':
|
||||
return GAME_PROFILES, BAD_GAME_PROFILES
|
||||
if parser == 'minecraft:uuid':
|
||||
return UUIDS, BAD_UUIDS
|
||||
if parser == 'minecraft:message':
|
||||
return MESSAGES, BAD_MESSAGES
|
||||
if parser == 'minecraft:component':
|
||||
return COMPONENTS, BAD_COMPONENTS
|
||||
if parser == 'minecraft:style':
|
||||
return STYLES, BAD_STYLES
|
||||
if parser == 'minecraft:nbt_compound_tag':
|
||||
return NBT_COMPOUNDS, BAD_NBT_COMPOUNDS
|
||||
if parser == 'minecraft:nbt_tag':
|
||||
return NBT_TAGS, BAD_NBT_TAGS
|
||||
if parser == 'minecraft:nbt_path':
|
||||
return NBT_PATHS, BAD_NBT_PATHS
|
||||
if parser == 'minecraft:objective':
|
||||
return ['kills', 'obj', 'health', 'x'], []
|
||||
if parser == 'minecraft:objective_criteria':
|
||||
return OBJECTIVE_CRITERIA, BAD_OBJECTIVE_CRITERIA
|
||||
if parser == 'minecraft:operation':
|
||||
return OPERATIONS, BAD_OPERATIONS
|
||||
if parser == 'minecraft:scoreboard_slot':
|
||||
return SCOREBOARD_SLOTS, BAD_SCOREBOARD_SLOTS
|
||||
if parser == 'minecraft:team':
|
||||
return ['red', 'blue', 'x'], []
|
||||
if parser == 'minecraft:team_color':
|
||||
return TEAM_COLORS, BAD_TEAM_COLORS
|
||||
if parser == 'minecraft:hex_color':
|
||||
return HEX_COLORS, BAD_HEX_COLORS
|
||||
if parser == 'minecraft:int_range':
|
||||
return INT_RANGES, BAD_INT_RANGES
|
||||
if parser == 'minecraft:float_range':
|
||||
return FLOAT_RANGES, BAD_FLOAT_RANGES
|
||||
if parser == 'minecraft:time':
|
||||
return TIMES, BAD_TIMES
|
||||
if parser == 'minecraft:resource_location':
|
||||
return RESOURCE_LOCATIONS, BAD_RESOURCE_LOCATIONS
|
||||
if parser in ('minecraft:resource', 'minecraft:resource_key'):
|
||||
return registry_samples(registries, props.get('registry', ''), False)
|
||||
if parser in ('minecraft:resource_or_tag', 'minecraft:resource_or_tag_key'):
|
||||
return registry_samples(registries, props.get('registry', ''), True)
|
||||
if parser == 'minecraft:resource_selector':
|
||||
valid, bad = registry_samples(registries, props.get('registry', ''), True)
|
||||
return valid + ['*', 'minecraft:*', '#minecraft:*'], bad
|
||||
if parser == 'minecraft:dimension':
|
||||
return DIMENSIONS, BAD_DIMENSIONS
|
||||
if parser == 'minecraft:function':
|
||||
return FUNCTIONS, BAD_FUNCTIONS
|
||||
if parser == 'minecraft:item_stack':
|
||||
return ITEM_STACKS, BAD_ITEM_STACKS
|
||||
if parser == 'minecraft:item_predicate':
|
||||
return ITEM_PREDICATES, BAD_ITEM_PREDICATES
|
||||
if parser == 'minecraft:block_state':
|
||||
return BLOCK_STATES, BAD_BLOCK_STATES
|
||||
if parser == 'minecraft:block_predicate':
|
||||
return BLOCK_PREDICATES, BAD_BLOCK_PREDICATES
|
||||
if parser == 'minecraft:particle':
|
||||
return PARTICLES, BAD_PARTICLES
|
||||
if parser == 'minecraft:item_slot':
|
||||
return ITEM_SLOTS, BAD_ITEM_SLOTS
|
||||
if parser == 'minecraft:slot_source':
|
||||
return SLOT_SOURCES, BAD_SLOT_SOURCES
|
||||
if parser == 'minecraft:swizzle':
|
||||
return SWIZZLES, BAD_SWIZZLES
|
||||
if parser == 'minecraft:entity_anchor':
|
||||
return ENTITY_ANCHORS, BAD_ENTITY_ANCHORS
|
||||
if parser == 'minecraft:heightmap':
|
||||
return HEIGHTMAPS, BAD_HEIGHTMAPS
|
||||
if parser == 'minecraft:gamemode':
|
||||
return GAMEMODES, BAD_GAMEMODES
|
||||
if parser == 'minecraft:template_mirror':
|
||||
return MIRRORS, BAD_MIRRORS
|
||||
if parser == 'minecraft:template_rotation':
|
||||
return ROTATIONS, BAD_ROTATIONS
|
||||
if parser == 'minecraft:swing_animation':
|
||||
return SWINGS, BAD_SWINGS
|
||||
if parser == 'minecraft:context_int_provider':
|
||||
return CONTEXT_INTS, BAD_CONTEXT_INTS
|
||||
if parser == 'minecraft:context_float_provider':
|
||||
return CONTEXT_FLOATS, BAD_CONTEXT_FLOATS
|
||||
if parser == 'minecraft:dialog':
|
||||
return DIALOGS, BAD_DIALOGS
|
||||
if parser in ('minecraft:loot_table', 'minecraft:loot_modifier', 'minecraft:loot_predicate'):
|
||||
registry = {'minecraft:loot_table': 'minecraft:loot_table', 'minecraft:loot_modifier': 'minecraft:item_modifier', 'minecraft:loot_predicate': 'minecraft:predicate'}[parser]
|
||||
valid, bad = registry_samples(registries, registry, False)
|
||||
return valid + ['{}', '{type:"minecraft:chest",pools:[]}', '{"function":"minecraft:set_count","count":1}'], bad + ['{', '{"function":"nope"}']
|
||||
if parser == 'minecraft:feature':
|
||||
return registry_samples(registries, 'minecraft:worldgen/configured_feature', False)
|
||||
return ['0'], ['@@bad@@']
|
||||
|
||||
|
||||
def resolve(tree, path):
|
||||
node = tree
|
||||
for name in path:
|
||||
node = node['children'][name]
|
||||
return node
|
||||
|
||||
|
||||
SKIP_ROOTS = {'test', 'jfr', 'perf', 'debug'}
|
||||
|
||||
|
||||
def walk(tree, registries, limit_per_root=0):
|
||||
"""Yield command token lists: (tokens, kinds) where kinds[i] is None for literals or (valid, bad) pools."""
|
||||
out = []
|
||||
|
||||
def rec(node, tokens, kinds, redirects, counter):
|
||||
if node.get('executable') and tokens:
|
||||
out.append((list(tokens), list(kinds)))
|
||||
children = node.get('children', {})
|
||||
redirect = node.get('redirect')
|
||||
if redirect is not None and redirects < 1:
|
||||
target = resolve(tree, redirect)
|
||||
rec(target, tokens, kinds, redirects + 1, counter)
|
||||
for name, child in children.items():
|
||||
if len(tokens) == 0 and name in SKIP_ROOTS:
|
||||
continue
|
||||
if child['type'] == 'literal':
|
||||
tokens.append(name)
|
||||
kinds.append(None)
|
||||
else:
|
||||
valid, bad = pools(child['parser'], child.get('properties'), registries)
|
||||
pick = valid[0]
|
||||
tokens.append(pick)
|
||||
kinds.append((valid, bad, child['parser'], name))
|
||||
rec(child, tokens, kinds, redirects, counter)
|
||||
tokens.pop()
|
||||
kinds.pop()
|
||||
|
||||
rec(tree, [], [], 0, [0])
|
||||
return out
|
||||
|
||||
|
||||
def corpus(tree, registries):
|
||||
seen = {}
|
||||
|
||||
def add(line):
|
||||
if line not in seen:
|
||||
seen[line] = True
|
||||
|
||||
paths = walk(tree, registries)
|
||||
budget = {}
|
||||
|
||||
def spend(key, limit=2):
|
||||
used = budget.get(key, 0)
|
||||
if used >= limit:
|
||||
return False
|
||||
budget[key] = used + 1
|
||||
return True
|
||||
|
||||
for tokens, kinds in paths:
|
||||
add(' '.join(tokens))
|
||||
for tokens, kinds in paths:
|
||||
n = len(tokens)
|
||||
for i in range(1, n + 1):
|
||||
add(' '.join(tokens[:i]))
|
||||
add(' '.join(tokens[:i]) + ' ')
|
||||
for i, kind in enumerate(kinds):
|
||||
if kind is None:
|
||||
continue
|
||||
valid, bad, parser, name = kind
|
||||
head = ' '.join(tokens[:i])
|
||||
head = head + ' ' if head else head
|
||||
for v in valid:
|
||||
if spend((parser, v, 'v')):
|
||||
add(head + v)
|
||||
add(head + v + ' ')
|
||||
for b in bad:
|
||||
if spend((parser, b, 'b')):
|
||||
add(head + b)
|
||||
add(head + b + ' x')
|
||||
value = tokens[i]
|
||||
if spend((parser, value, 'cut')):
|
||||
for cut in range(1, min(len(value), 6)):
|
||||
add(head + value[:cut])
|
||||
if spend((tokens[0], 'extra'), 3):
|
||||
add(' '.join(tokens) + ' extra')
|
||||
add(' '.join(tokens) + ' ')
|
||||
for line in EXTRA:
|
||||
add(line)
|
||||
for line in [l for l in seen]:
|
||||
pass
|
||||
return list(seen)
|
||||
|
||||
|
||||
EXTRA = [
|
||||
'', ' ', 'nope', 'Help', '/help', 'help ', 'he', 'h', 'g', 'give', 'give ', 'give @s', 'give @s minecraft:stone 0', 'give @s minecraft:stone 100000',
|
||||
'tp 1 2 3', 'tp @s 1 2 3', 'tp @s @a', 'tp @e[type=pig] ~ ~ ~', 'tp @s 1 2 3 90 0', 'tp @s ~ ~ ~ facing 0 0 0', 'tp @s ~ ~ ~ facing entity @a eyes',
|
||||
'teleport @s ~ ~ ~ facing entity @p feet', 'execute as @a at @s run say hi', 'execute if entity @s run say x', 'execute store result score @s kills run say x',
|
||||
'execute positioned ~ ~ ~ rotated ~ ~ run say x', 'execute run', 'execute', 'execute as', 'execute as @a', 'execute foo',
|
||||
'execute if score @s kills matches 1..5 run say x', 'execute if block ~ ~ ~ minecraft:stone run say x', 'execute unless dimension minecraft:overworld run say',
|
||||
'execute if data entity @s {a:1} run say x', 'execute if predicate minecraft:foo run say x', 'execute summon minecraft:pig run say x',
|
||||
'execute on vehicle run say x', 'execute on passengers run say x', 'execute on origin run say x', 'execute on nope run say x',
|
||||
'execute align xyz run say x', 'execute align xx run say x', 'execute align q run say x', 'execute anchored eyes run say x',
|
||||
'execute in minecraft:the_nether run say x', 'execute in nope run say x', 'execute facing 1 2 3 run say x', 'execute rotated as @s run say x',
|
||||
'execute positioned over world_surface run say x', 'execute positioned as @s run say x', 'execute store success storage a:b c int 1.0 run say x',
|
||||
'execute store result bossbar a:b value run say x', 'execute store result entity @s Health float 1 run say x',
|
||||
'execute store result block 0 0 0 a byte 2 run say x', 'execute if biome ~ ~ ~ minecraft:plains run say x', 'execute if loaded ~ ~ ~ run say x',
|
||||
'execute if items entity @s weapon.mainhand minecraft:stone run say x', 'execute if function foo:bar run say x', 'execute if stopwatch foo:bar 1.. run say x',
|
||||
'execute if blocks 0 0 0 1 1 1 2 2 2 all run say x', 'execute if blocks 0 0 0 1 1 1 2 2 2 masked run say x', 'execute if blocks 0 0 0 1 1 1 2 2 2 nope run say x',
|
||||
'scoreboard objectives add a dummy', 'scoreboard objectives add a dummy "Disp"', 'scoreboard objectives add a dummy {"text":"x"}', 'scoreboard objectives add bad!name dummy',
|
||||
'scoreboard objectives add a nope', 'scoreboard players set @s kills 1', 'scoreboard players set @s kills a', 'scoreboard players add Player kills -5',
|
||||
'scoreboard players operation @s kills += @a health', 'scoreboard players operation @s kills >< @a health', 'scoreboard objectives setdisplay sidebar kills',
|
||||
'scoreboard objectives modify kills numberformat fixed {"text":"x"}', 'scoreboard objectives modify kills numberformat styled {"color":"red"}',
|
||||
'scoreboard objectives modify kills numberformat blank', 'scoreboard objectives modify kills rendertype hearts', 'scoreboard objectives modify kills displayautoupdate true',
|
||||
'scoreboard players display name @s kills "x"', 'scoreboard players display numberformat @s kills fixed {"text":"x"}', 'scoreboard players enable @s kills',
|
||||
'scoreboard players get @s kills', 'scoreboard players list', 'scoreboard players list @s', 'scoreboard players reset *', 'scoreboard players reset @s kills',
|
||||
'team add red', 'team add red "Display"', 'team modify red color red', 'team modify red friendlyFire true', 'team modify red prefix {"text":"p"}',
|
||||
'team modify red nametagVisibility never', 'team modify red collisionRule pushOtherTeams', 'team modify red deathMessageVisibility hideForOtherTeams',
|
||||
'team modify red seeFriendlyInvisibles false', 'team join red @a', 'team join red', 'team leave @a', 'team empty red', 'team remove red', 'team list', 'team list red',
|
||||
'data get entity @s', 'data get entity @s Health', 'data get entity @s Health 2', 'data get block 0 0 0 Items[0]', 'data get storage a:b x', 'data merge entity @s {a:1}',
|
||||
'data merge block 0 0 0 {a:1}', 'data merge storage a:b {a:1}', 'data modify entity @s a set value 1', 'data modify storage a:b x append value 1',
|
||||
'data modify storage a:b x prepend from entity @s Pos', 'data modify storage a:b x insert 0 value 1', 'data modify storage a:b x merge value {a:1}',
|
||||
'data modify storage a:b x set string entity @s CustomName 1 2', 'data modify storage a:b x set string entity @s CustomName', 'data modify storage a:b x set from storage a:c y',
|
||||
'data remove entity @s a', 'data remove storage a:b x.y[0]', 'data get entity @s a 1.5', 'data modify storage a:b x nope value 1',
|
||||
'fill 0 0 0 1 1 1 minecraft:stone', 'fill 0 0 0 1 1 1 stone replace dirt', 'fill 0 0 0 1 1 1 stone outline', 'fill 0 0 0 1 1 1 stone hollow', 'fill 0 0 0 1 1 1 stone destroy',
|
||||
'fill 0 0 0 1 1 1 stone keep', 'fill 0 0 0 1 1 1 stone replace', 'fill 0 0 0 1 1 1 stone replace #logs[axis=y]', 'fill 0 0 0 1 1 1 stone nope',
|
||||
'fillbiome 0 0 0 1 1 1 minecraft:plains', 'fillbiome 0 0 0 1 1 1 minecraft:plains replace #minecraft:is_ocean', 'clone 0 0 0 1 1 1 2 2 2', 'clone 0 0 0 1 1 1 2 2 2 replace move',
|
||||
'clone 0 0 0 1 1 1 2 2 2 masked force', 'clone 0 0 0 1 1 1 2 2 2 filtered stone normal', 'clone from minecraft:overworld 0 0 0 1 1 1 to minecraft:the_nether 2 2 2',
|
||||
'setblock 0 0 0 stone', 'setblock 0 0 0 stone destroy', 'setblock 0 0 0 stone keep', 'setblock 0 0 0 stone replace', 'setblock 0 0 0 stone strict', 'setblock ~ ~ ~ oak_stairs[facing=north]{a:1}',
|
||||
'summon pig', 'summon pig ~ ~ ~', 'summon pig ~ ~ ~ {NoAI:1b}', 'summon minecraft:nope', 'summon pig ~ ~ ~ {', 'summon minecraft:player', 'summon item ~ ~ ~ {Item:{id:"minecraft:stone",count:1}}',
|
||||
'kill', 'kill @e[type=pig]', 'kill Player', 'kill @', 'effect give @s minecraft:speed', 'effect give @s speed 10 1 true', 'effect give @s speed infinite', 'effect give @s speed 0', 'effect give @s speed 1000000 255',
|
||||
'effect give @s speed 1000000 256', 'effect give @s nope', 'effect clear @s', 'effect clear @s speed', 'enchant @s sharpness', 'enchant @s minecraft:sharpness 2', 'enchant @s nope',
|
||||
'experience add @s 5', 'experience add @s 5 levels', 'experience add @s 5 points', 'experience set @s 5 levels', 'experience query @s levels', 'experience query @s nope', 'xp add @s 1',
|
||||
'gamemode creative', 'gamemode creative @s', 'gamemode nope', 'gamemode 1', 'defaultgamemode survival', 'difficulty hard', 'difficulty nope', 'difficulty 1',
|
||||
'time set day', 'time set noon', 'time set 1000', 'time set 1d', 'time set 1s', 'time set nope', 'time add 1', 'time add 1d', 'time query daytime', 'time query gametime', 'time query day',
|
||||
'time set minecraft:day', 'time of minecraft:overworld set 5', 'time query nope', 'weather clear', 'weather rain 10', 'weather thunder 5t', 'weather clear 1d', 'weather nope',
|
||||
'say hello', 'say', 'say @a', 'say @e[', 'me waves', 'msg @a hello', 'tell @a hello', 'w @a hello', 'teammsg hello', 'tm hello', 'tellraw @a {"text":"x"}', 'tellraw @a "x"', 'tellraw @a',
|
||||
'title @a title {"text":"x"}', 'title @a subtitle "x"', 'title @a actionbar "x"', 'title @a times 1 2 3', 'title @a times 1s 2s 3s', 'title @a clear', 'title @a reset', 'title @a title', 'title @a nope',
|
||||
'list', 'list uuids', 'list nope', 'seed', 'locate structure minecraft:village_plains', 'locate structure #minecraft:village', 'locate biome minecraft:plains', 'locate biome #minecraft:is_ocean',
|
||||
'locate poi minecraft:home', 'locate structure nope', 'spawnpoint', 'spawnpoint @s', 'spawnpoint @s 0 0 0', 'spawnpoint @s 0 0 0 90', 'spawnpoint @s ~ ~ ~ ~ ~', 'setworldspawn', 'setworldspawn 0 0 0',
|
||||
'setworldspawn 0 0 0 90', 'setworldspawn 0 0 0 90 0', 'clear', 'clear @s', 'clear @s minecraft:stone', 'clear @s stone 0', 'clear @s stone 5', 'clear @s *', 'clear @s #logs', 'clear @s stone[damage=5] 0',
|
||||
'gamerule', 'gamerule keepInventory', 'gamerule keep_inventory', 'gamerule keep_inventory true', 'gamerule minecraft:keep_inventory true', 'gamerule max_command_sequence_length 5', 'gamerule nope', 'gamerule keep_inventory 5',
|
||||
'worldborder get', 'worldborder set 100', 'worldborder set 100 10', 'worldborder set 100 10s', 'worldborder add 10 5', 'worldborder center 0 0', 'worldborder damage amount 1', 'worldborder damage buffer 1',
|
||||
'worldborder warning distance 5', 'worldborder warning time 5', 'worldborder set -1', 'worldborder set 1e10', 'worldborder nope',
|
||||
'bossbar add a:b "x"', 'bossbar set a:b color red', 'bossbar set a:b style notched_6', 'bossbar set a:b value 5', 'bossbar set a:b max 5', 'bossbar set a:b visible true', 'bossbar set a:b players @a',
|
||||
'bossbar set a:b name "x"', 'bossbar get a:b value', 'bossbar list', 'bossbar remove a:b', 'bossbar set a:b color nope',
|
||||
'tag @s add x', 'tag @s remove x', 'tag @s list', 'tag @s add', 'tag @s add "quoted tag"', 'ride @s mount @e[limit=1]', 'ride @s dismount', 'ride @s mount', 'ride @s evict', 'ride @s nope',
|
||||
'item replace entity @s weapon.mainhand with stone', 'item replace entity @s weapon.mainhand with stone 5', 'item replace block 0 0 0 container.0 with stone', 'item replace entity @s container.0 from entity @a weapon.mainhand',
|
||||
'item replace entity @s container.0 from block 0 0 0 container.1 minecraft:foo', 'item modify entity @s weapon.mainhand minecraft:foo', 'item modify block 0 0 0 container.0 minecraft:foo',
|
||||
'loot give @s loot minecraft:chests/simple_dungeon', 'loot give @s kill @e[limit=1]', 'loot give @s mine 0 0 0', 'loot give @s mine 0 0 0 mainhand', 'loot give @s fish minecraft:gameplay/fishing 0 0 0',
|
||||
'loot give @s fish minecraft:gameplay/fishing 0 0 0 mainhand', 'loot spawn 0 0 0 loot minecraft:chests/simple_dungeon', 'loot insert 0 0 0 loot minecraft:chests/simple_dungeon', 'loot replace entity @s weapon.mainhand loot minecraft:chests/simple_dungeon',
|
||||
'loot replace entity @s weapon.mainhand 2 loot minecraft:chests/simple_dungeon', 'loot replace block 0 0 0 container.0 loot minecraft:chests/simple_dungeon', 'loot give @s nope',
|
||||
'particle flame', 'particle flame ~ ~ ~', 'particle flame ~ ~ ~ 1 1 1 0 10', 'particle flame ~ ~ ~ 1 1 1 0 10 force', 'particle flame ~ ~ ~ 1 1 1 0 10 normal @a', 'particle flame ~ ~ ~ 1 1 1 0 0 nope',
|
||||
'playsound minecraft:entity.pig.ambient master @s', 'playsound minecraft:entity.pig.ambient master @s ~ ~ ~ 1 1 0', 'playsound entity.pig.ambient nope @s', 'stopsound @s', 'stopsound @s master', 'stopsound @s master minecraft:entity.pig.ambient',
|
||||
'stopsound @s * minecraft:entity.pig.ambient', 'attribute @s minecraft:max_health get', 'attribute @s max_health base set 20', 'attribute @s max_health modifier add a:b 1 add_value', 'attribute @s max_health modifier add a:b 1 nope',
|
||||
'attribute @s max_health modifier remove a:b', 'attribute @s max_health modifier value get a:b 2', 'attribute @s max_health base get 2', 'attribute @s nope get',
|
||||
'damage @s 5', 'damage @s 5 minecraft:generic', 'damage @s 5 minecraft:generic by @a', 'damage @s 5 minecraft:generic by @a from @p', 'damage @s 5 minecraft:generic at 0 0 0', 'damage @s -5', 'damage @s 5 nope',
|
||||
'rotate @s 0 0', 'rotate @s ~ ~', 'rotate @s facing 0 0 0', 'rotate @s facing entity @a', 'rotate @s facing entity @a eyes', 'swing @s', 'swing @s mainhand', 'swing @s offhand', 'swing @s nope',
|
||||
'spreadplayers 0 0 5 10 false @a', 'spreadplayers 0 0 5 10 under 100 false @a', 'spreadplayers 0 0 5 10 true @a', 'spreadplayers 0 0 0 10 false @a', 'spreadplayers 0 0 5 5 false @a',
|
||||
'forceload add 0 0', 'forceload add 0 0 16 16', 'forceload remove all', 'forceload remove 0 0', 'forceload query', 'forceload query 0 0', 'forceload nope', 'recipe give @s *', 'recipe give @s minecraft:stick', 'recipe take @s *',
|
||||
'advancement grant @s everything', 'advancement grant @s only minecraft:story/root', 'advancement grant @s only minecraft:story/root criterion', 'advancement grant @s from minecraft:story/root', 'advancement grant @s through minecraft:story/root',
|
||||
'advancement grant @s until minecraft:story/root', 'advancement revoke @s everything', 'advancement nope', 'function foo:bar', 'function #foo:bar', 'function foo:bar {a:1}', 'function foo:bar with entity @s a',
|
||||
'function foo:bar with storage a:b c', 'function foo:bar with block 0 0 0 a', 'schedule function foo:bar 1t', 'schedule function foo:bar 1d append', 'schedule function foo:bar 1s replace', 'schedule clear foo:bar',
|
||||
'schedule function #foo:bar 1t', 'schedule function foo:bar 0t', 'trigger kills', 'trigger kills add 5', 'trigger kills set 5', 'trigger kills nope', 'return 5', 'return fail', 'return run say x', 'return run return 1',
|
||||
'random value 1..5', 'random value 1', 'random value 5..1', 'random value ..5', 'random roll 1..5', 'random roll 1..5 foo:bar', 'random reset *', 'random reset foo:bar 5', 'random reset foo:bar 5 true', 'random reset foo:bar 5 true true',
|
||||
'random reset * 5 true true 7', 'tick query', 'tick rate 20', 'tick rate 20.5', 'tick rate 0.1', 'tick rate 10000', 'tick rate 1000000', 'tick freeze', 'tick unfreeze', 'tick step', 'tick step 5', 'tick step 5s', 'tick sprint 100', 'tick sprint stop', 'tick nope',
|
||||
'reload', 'datapack list', 'datapack list enabled', 'datapack list available', 'datapack enable "vanilla"', 'datapack disable "vanilla"', 'datapack enable "x" first', 'datapack enable "x" last', 'datapack enable "x" before "y"', 'datapack enable "x" after "y"',
|
||||
'place feature minecraft:oak', 'place feature minecraft:oak ~ ~ ~', 'place jigsaw minecraft:bastion/starts minecraft:bastion/bridge/start 5', 'place jigsaw a:b c:d 5 ~ ~ ~', 'place structure minecraft:village_plains', 'place structure minecraft:village_plains ~ ~ ~',
|
||||
'place template minecraft:igloo/top', 'place template minecraft:igloo/top ~ ~ ~ clockwise_90 front_back 0.5 5', 'place template minecraft:igloo/top ~ ~ ~ nope', 'raid start 5', 'compute',
|
||||
'stopwatch create foo:bar', 'stopwatch query foo:bar', 'stopwatch query foo:bar 1.5', 'stopwatch restart foo:bar', 'stopwatch remove foo:bar', 'spectate', 'spectate @e[limit=1]', 'spectate @e[limit=1] @s', 'spectate @e[limit=1] nope',
|
||||
'waypoint list', 'waypoint modify @s color red', 'waypoint modify @s color hex ff0000', 'waypoint modify @s style default', 'waypoint modify @s style reset', 'waypoint modify @s color reset', 'waypoint modify @s style nope',
|
||||
'dialog show @s foo:bar', 'dialog clear @s', 'dialog show @s {type:"minecraft:notice",title:"x"}', 'publish', 'publish true', 'publish true survival 25565', 'publish false creative', 'publish nope', 'unpublish',
|
||||
'version', 'help execute', 'help execute run', 'help nope', 'help give', 'help tp', 'kick @s', 'kick @s "reason"', 'fetchprofile name Notch', 'fetchprofile id 00000000-0000-0000-0000-000000000001',
|
||||
'posteffect @s minecraft:x', 'posteffect', 'ban Player', 'op Player', 'whitelist add Player', 'stop', 'save-all', 'debug start', 'debug stop', 'debug report', 'debug function foo:bar',
|
||||
'time set 1', 'time set 1', ' time set 1', 'time\tset 1', 'say \u00e9\u00e9', 'say \U0001f600', 'tp \u00e9 1 2 3', 'give \U0001f600 stone', 'execute as @e[name="\u00e9"] run say \u00e9',
|
||||
]
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Group the mismatches of tools/test_command_parse_parity.py by cause.
|
||||
|
||||
usage: command_parse_summary.py MISMATCHES.jsonl [ROOT]
|
||||
"""
|
||||
import collections
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def describe(side, kind):
|
||||
if kind == 'parse':
|
||||
if side.get('ok'):
|
||||
return 'OK'
|
||||
return f"ERR {side.get('error')!r}@{'c' if side.get('cursor') else '0'}"
|
||||
return f"SUGG[{len(side['list'])}]"
|
||||
|
||||
|
||||
path = Path(sys.argv[1])
|
||||
only = sys.argv[2] if len(sys.argv) > 2 else None
|
||||
groups = collections.Counter()
|
||||
examples = {}
|
||||
for line in path.open(encoding='utf-8'):
|
||||
m = json.loads(line)
|
||||
root = m['in'].split(' ')[0]
|
||||
if only and root != only:
|
||||
continue
|
||||
key = (m['kind'], describe(m['vanilla'], m['kind']), describe(m['rust'], m['kind']))
|
||||
if m['kind'] == 'parse':
|
||||
key = key[:1] + (key[1][:90], key[2][:90])
|
||||
groups[key] += 1
|
||||
examples.setdefault(key, m)
|
||||
for key, count in sorted(groups.items(), key=lambda kv: -kv[1])[:int(sys.argv[3]) if len(sys.argv) > 3 else 40]:
|
||||
ex = examples[key]
|
||||
print(f'{count:6} {key[0]} vanilla={key[1]} rust={key[2]}\n e.g. {ex["in"]!r}')
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Structural diff between vanilla's exported command tree and Horizon's.
|
||||
|
||||
usage: command_tree_diff.py VANILLA_TREE.json RUST_TREE.json [ROOT]
|
||||
|
||||
Reports, for every shared node, the children Horizon lacks or adds, differing
|
||||
argument parsers and executable/redirect flags. Missing subtrees are reported
|
||||
once at their root.
|
||||
"""
|
||||
import json
|
||||
import sys
|
||||
|
||||
LOOSE = {
|
||||
# Horizon's coarse argument kinds that stand in for several vanilla parsers.
|
||||
'brigadier:string': {'brigadier:string', 'minecraft:message', 'minecraft:component'},
|
||||
}
|
||||
|
||||
|
||||
def same_parser(vanilla, rust):
|
||||
if vanilla == rust:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def keyed(children):
|
||||
"""Literals by name; arguments by position (their names are internal)."""
|
||||
out = {}
|
||||
index = 0
|
||||
for name, child in children.items():
|
||||
if child['type'] == 'literal':
|
||||
out[('l', name)] = (name, child)
|
||||
else:
|
||||
out[('a', index)] = (name, child)
|
||||
index += 1
|
||||
return out
|
||||
|
||||
|
||||
def diff(path, v, r, out):
|
||||
vc, rc = keyed(v.get('children', {})), keyed(r.get('children', {}))
|
||||
for key, (name, node) in vc.items():
|
||||
if key not in rc:
|
||||
out.append(('missing', path + [name], node.get('parser') or 'literal', count(node)))
|
||||
for key, (name, node) in rc.items():
|
||||
if key not in vc:
|
||||
out.append(('extra', path + [name], node.get('parser') or 'literal', count(node)))
|
||||
for key, (name, a) in vc.items():
|
||||
if key not in rc:
|
||||
continue
|
||||
_, b = rc[key]
|
||||
if a['type'] == 'argument' and not same_parser(a['parser'], b['parser']):
|
||||
out.append(('parser', path + [name], f"{a['parser']} vs {b['parser']}", 0))
|
||||
if bool(a.get('executable')) != bool(b.get('executable')):
|
||||
out.append(('executable', path + [name], f"vanilla={bool(a.get('executable'))}", 0))
|
||||
if bool(a.get('redirect')) != bool(b.get('redirect')):
|
||||
out.append(('redirect', path + [name], f"vanilla={bool(a.get('redirect'))}", 0))
|
||||
diff(path + [name], a, b, out)
|
||||
|
||||
|
||||
def count(node):
|
||||
return 1 + sum(count(c) for c in node.get('children', {}).values())
|
||||
|
||||
|
||||
def main():
|
||||
vanilla = json.load(open(sys.argv[1]))
|
||||
rust = json.load(open(sys.argv[2]))
|
||||
only = sys.argv[3] if len(sys.argv) > 3 else None
|
||||
if only:
|
||||
vanilla = {'children': {only: vanilla['children'][only]}, 'type': 'root'}
|
||||
rust = {'children': {only: rust['children'].get(only, {'children': {}, 'type': 'literal'})}, 'type': 'root'}
|
||||
out = []
|
||||
diff([], vanilla, rust, out)
|
||||
for kind, path, detail, size in out:
|
||||
print(f'{kind:10} {" ".join(path)} [{detail}]' + (f' ({size} nodes)' if size else ''))
|
||||
missing = sum(size for kind, _, _, size in out if kind == 'missing')
|
||||
print(f'-- {len(out)} differences, {missing} vanilla nodes missing in Horizon')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare vanilla updateShape and neighborChanged with horizon-world, state by state.
|
||||
|
||||
Every block state is put at the origin of a random neighbourhood; `shape` cases
|
||||
call `BlockState.updateShape` for one direction with a (consistent) neighbour
|
||||
state and compare the resulting state, requested scheduled ticks, side effects and
|
||||
RNG use; `neighbor` cases call `handleNeighborChanged` from one direction.
|
||||
"""
|
||||
import random
|
||||
try:
|
||||
from . import block_update_harness as h
|
||||
except ImportError:
|
||||
import block_update_harness as h
|
||||
|
||||
|
||||
def cases(facts, count, seed, only):
|
||||
rng = random.Random(seed)
|
||||
pool = h.state_pool(facts, only)
|
||||
air = facts.defaults['minecraft:air']
|
||||
for n in range(count):
|
||||
state = pool[n % len(pool)]
|
||||
direction = rng.randrange(6)
|
||||
cells = facts.cells(rng, state)
|
||||
case = {**h.environment(rng), 'pos': [0, 0, 0], 'dir': direction}
|
||||
dx, dy, dz = h.DIRS[direction]
|
||||
if n % 3 == 2:
|
||||
case['mode'] = 'neighbor'
|
||||
case['from'] = [dx, dy, dz]
|
||||
else:
|
||||
case['mode'] = 'shape'
|
||||
neighbour = facts.neighbour(rng, state)
|
||||
neighbour = air if neighbour is None else neighbour
|
||||
h.put(cells, (dx, dy, dz), neighbour)
|
||||
case['neighbor'] = neighbour
|
||||
case['cells'] = cells
|
||||
yield case
|
||||
|
||||
|
||||
def main():
|
||||
args = h.argument_parser(__doc__).parse_args()
|
||||
facts = h.load_facts()
|
||||
differing = h.execute('block-update-parity', list(cases(facts, args.count, args.seed, args.only)), args, facts)
|
||||
h.finish(differing)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare Horizon's command parser with vanilla's real Brigadier command tree.
|
||||
|
||||
Java (VanillaCommandParseOracle) builds vanilla's `Commands` dispatcher with
|
||||
the real registries and data-pack loaded tags, exports the whole tree, and
|
||||
parses a corpus of command strings. The corpus is generated by walking that
|
||||
tree (every command and subcommand with valid and invalid sample values per
|
||||
argument type) plus hand-written edge cases for selectors, NBT paths,
|
||||
coordinates, ranges, resource locations and block/item predicates. For every
|
||||
input the parse success, the exact error text and cursor, the parsed node
|
||||
names and the completion suggestions at the end of the input must match.
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
try:
|
||||
from . import lab, test_rust_parity as base
|
||||
from . import command_parse_corpus as corpus_module
|
||||
except ImportError:
|
||||
import lab
|
||||
import test_rust_parity as base
|
||||
import command_parse_corpus as corpus_module
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--prepare', action='store_true')
|
||||
parser.add_argument('--permission', type=int, nargs='*', default=[4, 2, 0])
|
||||
parser.add_argument('--limit', type=int, default=0, help='print at most this many mismatches per class')
|
||||
parser.add_argument('--allow-gaps', action='store_true', help='report mismatches without failing')
|
||||
args = parser.parse_args()
|
||||
build = lab.LOCAL / 'command-parse-parity'
|
||||
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/VanillaCommandParseOracle.java'
|
||||
classes = build / 'classes'
|
||||
classes.mkdir(exist_ok=True)
|
||||
dependency_path = os.pathsep.join(map(str, libraries))
|
||||
|
||||
def run(command, name):
|
||||
with (build / (name + '.log')).open('w', encoding='utf-8') as log:
|
||||
result = subprocess.run(list(map(str, command)), cwd=lab.ROOT, stdout=log, stderr=subprocess.STDOUT)
|
||||
if result.returncode:
|
||||
tail = (build / (name + '.log')).read_text(errors='replace')[-2500:]
|
||||
sys.exit(f'{name} failed ({result.returncode}):\n{tail}')
|
||||
|
||||
run(['javac', '--release', lock['minecraft']['java_major'], '-proc:none', '-cp', str(jars['server']) + os.pathsep + dependency_path, '-d', classes, oracle], 'compile-java')
|
||||
|
||||
def java(*arguments):
|
||||
run(['java', '-Xmx1G', '-cp', os.pathsep.join([str(classes), str(jars['server']), dependency_path]), 'dev.horizonlab.parity.VanillaCommandParseOracle', *arguments], 'java-' + arguments[0])
|
||||
|
||||
java('registries', str(build))
|
||||
java('tree', str(build))
|
||||
tree = json.loads((build / 'tree.json').read_text())
|
||||
registries = json.loads((build / 'registries.json').read_text())
|
||||
corpus = corpus_module.corpus(tree, registries)
|
||||
(build / 'corpus.txt').write_text(''.join(line + '\n' for line in corpus), encoding='utf-8')
|
||||
run(['cargo', 'build', '--release', '-p', 'horizon-client', '--example', 'command_parse_fixture'], 'compile-rust')
|
||||
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' / ('command_parse_fixture.exe' if os.name == 'nt' else 'command_parse_fixture')
|
||||
resources = lab.LOCAL / 'horizon-client/26.3'
|
||||
total_failures = 0
|
||||
summary = []
|
||||
for permission in args.permission:
|
||||
level_dir = build / f'perm{permission}'
|
||||
level_dir.mkdir(exist_ok=True)
|
||||
(level_dir / 'registries.json').write_bytes((build / 'registries.json').read_bytes())
|
||||
stamp = level_dir / 'vanilla.stamp'
|
||||
digest = lab.digest(build / 'corpus.txt', 'sha256') + lab.digest(oracle, 'sha256')
|
||||
if not (stamp.exists() and stamp.read_text() == digest and (level_dir / 'vanilla.jsonl').exists()):
|
||||
java('run', str(level_dir), str(build / 'corpus.txt'), str(permission))
|
||||
stamp.write_text(digest)
|
||||
run([binary, resources, build / 'registries.json', build / 'corpus.txt', str(permission), level_dir / 'rust.jsonl'], f'rust{permission}')
|
||||
failures = compare(level_dir / 'vanilla.jsonl', level_dir / 'rust.jsonl', args.limit)
|
||||
count = sum(1 for _ in (level_dir / 'vanilla.jsonl').open())
|
||||
print(f'permission {permission}: {count - failures}/{count} commands match', flush=True)
|
||||
summary.append({'permission': permission, 'commands': count, 'mismatches': failures})
|
||||
total_failures += failures
|
||||
report = {'schema': 1, 'minecraft': lock['minecraft']['version'], 'platform': platform.platform(), 'results': summary,
|
||||
'scope': 'Parse success, error text and cursor, parsed node names and end-of-input suggestions for a tree-walked corpus.'}
|
||||
lab.write_json(report_path, report)
|
||||
if total_failures and not args.allow_gaps:
|
||||
sys.exit(f'{total_failures} command parse mismatches; see {build}')
|
||||
print(f'Command parse parity report: {report_path}')
|
||||
|
||||
|
||||
def compare(vanilla_path, rust_path, limit):
|
||||
vanilla = [json.loads(line) for line in vanilla_path.open(encoding='utf-8')]
|
||||
rust = [json.loads(line) for line in rust_path.open(encoding='utf-8')]
|
||||
if len(vanilla) != len(rust):
|
||||
raise SystemExit(f'line count differs: vanilla {len(vanilla)} rust {len(rust)}')
|
||||
shown = {}
|
||||
failures = 0
|
||||
mismatches = []
|
||||
for v, r in zip(vanilla, rust):
|
||||
assert v['in'] == r['in'], (v['in'], r['in'])
|
||||
kind = None
|
||||
if 'crash' in v:
|
||||
continue # oracle could not evaluate (missing server state)
|
||||
# Node names are internal to each implementation; only success matters.
|
||||
vp = {k: val for k, val in v['parse'].items() if k != 'nodes'}
|
||||
rp = {k: val for k, val in r['parse'].items() if k != 'nodes'}
|
||||
if vp != rp:
|
||||
kind = 'parse'
|
||||
elif v['sugg'] != r['sugg']:
|
||||
kind = 'suggestions'
|
||||
if kind:
|
||||
failures += 1
|
||||
mismatches.append({'kind': kind, 'in': v['in'], 'vanilla': v['parse'] if kind == 'parse' else v['sugg'], 'rust': r['parse'] if kind == 'parse' else r['sugg']})
|
||||
out = vanilla_path.with_name('mismatches.jsonl')
|
||||
out.write_text(''.join(json.dumps(m, ensure_ascii=False) + '\n' for m in mismatches), encoding='utf-8')
|
||||
for m in mismatches:
|
||||
n = shown.get(m['kind'], 0)
|
||||
if limit and n >= limit:
|
||||
continue
|
||||
shown[m['kind']] = n + 1
|
||||
print(m['kind'], repr(m['in']), '\n vanilla', json.dumps(m['vanilla'], ensure_ascii=False)[:300], '\n rust ', json.dumps(m['rust'], ensure_ascii=False)[:300])
|
||||
return failures
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,380 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare item model resolution with the pinned client's own item pipeline.
|
||||
|
||||
The vanilla side (VanillaItemModelOracle) decodes every `items/*.json` with the
|
||||
client codec, discovers and bakes all models with `ModelBakery` against real
|
||||
PNG sprites, and resolves stacks through `ItemStackRenderState` layers. The
|
||||
Rust side (`item_model_fixture`) must pick the same layers, tints, foil,
|
||||
transformations, special-renderer configurations and baked quads."""
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import random
|
||||
import subprocess
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
try:
|
||||
from . import lab, test_rust_parity as base, test_model_baking_parity as baking
|
||||
except ImportError:
|
||||
import lab, test_rust_parity as base, test_model_baking_parity as baking
|
||||
|
||||
CONTEXTS = ['gui', 'ground', 'fixed', 'head', 'thirdperson_righthand', 'thirdperson_lefthand',
|
||||
'firstperson_righthand', 'firstperson_lefthand', 'on_shelf', 'none']
|
||||
DYES = ['white', 'orange', 'magenta', 'light_blue', 'yellow', 'lime', 'pink', 'gray', 'light_gray', 'cyan',
|
||||
'purple', 'blue', 'brown', 'green', 'red', 'black']
|
||||
TRIM_MATERIALS = ['quartz', 'iron', 'netherite', 'redstone', 'copper', 'gold', 'emerald', 'diamond', 'lapis',
|
||||
'amethyst', 'resin']
|
||||
NEEDED = ('assets/minecraft/items/', 'assets/minecraft/models/', 'assets/minecraft/textures/item/',
|
||||
'assets/minecraft/textures/block/', 'assets/minecraft/textures/trims/',
|
||||
'assets/minecraft/textures/colormap/')
|
||||
|
||||
|
||||
def extract(jar, destination):
|
||||
marker = destination / '.jar-sha256'
|
||||
digest = lab.digest(jar, 'sha256')
|
||||
if marker.exists() and marker.read_text() == digest:
|
||||
return
|
||||
destination.mkdir(parents=True, exist_ok=True)
|
||||
with zipfile.ZipFile(jar) as archive:
|
||||
for name in archive.namelist():
|
||||
if name.startswith(NEEDED) and not name.endswith('/'):
|
||||
target = destination / name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(archive.read(name))
|
||||
marker.write_text(digest)
|
||||
|
||||
|
||||
def owner(using, remaining, arm='right', entity='minecraft:player'):
|
||||
return {'using': using, 'remaining': remaining, 'main_arm': arm, 'entity_type': entity}
|
||||
|
||||
|
||||
def corpus(prototypes):
|
||||
"""Representative stacks for every registered item."""
|
||||
rng = random.Random(0x4954454d)
|
||||
cases = []
|
||||
def add(item, context='gui', count=1, components=None, **extra):
|
||||
case = {'id': str(len(cases)), 'item': item, 'count': count, 'context': context}
|
||||
if components: case['components'] = components
|
||||
case.update(extra)
|
||||
cases.append(case)
|
||||
for item, components in prototypes.items():
|
||||
stack = components.get('minecraft:max_stack_size', 64)
|
||||
for context in CONTEXTS: add(item, context)
|
||||
max_damage = components.get('minecraft:max_damage', 0)
|
||||
if max_damage:
|
||||
for damage in sorted({0, 1, max_damage // 2, max_damage - 2, max_damage - 1, max_damage}):
|
||||
add(item, 'gui', components={'minecraft:damage': damage})
|
||||
add(item, 'gui', components={'minecraft:damage': max_damage - 1, 'minecraft:unbreakable': {}})
|
||||
add(item, 'gui', components={'!minecraft:max_damage': {}})
|
||||
for count in sorted({2, stack // 2, stack}):
|
||||
if 1 <= count <= stack: add(item, 'gui', count=count)
|
||||
for color in (0xFF0000, 0x123456, 0xFFFFFF, 0):
|
||||
add(item, 'gui', components={'minecraft:dyed_color': color})
|
||||
for material in TRIM_MATERIALS:
|
||||
add(item, 'gui', components={'minecraft:trim': {'material': 'minecraft:' + material, 'pattern': 'minecraft:coast'}})
|
||||
add(item, 'gui', components={'minecraft:custom_model_data': {'floats': [0.0, 0.5, 1.0, 2.5, 7.0],
|
||||
'flags': [True, False, True], 'strings': ['a', 'b', 'c'], 'colors': [0xFF0000, 0x00FF00]}})
|
||||
add(item, 'gui', components={'minecraft:custom_model_data': {'floats': [3.0]}})
|
||||
for context in ('gui', 'ground', 'head'):
|
||||
add(item, context, components={'minecraft:enchantments': {'minecraft:sharpness': 1}})
|
||||
add(item, 'gui', components={'minecraft:enchantment_glint_override': True})
|
||||
add(item, 'gui', components={'minecraft:enchantment_glint_override': False,
|
||||
'minecraft:enchantments': {'minecraft:sharpness': 1}})
|
||||
add(item, 'gui', components={'minecraft:potion_contents': {'custom_color': 0x00FF7F}})
|
||||
add(item, 'gui', components={'minecraft:potion_contents': {'potion': 'minecraft:water'}})
|
||||
add(item, 'gui', components={'minecraft:potion_contents': {}})
|
||||
for colors in ([], [0xFF0000], [0xFF0000, 0x0000FF], [0x112233, 0x445566, 0x778899]):
|
||||
add(item, 'gui', components={'minecraft:firework_explosion': {'shape': 'small_ball', 'colors': colors}})
|
||||
add(item, 'gui', components={'minecraft:item_model': 'minecraft:diamond'})
|
||||
add(item, 'gui', components={'minecraft:item_model': 'minecraft:horizon_unknown'})
|
||||
add(item, 'gui', components={'!minecraft:item_model': {}})
|
||||
add(item, 'gui', components={'minecraft:item_model': 'minecraft:bundle'}, bundle_selected=0)
|
||||
for state in ({'honey_level': '0'}, {'honey_level': '5'}, {'light_level': '7'}, {'level': '1'},
|
||||
{'age': '3'}, {'powered': 'true'}, {'unknown': 'x'}):
|
||||
add(item, 'gui', components={'minecraft:block_state': state})
|
||||
for projectile in ('minecraft:arrow', 'minecraft:firework_rocket'):
|
||||
add(item, 'gui', components={'minecraft:charged_projectiles': [{'id': projectile, 'count': 1}]})
|
||||
add(item, 'gui', components={'minecraft:charged_projectiles': []})
|
||||
add(item, 'gui', components={'minecraft:lodestone_tracker': {}})
|
||||
add(item, 'gui', components={'minecraft:lodestone_tracker': {'tracked': True,
|
||||
'target': {'dimension': 'minecraft:overworld', 'pos': [1, 2, 3]}}})
|
||||
add(item, 'gui', components={'minecraft:banner_patterns': [{'pattern': 'minecraft:circle', 'color': 'red'},
|
||||
{'pattern': 'minecraft:border', 'color': 'blue'}]})
|
||||
add(item, 'gui', components={'minecraft:base_color': 'green',
|
||||
'minecraft:banner_patterns': [{'pattern': 'minecraft:globe', 'color': 'yellow'}]})
|
||||
add(item, 'gui', components={'minecraft:pot_decorations': {'back': {'id': 'minecraft:brick'},
|
||||
'left': {'id': 'minecraft:angler_pottery_sherd'}, 'front': {'id': 'minecraft:blade_pottery_sherd'}}})
|
||||
add(item, 'gui', components={'minecraft:profile': {'name': 'Notch'}})
|
||||
add(item, 'gui', components={'minecraft:bundle_contents': [{'id': 'minecraft:stone', 'count': 3},
|
||||
{'id': 'minecraft:diamond_sword', 'count': 1},
|
||||
{'id': 'minecraft:dirt', 'count': 20}]}, bundle_selected=1)
|
||||
add(item, 'gui', components={'minecraft:bundle_contents': [{'id': 'minecraft:stone', 'count': 3}]}, bundle_selected=-1)
|
||||
for time in ('12-24', '12-25', '12-26', '10-09', ''):
|
||||
add(item, 'gui', local_time=time)
|
||||
for dimension in ('minecraft:overworld', 'minecraft:the_nether', 'minecraft:the_end', 'horizon:other'):
|
||||
add(item, 'gui', dimension=dimension)
|
||||
for arm in ('left', 'right'):
|
||||
for entity in ('minecraft:player', 'minecraft:zombie'):
|
||||
add(item, 'firstperson_righthand', owner=owner(False, 0, arm, entity))
|
||||
for remaining in (0, 1, 3, 7, 13, 20, 71000, 71990, 72000):
|
||||
for context in ('firstperson_righthand', 'thirdperson_righthand'):
|
||||
add(item, context, owner=owner(True, remaining))
|
||||
add(item, 'firstperson_righthand', owner=owner(False, 5))
|
||||
# Item definitions with every shape the codec accepts and rejects.
|
||||
return cases
|
||||
|
||||
|
||||
def definitions():
|
||||
"""Synthetic client item definitions: valid and invalid shapes."""
|
||||
model = {'type': 'minecraft:model', 'model': 'minecraft:item/stick'}
|
||||
other = {'type': 'minecraft:model', 'model': 'minecraft:item/diamond'}
|
||||
rows = {}
|
||||
def put(name, definition):
|
||||
rows['horizon:' + name] = definition if isinstance(definition, str) else json.dumps(definition)
|
||||
put('plain', {'model': model})
|
||||
put('props', {'model': model, 'hand_animation_on_swap': False, 'oversized_in_gui': True, 'swap_animation_scale': 2.5})
|
||||
put('no_model', {})
|
||||
put('unknown_type', {'model': {'type': 'minecraft:horizon'}})
|
||||
put('empty', {'model': {'type': 'minecraft:empty'}})
|
||||
put('composite', {'model': {'type': 'minecraft:composite', 'models': [model, other, {'type': 'minecraft:empty'}]}})
|
||||
put('composite_empty', {'model': {'type': 'minecraft:composite', 'models': []}})
|
||||
put('composite_one', {'model': {'type': 'minecraft:composite', 'models': [model],
|
||||
'transformation': [1, 0, 0, 0.5, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]}})
|
||||
put('matrix', {'model': dict(model, transformation=[0.5, 0, 0, 1, 0, 0.5, 0, 2, 0, 0, 0.5, 3, 0, 0, 0, 1])})
|
||||
put('matrix_short', {'model': dict(model, transformation=[1, 0, 0])})
|
||||
quarter = [0.0, 0.0, 0.70710677, 0.70710677]
|
||||
put('decomposed', {'model': dict(model, transformation={'translation': [1, 2, 3], 'left_rotation': quarter,
|
||||
'scale': [1, 2, 3], 'right_rotation': [0, 0.38268343, 0, 0.9238795]})})
|
||||
put('axis_angle', {'model': dict(model, transformation={'translation': [0, 0, 0],
|
||||
'left_rotation': {'angle': 1.5707964, 'axis': [0, 0, 1]}, 'scale': [1, 1, 1], 'right_rotation': [0, 0, 0, 1]})})
|
||||
put('decomposed_partial', {'model': dict(model, transformation={'translation': [0, 0, 0], 'scale': [1, 1, 1]})})
|
||||
put('nested_transform', {'model': {'type': 'minecraft:condition', 'property': 'minecraft:damaged',
|
||||
'transformation': [2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1], 'on_true': dict(model, transformation=[1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]), 'on_false': other}})
|
||||
put('tints', {'model': dict(model, tints=[{'type': 'minecraft:constant', 'value': 0x123456},
|
||||
{'type': 'minecraft:constant', 'value': [0.5, 0.25, 1.0]},
|
||||
{'type': 'minecraft:dye', 'default': -6265536}, {'type': 'minecraft:grass', 'temperature': 0.5, 'downfall': 1.0},
|
||||
{'type': 'minecraft:grass', 'temperature': 0.0, 'downfall': 0.0}, {'type': 'minecraft:grass', 'temperature': 1.0, 'downfall': 0.3},
|
||||
{'type': 'minecraft:firework', 'default': 7}, {'type': 'minecraft:potion', 'default': 9},
|
||||
{'type': 'minecraft:team', 'default': 11},
|
||||
{'type': 'minecraft:custom_model_data', 'index': 1, 'default': 0x0000FF}])})
|
||||
put('bad_tint', {'model': dict(model, tints=[{'type': 'minecraft:horizon'}])})
|
||||
put('bad_grass', {'model': dict(model, tints=[{'type': 'minecraft:grass', 'temperature': 2.0, 'downfall': 0.0}])})
|
||||
put('condition_missing_branch', {'model': {'type': 'minecraft:condition', 'property': 'minecraft:damaged', 'on_true': model}})
|
||||
for prop in ('broken', 'damaged', 'using_item', 'selected', 'carried', 'view_entity', 'extended_view',
|
||||
'fishing_rod/cast', 'bundle/has_selected_item'):
|
||||
put('cond_' + prop.replace('/', '_'), {'model': {'type': 'minecraft:condition', 'property': 'minecraft:' + prop, 'on_true': model, 'on_false': other}})
|
||||
for index in (0, 1, 3, -1):
|
||||
put(f'cond_cmd_{index}', {'model': {'type': 'minecraft:condition', 'property': 'minecraft:custom_model_data', 'index': index, 'on_true': model, 'on_false': other}})
|
||||
for ignore in (True, False):
|
||||
for component in ('minecraft:damage', 'minecraft:enchantments', 'minecraft:max_damage', 'minecraft:custom_name', 'minecraft:horizon'):
|
||||
put(f'cond_has_{ignore}_{component}'.lower().replace(':', '_'), {'model': {'type': 'minecraft:condition', 'property': 'minecraft:has_component',
|
||||
'component': component, 'ignore_default': ignore, 'on_true': model, 'on_false': other}})
|
||||
select = lambda prop, cases, **extra: {'model': dict({'type': 'minecraft:select', 'property': 'minecraft:' + prop,
|
||||
'cases': [{'when': w, 'model': m} for w, m in cases]}, **extra)}
|
||||
put('select_ctx', select('display_context', [(['gui', 'ground'], model), ('head', other)], fallback={'type': 'minecraft:empty'}))
|
||||
put('select_ctx_nofallback', select('display_context', [('gui', model)]))
|
||||
put('select_ctx_bad', select('display_context', [('guii', model)]))
|
||||
put('select_dup', select('display_context', [('gui', model), (['gui', 'head'], other)]))
|
||||
put('select_empty_cases', select('display_context', []))
|
||||
put('select_empty_when', select('display_context', [([], model)]))
|
||||
put('select_arm', select('main_hand', [('left', model), ('right', other)]))
|
||||
put('select_arm_fallback', select('main_hand', [('left', model)], fallback=other))
|
||||
put('select_charge', select('charge_type', [('none', model), ('arrow', other), ('rocket', {'type': 'minecraft:empty'})]))
|
||||
put('select_trim', select('trim_material', [(['minecraft:quartz', 'iron'], model), ('minecraft:gold', other)], fallback={'type': 'minecraft:empty'}))
|
||||
put('select_state', select('block_state', [('3', model), ('5', other)], block_state_property='honey_level', fallback=model))
|
||||
put('select_state_missing_prop', select('block_state', [('3', model)]))
|
||||
put('select_entity', select('context_entity_type', [('minecraft:player', model), ('zombie', other)], fallback={'type': 'minecraft:empty'}))
|
||||
put('select_dimension', select('context_dimension', [('minecraft:overworld', model), ('the_nether', other)], fallback={'type': 'minecraft:empty'}))
|
||||
put('select_cmd', select('custom_model_data', [('a', model), ('c', other)], index=2, fallback={'type': 'minecraft:empty'}))
|
||||
put('select_time', select('local_time', [('12-25', model)], pattern='MM-dd', fallback=other))
|
||||
put('select_time_bad', select('local_time', [('12-25', model)], pattern='Q{', fallback=other))
|
||||
put('select_component', select('component', [('minecraft:diamond_sword', model)], component='minecraft:item_model', fallback=other))
|
||||
put('select_unknown_prop', select('horizon', [('a', model)]))
|
||||
ranges = lambda prop, entries, **extra: {'model': dict({'type': 'minecraft:range_dispatch', 'property': 'minecraft:' + prop,
|
||||
'entries': [{'threshold': t, 'model': m} for t, m in entries]}, **extra)}
|
||||
put('range_damage', ranges('damage', [(0.0, model), (0.5, other), (0.99, {'type': 'minecraft:empty'})], fallback={'type': 'minecraft:empty'}))
|
||||
put('range_damage_raw', ranges('damage', [(0, model), (10, other)], normalize=False))
|
||||
put('range_count', ranges('count', [(0.0, model), (0.5, other), (1.0, {'type': 'minecraft:empty'})]))
|
||||
put('range_count_raw', ranges('count', [(1, model), (32, other)], normalize=False))
|
||||
put('range_scale', ranges('damage', [(0, model), (50, other)], scale=100))
|
||||
put('range_nofallback', ranges('damage', [(0.4, model)]))
|
||||
put('range_unsorted', ranges('count', [(0.9, other), (0.1, model), (0.5, {'type': 'minecraft:empty'}), (0.1, other)]))
|
||||
put('range_many', ranges('count', [(i / 20, model if i % 2 else other) for i in range(20)]))
|
||||
put('range_cmd', ranges('custom_model_data', [(0, model), (1, other), (2.5, {'type': 'minecraft:empty'})], index=0))
|
||||
put('range_cooldown', ranges('cooldown', [(0, model), (0.5, other)]))
|
||||
put('range_use_duration', ranges('use_duration', [(0, model), (10, other)]))
|
||||
put('range_use_remaining', ranges('use_duration', [(0, model), (10, other)], remaining=True))
|
||||
put('range_cycle', ranges('use_cycle', [(0, model), (2, other)], period=4))
|
||||
put('range_cycle_bad', ranges('use_cycle', [(0, model)], period=0))
|
||||
put('range_crossbow', ranges('crossbow/pull', [(0, model), (0.5, other)]))
|
||||
put('range_fullness', ranges('bundle/fullness', [(0, model), (0.5, other)]))
|
||||
put('range_time', ranges('time', [(0, model)], source='daytime'))
|
||||
put('range_compass', ranges('compass', [(0, model)], target='spawn'))
|
||||
put('range_compass_bad', ranges('compass', [(0, model)], target='moon'))
|
||||
put('range_nan_threshold', ranges('damage', [(float('nan'), model)]))
|
||||
put('range_no_entries', {'model': {'type': 'minecraft:range_dispatch', 'property': 'minecraft:damage'}})
|
||||
for kind, config in [('banner', {'color': 'red'}), ('banner', {'color': 'blue', 'attachment': 'wall'}),
|
||||
('banner', {'color': 'pink', 'attachment': 'ground'}), ('banner', {'color': 'nope'}), ('banner', {}),
|
||||
('bell', {}), ('book', {'open_angle': 1.0, 'page1': 0.25, 'page2': 0.75}), ('book', {'open_angle': 1.0}),
|
||||
('chest', {'texture': 'minecraft:normal'}), ('chest', {'texture': 'christmas', 'openness': 0.5, 'chest_type': 'left'}),
|
||||
('chest', {'texture': 'minecraft:normal', 'chest_type': 'triple'}), ('chest', {}),
|
||||
('conduit', {}), ('copper_golem_statue', {'texture': 'minecraft:copper', 'pose': 'star'}),
|
||||
('copper_golem_statue', {'texture': 'minecraft:copper', 'pose': 'dancing'}),
|
||||
('decorated_pot', {}), ('end_cube', {'effect': 'portal'}), ('end_cube', {'effect': 'void'}),
|
||||
('head', {'kind': 'dragon'}), ('head', {'kind': 'player', 'texture': 'horizon:custom', 'animation': 1.5}),
|
||||
('head', {'kind': 'ghast'}), ('player_head', {}),
|
||||
('shulker_box', {}), ('shulker_box', {'texture': 'minecraft:shulker_red', 'openness': 0.25}),
|
||||
('shield', {}), ('trident', {}), ('horizon', {})]:
|
||||
put(f'special_{kind}_{len(rows)}', {'model': {'type': 'minecraft:special', 'base': 'minecraft:item/shield' if kind == 'shield' else 'minecraft:item/template_banner',
|
||||
'model': dict(config, type='minecraft:' + kind)}})
|
||||
put('special_transformed', {'model': {'type': 'minecraft:special', 'base': 'minecraft:item/trident_in_hand', 'model': {'type': 'minecraft:trident'},
|
||||
'transformation': {'left_rotation': [0, 0, 0, 1], 'right_rotation': [0, 0, 0, 1], 'scale': [1, -1, -1], 'translation': [0, 0, 0]}}})
|
||||
put('bundle_selected', {'model': {'type': 'minecraft:composite', 'models': [model, {'type': 'minecraft:bundle/selected_item'}, other]}})
|
||||
for pack in ('', '_x'):
|
||||
put('trailing' + pack, json.dumps({'model': model}) + pack)
|
||||
put('not_object', '[]')
|
||||
put('null_model', {'model': None})
|
||||
put('number_scale', {'model': model, 'swap_animation_scale': 'x'})
|
||||
put('bool_flag_number', {'model': model, 'oversized_in_gui': 1})
|
||||
put('bool_flag_string', {'model': model, 'oversized_in_gui': 'true'})
|
||||
put('bool_flag_float', {'model': model, 'oversized_in_gui': 0.5})
|
||||
put('swap_bool', {'model': model, 'swap_animation_scale': True})
|
||||
put('int_float_index', {'model': {'type': 'minecraft:condition', 'property': 'minecraft:custom_model_data', 'index': 1.5, 'on_true': model, 'on_false': other}})
|
||||
put('int_bool_index', {'model': {'type': 'minecraft:condition', 'property': 'minecraft:custom_model_data', 'index': True, 'on_true': model, 'on_false': other}})
|
||||
put('bool_as_number', {'model': dict({'type': 'minecraft:range_dispatch', 'property': 'minecraft:damage', 'entries': [{'threshold': True, 'model': model}]})})
|
||||
return rows
|
||||
|
||||
|
||||
def definition_cases(rows):
|
||||
cases = []
|
||||
stacks = [('minecraft:diamond_sword', {'minecraft:damage': 100}, 1), ('minecraft:diamond_sword', {'minecraft:damage': 1560}, 1),
|
||||
('minecraft:diamond_sword', {}, 1), ('minecraft:stone', {}, 64), ('minecraft:stone', {}, 17), ('minecraft:stone', {}, 1),
|
||||
('minecraft:bow', {}, 1), ('minecraft:leather_helmet', {'minecraft:trim': {'material': 'minecraft:gold', 'pattern': 'minecraft:coast'}}, 1),
|
||||
('minecraft:beehive', {'minecraft:block_state': {'honey_level': '3'}}, 1),
|
||||
('minecraft:beehive', {'minecraft:block_state': {'honey_level': '5'}}, 1), ('minecraft:crossbow', {}, 1),
|
||||
('minecraft:crossbow', {'minecraft:charged_projectiles': [{'id': 'minecraft:arrow', 'count': 1}]}, 1),
|
||||
('minecraft:diamond_sword', {'minecraft:custom_model_data': {'floats': [0.0, 1.0, 3.0], 'flags': [True], 'strings': ['a', 'b', 'c']}}, 1),
|
||||
('minecraft:diamond_sword', {'minecraft:custom_model_data': {'floats': [2.5], 'flags': [False, True], 'strings': ['x']}}, 1),
|
||||
('minecraft:bundle', {'minecraft:bundle_contents': [{'id': 'minecraft:diamond_sword', 'count': 1}, {'id': 'minecraft:stone', 'count': 3}]}, 1),
|
||||
('minecraft:bundle', {'minecraft:bundle_contents': []}, 1),
|
||||
('minecraft:stone', {'minecraft:enchantments': {'minecraft:sharpness': 1}}, 1),
|
||||
('minecraft:stone', {'minecraft:custom_name': '"x"'}, 1)]
|
||||
for name in rows:
|
||||
for stack_index, (item, components, count) in enumerate(stacks):
|
||||
for context in ('gui', 'head', 'firstperson_lefthand', 'ground'):
|
||||
for owner_state in (None, owner(True, 9), owner(False, 0, 'left', 'minecraft:zombie')):
|
||||
for dimension in (None, 'minecraft:overworld', 'minecraft:the_nether'):
|
||||
if dimension and context != 'gui': continue
|
||||
case = {'id': f'd{len(cases)}', 'item': item, 'count': count, 'context': context,
|
||||
'components': dict(components, **{'minecraft:item_model': name})}
|
||||
if owner_state: case['owner'] = owner_state
|
||||
if dimension: case['dimension'] = dimension
|
||||
if 'bundle_contents' in str(components) and count == 1 and 'diamond_sword' in str(components):
|
||||
case['bundle_selected'] = stack_index % 2
|
||||
case['local_time'] = '12-25' if stack_index % 2 else '01-01'
|
||||
cases.append(case)
|
||||
return cases
|
||||
|
||||
|
||||
import struct
|
||||
def float_bits(value):
|
||||
return struct.unpack('<I', struct.pack('<f', value))[0]
|
||||
THIN = (float_bits(7.5 / 16), float_bits(8.5 / 16))
|
||||
|
||||
|
||||
def canonical_quads(quads):
|
||||
"""The extruded sides of generated layers come out of a hash set in vanilla: no order to keep."""
|
||||
if quads and all(THIN[0] <= p[2] <= THIN[1] for q in quads for p in q['positions']):
|
||||
return sorted(quads, key=lambda q: json.dumps(q, sort_keys=True))
|
||||
return quads
|
||||
|
||||
|
||||
def matrix(bits):
|
||||
return [0 if b == 0x80000000 else b for b in bits]
|
||||
|
||||
|
||||
def main():
|
||||
lock, jars, libraries = base.verify_artifacts()
|
||||
build = lab.LOCAL / 'item-model-parity'; build.mkdir(parents=True, exist_ok=True)
|
||||
report_path = build / 'report.json'; report_path.unlink(missing_ok=True)
|
||||
oracle = lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/VanillaItemModelOracle.java'
|
||||
crate = lab.ROOT / 'crates/horizon-assets'
|
||||
sources = [oracle, Path(__file__), lab.ROOT / 'tools/lab.py', lab.ROOT / 'tools/test_rust_parity.py', lab.ROOT / 'Cargo.toml',
|
||||
lab.ROOT / 'Cargo.lock', crate / 'Cargo.toml', *sorted(crate.rglob('*.rs'))]
|
||||
tested = base.source_hashes(sources)
|
||||
resources = build / 'resources'
|
||||
extract(jars['client'], resources)
|
||||
_, directory = lab.config()
|
||||
prototypes_path = lab.LOCAL / 'horizon-client' / lock['minecraft']['version'] / 'items.json'
|
||||
prototypes = json.loads(prototypes_path.read_text())
|
||||
cases = corpus(prototypes)
|
||||
rows = definitions()
|
||||
cases += definition_cases(rows)
|
||||
inputs = build / 'cases.jsonl'; inputs.write_text(''.join(json.dumps(c) + '\n' for c in cases))
|
||||
(build / 'cases.jsonl.definitions').write_text(''.join(json.dumps({'name': n, 'json': j}) + '\n' for n, j in rows.items()))
|
||||
classes = build / 'classes'; classes.mkdir(exist_ok=True)
|
||||
def run(command, name):
|
||||
with (build / (name + '.log')).open('w') as log:
|
||||
subprocess.run(list(map(str, command)), cwd=lab.ROOT, check=True, timeout=3600, stdout=log, stderr=subprocess.STDOUT)
|
||||
dependencies = os.pathsep.join(map(str, [jars['client'], *baking.client_libraries()]))
|
||||
run(['javac', '--release', lock['minecraft']['java_major'], '-proc:none', '-cp', dependencies, '-d', classes, oracle], 'compile-java')
|
||||
run(['cargo', 'build', '--locked', '-p', 'horizon-assets', '--example', 'item_model_fixture'], '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' / ('item_model_fixture.exe' if os.name == 'nt' else 'item_model_fixture')
|
||||
run(['java', '-Xmx2G', '-cp', str(classes) + os.pathsep + dependencies, 'dev.horizonlab.parity.VanillaItemModelOracle',
|
||||
resources, inputs, build / 'client.jsonl', prototypes_path], 'client')
|
||||
# The host inputs vanilla derives from the stack (use duration, charge time).
|
||||
client = [json.loads(line) for line in (build / 'client.jsonl').read_text().splitlines()]
|
||||
derived = {r['id']: r['derived'] for r in client if r.get('row') == 'case' and 'derived' in r}
|
||||
rust_cases = []
|
||||
for case in cases:
|
||||
case = dict(case)
|
||||
if case['id'] in derived: case['derived'] = derived[case['id']]
|
||||
rust_cases.append(case)
|
||||
rust_inputs = build / 'rust-cases.jsonl'
|
||||
rust_inputs.write_text(''.join(json.dumps(c) + '\n' for c in rust_cases))
|
||||
(build / 'rust-cases.jsonl.definitions').write_text((build / 'cases.jsonl.definitions').read_text())
|
||||
run([binary, resources, prototypes_path, rust_inputs, build / 'rust.jsonl'], 'rust')
|
||||
rust = [json.loads(line) for line in (build / 'rust.jsonl').read_text().splitlines()]
|
||||
mismatches, compared, skipped, decoded = [], 0, 0, 0
|
||||
vanilla_by_key = {(r['row'], r.get('id') or r.get('name')): r for r in client if r['row'] in ('case', 'decode', 'components')}
|
||||
rust_by_key = {(r['row'], r.get('id') or r.get('name')): r for r in rust}
|
||||
assert vanilla_by_key.keys() == rust_by_key.keys(), 'The two sides produced different rows'
|
||||
assert vanilla_by_key[('components', None)]['names'] == rust_by_key[('components', None)]['names'], 'Data component registry differs'
|
||||
unbaked = [r['name'] for r in client if r['row'] == 'unbaked']
|
||||
for key, left in vanilla_by_key.items():
|
||||
right = rust_by_key[key]
|
||||
if key[0] == 'components': continue
|
||||
if key[0] == 'decode':
|
||||
decoded += 1
|
||||
if left['ok'] != right['ok']: mismatches.append(('decode', key[1], left, right))
|
||||
continue
|
||||
if 'error' in left:
|
||||
skipped += 1
|
||||
continue
|
||||
compared += 1
|
||||
for side in (left, right):
|
||||
for layer in side['layers']:
|
||||
layer['matrix'] = matrix(layer['matrix'])
|
||||
layer.pop('has_transform', None)
|
||||
if layer.get('quads') is not None: layer['quads'] = canonical_quads(layer['quads'])
|
||||
if left != right:
|
||||
mismatches.append(('case', key[1], left, right))
|
||||
if mismatches:
|
||||
for kind, name, left, right in mismatches[:5]:
|
||||
print(kind, name, '\nvanilla:', json.dumps(left)[:1500], '\nrust: ', json.dumps(right)[:1500])
|
||||
raise AssertionError(f'{len(mismatches)} item model mismatches')
|
||||
base.ensure_sources_unchanged(sources, tested)
|
||||
assert compared > 1000, 'Too few cases compared'
|
||||
assert skipped * 20 < len(cases), f'Too many cases rejected by vanilla: {skipped}'
|
||||
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(),
|
||||
'cases': len(cases), 'compared': compared, 'rejected_by_vanilla': skipped, 'definitions_decoded': decoded,
|
||||
'definitions_unbaked': unbaked, 'sources_sha256': tested,
|
||||
'scope': 'Actual ClientItem codec, ModelDiscovery, ModelBakery item baking and ItemModelResolver semantics against real sprites in a unit atlas. Every bundled items/*.json and synthetic definitions; every item prototype in every display context with representative components. Layer content, tints, foil, composed transformation matrices (numeric equality), special-renderer codec forms and arguments, baked quads by float bits, render properties. Not covered: GPU rendering, atlas packing, level-dependent needles (see the needle tests), player/keybind/team-based properties that need a live client.'}
|
||||
lab.write_json(report_path, report)
|
||||
print(f'Item models: {compared:,} resolved stacks match ({skipped:,} rejected by vanilla, {decoded:,} definitions); {report_path}', flush=True)
|
||||
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
Reference in New Issue
Block a user