diff --git a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/ModDatabase.java b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/ModDatabase.java index bca8c73..968b986 100644 --- a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/ModDatabase.java +++ b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/ModDatabase.java @@ -15,12 +15,13 @@ import com.mojang.datafixers.DataFixerBuilder; import com.mojang.datafixers.schemas.Schema; import com.mojang.datafixers.types.templates.TypeTemplate; +import com.mojang.serialization.Dynamic; import net.fabricmc.loader.api.FabricLoader; import net.modificationstation.stationapi.api.datafixer.DataFixers; import net.modificationstation.stationapi.api.datafixer.TypeReferences; import net.modificationstation.stationapi.api.registry.ModID; -import io.github.betterthanupdates.apron.stapi.dataconverter.fixer.BlockIdFixer; +import io.github.betterthanupdates.apron.stapi.dataconverter.fixer.BlockStateFixer; import io.github.betterthanupdates.apron.stapi.dataconverter.fixer.EntityIdFixer; import io.github.betterthanupdates.apron.stapi.dataconverter.fixer.ItemIdFixer; @@ -48,7 +49,7 @@ public DataFixer apply(Executor executor) { Schema schema = builder.addSchema(1, this::baseSchema); builder.addFixer(new ItemIdFixer(this, schema)); builder.addFixer(new EntityIdFixer(this, schema)); - builder.addFixer(new BlockIdFixer(this, schema)); + builder.addFixer(new BlockStateFixer(this, schema)); return builder.buildOptimized(Set.of(TypeReferences.LEVEL), executor); } @@ -139,4 +140,16 @@ public void entitySchema(Schema schema, Map> map) schema.registerSimple(map, entry.getValue()); } } + + public Dynamic blockState(String id, Dynamic dynamic) { + return dynamic; + } + + public boolean hasBlockOld(String id) { + return this.BLOCKS.containsKey(id); + } + + public boolean hasBlockNew(String id) { + return this.BLOCKS.containsValue(id); + } } diff --git a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockIdFixer.java b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockStateFixer.java similarity index 57% rename from apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockIdFixer.java rename to apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockStateFixer.java index d6b5d3c..a39ae45 100644 --- a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockIdFixer.java +++ b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/fixer/BlockStateFixer.java @@ -1,7 +1,5 @@ package io.github.betterthanupdates.apron.stapi.dataconverter.fixer; -import static net.modificationstation.stationapi.impl.vanillafix.datafixer.VanillaDataFixerImpl.STATION_ID; - import com.mojang.datafixers.DataFix; import com.mojang.datafixers.TypeRewriteRule; import com.mojang.datafixers.schemas.Schema; @@ -10,9 +8,9 @@ import io.github.betterthanupdates.apron.stapi.dataconverter.ModDatabase; -public class BlockIdFixer extends DataFix { +public class BlockStateFixer extends DataFix { private final ModDatabase database; - public BlockIdFixer(ModDatabase database, Schema outputSchema) { + public BlockStateFixer(ModDatabase database, Schema outputSchema) { super(outputSchema, false); this.database = database; } @@ -20,14 +18,24 @@ public BlockIdFixer(ModDatabase database, Schema outputSchema) { @Override protected TypeRewriteRule makeRule() { return writeFixAndRead( - this.database.getName() + "_BlockStateIdFix", + this.database.getName() + "_BlockStateFix", getInputSchema().getType(TypeReferences.BLOCK_STATE), getOutputSchema().getType(TypeReferences.BLOCK_STATE), - dynamic -> dynamic.get("Name").result().>map( - value -> dynamic.set("Name", dynamic.createString( - this.database.block(value.asString("minecraft:air")) - )) - ).orElse(dynamic) + dynamic -> { + var dyn = dynamic.get("Name").result(); + + String id = "minecraft:air"; + + if (dyn.isPresent()) { + id = dyn.get().asString("minecraft:air"); + } + + dynamic = dynamic.set("Name", dynamic.createString(this.database.block(id))); + + dynamic = this.database.blockState(id, dynamic); + + return dynamic; + } ); } } diff --git a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/stonewall/StoneWallDatabase.java b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/stonewall/StoneWallDatabase.java index 90f7a8c..6b9ad0a 100644 --- a/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/stonewall/StoneWallDatabase.java +++ b/apron-stapi/src/main/java/io/github/betterthanupdates/apron/stapi/dataconverter/stonewall/StoneWallDatabase.java @@ -2,8 +2,12 @@ import java.util.Properties; +import com.mojang.serialization.Dynamic; +import net.modificationstation.stationapi.api.nbt.NbtOps; import net.modificationstation.stationapi.api.registry.ModID; +import net.minecraft.util.io.CompoundTag; + import io.github.betterthanupdates.apron.stapi.dataconverter.ModDatabase; public class StoneWallDatabase extends ModDatabase { @@ -21,4 +25,19 @@ public void register() { blockAndItem(config.getProperty("blockbrickWallID", "248"), "brick_wall"); blockAndItem(config.getProperty("blockSandstoneWallID", "247"), "sandstone_wall"); } + + @Override + public Dynamic blockState(String id, Dynamic dynamic) { + if (this.hasBlockOld(id)) { + CompoundTag tag = new CompoundTag(); + tag.put("east", "none"); + tag.put("north", "none"); + tag.put("west", "none"); + tag.put("south", "none"); + tag.put("up", false); + dynamic = dynamic.set("Properties", new Dynamic<>(NbtOps.INSTANCE, tag)); + } + + return super.blockState(id, dynamic); + } }