diff --git a/src/main/java/com/jsorrell/skyblock/datafixer/Schema2551.java b/src/main/java/com/jsorrell/skyblock/datafixer/Schema2551.java new file mode 100644 index 00000000..86cfc470 --- /dev/null +++ b/src/main/java/com/jsorrell/skyblock/datafixer/Schema2551.java @@ -0,0 +1,43 @@ +package com.jsorrell.skyblock.datafixer; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import net.minecraft.datafixer.TypeReferences; +import net.minecraft.datafixer.schema.IdentifierNormalizingSchema; + +import java.util.Map; +import java.util.function.Supplier; + +public class Schema2551 extends IdentifierNormalizingSchema { + public Schema2551(int versionKey, Schema parent) { + super(versionKey, parent); + } + + @Override + public void registerTypes(Schema schema, Map> entityTypes, Map> blockEntityTypes) { + super.registerTypes(schema, entityTypes, blockEntityTypes); + schema.registerType(false, TypeReferences.WORLD_GEN_SETTINGS, () -> { + return DSL.fields("dimensions", DSL.compoundList(DSL.constType(getIdentifierType()), DSL.fields("generator", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:debug", DSL::remainder, "minecraft:flat", () -> { + return DSL.optionalFields("settings", DSL.optionalFields("biome", TypeReferences.BIOME.in(schema), "layers", DSL.list(DSL.optionalFields("block", TypeReferences.BLOCK_NAME.in(schema))))); + }, "minecraft:noise", () -> { + return DSL.optionalFields("biome_source", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:fixed", () -> { + return DSL.fields("biome", TypeReferences.BIOME.in(schema)); + }, "minecraft:multi_noise", () -> { + return DSL.list(DSL.fields("biome", TypeReferences.BIOME.in(schema))); + }, "minecraft:checkerboard", () -> { + return DSL.fields("biomes", DSL.list(TypeReferences.BIOME.in(schema))); + }, "minecraft:vanilla_layered", DSL::remainder, "minecraft:the_end", DSL::remainder)), "settings", DSL.or(DSL.constType(DSL.string()), DSL.optionalFields("default_block", TypeReferences.BLOCK_NAME.in(schema), "default_fluid", TypeReferences.BLOCK_NAME.in(schema)))); + }, "minecraft:skyblock", () -> { // Add minecraft:skyblock as valid option + return DSL.optionalFields("biome_source", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:fixed", () -> { + return DSL.fields("biome", TypeReferences.BIOME.in(schema)); + }, "minecraft:multi_noise", () -> { + return DSL.list(DSL.fields("biome", TypeReferences.BIOME.in(schema))); + }, "minecraft:checkerboard", () -> { + return DSL.fields("biomes", DSL.list(TypeReferences.BIOME.in(schema))); + }, "minecraft:vanilla_layered", DSL::remainder, "minecraft:the_end", DSL::remainder)), "settings", DSL.or(DSL.constType(DSL.string()), DSL.optionalFields("default_block", TypeReferences.BLOCK_NAME.in(schema), "default_fluid", TypeReferences.BLOCK_NAME.in(schema)))); + }))))); + }); + } +} diff --git a/src/main/java/com/jsorrell/skyblock/datafixer/Schema2832.java b/src/main/java/com/jsorrell/skyblock/datafixer/Schema2832.java new file mode 100644 index 00000000..c6781877 --- /dev/null +++ b/src/main/java/com/jsorrell/skyblock/datafixer/Schema2832.java @@ -0,0 +1,46 @@ +package com.jsorrell.skyblock.datafixer; + +import com.google.common.collect.ImmutableMap; +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import net.minecraft.datafixer.TypeReferences; +import net.minecraft.datafixer.schema.IdentifierNormalizingSchema; + +import java.util.Map; +import java.util.function.Supplier; + +public class Schema2832 extends IdentifierNormalizingSchema { + public Schema2832(int versionKey, Schema parent) { + super(versionKey, parent); + } + + @Override + public void registerTypes(Schema schema, Map> entityTypes, Map> blockEntityTypes) { + super.registerTypes(schema, entityTypes, blockEntityTypes); + schema.registerType(false, TypeReferences.CHUNK, () -> { + return DSL.fields("Level", DSL.optionalFields("Entities", DSL.list(TypeReferences.ENTITY_TREE.in(schema)), "TileEntities", DSL.list(DSL.or(TypeReferences.BLOCK_ENTITY.in(schema), DSL.remainder())), "TileTicks", DSL.list(DSL.fields("i", TypeReferences.BLOCK_NAME.in(schema))), "Sections", DSL.list(DSL.optionalFields("biomes", DSL.optionalFields("palette", DSL.list(TypeReferences.BIOME.in(schema))), "block_states", DSL.optionalFields("palette", DSL.list(TypeReferences.BLOCK_STATE.in(schema))))), "Structures", DSL.optionalFields("Starts", DSL.compoundList(TypeReferences.STRUCTURE_FEATURE.in(schema))))); + }); + schema.registerType(false, TypeReferences.WORLD_GEN_SETTINGS, () -> { + return DSL.fields("dimensions", DSL.compoundList(DSL.constType(getIdentifierType()), DSL.fields("generator", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:debug", DSL::remainder, "minecraft:flat", () -> { + return DSL.optionalFields("settings", DSL.optionalFields("biome", TypeReferences.BIOME.in(schema), "layers", DSL.list(DSL.optionalFields("block", TypeReferences.BLOCK_NAME.in(schema))))); + }, "minecraft:noise", () -> { + return DSL.optionalFields("biome_source", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:fixed", () -> { + return DSL.fields("biome", TypeReferences.BIOME.in(schema)); + }, "minecraft:multi_noise", () -> { + return DSL.or(DSL.fields("preset", getIdentifierType().template()), DSL.list(DSL.fields("biome", TypeReferences.BIOME.in(schema)))); + }, "minecraft:checkerboard", () -> { + return DSL.fields("biomes", DSL.list(TypeReferences.BIOME.in(schema))); + }, "minecraft:the_end", DSL::remainder)), "settings", DSL.or(DSL.constType(DSL.string()), DSL.optionalFields("default_block", TypeReferences.BLOCK_NAME.in(schema), "default_fluid", TypeReferences.BLOCK_NAME.in(schema)))); + }, "minecraft:skyblock", () -> { // Add minecraft:skyblock as valid option + return DSL.optionalFields("biome_source", DSL.taggedChoiceLazy("type", DSL.string(), ImmutableMap.of("minecraft:fixed", () -> { + return DSL.fields("biome", TypeReferences.BIOME.in(schema)); + }, "minecraft:multi_noise", () -> { + return DSL.or(DSL.fields("preset", getIdentifierType().template()), DSL.list(DSL.fields("biome", TypeReferences.BIOME.in(schema)))); + }, "minecraft:checkerboard", () -> { + return DSL.fields("biomes", DSL.list(TypeReferences.BIOME.in(schema))); + }, "minecraft:the_end", DSL::remainder)), "settings", DSL.or(DSL.constType(DSL.string()), DSL.optionalFields("default_block", TypeReferences.BLOCK_NAME.in(schema), "default_fluid", TypeReferences.BLOCK_NAME.in(schema)))); + }))))); + }); + } +} diff --git a/src/main/java/com/jsorrell/skyblock/mixin/MissingDimensionFixMixin.java b/src/main/java/com/jsorrell/skyblock/mixin/MissingDimensionFixMixin.java new file mode 100644 index 00000000..5943a4d0 --- /dev/null +++ b/src/main/java/com/jsorrell/skyblock/mixin/MissingDimensionFixMixin.java @@ -0,0 +1,30 @@ +package com.jsorrell.skyblock.mixin; + +import com.mojang.datafixers.DataFix; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.Type; +import net.minecraft.datafixer.fix.MissingDimensionFix; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +import java.util.HashMap; +import java.util.Map; + +@Mixin(MissingDimensionFix.class) +public abstract class MissingDimensionFixMixin extends DataFix { + public MissingDimensionFixMixin(Schema outputSchema, boolean changesType) { + super(outputSchema, changesType); + } + + @ModifyArg(method = "makeRule", + at = @At(value = "INVOKE", + target = "Lcom/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType;(Ljava/lang/String;Lcom/mojang/datafixers/types/Type;Ljava/util/Map;)V", + ordinal = 0), + index = 2) + private Map> modifyTypes(Map> types) { + Map> newTypes = new HashMap<>(types); + newTypes.put("minecraft:skyblock", types.get("minecraft:noise")); + return newTypes; + } +} diff --git a/src/main/java/com/jsorrell/skyblock/mixin/SchemasMixin.java b/src/main/java/com/jsorrell/skyblock/mixin/SchemasMixin.java new file mode 100644 index 00000000..6b6e85aa --- /dev/null +++ b/src/main/java/com/jsorrell/skyblock/mixin/SchemasMixin.java @@ -0,0 +1,36 @@ +package com.jsorrell.skyblock.mixin; + +import com.jsorrell.skyblock.datafixer.Schema2551; +import com.jsorrell.skyblock.datafixer.Schema2832; +import com.mojang.datafixers.schemas.Schema; +import net.minecraft.datafixer.Schemas; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +import java.util.function.BiFunction; + +@Mixin(Schemas.class) +public abstract class SchemasMixin { + @ModifyArg( + method = "build", + at = @At(value = "INVOKE", + target = "Lcom/mojang/datafixers/DataFixerBuilder;addSchema(ILjava/util/function/BiFunction;)Lcom/mojang/datafixers/schemas/Schema;", + ordinal = 112), + index = 1 + ) + private static BiFunction replaceSchema2551(BiFunction factory) { + return Schema2551::new; + } + + @ModifyArg( + method = "build", + at = @At(value = "INVOKE", + target = "Lcom/mojang/datafixers/DataFixerBuilder;addSchema(ILjava/util/function/BiFunction;)Lcom/mojang/datafixers/schemas/Schema;", + ordinal = 136), + index = 1 + ) + private static BiFunction replaceSchema2832(BiFunction factory) { + return Schema2832::new; + } +} diff --git a/src/main/java/com/jsorrell/skyblock/mixin/WorldGenSettingsHeightAndBiomeFixMixin.java b/src/main/java/com/jsorrell/skyblock/mixin/WorldGenSettingsHeightAndBiomeFixMixin.java new file mode 100644 index 00000000..df521345 --- /dev/null +++ b/src/main/java/com/jsorrell/skyblock/mixin/WorldGenSettingsHeightAndBiomeFixMixin.java @@ -0,0 +1,15 @@ +package com.jsorrell.skyblock.mixin; + +import net.minecraft.datafixer.fix.WorldGenSettingsHeightAndBiomeFix; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(WorldGenSettingsHeightAndBiomeFix.class) +public class WorldGenSettingsHeightAndBiomeFixMixin { + @Redirect(method = "method_38834(ZZLcom/mojang/serialization/Dynamic;)Lcom/mojang/serialization/Dynamic;", + at = @At(value = "INVOKE", target = "Ljava/lang/String;equals(Ljava/lang/Object;)Z")) + private static boolean datafixSkyBlock(String s1, Object s2) { + return s1.equals(s2) || "minecraft:skyblock".equals(s2); + } +} diff --git a/src/main/resources/skyblock.mixins.json b/src/main/resources/skyblock.mixins.json index 331e23df..986a41d5 100644 --- a/src/main/resources/skyblock.mixins.json +++ b/src/main/resources/skyblock.mixins.json @@ -16,12 +16,15 @@ "LightningEntityMixin", "LivingEntityMixin", "MinecraftServerMixin", + "MissingDimensionFixMixin", "RamImpactTaskMixin", "SaplingBlockMixin", + "SchemasMixin", "SinglePoolElementAccessor", "SpawnRestrictionAccessor", "SpiderEntityMixin", - "WanderingTraderEntityMixin" + "WanderingTraderEntityMixin", + "WorldGenSettingsHeightAndBiomeFixMixin" ], "client": [ "GeneratorTypeAccessor"