Skip to content

Commit

Permalink
Add MCBE 1.20.70 updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alemiz112 committed Feb 23, 2024
1 parent 9fd6b58 commit 15a7635
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, Object> 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<String, String> 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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 15a7635

Please # to comment.