diff --git a/crates/horizon-world/src/datafix/fixes_a.rs b/crates/horizon-world/src/datafix/fixes_a.rs index 89a5bfee5..433a2796f 100644 --- a/crates/horizon-world/src/datafix/fixes_a.rs +++ b/crates/horizon-world/src/datafix/fixes_a.rs @@ -48,7 +48,7 @@ pub(super) fn register(out: &mut Vec<(Key, FixFn)>) { // ------------------------------------------------------------------ 3564 /// `BlockEntitySignDoubleSidedEditableTextFix.FIELDS_TO_DROP`. -const SIGN_FIELDS_TO_DROP: [&str; 10] = [ +pub(super) const SIGN_FIELDS_TO_DROP: [&str; 10] = [ "Text1", "Text2", "Text3", "Text4", "FilteredText1", "FilteredText2", "FilteredText3", "FilteredText4", "Color", "GlowingText", ]; diff --git a/crates/horizon-world/src/datafix/fixes_old.rs b/crates/horizon-world/src/datafix/fixes_old.rs new file mode 100644 index 000000000..b3835bc30 --- /dev/null +++ b/crates/horizon-world/src/datafix/fixes_old.rs @@ -0,0 +1,555 @@ +//! Fixes of 1.19 to 1.20 (keys 3076 to 3459): what worlds saved by 1.18.2 to +//! 1.19.4 need before the fixes of [`super::fixes_a`]. The options fixes of +//! this range (3201, 3214, 3319) are client settings, not world data. +use super::dynamic::{as_number, as_str, is_list, namespaced, remove, rename, set, stream, string, update}; +use super::fixes_a::fix_block_pos; +use super::fixes_b::feature_flag_remove; +use super::schema::{Key, Ty, key}; +use super::{Cx, FixFn, id_is, renamer, reread_as}; +use crate::nbt::{Compound, Tag}; + +pub(super) fn register(out: &mut Vec<(Key, FixFn)>) { + out.push((key(3077, 0), chunk_delete_ignored_light)); + out.push((key(3084, 0), |cx| cx.rename(Ty::GameEventName, renamer(GAME_EVENTS)))); + out.push((key(3086, 0), |cx| entity_variant(cx, "minecraft:cat", "CatType", cat_type))); + out.push((key(3086, 0), |cx| { + criteria_rename(cx, "minecraft:husbandry/complete_catalogue", &|s| { + CAT_TEXTURES.iter().find(|(from, _)| *from == s).map(|(_, to)| (*to).to_owned()) + }); + })); + out.push((key(3087, 0), |cx| { + entity_variant(cx, "minecraft:frog", "Variant", |n| match n { + 0 => Some("minecraft:temperate"), + 1 => Some("minecraft:warm"), + 2 => Some("minecraft:cold"), + _ => None, + }) + })); + out.push((key(3090, 0), |cx| { + cx.entity("minecraft:painting", |e| { + rename(e, "Motive", "variant"); + rename(e, "Facing", "facing"); + }) + })); + out.push((key(3093, 0), |cx| { + cx.entity("minecraft:goat", |e| { + set(e, "HasLeftHorn", Tag::Byte(1)); + set(e, "HasRightHorn", Tag::Byte(1)); + }) + })); + out.push((key(3094, 0), goat_horn_id)); + out.push((key(3097, 0), filtered_books)); + out.push((key(3097, 0), filtered_signs)); + out.push((key(3097, 0), |cx| { + cx.entity("minecraft:cat", |e| { + if as_str(e.get("variant")).as_deref() == Some("minecraft:british") { + set(e, "variant", string("minecraft:british_shorthair")); + } + }) + })); + out.push((key(3097, 0), |cx| { + criteria_rename(cx, "minecraft:husbandry/complete_catalogue", &|s| { + (s == "minecraft:british").then(|| "minecraft:british_shorthair".to_owned()) + }); + })); + out.push((key(3097, 0), |cx| { + poi_records(cx, |r| { + !matches!(as_str(r.get("type")).as_deref(), Some("minecraft:unemployed" | "minecraft:nitwit") | None) + }) + })); + out.push((key(3108, 0), |cx| { + cx.each_out(Ty::Chunk, |c| { + let dimension = c.get("__context").and_then(|x| as_str(x.get("dimension"))); + if dimension.as_deref() != Some("minecraft:overworld") { + remove(c, "blending_data"); + } + }) + })); + out.push((key(3209, 0), pig_spawn_egg)); + out.push((key(3322, 0), effect_duration)); + out.push((key(3438, 0), |cx| { + cx.each(Ty::BlockEntity, |be| { + if id_is(be, "minecraft:suspicious_sand") { + set(be, "id", string("minecraft:brushable_block")); + } + }) + })); + out.push((key(3438, 0), |cx| { + cx.each_out(Ty::BlockEntity, |be| { + if id_is(be, "minecraft:brushable_block") { + rename(be, "loot_table", "LootTable"); + rename(be, "loot_table_seed", "LootTableSeed"); + } + }) + })); + out.push((key(3438, 0), |cx| cx.rename(Ty::ItemName, renamer(POTTERY_SHARDS)))); + out.push((key(3439, 0), |cx| sign_double_sided(cx, "minecraft:sign"))); + out.push((key(3439, 1), |cx| sign_double_sided(cx, "minecraft:hanging_sign"))); + out.push((key(3440, 0), multi_noise_preset)); + out.push((key(3440, 0), |cx| feature_flag_remove(cx, &["minecraft:update_1_20"]))); + out.push((key(3447, 0), |cx| { + cx.rename(Ty::ItemName, |id| { + let id = namespaced(id); + POTTERY_SHERDS.iter().find(|(from, _)| *from == id).map(|(_, to)| *to) + }) + })); + // DecoratedPotFieldRenameFix converts unchecked: the typed shards are written + // as sherds, and the raw shards come back from the block entity's remainder. + out.push((key(3448, 0), |cx| { + cx.each(Ty::BlockEntity, |be| { + if id_is(be, "minecraft:decorated_pot") + && let Some(shards) = be.get("shards").cloned() + { + set(be, "sherds", shards); + super::drop_typed(be, "shards"); + } + }) + })); + out.push((key(3450, 0), remap_chunk_status)); + out.push((key(3451, 0), chunk_delete_light)); + out.push((key(3459, 0), legacy_dragon_fight)); +} + +// ------------------------------------------------------------------ 3077, 3451 + +/// `ChunkDeleteIgnoredLightDataFix`. +fn chunk_delete_ignored_light(cx: &mut Cx) { + cx.each(Ty::Chunk, |c| { + let light_on = c.get("isLightOn").and_then(as_number).is_some_and(|n| n.double_value() != 0.0); + if !light_on && let Some(Tag::List(sections)) = c.get_mut("sections") { + for s in sections { + remove(s, "BlockLight"); + remove(s, "SkyLight"); + } + } + }); +} + +/// `ChunkDeleteLightFix`. +fn chunk_delete_light(cx: &mut Cx) { + cx.each(Ty::Chunk, |c| { + remove(c, "isLightOn"); + if let Some(Tag::List(sections)) = c.get_mut("sections") { + for s in sections { + remove(s, "BlockLight"); + remove(s, "SkyLight"); + } + } + }); +} + +// ------------------------------------------------------------------ 3084 + +const GAME_EVENTS: &[(&str, &str)] = &[ + ("minecraft:block_press", "minecraft:block_activate"), + ("minecraft:block_switch", "minecraft:block_activate"), + ("minecraft:block_unpress", "minecraft:block_deactivate"), + ("minecraft:block_unswitch", "minecraft:block_deactivate"), + ("minecraft:drinking_finish", "minecraft:drink"), + ("minecraft:elytra_free_fall", "minecraft:elytra_glide"), + ("minecraft:entity_damaged", "minecraft:entity_damage"), + ("minecraft:entity_dying", "minecraft:entity_die"), + ("minecraft:entity_killed", "minecraft:entity_die"), + ("minecraft:mob_interact", "minecraft:entity_interact"), + ("minecraft:ravager_roar", "minecraft:entity_roar"), + ("minecraft:ring_bell", "minecraft:block_change"), + ("minecraft:shulker_close", "minecraft:container_close"), + ("minecraft:shulker_open", "minecraft:container_open"), + ("minecraft:wolf_shaking", "minecraft:entity_shake"), +]; + +// ------------------------------------------------------------------ 3086, 3087, 3097 + +fn cat_type(n: i32) -> Option<&'static str> { + Some(match n { + 1 => "minecraft:black", + 2 => "minecraft:red", + 3 => "minecraft:siamese", + 4 => "minecraft:british", + 5 => "minecraft:calico", + 6 => "minecraft:persian", + 7 => "minecraft:ragdoll", + 8 => "minecraft:white", + 9 => "minecraft:jellie", + 10 => "minecraft:all_black", + // The map's default return value. + _ => "minecraft:tabby", + }) +} + +/// `EntityVariantFix`: the numeric variant written to `variant`; the old field +/// stays (`updateAndRename` only sets the new key). An id the map has no entry +/// for gives Java's `null`, which `createString` cannot take: such a variant is +/// left as the number. +fn entity_variant(cx: &mut Cx, id: &str, field: &str, ids: fn(i32) -> Option<&'static str>) { + cx.entity(id, |e| { + let Some(value) = e.get(field).cloned() else { + return; + }; + let new = match as_number(&value).map(|n| ids(n.int_value())) { + Some(Some(name)) => string(name), + _ => value, + }; + set(e, "variant", new); + }); +} + +const CAT_TEXTURES: &[(&str, &str)] = &[ + ("textures/entity/cat/tabby.png", "minecraft:tabby"), + ("textures/entity/cat/black.png", "minecraft:black"), + ("textures/entity/cat/red.png", "minecraft:red"), + ("textures/entity/cat/siamese.png", "minecraft:siamese"), + ("textures/entity/cat/british_shorthair.png", "minecraft:british"), + ("textures/entity/cat/calico.png", "minecraft:calico"), + ("textures/entity/cat/persian.png", "minecraft:persian"), + ("textures/entity/cat/ragdoll.png", "minecraft:ragdoll"), + ("textures/entity/cat/white.png", "minecraft:white"), + ("textures/entity/cat/jellie.png", "minecraft:jellie"), + ("textures/entity/cat/all_black.png", "minecraft:all_black"), +]; + +/// `CriteriaRenameFix`: the criteria keys of one advancement. +fn criteria_rename(cx: &mut Cx, advancement: &str, conversions: &dyn Fn(&str) -> Option) { + cx.each(Ty::Advancements, |v| { + let Some(criteria) = v.get_mut(advancement).and_then(|a| a.get_mut("criteria")) else { + return; + }; + if let Tag::Compound(c) = criteria { + let old = std::mem::take(c); + for (k, value) in old { + let name = k.to_string_lossy(); + let k = conversions(&name).map_or(k, |n| n.as_str().into()); + c.insert(k, value); + } + } + }); +} + +// ------------------------------------------------------------------ 3094, 3097 + +/// The `tag` of every stack whose id passes `filter` (`ItemStackTagFix`). +fn item_tag(cx: &mut Cx, filter: impl Fn(&str) -> bool, mut f: impl FnMut(&mut Tag)) { + cx.item(filter, |s| { + if let Some(tag) = s.get_mut("tag") { + f(tag); + } + }); +} + +const INSTRUMENTS: [&str; 8] = [ + "minecraft:ponder_goat_horn", + "minecraft:sing_goat_horn", + "minecraft:seek_goat_horn", + "minecraft:feel_goat_horn", + "minecraft:admire_goat_horn", + "minecraft:call_goat_horn", + "minecraft:yearn_goat_horn", + "minecraft:dream_goat_horn", +]; + +/// `GoatHornIdFix`. +fn goat_horn_id(cx: &mut Cx) { + item_tag( + cx, + |id| id == "minecraft:goat_horn", + |tag| { + let variant = super::dynamic::as_int(tag.get("SoundVariant"), 0); + let sound = INSTRUMENTS[if (0..8).contains(&variant) { variant as usize } else { 0 }]; + remove(tag, "SoundVariant"); + set(tag, "instrument", string(sound)); + }, + ); +} + +/// `FilteredBooksFix`. +fn filtered_books(cx: &mut Cx) { + item_tag( + cx, + |id| id == "minecraft:writable_book" || id == "minecraft:written_book", + |tag| { + remove(tag, "filtered_title"); + remove(tag, "filtered_pages"); + }, + ); +} + +/// `FilteredSignsFix` (a `NamedEntityWriteReadFix` over signs only). +fn filtered_signs(cx: &mut Cx) { + let k = cx.k; + cx.block_entity("minecraft:sign", |be| { + for i in 1..=4 { + remove(be, &format!("FilteredText{i}")); + } + reread_as(Ty::BlockEntity, k, be); + }); +} + +/// `AbstractPoiSectionFix`: the records of every POI section kept by `keep`. +fn poi_records(cx: &mut Cx, keep: impl Fn(&Tag) -> bool) { + cx.each(Ty::PoiChunk, |poi| { + let Some(Tag::Compound(sections)) = poi.get_mut("Sections") else { + return; + }; + for section in sections.values_mut() { + if let Some(records) = section.get("Records") + && is_list(Some(records)) + { + let kept: Vec = stream(Some(records)).into_iter().filter(|r| keep(r)).collect(); + set(section, "Records", Tag::List(kept)); + } + } + }); +} + +// ------------------------------------------------------------------ 3209 + +/// `ItemStackSpawnEggFix` for `minecraft:pig_spawn_egg`: an egg whose entity has +/// an id becomes that entity's egg. +fn pig_spawn_egg(cx: &mut Cx) { + cx.item( + |id| id == "minecraft:pig_spawn_egg", + |s| { + let entity = s.get("tag").and_then(|t| t.get("EntityTag")).and_then(|e| as_str(e.get("id"))); + if let Some(entity) = entity { + let egg = SPAWN_EGGS + .iter() + .find(|(e, _)| *e == namespaced(&entity)) + .map_or("minecraft:pig_spawn_egg", |(_, egg)| egg); + set(s, "id", string(egg)); + } + }, + ); +} + +const SPAWN_EGGS: &[(&str, &str)] = &[ + ("minecraft:bat", "minecraft:bat_spawn_egg"), + ("minecraft:blaze", "minecraft:blaze_spawn_egg"), + ("minecraft:cave_spider", "minecraft:cave_spider_spawn_egg"), + ("minecraft:chicken", "minecraft:chicken_spawn_egg"), + ("minecraft:cow", "minecraft:cow_spawn_egg"), + ("minecraft:creeper", "minecraft:creeper_spawn_egg"), + ("minecraft:donkey", "minecraft:donkey_spawn_egg"), + ("minecraft:elder_guardian", "minecraft:elder_guardian_spawn_egg"), + ("minecraft:ender_dragon", "minecraft:ender_dragon_spawn_egg"), + ("minecraft:enderman", "minecraft:enderman_spawn_egg"), + ("minecraft:endermite", "minecraft:endermite_spawn_egg"), + ("minecraft:evocation_illager", "minecraft:evocation_illager_spawn_egg"), + ("minecraft:ghast", "minecraft:ghast_spawn_egg"), + ("minecraft:guardian", "minecraft:guardian_spawn_egg"), + ("minecraft:horse", "minecraft:horse_spawn_egg"), + ("minecraft:husk", "minecraft:husk_spawn_egg"), + ("minecraft:iron_golem", "minecraft:iron_golem_spawn_egg"), + ("minecraft:llama", "minecraft:llama_spawn_egg"), + ("minecraft:magma_cube", "minecraft:magma_cube_spawn_egg"), + ("minecraft:mooshroom", "minecraft:mooshroom_spawn_egg"), + ("minecraft:mule", "minecraft:mule_spawn_egg"), + ("minecraft:ocelot", "minecraft:ocelot_spawn_egg"), + ("minecraft:pufferfish", "minecraft:pufferfish_spawn_egg"), + ("minecraft:parrot", "minecraft:parrot_spawn_egg"), + ("minecraft:pig", "minecraft:pig_spawn_egg"), + ("minecraft:polar_bear", "minecraft:polar_bear_spawn_egg"), + ("minecraft:rabbit", "minecraft:rabbit_spawn_egg"), + ("minecraft:sheep", "minecraft:sheep_spawn_egg"), + ("minecraft:shulker", "minecraft:shulker_spawn_egg"), + ("minecraft:silverfish", "minecraft:silverfish_spawn_egg"), + ("minecraft:skeleton", "minecraft:skeleton_spawn_egg"), + ("minecraft:skeleton_horse", "minecraft:skeleton_horse_spawn_egg"), + ("minecraft:slime", "minecraft:slime_spawn_egg"), + ("minecraft:snow_golem", "minecraft:snow_golem_spawn_egg"), + ("minecraft:spider", "minecraft:spider_spawn_egg"), + ("minecraft:squid", "minecraft:squid_spawn_egg"), + ("minecraft:stray", "minecraft:stray_spawn_egg"), + ("minecraft:turtle", "minecraft:turtle_spawn_egg"), + ("minecraft:vex", "minecraft:vex_spawn_egg"), + ("minecraft:villager", "minecraft:villager_spawn_egg"), + ("minecraft:vindication_illager", "minecraft:vindication_illager_spawn_egg"), + ("minecraft:witch", "minecraft:witch_spawn_egg"), + ("minecraft:wither", "minecraft:wither_spawn_egg"), + ("minecraft:wither_skeleton", "minecraft:wither_skeleton_spawn_egg"), + ("minecraft:wolf", "minecraft:wolf_spawn_egg"), + ("minecraft:zombie", "minecraft:zombie_spawn_egg"), + ("minecraft:zombie_horse", "minecraft:zombie_horse_spawn_egg"), + ("minecraft:zombie_pigman", "minecraft:zombie_pigman_spawn_egg"), + ("minecraft:zombie_villager", "minecraft:zombie_villager_spawn_egg"), +]; + +// ------------------------------------------------------------------ 3322 + +const POTION_ITEMS: [&str; 4] = + ["minecraft:potion", "minecraft:splash_potion", "minecraft:lingering_potion", "minecraft:tipped_arrow"]; + +/// `EffectDurationFix.fix`: every effect's factor data counts ticks active. +fn effect_list(list: Tag) -> Tag { + if !is_list(Some(&list)) { + return list; + } + Tag::List( + stream(Some(&list)) + .into_iter() + .map(|mut effect| { + let duration = super::dynamic::as_int(effect.get("Duration"), -1); + update(&mut effect, "FactorCalculationData", |mut data| { + let timestamp = super::dynamic::as_int(data.get("effect_changed_timestamp"), -1); + remove(&mut data, "effect_changed_timestamp"); + set(&mut data, "ticks_active", Tag::Int(timestamp.wrapping_sub(duration))); + data + }); + effect + }) + .collect(), + ) +} + +fn effect_duration(cx: &mut Cx) { + let living = |e: &mut Tag| { + for field in ["Effects", "ActiveEffects", "CustomPotionEffects"] { + update(e, field, effect_list); + } + }; + cx.each(Ty::Entity, living); + cx.each(Ty::Player, living); + item_tag(cx, |id| POTION_ITEMS.contains(&id), |tag| update(tag, "CustomPotionEffects", effect_list)); +} + +// ------------------------------------------------------------------ 3438, 3447 + +const POTTERY_SHARDS: &[(&str, &str)] = &[ + ("minecraft:pottery_shard_archer", "minecraft:archer_pottery_shard"), + ("minecraft:pottery_shard_prize", "minecraft:prize_pottery_shard"), + ("minecraft:pottery_shard_arms_up", "minecraft:arms_up_pottery_shard"), + ("minecraft:pottery_shard_skull", "minecraft:skull_pottery_shard"), +]; + +const POTTERY_SHERDS: &[(&str, &str)] = &[ + ("minecraft:angler_pottery_shard", "minecraft:angler_pottery_sherd"), + ("minecraft:archer_pottery_shard", "minecraft:archer_pottery_sherd"), + ("minecraft:arms_up_pottery_shard", "minecraft:arms_up_pottery_sherd"), + ("minecraft:blade_pottery_shard", "minecraft:blade_pottery_sherd"), + ("minecraft:brewer_pottery_shard", "minecraft:brewer_pottery_sherd"), + ("minecraft:burn_pottery_shard", "minecraft:burn_pottery_sherd"), + ("minecraft:danger_pottery_shard", "minecraft:danger_pottery_sherd"), + ("minecraft:explorer_pottery_shard", "minecraft:explorer_pottery_sherd"), + ("minecraft:friend_pottery_shard", "minecraft:friend_pottery_sherd"), + ("minecraft:heart_pottery_shard", "minecraft:heart_pottery_sherd"), + ("minecraft:heartbreak_pottery_shard", "minecraft:heartbreak_pottery_sherd"), + ("minecraft:howl_pottery_shard", "minecraft:howl_pottery_sherd"), + ("minecraft:miner_pottery_shard", "minecraft:miner_pottery_sherd"), + ("minecraft:mourner_pottery_shard", "minecraft:mourner_pottery_sherd"), + ("minecraft:plenty_pottery_shard", "minecraft:plenty_pottery_sherd"), + ("minecraft:prize_pottery_shard", "minecraft:prize_pottery_sherd"), + ("minecraft:sheaf_pottery_shard", "minecraft:sheaf_pottery_sherd"), + ("minecraft:shelter_pottery_shard", "minecraft:shelter_pottery_sherd"), + ("minecraft:skull_pottery_shard", "minecraft:skull_pottery_sherd"), + ("minecraft:snort_pottery_shard", "minecraft:snort_pottery_sherd"), +]; + +// ------------------------------------------------------------------ 3439 + +/// `LegacyComponentDataFixUtils.createEmptyComponent`. +fn empty_component() -> Tag { + string("{\"text\":\"\"}") +} + +/// `BlockEntitySignDoubleSidedEditableTextFix` (a `NamedEntityWriteReadFix`). +fn sign_double_sided(cx: &mut Cx, id: &str) { + let k = cx.k; + cx.block_entity(id, |be| { + let lines: Vec = + (1..=4).map(|i| be.get(&format!("Text{i}")).cloned().unwrap_or_else(empty_component)).collect(); + let filtered: Vec> = (1..=4).map(|i| be.get(&format!("FilteredText{i}")).cloned()).collect(); + let mut front = Compound::new(); + front.insert("messages".into(), Tag::List(lines.clone())); + front.insert("color".into(), be.get("Color").cloned().unwrap_or_else(|| string("black"))); + front.insert("has_glowing_text".into(), be.get("GlowingText").cloned().unwrap_or(Tag::Byte(0))); + if filtered.iter().any(Option::is_some) { + let messages = + filtered.into_iter().zip(&lines).map(|(f, line)| f.unwrap_or_else(|| line.clone())).collect(); + front.insert("filtered_messages".into(), Tag::List(messages)); + } + set(be, "front_text", Tag::Compound(front)); + let back = Tag::compound([ + ("messages", Tag::List(vec![empty_component(); 4])), + ("color", string("black")), + ("has_glowing_text", Tag::Byte(0)), + ]); + set(be, "back_text", back); + set(be, "is_waxed", Tag::Byte(0)); + set(be, "_filtered_correct", Tag::Byte(1)); + for field in super::fixes_a::SIGN_FIELDS_TO_DROP { + remove(be, field); + } + reread_as(Ty::BlockEntity, k, be); + }); +} + +// ------------------------------------------------------------------ 3440 + +/// `NamespacedTypeRenameFix` over `MULTI_NOISE_BIOME_SOURCE_PARAMETER_LIST`: the +/// preset of a multi-noise biome source in the world generation settings. +fn multi_noise_preset(cx: &mut Cx) { + cx.each(Ty::WorldGenSettings, |v| { + let Some(Tag::Compound(dims)) = v.get_mut("dimensions") else { + return; + }; + for dim in dims.values_mut() { + let Some(g) = dim.get_mut("generator") else { + continue; + }; + if as_str(g.get("type")).as_deref() != Some("minecraft:noise") { + continue; + } + let Some(source) = g.get_mut("biome_source") else { + continue; + }; + if as_str(source.get("type")).as_deref() != Some("minecraft:multi_noise") { + continue; + } + if let Some(preset) = as_str(source.get("preset")) + && namespaced(&preset) == "minecraft:overworld_update_1_20" + { + set(source, "preset", string("minecraft:overworld")); + } + } + }); +} + +// ------------------------------------------------------------------ 3450, 3459 + +/// `RemapChunkStatusFix`: statuses namespaced, then mapped. +fn remap_chunk_status(cx: &mut Cx) { + let fix = |v: Tag| match as_str(Some(&v)) { + Some(s) => { + let s = namespaced(&s); + string(match s.as_str() { + "minecraft:liquid_carvers" => "minecraft:carvers", + "minecraft:heightmaps" => "minecraft:spawn", + other => other, + }) + } + None => v, + }; + cx.each(Ty::Chunk, |c| { + update(c, "Status", fix); + if let Some(retrogen) = c.get_mut("below_zero_retrogen") { + update(retrogen, "target_status", fix); + } + }); +} + +/// `LegacyDragonFightFix`. +fn legacy_dragon_fight(cx: &mut Cx) { + cx.each(Ty::Level, |level| { + if level.get("DragonFight").is_some() { + return; + } + let legacy = level + .get("DimensionData") + .and_then(|d| d.get("1")) + .and_then(|d| d.get("DragonFight")) + .cloned() + .unwrap_or_else(super::dynamic::empty_map); + let mut fight = legacy; + update(&mut fight, "ExitPortalLocation", fix_block_pos); + set(level, "DragonFight", fight); + }); +} diff --git a/crates/horizon-world/src/datafix/mod.rs b/crates/horizon-world/src/datafix/mod.rs index a29fc0f21..1e046fced 100644 --- a/crates/horizon-world/src/datafix/mod.rs +++ b/crates/horizon-world/src/datafix/mod.rs @@ -13,6 +13,7 @@ pub mod dynamic; mod fixes_a; mod fixes_b; mod fixes_c; +mod fixes_old; pub mod files; mod items; pub mod json; @@ -25,8 +26,9 @@ use schema::{Key, Ty, key, walk}; /// The DataVersion of the game. pub const CURRENT: i32 = crate::DATA_VERSION; -/// Data saved before this DataVersion (1.20) needs fixes that are not ported. -pub const OLDEST_SUPPORTED: i32 = 3463; +/// Data saved before this DataVersion (1.18.2 is 2975) needs fixes that are not +/// ported (2967 and 2970, and everything before). +pub const OLDEST_SUPPORTED: i32 = 2970; /// `Identifier.tryParse` validity, as `NamespacedSchema.ensureNamespaced` uses it. pub fn identifier(id: &str) -> Option<(String, String)> { @@ -103,7 +105,7 @@ impl Cx<'_> { /// from that read. Each entity keeps that map under this key while fixes run. const LAST_READ: &str = "\u{0}last_read"; -/// Remember an entity's current fields as the map it was read from. +/// Remember a record's current fields as the map it was read from. pub fn mark_read(e: &mut Tag) { if let Tag::Compound(_) = e { let mut raw = e.clone(); @@ -116,7 +118,13 @@ pub fn mark_read(e: &mut Tag) { /// written and read again with the output schema, so it (and every entity inside /// it) now remembers its current fields as the map it was last read from. pub fn reread(k: Key, e: &mut Tag) { - walk(Ty::Entity, e, k, Ty::Entity, &mut mark_read); + reread_as(Ty::Entity, k, e); +} + +/// [`reread`] for a value of another type (a block entity). +pub fn reread_as(ty: Ty, k: Key, v: &mut Tag) { + walk(ty, v, k, Ty::BlockEntity, &mut mark_read); + walk(ty, v, k, Ty::Entity, &mut mark_read); } /// A typed field dropped from an entity: what writing the entity gives back for @@ -158,9 +166,10 @@ pub fn renamer<'a>(table: &'a [(&'a str, &'static str)]) -> impl Fn(&str) -> Opt type FixFn = fn(&mut Cx); -/// Every fix from the 1.20 schemas on, in DataFixers order. +/// Every ported fix (from the 1.19 schemas on), in DataFixers order. fn fixes() -> Vec<(Key, FixFn)> { let mut out = Vec::new(); + fixes_old::register(&mut out); fixes_a::register(&mut out); fixes_b::register(&mut out); fixes_c::register(&mut out); @@ -175,6 +184,7 @@ pub fn update(root: Ty, data: &mut Tag, from: i32, to: i32) { let from_key = key(from.max(0) as u32, 0); let to_version = to as u32; // The data is read once with the schema of its version (its read hooks)... + walk(root, data, from_key, Ty::BlockEntity, &mut mark_read); walk(root, data, from_key, Ty::Entity, &mut mark_read); read_hooks(root, data, from_key); // ...then every fix above that key, up to the target version... diff --git a/crates/horizon-world/src/datafix/schema.rs b/crates/horizon-world/src/datafix/schema.rs index 33d0963db..5515b6bae 100644 --- a/crates/horizon-world/src/datafix/schema.rs +++ b/crates/horizon-world/src/datafix/schema.rs @@ -509,12 +509,14 @@ impl Walker<'_> { self.field(Ty::ItemStack, s, side); } } - } else { + } else if k >= key(3448, 0) { self.list(Ty::ItemName, v, "sherds"); + } else { + self.list(Ty::ItemName, v, "shards"); } self.field(Ty::ItemStack, v, "item"); } - "minecraft:brushable_block" => self.field(Ty::ItemStack, v, "item"), + "minecraft:brushable_block" | "minecraft:suspicious_sand" => self.field(Ty::ItemStack, v, "item"), "minecraft:trial_spawner" if k >= key(3689, 0) => { if let Some(Tag::List(items)) = v.get_mut("spawn_potentials") { for p in items { @@ -749,6 +751,12 @@ impl Walker<'_> { pub fn block_entity_known(be: &Tag, k: Key) -> bool { let id = namespaced(&as_str(be.get("id")).unwrap_or_default()); let since = match id.as_str() { + "minecraft:sculk_catalyst" => key(3076, 0), + "minecraft:sculk_shrieker" => key(3078, 0), + "minecraft:hanging_sign" => key(3202, 0), + "minecraft:chiseled_bookshelf" => key(3204, 0), + "minecraft:decorated_pot" => key(3327, 0), + "minecraft:suspicious_sand" => return (key(3327, 0)..key(3438, 0)).contains(&k), "minecraft:crafter" => key(3682, 0), "minecraft:trial_spawner" => key(3689, 0), "minecraft:vault" => key(3807, 0), @@ -758,7 +766,6 @@ pub fn block_entity_known(be: &Tag, k: Key) -> bool { "minecraft:shelf" => key(4533, 0), "minecraft:potent_sulfur" => key(4881, 0), "minecraft:bed" => return k < key(4885, 0), - "minecraft:suspicious_sand" => return k < key(3438, 0), "minecraft:brushable_block" | "minecraft:calibrated_sculk_sensor" => key(3438, 0), _ => 0, }; diff --git a/tools/datafix_scene.py b/tools/datafix_scene.py index 5a5fd8fda..7f0e047e9 100644 --- a/tools/datafix_scene.py +++ b/tools/datafix_scene.py @@ -58,6 +58,7 @@ ITEMS_A = [ '{id:"minecraft:chest",Count:1b,tag:{BlockEntityTag:{LootTable:"minecraft:chests/simple_dungeon",LootTableSeed:5L}}}', '{id:"minecraft:pig_spawn_egg",Count:1b,tag:{EntityTag:{CustomName:\'"Babe"\',Age:-24000}}}', '{id:"minecraft:armor_stand",Count:1b,tag:{EntityTag:{Small:1b}}}', + '{id:"minecraft:pig_spawn_egg",Count:1b,tag:{EntityTag:{id:"minecraft:cow"}}}', '{id:"minecraft:leather_chestplate",Count:1b,tag:{display:{color:16711680},' 'Trim:{material:"minecraft:gold",pattern:"minecraft:coast"}}}', '{id:"minecraft:goat_horn",Count:1b,tag:{instrument:"minecraft:sing_goat_horn"}}', @@ -123,6 +124,8 @@ 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 3218 <= version < 3440: + packs.append('update_1_20') if 3698 <= version < 3939: packs.append('update_1_21') if 3700 <= version < 4067: @@ -137,11 +140,27 @@ def items(e, version=None): 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] + return [v for v in (versioned(s, version) for s in stacks) if available(v, version)] + + +# Items era A worlds older than each DataVersion do not have. +ITEM_SINCE = { + 'minecraft:goat_horn': 3105, + 'minecraft:decorated_pot': 3327, +} + + +def available(stack, version): + return all(version >= since for item, since in ITEM_SINCE.items() if f'"{item}"' in stack) def versioned(stack, version): """Rewrite the components whose format changed inside an era.""" + if version < 3448: # 1.19.4: pots hold shards, sherds were pottery_shard_* + stack = (stack.replace('sherds:', 'shards:') + .replace('"minecraft:angler_pottery_sherd"', '"minecraft:pottery_shard_prize"') + .replace('"minecraft:arms_up_pottery_sherd"', '"minecraft:pottery_shard_arms_up"') + .replace('"minecraft:skull_pottery_sherd"', '"minecraft:pottery_shard_skull"')) if version >= 4541: # chain renamed to iron_chain stack = stack.replace('"minecraft:chain"', '"minecraft:iron_chain"') if '"minecraft:attribute_modifiers"' in stack: @@ -184,8 +203,13 @@ def block_entities(e, version): 'is_waxed:1b}') sign_c = ('{front_text:{messages:[{text:"one"},"two","",""],color:"red",has_glowing_text:1b},' 'back_text:{messages:["b","","",""]},is_waxed:1b}') - sign = sign_c if e == C else sign_a - out += [('oak_sign', sign), ('oak_hanging_sign', sign)] + # Before 1.20 (3439) a sign has one side of loose Text fields. + sign_old = ('{Text1:\'{"text":"one"}\',Text2:\'"two"\',Text3:\'""\',Text4:\'""\',Color:"red",GlowingText:1b,' + 'FilteredText1:\'"x"\'}') + sign = sign_c if e == C else sign_a if version >= 3439 else sign_old + out.append(('oak_sign', sign)) + if version >= 3218: # hanging signs: 1.19.3 with the 1.20 experiment + out.append(('oak_hanging_sign', sign)) if e == A: out += [ ('white_banner', '{Patterns:[{Pattern:"cre",Color:15}],CustomName:\'{"translate":"block.minecraft.ominous_banner"}\'}'), @@ -210,6 +234,9 @@ def block_entities(e, 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. + since = {'decorated_pot': 3327, 'suspicious_sand': 3327, 'chiseled_bookshelf': 3218} + out = [(b, versioned(nbt, version)) for b, nbt in out if version >= since.get(b, 0)] else: out += [ ('white_banner', '{patterns:[{pattern:"minecraft:creeper",color:"black"}],CustomName:%s}' % name("Flag")), @@ -276,7 +303,17 @@ def entities(e, version): ('piglin', 'Inventory:[{id:"minecraft:gold_ingot",Count:2b}]'), ('firework_rocket', 'FireworksItem:{id:"minecraft:firework_rocket",Count:1b,tag:{Fireworks:{Flight:1b}}}'), ('allay', 'Inventory:[{id:"minecraft:diamond",Count:1b}]'), + ('goat', ''), ] + since = {'allay': 3105, 'chest_boat': 3105, 'text_display': 3325, 'item_display': 3325} + out = [(k, x) for k, x in out if version >= since.get(k, 0)] + 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 + out.append(('pig', 'ActiveEffects:[{Id:33b,Amplifier:0b,Duration:200,ShowParticles:1b,' + 'FactorCalculationData:{padding_duration:22,factor_start:0.0f,factor_target:1.0f,' + 'factor_current:0.0f,effect_changed_timestamp:5,factor_previous_frame:0.0f,' + 'had_effect_last_tick:0b}}]')) return out sword = '{id:"minecraft:iron_sword",count:1}' helmet = '{id:"minecraft:iron_helmet",count:1}' diff --git a/tools/datafix_worlds.py b/tools/datafix_worlds.py index 1b9553977..985881985 100644 --- a/tools/datafix_worlds.py +++ b/tools/datafix_worlds.py @@ -33,8 +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.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'] +VERSIONS = ['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'] MANIFEST = 'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json' BOT = 'Upgrader' UUID_BASE = 0x6000 @@ -163,7 +163,13 @@ class Bot: self.protocol = protocol self.stop = threading.Event() self.send(0, varint(protocol) + mcstring('127.0.0.1') + struct.pack('>H', port) + varint(2)) - if protocol <= 763: # 1.20.1: optional UUID + if protocol <= 758: # 1.18.2: the name only + self.send(0, mcstring(name)) + elif protocol == 759: # 1.19: no signature data + self.send(0, mcstring(name) + b'\x00') + elif protocol == 760: # 1.19.2: no signature data, optional UUID + self.send(0, mcstring(name) + b'\x00' + b'\x01' + offline_uuid(name).bytes) + elif protocol <= 763: # 1.19.3 - 1.20.1: optional UUID self.send(0, mcstring(name) + b'\x01' + offline_uuid(name).bytes) else: self.send(0, mcstring(name) + offline_uuid(name).bytes)