From 15a76350342165c52619cf6e6296c025949a94ff Mon Sep 17 00:00:00 2001 From: Alemiz Date: Fri, 23 Feb 2024 18:38:38 +0100 Subject: [PATCH] Add MCBE 1.20.70 updaters --- build.gradle.kts | 2 +- .../BlockStateUpdater_1_20_70.java | 44 +++++++++++++++++++ .../blockstateupdater/BlockStateUpdaters.java | 1 + .../tagupdater/CompoundTagUpdaterContext.java | 13 ++++-- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdater_1_20_70.java diff --git a/build.gradle.kts b/build.gradle.kts index 7f25b26..4e98256 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { id("signing") } -version = "1.20.60-SNAPSHOT" +version = "1.20.70-SNAPSHOT" group = "org.cloudburstmc" description = "Updates Minecraft: Bedrock Edition block states to the latest revision" diff --git a/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdater_1_20_70.java b/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdater_1_20_70.java new file mode 100644 index 0000000..670bb63 --- /dev/null +++ b/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdater_1_20_70.java @@ -0,0 +1,44 @@ +package org.cloudburstmc.blockstateupdater; + +import org.cloudburstmc.blockstateupdater.util.tagupdater.CompoundTagUpdaterContext; + +import java.util.Map; +import java.util.function.Function; + +public class BlockStateUpdater_1_20_70 implements BlockStateUpdater { + + public static final BlockStateUpdater INSTANCE = new BlockStateUpdater_1_20_70(); + + @Override + public void registerUpdaters(CompoundTagUpdaterContext ctx) { + this.addTypeUpdater(ctx, "minecraft:double_wooden_slab", "wood_type", type -> "minecraft:" + type + "_double_slab"); + this.addTypeUpdater(ctx, "minecraft:leaves", "old_leaf_type", type -> "minecraft:" + type + "_leaves"); + this.addTypeUpdater(ctx, "minecraft:leaves2", "new_leaf_type", type -> "minecraft:" + type + "_leaves"); + this.addTypeUpdater(ctx, "minecraft:wooden_slab", "wood_type", type -> "minecraft:" + type + "_slab"); + + ctx.addUpdater(1, 20, 70) + .match("name", "minecraft:wood") + .edit("states", helper -> { + Map states = helper.getCompoundTag(); + Object bit = states.remove("stripped_bit"); + boolean toggles = bit instanceof Byte && (byte) bit == 1 || bit instanceof Boolean && (boolean) bit; + + String type = (String) states.remove("wood_type"); + helper.getRootTag().put("name", toggles ? "minecraft:stripped_" + type + "_wood" : "minecraft:" + type + "_wood"); + }); + + // Vanilla does not use updater for this block for some reason + ctx.addUpdater(1, 20, 70, false, false) + .match("name", "minecraft:grass") + .edit("name", helper -> helper.replaceWith("name", "minecraft:grass_block")); + } + + private void addTypeUpdater(CompoundTagUpdaterContext context, String identifier, String typeState, Function rename) { + context.addUpdater(1, 20, 70) + .match("name", identifier) + .visit("states") + .edit(typeState, helper -> helper.getRootTag().put("name", rename.apply((String) helper.getTag()))) + .remove(typeState); + + } +} diff --git a/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdaters.java b/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdaters.java index 1da0001..42bcc33 100644 --- a/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdaters.java +++ b/src/main/java/org/cloudburstmc/blockstateupdater/BlockStateUpdaters.java @@ -38,6 +38,7 @@ public class BlockStateUpdaters { updaters.add(BlockStateUpdater_1_20_40.INSTANCE); updaters.add(BlockStateUpdater_1_20_50.INSTANCE); updaters.add(BlockStateUpdater_1_20_60.INSTANCE); + updaters.add(BlockStateUpdater_1_20_70.INSTANCE); CompoundTagUpdaterContext context = new CompoundTagUpdaterContext(); updaters.forEach(updater -> updater.registerUpdaters(context)); diff --git a/src/main/java/org/cloudburstmc/blockstateupdater/util/tagupdater/CompoundTagUpdaterContext.java b/src/main/java/org/cloudburstmc/blockstateupdater/util/tagupdater/CompoundTagUpdaterContext.java index 14b4d50..b45cb89 100644 --- a/src/main/java/org/cloudburstmc/blockstateupdater/util/tagupdater/CompoundTagUpdaterContext.java +++ b/src/main/java/org/cloudburstmc/blockstateupdater/util/tagupdater/CompoundTagUpdaterContext.java @@ -32,15 +32,22 @@ public CompoundTagUpdater.Builder addUpdater(int major, int minor, int patch) { return this.addUpdater(major, minor, patch, false); } - public CompoundTagUpdater.Builder addUpdater(int major, int minor, int patch, boolean ignoreVersion) { + public CompoundTagUpdater.Builder addUpdater(int major, int minor, int patch, boolean resetVersion) { + return this.addUpdater(major, minor, patch, resetVersion, true); + } + + public CompoundTagUpdater.Builder addUpdater(int major, int minor, int patch, boolean resetVersion, boolean bumpVersion) { int version = makeVersion(major, minor, patch); CompoundTagUpdater prevUpdater = this.getLatestUpdater(); int updaterVersion; - if (ignoreVersion || prevUpdater == null || baseVersion(prevUpdater.getVersion()) != version) { + if (resetVersion || prevUpdater == null || baseVersion(prevUpdater.getVersion()) != version) { updaterVersion = 0; } else { - updaterVersion = updaterVersion(prevUpdater.getVersion()) + 1; + updaterVersion = updaterVersion(prevUpdater.getVersion()); + if (bumpVersion) { + updaterVersion++; + } } version = mergeVersions(version, updaterVersion);