Started DataPack Handling

This commit is contained in:
Frank 2022-05-23 01:01:48 +02:00
parent dd0c259b56
commit 781d6d4709
8 changed files with 103 additions and 9 deletions

View file

@ -7,7 +7,11 @@ import org.betterx.bclib.BCLib;
import org.betterx.bclib.interfaces.BiomeSourceAccessor; import org.betterx.bclib.interfaces.BiomeSourceAccessor;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.List;
import java.util.Set; import java.util.Set;
@Mixin(BiomeSource.class) @Mixin(BiomeSource.class)
@ -21,4 +25,14 @@ public abstract class BiomeSourceMixin implements BiomeSourceAccessor {
BCLib.LOGGER.info("Rebuilding features in BiomeSource " + this); BCLib.LOGGER.info("Rebuilding features in BiomeSource " + this);
//featuresPerStep = Suppliers.memoize(() -> FeatureSorter.buildFeaturesPerStep(this.possibleBiomes().stream().toList(), true)); //featuresPerStep = Suppliers.memoize(() -> FeatureSorter.buildFeaturesPerStep(this.possibleBiomes().stream().toList(), true));
} }
@Inject(method = "<init>(Ljava/util/List;)V", at = @At("TAIL"))
public void bcl_init(List list, CallbackInfo ci) {
System.out.println("new BiomeSource (" + Integer.toHexString(hashCode()) + ", biomes=" + possibleBiomes().size() + ")");
if (possibleBiomes().size() == 27) {
System.out.println("Nether????");
} else if (possibleBiomes().size() == 2) {
System.out.println("Datapack Nether???");
}
}
} }

View file

@ -22,14 +22,14 @@ public class MultiPackResourceManagerMixin {
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true) @Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Optional<Resource>> info) { private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Optional<Resource>> info) {
// if (resourceLocation.getNamespace().equals("minecraft")) { if (resourceLocation.getNamespace().equals("minecraft")) {
// for (String key : BCLIB_MISSING_RESOURCES) { for (String key : BCLIB_MISSING_RESOURCES) {
// if (resourceLocation.getPath().equals(key)) { if (resourceLocation.getPath().equals(key)) {
// info.setReturnValue(Optional.empty()); // info.setReturnValue(Optional.empty());
// info.cancel(); // info.cancel();
// return; return;
// } }
// } }
// } }
} }
} }

View file

@ -0,0 +1,26 @@
package org.betterx.bclib.mixin.common;
import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
import net.minecraft.world.level.dimension.LevelStem;
import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.PrimaryLevelData;
import org.betterx.bclib.presets.worldgen.WorldPresets;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
@Mixin(PrimaryLevelData.class)
public class PrimaryLevelDataMixin {
@Shadow
private LevelSettings settings;
@ModifyArg(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/storage/PrimaryLevelData;<init>(Lcom/mojang/datafixers/DataFixer;ILnet/minecraft/nbt/CompoundTag;ZIIIFJJIIIZIZZZLnet/minecraft/world/level/border/WorldBorder$Settings;IILjava/util/UUID;Ljava/util/Set;Lnet/minecraft/world/level/timers/TimerQueue;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/nbt/CompoundTag;Lnet/minecraft/world/level/LevelSettings;Lnet/minecraft/world/level/levelgen/WorldGenSettings;Lcom/mojang/serialization/Lifecycle;)V"))
private static WorldGenSettings bcl_fixSettings(WorldGenSettings settings) {
settings = WorldPresets.fixSettingsInCurrentWorld(LevelStem.NETHER, BuiltinDimensionTypes.NETHER, settings);
settings = WorldPresets.fixSettingsInCurrentWorld(LevelStem.END, BuiltinDimensionTypes.END, settings);
return settings;
}
}

View file

@ -3,12 +3,20 @@ package org.betterx.bclib.mixin.common;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows; import net.minecraft.client.gui.screens.worldselection.WorldOpenFlows;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.RegistryOps;
import net.minecraft.server.ReloadableServerResources; import net.minecraft.server.ReloadableServerResources;
import net.minecraft.server.WorldLoader;
import net.minecraft.server.WorldStem;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.level.DataPackConfig;
import net.minecraft.world.level.LevelSettings; import net.minecraft.world.level.LevelSettings;
import net.minecraft.world.level.levelgen.WorldGenSettings; import net.minecraft.world.level.levelgen.WorldGenSettings;
import net.minecraft.world.level.storage.LevelStorageSource; import net.minecraft.world.level.storage.LevelStorageSource;
import net.minecraft.world.level.storage.WorldData; import net.minecraft.world.level.storage.WorldData;
import com.mojang.datafixers.util.Pair;
import org.betterx.bclib.api.LifeCycleAPI; import org.betterx.bclib.api.LifeCycleAPI;
import org.betterx.bclib.api.biomes.BiomeAPI; import org.betterx.bclib.api.biomes.BiomeAPI;
import org.betterx.bclib.api.dataexchange.DataExchangeAPI; import org.betterx.bclib.api.dataexchange.DataExchangeAPI;
@ -20,6 +28,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(WorldOpenFlows.class) @Mixin(WorldOpenFlows.class)
public abstract class WorldOpenFlowsMixin { public abstract class WorldOpenFlowsMixin {
@ -77,4 +86,24 @@ public abstract class WorldOpenFlowsMixin {
DataFixerAPI.createWorldData(levelStorageAccess, worldData.worldGenSettings()); DataFixerAPI.createWorldData(levelStorageAccess, worldData.worldGenSettings());
LifeCycleAPI._runBeforeLevelLoad(); LifeCycleAPI._runBeforeLevelLoad();
} }
@Inject(method = "loadWorldStem(Lnet/minecraft/server/WorldLoader$PackConfig;Lnet/minecraft/server/WorldLoader$WorldDataSupplier;)Lnet/minecraft/server/WorldStem;", at = @At("RETURN"))
public void bcl_loadWorldStem(WorldLoader.PackConfig packConfig,
WorldLoader.WorldDataSupplier<WorldData> worldDataSupplier,
CallbackInfoReturnable<WorldStem> cir) {
WorldStem result = cir.getReturnValue();
}
@Inject(method = "method_41887", at = @At("RETURN"))
private static void bcl_loadWorldStem(LevelStorageSource.LevelStorageAccess levelStorageAccess,
ResourceManager resourceManager,
DataPackConfig dataPackConfig,
CallbackInfoReturnable<Pair> cir) {
RegistryAccess.Writable writable = RegistryAccess.builtinCopy();
RegistryOps<Tag> dynamicOps = RegistryOps.create(NbtOps.INSTANCE, writable);
WorldData worldData = levelStorageAccess.getDataTag(dynamicOps,
dataPackConfig,
writable.allElementsLifecycle());
Pair<WorldData, RegistryAccess> p = cir.getReturnValue();
}
} }

View file

@ -132,6 +132,29 @@ public class WorldPresets {
return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong()); return createDefaultWorldFromPreset(registryAccess, RandomSource.create().nextLong());
} }
public static WorldGenSettings fixSettingsInCurrentWorld(ResourceKey<LevelStem> dimensionKey,
ResourceKey<DimensionType> dimensionTypeKey,
WorldGenSettings settings) {
var oldNether = settings.dimensions().getHolder(dimensionKey);
//TODO: Make sure our BiomeSource reuses the BiomeList from the Datapack Source
int loaderVersion = BCLChunkGenerator.getBiomeVersionForGenerator(oldNether
.map(h -> h.value().generator())
.orElse(null));
int targetVersion = BCLChunkGenerator.getBiomeVersionForCurrentWorld(dimensionKey);
if (loaderVersion != targetVersion) {
BCLib.LOGGER.info("Enforcing Correct Generator for " + dimensionKey.location().toString() + ".");
RegistryAccess access = RegistryAccess.builtinCopy();
return WorldPresets.replaceGenerator(dimensionKey,
dimensionTypeKey,
targetVersion,
access,
settings);
}
return settings;
}
public static WorldGenSettings replaceGenerator( public static WorldGenSettings replaceGenerator(
ResourceKey<LevelStem> dimensionKey, ResourceKey<LevelStem> dimensionKey,
ResourceKey<DimensionType> dimensionTypeKey, ResourceKey<DimensionType> dimensionTypeKey,

View file

@ -256,6 +256,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
@Override @Override
public String toString() { public String toString() {
return "BCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ")"; return "BCLib - The End BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", biomes=" + possibleBiomes().size() + ")";
} }
} }

View file

@ -176,6 +176,6 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
@Override @Override
public String toString() { public String toString() {
return "BCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ")"; return "BCLib - Nether BiomeSource (" + Integer.toHexString(hashCode()) + ", version=" + biomeSourceVersion + ", seed=" + currentSeed + ", biomes=" + possibleBiomes().size() + ")";
} }
} }

View file

@ -23,6 +23,7 @@
"MainMixin", "MainMixin",
"MinecraftServerMixin", "MinecraftServerMixin",
"MobSpawnSettingsAccessor", "MobSpawnSettingsAccessor",
"MultiPackResourceManagerMixin",
"NetherBiomeDataMixin", "NetherBiomeDataMixin",
"NoiseBasedChunkGeneratorMixin", "NoiseBasedChunkGeneratorMixin",
"NoiseGeneratorSettingsMixin", "NoiseGeneratorSettingsMixin",
@ -30,6 +31,7 @@
"PortalShapeMixin", "PortalShapeMixin",
"PotionBrewingAccessor", "PotionBrewingAccessor",
"PresetEditorMixin", "PresetEditorMixin",
"PrimaryLevelDataMixin",
"RecipeManagerAccessor", "RecipeManagerAccessor",
"RecipeManagerMixin", "RecipeManagerMixin",
"ServerLevelMixin", "ServerLevelMixin",