Skip to content

Commit

Permalink
[StAPI] StoneWall conversion is working now
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Nov 4, 2023
1 parent 9ab46ef commit 0756199
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -139,4 +140,16 @@ public void entitySchema(Schema schema, Map<String, Supplier<TypeTemplate>> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,24 +8,34 @@

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;
}

@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().<Dynamic<?>>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;
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}

0 comments on commit 0756199

Please sign in to comment.