Merge parity/old-saves into parity/old-saves-flat

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-13 02:00:29 +02:00
11 changed files with 2237 additions and 75 deletions
+18 -1
View File
@@ -38,6 +38,23 @@ pub fn read_dat(path: &Path) -> io::Result<Option<Tag>> {
Ok(Some(root.tag))
}
/// `SavedDataStorage.readTagFromDisk`: a file without the gzip header is plain NBT.
pub fn read_saved_dat(path: &Path) -> io::Result<Option<Tag>> {
let bytes = match fs::read(path) {
Ok(b) => b,
Err(e) if e.kind() == io::ErrorKind::NotFound => return Ok(None),
Err(e) => return Err(e),
};
let limits = Limits::default();
let raw = if bytes.starts_with(&[0x1f, 0x8b]) {
Compression::Gzip.decode(&bytes, limits.max_bytes)?
} else {
bytes
};
let (root, _) = nbt::read_named(&raw, limits).map_err(|e| invalid(e.to_string()))?;
Ok(Some(root.tag))
}
/// `NbtIo.writeCompressed`, creating the parent folders.
pub fn write_dat(path: &Path, tag: &Tag) -> io::Result<()> {
if let Some(parent) = path.parent() {
@@ -707,7 +724,7 @@ fn upgrade_saved_data(data: &Path) -> io::Result<()> {
let Some(ty) = super::saved_data_type(&relative) else {
continue;
};
if let Some(mut tag) = read_dat(&file)? {
if let Some(mut tag) = read_saved_dat(&file)? {
super::update_saved_data(ty, &mut tag);
set(&mut tag, "DataVersion", Tag::Int(CURRENT));
write_dat(&file, &tag)?;
+4 -1
View File
@@ -659,7 +659,10 @@ fn block_pos_format(cx: &mut Cx) {
// ------------------------------------------------------------------ 3814
fn attributes_rename_legacy(cx: &mut Cx, rename_fn: &dyn Fn(&str) -> Option<&'static str>) {
pub(super) fn attributes_rename_legacy(
cx: &mut Cx,
rename_fn: &dyn Fn(&str) -> Option<&'static str>,
) {
let fix_name = |v: &mut Tag, field: &str| {
if let Some(name) = as_str(v.get(field))
&& let Some(new) = rename_fn(&name)
+167 -43
View File
@@ -21,10 +21,16 @@ pub(super) fn register(out: &mut Vec<(Key, FixFn)>) {
}));
out.push((key(2690, 0), |cx| cx.rename(Ty::ItemName, renamer(COPPER))));
out.push((key(2690, 0), |cx| block_rename(cx, COPPER)));
out.push((key(2691, 0), |cx| cx.rename(Ty::ItemName, renamer(WAXED_COPPER))));
out.push((key(2691, 0), |cx| {
cx.rename(Ty::ItemName, renamer(WAXED_COPPER))
}));
out.push((key(2691, 0), |cx| block_rename(cx, WAXED_COPPER)));
out.push((key(2693, 0), |cx| add_flag(cx, "has_increased_height_already", false)));
out.push((key(2696, 0), |cx| cx.rename(Ty::ItemName, renamer(GRIMSTONE))));
out.push((key(2693, 0), |cx| {
add_flag(cx, "has_increased_height_already", false)
}));
out.push((key(2696, 0), |cx| {
cx.rename(Ty::ItemName, renamer(GRIMSTONE))
}));
out.push((key(2696, 0), |cx| block_rename(cx, GRIMSTONE)));
out.push((key(2700, 0), |cx| {
block_rename(
@@ -37,20 +43,28 @@ pub(super) fn register(out: &mut Vec<(Key, FixFn)>) {
}));
out.push((key(2701, 0), feature_pool_elements));
out.push((key(2702, 0), arrow_pickup));
out.push((key(2707, 0), |cx| add_flag(cx, "has_increased_height_already", true)));
out.push((key(2707, 0), |cx| {
add_flag(cx, "has_increased_height_already", true)
}));
out.push((key(2710, 0), |cx| {
stats_rename(cx, &[("minecraft:play_one_minute", "minecraft:play_time")])
}));
out.push((key(2717, 0), |cx| {
cx.rename(
Ty::ItemName,
renamer(&[("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves")]),
renamer(&[(
"minecraft:azalea_leaves_flowers",
"minecraft:flowering_azalea_leaves",
)]),
)
}));
out.push((key(2717, 0), |cx| {
block_rename(
cx,
&[("minecraft:azalea_leaves_flowers", "minecraft:flowering_azalea_leaves")],
&[(
"minecraft:azalea_leaves_flowers",
"minecraft:flowering_azalea_leaves",
)],
)
}));
out.push((key(2825, 0), |cx| {
@@ -372,53 +386,161 @@ fn cauldron_rename(cx: &mut Cx) {
}
const COPPER: &[(&str, &str)] = &[
("minecraft:weathered_copper_block", "minecraft:oxidized_copper_block"),
("minecraft:semi_weathered_copper_block", "minecraft:weathered_copper_block"),
("minecraft:lightly_weathered_copper_block", "minecraft:exposed_copper_block"),
("minecraft:weathered_cut_copper", "minecraft:oxidized_cut_copper"),
("minecraft:semi_weathered_cut_copper", "minecraft:weathered_cut_copper"),
("minecraft:lightly_weathered_cut_copper", "minecraft:exposed_cut_copper"),
("minecraft:weathered_cut_copper_stairs", "minecraft:oxidized_cut_copper_stairs"),
("minecraft:semi_weathered_cut_copper_stairs", "minecraft:weathered_cut_copper_stairs"),
("minecraft:lightly_weathered_cut_copper_stairs", "minecraft:exposed_cut_copper_stairs"),
("minecraft:weathered_cut_copper_slab", "minecraft:oxidized_cut_copper_slab"),
("minecraft:semi_weathered_cut_copper_slab", "minecraft:weathered_cut_copper_slab"),
("minecraft:lightly_weathered_cut_copper_slab", "minecraft:exposed_cut_copper_slab"),
("minecraft:waxed_semi_weathered_copper", "minecraft:waxed_weathered_copper"),
("minecraft:waxed_lightly_weathered_copper", "minecraft:waxed_exposed_copper"),
("minecraft:waxed_semi_weathered_cut_copper", "minecraft:waxed_weathered_cut_copper"),
("minecraft:waxed_lightly_weathered_cut_copper", "minecraft:waxed_exposed_cut_copper"),
("minecraft:waxed_semi_weathered_cut_copper_stairs", "minecraft:waxed_weathered_cut_copper_stairs"),
("minecraft:waxed_lightly_weathered_cut_copper_stairs", "minecraft:waxed_exposed_cut_copper_stairs"),
("minecraft:waxed_semi_weathered_cut_copper_slab", "minecraft:waxed_weathered_cut_copper_slab"),
("minecraft:waxed_lightly_weathered_cut_copper_slab", "minecraft:waxed_exposed_cut_copper_slab"),
(
"minecraft:weathered_copper_block",
"minecraft:oxidized_copper_block",
),
(
"minecraft:semi_weathered_copper_block",
"minecraft:weathered_copper_block",
),
(
"minecraft:lightly_weathered_copper_block",
"minecraft:exposed_copper_block",
),
(
"minecraft:weathered_cut_copper",
"minecraft:oxidized_cut_copper",
),
(
"minecraft:semi_weathered_cut_copper",
"minecraft:weathered_cut_copper",
),
(
"minecraft:lightly_weathered_cut_copper",
"minecraft:exposed_cut_copper",
),
(
"minecraft:weathered_cut_copper_stairs",
"minecraft:oxidized_cut_copper_stairs",
),
(
"minecraft:semi_weathered_cut_copper_stairs",
"minecraft:weathered_cut_copper_stairs",
),
(
"minecraft:lightly_weathered_cut_copper_stairs",
"minecraft:exposed_cut_copper_stairs",
),
(
"minecraft:weathered_cut_copper_slab",
"minecraft:oxidized_cut_copper_slab",
),
(
"minecraft:semi_weathered_cut_copper_slab",
"minecraft:weathered_cut_copper_slab",
),
(
"minecraft:lightly_weathered_cut_copper_slab",
"minecraft:exposed_cut_copper_slab",
),
(
"minecraft:waxed_semi_weathered_copper",
"minecraft:waxed_weathered_copper",
),
(
"minecraft:waxed_lightly_weathered_copper",
"minecraft:waxed_exposed_copper",
),
(
"minecraft:waxed_semi_weathered_cut_copper",
"minecraft:waxed_weathered_cut_copper",
),
(
"minecraft:waxed_lightly_weathered_cut_copper",
"minecraft:waxed_exposed_cut_copper",
),
(
"minecraft:waxed_semi_weathered_cut_copper_stairs",
"minecraft:waxed_weathered_cut_copper_stairs",
),
(
"minecraft:waxed_lightly_weathered_cut_copper_stairs",
"minecraft:waxed_exposed_cut_copper_stairs",
),
(
"minecraft:waxed_semi_weathered_cut_copper_slab",
"minecraft:waxed_weathered_cut_copper_slab",
),
(
"minecraft:waxed_lightly_weathered_cut_copper_slab",
"minecraft:waxed_exposed_cut_copper_slab",
),
];
const WAXED_COPPER: &[(&str, &str)] = &[
("minecraft:waxed_copper", "minecraft:waxed_copper_block"),
("minecraft:oxidized_copper_block", "minecraft:oxidized_copper"),
("minecraft:weathered_copper_block", "minecraft:weathered_copper"),
(
"minecraft:oxidized_copper_block",
"minecraft:oxidized_copper",
),
(
"minecraft:weathered_copper_block",
"minecraft:weathered_copper",
),
("minecraft:exposed_copper_block", "minecraft:exposed_copper"),
];
const GRIMSTONE: &[(&str, &str)] = &[
("minecraft:grimstone", "minecraft:deepslate"),
("minecraft:grimstone_slab", "minecraft:cobbled_deepslate_slab"),
("minecraft:grimstone_stairs", "minecraft:cobbled_deepslate_stairs"),
("minecraft:grimstone_wall", "minecraft:cobbled_deepslate_wall"),
("minecraft:polished_grimstone", "minecraft:polished_deepslate"),
("minecraft:polished_grimstone_slab", "minecraft:polished_deepslate_slab"),
("minecraft:polished_grimstone_stairs", "minecraft:polished_deepslate_stairs"),
("minecraft:polished_grimstone_wall", "minecraft:polished_deepslate_wall"),
(
"minecraft:grimstone_slab",
"minecraft:cobbled_deepslate_slab",
),
(
"minecraft:grimstone_stairs",
"minecraft:cobbled_deepslate_stairs",
),
(
"minecraft:grimstone_wall",
"minecraft:cobbled_deepslate_wall",
),
(
"minecraft:polished_grimstone",
"minecraft:polished_deepslate",
),
(
"minecraft:polished_grimstone_slab",
"minecraft:polished_deepslate_slab",
),
(
"minecraft:polished_grimstone_stairs",
"minecraft:polished_deepslate_stairs",
),
(
"minecraft:polished_grimstone_wall",
"minecraft:polished_deepslate_wall",
),
("minecraft:grimstone_tiles", "minecraft:deepslate_tiles"),
("minecraft:grimstone_tile_slab", "minecraft:deepslate_tile_slab"),
("minecraft:grimstone_tile_stairs", "minecraft:deepslate_tile_stairs"),
("minecraft:grimstone_tile_wall", "minecraft:deepslate_tile_wall"),
(
"minecraft:grimstone_tile_slab",
"minecraft:deepslate_tile_slab",
),
(
"minecraft:grimstone_tile_stairs",
"minecraft:deepslate_tile_stairs",
),
(
"minecraft:grimstone_tile_wall",
"minecraft:deepslate_tile_wall",
),
("minecraft:grimstone_bricks", "minecraft:deepslate_bricks"),
("minecraft:grimstone_brick_slab", "minecraft:deepslate_brick_slab"),
("minecraft:grimstone_brick_stairs", "minecraft:deepslate_brick_stairs"),
("minecraft:grimstone_brick_wall", "minecraft:deepslate_brick_wall"),
("minecraft:chiseled_grimstone", "minecraft:chiseled_deepslate"),
(
"minecraft:grimstone_brick_slab",
"minecraft:deepslate_brick_slab",
),
(
"minecraft:grimstone_brick_stairs",
"minecraft:deepslate_brick_stairs",
),
(
"minecraft:grimstone_brick_wall",
"minecraft:deepslate_brick_wall",
),
(
"minecraft:chiseled_grimstone",
"minecraft:chiseled_deepslate",
),
];
/// `SavedDataFeaturePoolElementFix`: the feature of jigsaw pieces' feature pool
@@ -446,7 +568,9 @@ fn feature_pool_elements(cx: &mut Cx) {
return child;
}
let element = child.get("pool_element");
let is_feature = element.and_then(|e| as_str(e.get("element_type"))).as_deref()
let is_feature = element
.and_then(|e| as_str(e.get("element_type")))
.as_deref()
== Some("minecraft:feature_pool_element");
if is_feature
&& let Some(f) = child
File diff suppressed because it is too large Load Diff
+2
View File
@@ -19,6 +19,7 @@ mod fixes_b;
mod fixes_c;
mod fixes_cliffs;
mod fixes_flat;
mod fixes_mid;
mod fixes_old;
mod flat_tables;
mod items;
@@ -183,6 +184,7 @@ type FixFn = fn(&mut Cx);
fn fixes() -> Vec<(Key, FixFn)> {
let mut out = Vec::new();
fixes_flat::register(&mut out);
fixes_mid::register(&mut out);
fixes_cliffs::register(&mut out);
fixes_old::register(&mut out);
fixes_a::register(&mut out);
+5 -1
View File
@@ -426,7 +426,11 @@ impl Walker<'_> {
"minecraft:item" | "minecraft:item_frame" | "minecraft:glow_item_frame" => {
self.field(Ty::ItemStack, v, "Item");
}
"minecraft:potion" if k < key(4306, 0) => self.field(Ty::ItemStack, v, "Item"),
"minecraft:potion" if k < key(4306, 0) => {
// V2511_1 renamed the typed field.
let field = if k < key(2511, 1) { "Potion" } else { "Item" };
self.field(Ty::ItemStack, v, field);
}
"minecraft:splash_potion" | "minecraft:lingering_potion" if k >= key(4306, 0) => {
self.field(Ty::ItemStack, v, "Item");
}
@@ -266,7 +266,11 @@ public final class VanillaDataFixOracle {
if (type == null) {
continue;
}
CompoundTag tag = NbtIo.readCompressed(file, NbtAccounter.unlimitedHeap());
// SavedDataStorage.readTagFromDisk: a file that does not start with the gzip header is plain NBT.
byte[] bytes = Files.readAllBytes(file);
boolean gzip = bytes.length >= 2 && (bytes[0] & 255) == 0x1f && (bytes[1] & 255) == 0x8b;
CompoundTag tag = gzip ? NbtIo.readCompressed(file, NbtAccounter.unlimitedHeap())
: NbtIo.read(new java.io.DataInputStream(new java.io.ByteArrayInputStream(bytes)));
int version = NbtUtils.getDataVersion(tag, 1343);
tag = type.update(fixer, tag, version, current);
NbtIo.writeCompressed(NbtUtils.addDataVersion(tag, current), file);
+37
View File
@@ -138,6 +138,9 @@ def experiments(version):
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 not None and version < 2586: # 1.13.2 to 1.15
import datafix_scene_old
stacks = stacks + datafix_scene_old.items(version)
if version is None:
return stacks
return [v for v in (versioned(s, version) for s in stacks) if available(v, version)]
@@ -237,6 +240,9 @@ def block_entities(e, version):
out = [(b, '{SpawnData:{id:"minecraft:zombie",ArmorItems:[{},{},{},{id:"minecraft:iron_helmet",Count:1b}]},'
'SpawnPotentials:[{Weight:1,Entity:{id:"minecraft:skeleton"}}]}') if b == 'spawner' else (b, nbt)
for b, nbt in out]
if version < 2586:
import datafix_scene_old
out += datafix_scene_old.block_entities(version)
if version >= 3682:
out.append(('crafter', '{Items:[{Slot:0b,id:"minecraft:stone",Count:1b}],triggered:1,crafting_ticks_remaining:2}'))
# Blocks the 1.20 experiment brought in 1.19.3 and 1.19.4.
@@ -312,6 +318,9 @@ def entities(e, version):
]
since = {'allay': 3105, 'chest_boat': 3105, 'text_display': 3325, 'item_display': 3325, 'goat': 2700}
out = [(k, x) for k, x in out if version >= since.get(k, 0)]
if version < 2514: # 1.13.2 to 1.15: entities in the formats those versions write
import datafix_scene_old
out += datafix_scene_old.entities(version)
if version < 3086: # cats before 1.19 have a numeric CatType
out = [(k, 'CatType:1' if k == 'cat' else x) for k, x in out]
if 3105 <= version < 3322: # darkness counts its factor from a timestamp before 1.19.4
@@ -363,6 +372,34 @@ def entities(e, version):
return out
def world_commands(version):
"""(command, seconds to wait) for the scoreboard, a boss bar and a trip through the other
dimensions, before 1.17: what makes level.dat, the scoreboard and the other dimension folders carry data."""
if version >= 2586:
return []
return [
('bossbar add upgrade:boss {"text":"Boss"}', 0),
('bossbar set upgrade:boss players @a', 0),
('scoreboard objectives add kills dummy {"text":"Kills"}', 0),
('scoreboard objectives add zombies minecraft.killed:minecraft.zombie', 0),
('scoreboard players set Upgrader kills 3', 0),
('team add red {"text":"Red"}', 0),
('team modify red prefix {"text":"[R]"}', 0),
('team join red Upgrader', 0),
('advancement grant @a only minecraft:story/root', 0),
('execute in minecraft:the_end run tp Upgrader 100 60 0', 20),
('execute in minecraft:the_nether run tp Upgrader 0 80 0', 15),
]
def blocks(version):
"""Plain blocks whose states changed over the versions."""
if version < 2586:
import datafix_scene_old
return datafix_scene_old.blocks(version)
return []
def player_commands(e, name, version=None):
"""Give the joined bot a varied inventory and ender chest."""
out = []
+119
View File
@@ -0,0 +1,119 @@
"""Scene additions for worlds saved by 1.13.2 to 1.16.5 (DataVersion 1631 to 2586): the entities, block
entities and items whose save format those versions changed, in the syntax and format of the version
that writes them (numeric UUIDMost/UUIDLeast, string owner UUIDs, Profession/Career villagers, ...).
Every entry is (minimum DataVersion, maximum DataVersion exclusive, value); datafix_scene.py adds the
ones valid for the world's version to its general scene.
"""
U1 = '11111111-2222-3333-4444-555555555555'
U2 = '66666666-7777-8888-9999-aaaaaaaaaaaa'
MODIFIERS = ('[{Name:"horse.jumpStrength",Base:0.7d},{Name:"generic.maxHealth",Base:20.0d,'
'Modifiers:[{Name:"m",Amount:1.0d,Operation:0,UUIDMost:5L,UUIDLeast:6L}]}]')
TRADES = ('{buy:{id:"minecraft:wheat",Count:20b},sell:{id:"minecraft:emerald",Count:1b},maxUses:16,uses:1,rewardExp:1b},'
'{buy:{id:"minecraft:paper",Count:24b},sell:{id:"minecraft:emerald",Count:1b},maxUses:16,uses:0},'
'{buy:{id:"minecraft:book",Count:4b},sell:{id:"minecraft:emerald",Count:1b},maxUses:12,uses:0},'
'{buy:{id:"minecraft:ink_sac",Count:5b},sell:{id:"minecraft:emerald",Count:1b},maxUses:12,uses:0}')
# (since, until, entity, fields)
ENTITIES = [
# 1.13.2: professions are numbers
(1631, 1900, 'villager', 'Profession:1,Career:2,CareerLevel:2,Offers:{Recipes:[%s]},Inventory:[{id:"minecraft:bread",Count:3b}]' % TRADES),
(1631, 1900, 'villager', 'Profession:3,Career:3,CareerLevel:1'),
(1631, 1900, 'zombie_villager', 'Profession:4,Career:2'),
(1631, 1900, 'ocelot', 'CatType:2,OwnerUUID:"%s"' % U1),
(1631, 1900, 'ocelot', 'CatType:0'),
(1631, 1900, 'ocelot', 'CatType:0,OwnerUUID:"%s"' % U2),
# 1.14: VillagerData and Xp; some without them
(1900, 2100, 'villager', 'VillagerData:{profession:"minecraft:farmer",level:1,type:"minecraft:plains"},'
'Offers:{Recipes:[%s]},Gossips:[{Type:"golem",Value:5},{Type:"major_positive",Value:2}]' % TRADES),
(1900, 2100, 'villager', 'VillagerData:{profession:"minecraft:armorer",level:3,type:"minecraft:desert"},Xp:70'),
(1900, 2100, 'zombie_villager', 'VillagerData:{profession:"minecraft:cleric",level:2,type:"minecraft:plains"}'),
(1900, 2100, 'cat', 'CatType:9'),
(1900, 2100, 'cat', 'CatType:3,CollarColor:5b'),
(1900, 2100, 'pillager', 'Inventory:[{id:"minecraft:arrow",Count:2b}]'),
(1900, 2100, 'fox', 'Type:"red",TrustedUUIDs:[{M:3L,L:4L}]'),
(1631, 2514, 'wolf', 'Owner:"%s",OwnerUUID:"%s",CollarColor:3b,Health:15.0f' % ('Steve', U1)),
(1631, 2514, 'horse', 'Tame:1b,OwnerUUID:"%s",SaddleItem:{id:"minecraft:saddle",Count:1b},'
'ArmorItem:{id:"minecraft:iron_horse_armor",Count:1b},Attributes:%s' % (U2, MODIFIERS)),
(1631, 2514, 'armor_stand', 'Attributes:%s' % MODIFIERS),
(1631, 2514, 'cow', 'Leash:{UUIDMost:7L,UUIDLeast:8L}'),
(1631, 2509, 'zombie_pigman', 'Anger:100s,HurtBy:"%s"' % U1),
(1631, 2514, 'item', 'Item:{id:"minecraft:diamond",Count:3b},Owner:{M:9L,L:10L},Thrower:{M:11L,L:12L}'),
(1631, 2514, 'area_effect_cloud', 'OwnerUUIDMost:13L,OwnerUUIDLeast:14L,Particle:"entity_effect",Radius:2.0f,Duration:600'),
(1631, 2514, 'arrow', 'OwnerUUIDMost:15L,OwnerUUIDLeast:16L,inGround:1b'),
(1631, 2514, 'trident', 'OwnerUUIDMost:17L,OwnerUUIDLeast:18L,Trident:{id:"minecraft:trident",Count:1b}'),
(1631, 2514, 'potion', 'Potion:{id:"minecraft:splash_potion",Count:1b,tag:{Potion:"minecraft:swiftness"}},owner:{M:19L,L:20L}'),
(1631, 2514, 'snowball', 'owner:{M:21L,L:22L}'),
(1631, 2514, 'egg', 'owner:{M:23L,L:24L}'),
(1631, 2514, 'ender_pearl', 'owner:{M:25L,L:26L}'),
(1631, 2514, 'experience_bottle', 'owner:{M:27L,L:28L}'),
(1631, 2514, 'llama_spit', 'Owner:{OwnerUUIDMost:29L,OwnerUUIDLeast:30L}'),
(1631, 2514, 'shulker_bullet', 'Owner:{M:31L,L:32L},Target:{M:33L,L:34L}'),
(1631, 2514, 'evoker_fangs', 'OwnerUUIDMost:35L,OwnerUUIDLeast:36L'),
(1631, 2514, 'shulker', 'Rotation:[40.0f,0.0f],Peek:0b'),
(1631, 2514, 'bat', ''),
(2100, 2514, 'bee', 'HurtBy:"%s",HasNectar:1b,Anger:50' % U1),
(2100, 2514, 'villager', 'VillagerData:{profession:"minecraft:farmer",level:2,type:"minecraft:plains"},Xp:20,'
'Brain:{memories:{"minecraft:job_site":{pos:[I;1,2,3],dimension:"minecraft:overworld"}}}'),
]
# (since, until, block, nbt)
BLOCK_ENTITIES = [
(1631, 2514, 'white_banner', '{CustomName:\'{"translate":"block.minecraft.illager_banner","color":"gold"}\','
'Patterns:[{Pattern:"cre",Color:15}]}'),
(1631, 2514, 'chest', '{LootTable:"minecraft:chests/village_blacksmith"}'),
(1631, 2514, 'furnace', '{BurnTime:100s,CookTime:20s,CookTimeTotal:200s,RecipesUsedSize:2,RecipeLocation0:"minecraft:iron_ingot",'
'RecipeAmount0:3,RecipeLocation1:"minecraft:glass",RecipeAmount1:1}'),
(1631, 2514, 'blast_furnace', '{RecipesUsedSize:1,RecipeLocation0:"minecraft:iron_ingot",RecipeAmount0:2}') if False else None,
(1631, 2514, 'player_head', '{Owner:{Id:"%s",Name:"Notch"}}' % U1),
(1631, 2514, 'conduit', '{target_uuid:{M:5L,L:6L},Target:{M:5L,L:6L}}'),
(1631, 2514, 'oak_sign', '{Text1:\'{"text":"one"}\',Text2:\'{"text":"two"}\'}'),
(1900, 2514, 'jigsaw[facing=up]', '{attachement_type:"minecraft:bottom",target_pool:"minecraft:village/plains/houses",'
'final_state:"minecraft:air"}'),
(1900, 2514, 'jigsaw[facing=east]', '{attachement_type:"minecraft:empty",target_pool:"minecraft:empty"}'),
(1900, 2514, 'lectern', '{Book:{id:"minecraft:written_book",Count:1b,tag:{title:"L",author:"A",pages:[\'"x"\']}},Page:0}'),
(2100, 2514, 'beehive', '{Bees:[{EntityData:{id:"minecraft:bee"},TicksInHive:3,MinOccupationTicks:600}]}'),
]
BLOCK_ENTITIES = [b for b in BLOCK_ENTITIES if b]
# Plain blocks whose states changed: (since, until, command tail after "setblock x y z")
BLOCKS = [
(1900, 2500, 'cobblestone_wall[east=true,west=false,north=true,south=false]'),
(1900, 2500, 'andesite_wall[east=true,west=true,north=false,south=false,up=true]'),
(1631, 2500, 'redstone_wire[east=none,west=none,north=none,south=none,power=0]'),
(1631, 2500, 'redstone_wire[east=up,west=none,north=none,south=none,power=3]'),
(1631, 2500, 'redstone_wire[east=none,west=none,north=side,south=none,power=1]'),
(1631, 2500, 'oak_sign[rotation=3]'),
(1631, 1900, 'stone_slab[type=bottom]'),
(1631, 2100, 'bee_nest') if False else None,
]
BLOCKS = [b for b in BLOCKS if b]
ITEMS = [
(1631, 2514, '{id:"minecraft:white_banner",Count:1b,tag:{display:{Name:\'{"translate":"block.minecraft.illager_banner","color":"gold"}\','
'Lore:[\'first\',\'{"text":"second"}\']},BlockEntityTag:{Patterns:[{Pattern:"cre",Color:15}]}}}'),
(1631, 2514, '{id:"minecraft:player_head",Count:1b,tag:{SkullOwner:{Id:"%s",Name:"Notch"}}}' % U2),
(1631, 2514, '{id:"minecraft:diamond_sword",Count:1b,tag:{AttributeModifiers:[{AttributeName:"generic.attackDamage",Name:"x",Amount:2.5d,'
'Operation:0,UUIDMost:41L,UUIDLeast:42L,Slot:"mainhand"}]}}'),
(1631, 2514, '{id:"minecraft:filled_map",Count:1b,tag:{map:0}}'),
(1631, 2514, '{id:"minecraft:cactus_green",Count:1b}') if False else None,
(1631, 2514, '{id:"minecraft:stone_slab",Count:2b}') if False else None,
]
ITEMS = [i for i in ITEMS if i]
def entities(version):
return [(kind, fields) for since, until, kind, fields in ENTITIES if since <= version < until]
def block_entities(version):
return [(block, nbt) for since, until, block, nbt in BLOCK_ENTITIES if since <= version < until]
def blocks(version):
return [block for since, until, block in BLOCKS if since <= version < until]
def items(version):
return [stack for since, until, stack in ITEMS if since <= version < until]
+64 -27
View File
@@ -38,8 +38,23 @@ LOCAL = ROOT / '.local' / 'datafix'
# Old server jars and their worlds are inputs, not outputs: keep them beside the
# vanilla data, which parallel worktrees share (.local/minecraft links there).
SHARED = (ROOT / '.local' / 'minecraft').resolve().parent / 'datafix'
VERSIONS = ['1.12.2', '1.13.2', '1.14.4', '1.16.5', '1.17.1', '1.18.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2', '1.20.4', '1.20.5', '1.20.6', '1.21.1',
VERSIONS = ['1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.1', '1.16.5', '1.17.1', '1.18.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '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']
# Extra worlds of one version with another world type, for the level.dat generator settings:
# name -> (version, server.properties). They get no scene, only a joined player.
VARIANTS = {
'1.13.2-flat': ('1.13.2', {'level-type': 'flat', 'generator-settings':
'3;minecraft:bedrock,2*minecraft:dirt,minecraft:grass_block;1;village,oceanmonument,mansion(distance=30)'}),
'1.14.4-flat': ('1.14.4', {'level-type': 'flat', 'generator-settings':
'3;minecraft:bedrock,3*minecraft:stone,minecraft:grass_block;2;stronghold(distance=20 count=5),village(distance=12),'
'oceanmonument(spacing=10 separation=4)'}),
'1.14.4-largebiomes': ('1.14.4', {'level-type': 'largebiomes'}),
'1.14.4-amplified': ('1.14.4', {'level-type': 'amplified'}),
'1.13.2-debug': ('1.13.2', {'level-type': 'debug_all_block_states'}),
'1.14.4-buffet': ('1.14.4', {'level-type': 'buffet', 'generator-settings':
'{"chunk_generator":{"type":"minecraft:surface"},"biome_source":{"type":"minecraft:fixed","options":'
'{"biomes":["minecraft:desert"]}}}'}),
}
MANIFEST = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'
LOCK = json.loads((ROOT / 'research-lock.json').read_text())['java_runtimes']
BOT = 'Upgrader'
@@ -137,7 +152,7 @@ def install_runtime(pin, home):
class Server:
def __init__(self, directory, jar, port, packs=(), java='java'):
def __init__(self, directory, jar, port, packs=(), java='java', props_override=None):
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',
@@ -145,6 +160,7 @@ class Server:
'enable-rcon': 'false', 'enable-query': 'false', 'max-tick-time': '-1'}
if packs:
props['initial-enabled-packs'] = ','.join(['vanilla', *packs])
props.update(props_override or {})
(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)
@@ -349,17 +365,55 @@ def uuid_nbt(i):
return f'[I;{UUID_BASE},0,0,{i}]'
def build(version, force=False):
def uuid_fields(data_version, i):
"""The UUID of a summoned entity: an int array since 1.16, two longs before."""
if data_version >= 2514:
return f'UUID:{uuid_nbt(i)}'
return f'UUIDMost:{UUID_BASE << 32}L,UUIDLeast:{i + 1}L'
def build_scene(server, run, Bot, port, protocol, props, era, data_version):
"""The scene of the generic generator; returns the bot that stays joined."""
if not props: # variants only differ in their world type
run('forceload add -48 -48 79 79')
run('fill 0 99 0 47 99 47 minecraft:stone')
run('fill 0 100 0 47 112 47 minecraft:air')
for i, (block, nbt) in enumerate(scene.block_entities(era, data_version)):
x, z = 1 + 3 * (i % 15), 1 + 3 * (i // 15)
run(f'setblock {x} 100 {z} minecraft:{block}{nbt}')
for i, (kind, extra) in enumerate(scene.entities(era, data_version)):
x, z = 1.5 + 3 * (i % 15), 25.5 + 3 * (i // 15)
fields = f'{uuid_fields(data_version, i)},NoAI:1b,Silent:1b,NoGravity:1b,Invulnerable:1b,PersistenceRequired:1b'
run(f'summon minecraft:{kind} {x} 100 {z} {{{fields}' + (',' + extra if extra else '') + '}')
for i, block in enumerate(scene.blocks(data_version)):
run(f'setblock {1 + 3 * (i % 15)} 100 {19 + 3 * (i // 15)} minecraft:{block}')
if not props:
run('setworldspawn 20 101 20')
bot = Bot(port, protocol, BOT)
time.sleep(3)
for command in scene.player_commands(era, BOT, data_version):
run(command)
time.sleep(3)
for command, wait in ([] if props else scene.world_commands(data_version)):
run(command)
time.sleep(wait)
run('save-all flush')
time.sleep(2)
return bot
def build(name, force=False):
version, props = VARIANTS.get(name, (name, None))
jar, data_version, protocol = server_jar(version)
target = SHARED / 'worlds' / version
target = SHARED / 'worlds' / name
if target.exists() and not force:
print(f'{version}: kept {target}')
return []
era = scene.era(data_version)
work = LOCAL / 'gen' / version
work = LOCAL / 'gen' / name
shutil.rmtree(work, ignore_errors=True)
port = 30000 + (os.getpid() + data_version) % 20000
server = Server(work, jar, port, scene.experiments(data_version), java(version))
server = Server(work, jar, port, scene.experiments(data_version), java(version), props)
problems = []
def run(command):
@@ -369,31 +423,14 @@ def build(version, force=False):
problems.append((command[:160], bad[:2]))
return out
if data_version < 1631: # 1.12 and older: tools/datafix_scene_12.py builds the scene and saves the world itself
if data_version < 1631 and not props: # 1.12 and older: tools/datafix_scene_12.py builds the scene and saves the world itself
bot = scene12.populate(server, Bot, port, protocol, BOT, problems)
else:
run('forceload add -48 -48 79 79')
run('fill 0 99 0 47 99 47 minecraft:stone')
run('fill 0 100 0 47 112 47 minecraft:air')
for i, (block, nbt) in enumerate(scene.block_entities(era, data_version)):
x, z = 1 + 3 * (i % 15), 1 + 3 * (i // 15)
run(f'setblock {x} 100 {z} minecraft:{block}{nbt}')
for i, (kind, extra) in enumerate(scene.entities(era, data_version)):
x, z = 1.5 + 3 * (i % 15), 25.5 + 3 * (i // 15)
fields = f'UUID:{uuid_nbt(i)},NoAI:1b,Silent:1b,NoGravity:1b,Invulnerable:1b,PersistenceRequired:1b'
run(f'summon minecraft:{kind} {x} 100 {z} {{{fields}' + (',' + extra if extra else '') + '}')
run('setworldspawn 20 101 20')
bot = Bot(port, protocol, BOT)
time.sleep(3)
for command in scene.player_commands(era, BOT, data_version):
run(command)
time.sleep(3)
run('save-all flush')
time.sleep(2)
bot = build_scene(server, run, Bot, port, protocol, props, era, data_version)
bot.leave()
time.sleep(2)
server.stop()
if data_version < 1631:
if data_version < 1631 and not props:
scene12.fixtures(work / 'world') # the few statistics a passive bot cannot cause, written by hand
# Copy aside, then rename: an interrupted copy must not look like a finished world.
partial = target.with_name(target.name + '.partial')
@@ -415,7 +452,7 @@ def main():
p.add_argument('versions', nargs='*')
p.add_argument('--force', action='store_true')
args = p.parse_args()
for version in args.versions or VERSIONS:
for version in args.versions or [*VERSIONS, *VARIANTS]:
build(version, args.force)
if version == '1.12.2':
scene12.build_flat(sys.modules[__name__], args.force) # and the flat world 1.12.2-flat
+1 -1
View File
@@ -214,7 +214,7 @@ def main():
WORLDS.parent.mkdir(parents=True, exist_ok=True)
with open(WORLDS.parent / 'generate.lock', 'w') as lock:
fcntl.flock(lock, fcntl.LOCK_EX) # another worktree may be generating them
missing = [v for v in datafix_worlds.VERSIONS if not (WORLDS / v / 'level.dat').exists()]
missing = [v for v in [*datafix_worlds.VERSIONS, *datafix_worlds.VARIANTS] if not (WORLDS / v / 'level.dat').exists()]
if missing:
print('generating sample worlds:', ' '.join(missing), flush=True)
subprocess.run([sys.executable, str(ROOT / 'tools' / 'datafix_worlds.py'), *missing], cwd=ROOT, check=True)