Keep the fields DataFixerUpper's remainders bring back when upgrading saves
DataFixerUpper reads typed fields without taking them out of a record's remainder, so a typed field a fix drops comes back on write with its value from the record's last read: entities keep their old ArmorItems, HandItems, body_armor_item, saddle, Trident and Particle next to the new fields, as vanilla 26.3 writes them. Fixes that write and read entities refresh that map. The area effect cloud particle moves to custom_particle (4420), boats keep Type (BoatSplitFix's remainder update misses), and region files with a short header read as empty, as vanilla's RegionFile does. The sample worlds now use the item formats each version accepts and enable its experiments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+46
-8
@@ -119,8 +119,45 @@ ITEMS_C = [
|
||||
]
|
||||
|
||||
|
||||
def items(e):
|
||||
return ITEMS_A if e == A else ITEMS_B if e == B else ITEMS_C
|
||||
def experiments(version):
|
||||
"""Experimental data packs a world of `version` turns on, so that the blocks behind
|
||||
them exist and the feature-flag fixes have flags to remove."""
|
||||
packs = []
|
||||
if 3698 <= version < 3939:
|
||||
packs.append('update_1_21')
|
||||
if 3700 <= version < 4067:
|
||||
packs.append('bundle')
|
||||
if 4080 <= version < 4180:
|
||||
packs.append('winter_drop')
|
||||
return packs
|
||||
|
||||
|
||||
def items(e, version=None):
|
||||
"""The sample stacks of an era, in the exact component formats `version` accepts."""
|
||||
stacks = ITEMS_A if e == A else ITEMS_B if e == B else ITEMS_C
|
||||
if version is None:
|
||||
return stacks
|
||||
return [versioned(s, version) for s in stacks]
|
||||
|
||||
|
||||
def versioned(stack, version):
|
||||
"""Rewrite the components whose format changed inside an era."""
|
||||
if version >= 4541: # chain renamed to iron_chain
|
||||
stack = stack.replace('"minecraft:chain"', '"minecraft:iron_chain"')
|
||||
if '"minecraft:attribute_modifiers"' in stack:
|
||||
if version < 3945: # 1.20.5: modifiers are named and carry a UUID
|
||||
stack = stack.replace('id:"minecraft:x",', 'uuid:[I;1,2,3,4],name:"x",')
|
||||
if version >= 4055: # 1.21.2: attribute ids lose their generic. prefix
|
||||
stack = stack.replace('minecraft:generic.attack_damage', 'minecraft:attack_damage')
|
||||
if version >= 4068: # 1.21.2: a lock is an item predicate
|
||||
stack = stack.replace('"minecraft:lock":"key"', '"minecraft:lock":{items:"minecraft:stick"}')
|
||||
if version >= 4064: # 1.21.2: fire_resistant became damage_resistant
|
||||
stack = stack.replace('"minecraft:fire_resistant":{}', '"minecraft:damage_resistant":{types:"#minecraft:is_fire"}')
|
||||
if version >= 4059: # 1.21.2: food lost eat_seconds (now in consumable)
|
||||
stack = stack.replace(',eat_seconds:1.0f', '')
|
||||
if version >= 4175: # 1.21.4: custom model data holds lists
|
||||
stack = stack.replace('"minecraft:custom_model_data":5', '"minecraft:custom_model_data":{floats:[5.0f]}')
|
||||
return stack
|
||||
|
||||
|
||||
def slotted(stacks):
|
||||
@@ -130,9 +167,9 @@ def slotted(stacks):
|
||||
return '[' + ','.join(out) + ']'
|
||||
|
||||
|
||||
def chests(e):
|
||||
def chests(e, version=None):
|
||||
"""Chests holding every sample item (27 per chest)."""
|
||||
st = items(e)
|
||||
st = items(e, version)
|
||||
return [st[i:i + 27] for i in range(0, len(st), 27)]
|
||||
|
||||
|
||||
@@ -140,7 +177,7 @@ def chests(e):
|
||||
def block_entities(e, version):
|
||||
name = lambda s: text(e, s)
|
||||
out = []
|
||||
for group in chests(e):
|
||||
for group in chests(e, version):
|
||||
out.append(('chest', f'{{Items:{slotted(group)},CustomName:{name("Stash")}}}'))
|
||||
sign_a = ('{front_text:{messages:[\'{"text":"one"}\',\'"two"\',\'""\',\'""\'],color:"red",has_glowing_text:1b},'
|
||||
'back_text:{messages:[\'"b"\',\'""\',\'""\',\'""\'],filtered_messages:[\'"x"\',\'""\',\'""\',\'""\']},'
|
||||
@@ -284,12 +321,13 @@ def entities(e, version):
|
||||
return out
|
||||
|
||||
|
||||
def player_commands(e, name):
|
||||
def player_commands(e, name, version=None):
|
||||
"""Give the joined bot a varied inventory and ender chest."""
|
||||
out = []
|
||||
for i, stack in enumerate(items(e)[:30]):
|
||||
stacks = items(e, version)
|
||||
for i, stack in enumerate(stacks[:30]):
|
||||
out.append(f'item replace entity {name} container.{i} with {give_form(e, stack)}')
|
||||
out.append(f'item replace entity {name} enderchest.0 with {give_form(e, items(e)[0])}')
|
||||
out.append(f'item replace entity {name} enderchest.0 with {give_form(e, stacks[0])}')
|
||||
out.append(f'item replace entity {name} armor.head with minecraft:iron_helmet')
|
||||
out.append(f'xp set {name} 5 levels')
|
||||
return out
|
||||
|
||||
@@ -33,7 +33,8 @@ import datafix_scene as scene # noqa: E402
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
LOCAL = ROOT / '.local' / 'datafix'
|
||||
VERSIONS = ['1.20.1', '1.20.4', '1.20.6', '1.21.1', '1.21.4', '1.21.5', '1.21.8', '1.21.10', '1.21.11', '26.1.2', '26.2']
|
||||
VERSIONS = ['1.20.1', '1.20.2', '1.20.4', '1.20.5', '1.20.6', '1.21.1', '1.21.3', '1.21.4', '1.21.5', '1.21.6', '1.21.8',
|
||||
'1.21.9', '1.21.10', '1.21.11', '26.1', '26.1.2', '26.2']
|
||||
MANIFEST = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'
|
||||
BOT = 'Upgrader'
|
||||
UUID_BASE = 0x6000
|
||||
@@ -56,12 +57,14 @@ def server_jar(version):
|
||||
|
||||
|
||||
class Server:
|
||||
def __init__(self, directory, jar, port):
|
||||
def __init__(self, directory, jar, port, packs=()):
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
(directory / 'eula.txt').write_text('eula=true\n')
|
||||
props = {'server-port': port, 'online-mode': 'false', 'level-name': 'world', 'level-seed': '4242',
|
||||
'view-distance': '4', 'simulation-distance': '4', 'spawn-protection': '0', 'sync-chunk-writes': 'true',
|
||||
'enable-rcon': 'false', 'enable-query': 'false', 'max-tick-time': '-1'}
|
||||
if packs:
|
||||
props['initial-enabled-packs'] = ','.join(['vanilla', *packs])
|
||||
(directory / 'server.properties').write_text(''.join(f'{k}={v}\n' for k, v in props.items()))
|
||||
self.process = subprocess.Popen(['java', '-Xmx2G', '-jar', str(jar), 'nogui'], cwd=directory,
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
@@ -270,7 +273,7 @@ def build(version, force=False):
|
||||
work = LOCAL / 'gen' / version
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
port = 30000 + (os.getpid() + data_version) % 20000
|
||||
server = Server(work, jar, port)
|
||||
server = Server(work, jar, port, scene.experiments(data_version))
|
||||
problems = []
|
||||
|
||||
def run(command):
|
||||
@@ -293,7 +296,7 @@ def build(version, force=False):
|
||||
run('setworldspawn 20 101 20')
|
||||
bot = Bot(port, protocol, BOT)
|
||||
time.sleep(3)
|
||||
for command in scene.player_commands(era, BOT):
|
||||
for command in scene.player_commands(era, BOT, data_version):
|
||||
run(command)
|
||||
time.sleep(3)
|
||||
run('save-all flush')
|
||||
|
||||
Reference in New Issue
Block a user