Datapack biome source fix
This commit is contained in:
parent
28228b35e2
commit
9e051d9ab9
4 changed files with 120 additions and 10 deletions
|
@ -4,8 +4,6 @@ import net.fabricmc.api.EnvType;
|
|||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.bclib.api.TagAPI;
|
||||
import ru.bclib.api.WorldDataAPI;
|
||||
import ru.bclib.api.dataexchange.DataExchangeAPI;
|
||||
|
@ -49,14 +47,6 @@ public class BCLib implements ModInitializer {
|
|||
));
|
||||
|
||||
Configs.save();
|
||||
|
||||
if (isDevEnvironment()) {
|
||||
BiomeAPI.registerEndLandBiome(BiomeAPI.getFromRegistry(Biomes.FOREST));
|
||||
BiomeAPI.registerEndLandBiome(BiomeAPI.getFromRegistry(Biomes.WARPED_FOREST));
|
||||
BiomeAPI.registerEndLandBiome(BiomeAPI.getFromRegistry(Biomes.TAIGA));
|
||||
BiomeAPI.registerEndLandBiome(BiomeAPI.getFromRegistry(Biomes.ICE_SPIKES));
|
||||
BiomeAPI.registerEndLandBiome(BiomeAPI.getFromRegistry(Biomes.MUSHROOM_FIELDS));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDevEnvironment() {
|
||||
|
|
80
src/main/java/ru/bclib/DataFixer.java
Normal file
80
src/main/java/ru/bclib/DataFixer.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
package ru.bclib;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import ru.bclib.api.datafixer.DataFixerAPI;
|
||||
import ru.bclib.api.datafixer.Patch;
|
||||
import ru.bclib.api.datafixer.PatchFunction;
|
||||
|
||||
public class DataFixer {
|
||||
private static final String NETHER_BIOME_SOURCE = "bclib:nether_biome_source";
|
||||
private static final String END_BIOME_SOURCE = "bclib:end_biome_source";
|
||||
|
||||
public static void register() {
|
||||
DataFixerAPI.registerPatch(() -> new BCLibPatch());
|
||||
}
|
||||
|
||||
private static final class BCLibPatch extends Patch {
|
||||
protected BCLibPatch() {
|
||||
super(BCLib.MOD_ID, "0.4.0");
|
||||
}
|
||||
|
||||
public PatchFunction<CompoundTag, Boolean> getLevelDatPatcher() {
|
||||
return (root, profile) -> {
|
||||
CompoundTag worldGenSettings = root.getCompound("Data").getCompound("WorldGenSettings");
|
||||
CompoundTag dimensions = worldGenSettings.getCompound("dimensions");
|
||||
long seed = worldGenSettings.getLong("seed");
|
||||
boolean result = false;
|
||||
|
||||
if (dimensions.contains("minecraft:the_nether")) {
|
||||
CompoundTag dimRoot = dimensions.getCompound("minecraft:the_nether");
|
||||
CompoundTag biomeSource = dimRoot.getCompound("generator").getCompound("biome_source");
|
||||
if (!biomeSource.getString("type").equals(NETHER_BIOME_SOURCE)) {
|
||||
BCLib.LOGGER.info("Applying Nether biome source patch");
|
||||
dimRoot.put("generator", makeNetherGenerator(seed));
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dimensions.contains("minecraft:the_end")) {
|
||||
CompoundTag dimRoot = dimensions.getCompound("minecraft:the_end");
|
||||
CompoundTag biomeSource = dimRoot.getCompound("generator").getCompound("biome_source");
|
||||
if (!biomeSource.getString("type").equals(END_BIOME_SOURCE)) {
|
||||
BCLib.LOGGER.info("Applying End biome source patch");
|
||||
dimRoot.put("generator", makeEndGenerator(seed));
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
private CompoundTag makeNetherGenerator(long seed) {
|
||||
CompoundTag generator = new CompoundTag();
|
||||
generator.putString("type", "minecraft:noise");
|
||||
generator.putString("settings", "minecraft:nether");
|
||||
generator.putLong("seed", seed);
|
||||
|
||||
CompoundTag biomeSource = new CompoundTag();
|
||||
biomeSource.putString("type", NETHER_BIOME_SOURCE);
|
||||
biomeSource.putLong("seed", seed);
|
||||
generator.put("biome_source", biomeSource);
|
||||
|
||||
return generator;
|
||||
}
|
||||
|
||||
private CompoundTag makeEndGenerator(long seed) {
|
||||
CompoundTag generator = new CompoundTag();
|
||||
generator.putString("type", "minecraft:noise");
|
||||
generator.putString("settings", "minecraft:end");
|
||||
generator.putLong("seed", seed);
|
||||
|
||||
CompoundTag biomeSource = new CompoundTag();
|
||||
biomeSource.putString("type", END_BIOME_SOURCE);
|
||||
biomeSource.putLong("seed", seed);
|
||||
generator.put("biome_source", biomeSource);
|
||||
|
||||
return generator;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package ru.bclib.mixin.common;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
||||
import net.minecraft.server.packs.resources.SimpleReloadableResourceManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(SimpleReloadableResourceManager.class)
|
||||
public class SimpleReloadableResourceManagerMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private Map<String, FallbackResourceManager> namespacedPacks;
|
||||
|
||||
private static final String[] BCLIB_MISSING_RESOURCES = new String[] {
|
||||
"dimension/the_end.json",
|
||||
"dimension/the_nether.json",
|
||||
"dimension_type/the_end.json",
|
||||
"dimension_type/the_nether.json"
|
||||
};
|
||||
|
||||
@Inject(method = "hasResource", at = @At("HEAD"), cancellable = true)
|
||||
private void hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Boolean> info) {
|
||||
if (resourceLocation.getNamespace().equals("minecraft")) {
|
||||
for (String key: BCLIB_MISSING_RESOURCES) {
|
||||
if (resourceLocation.getPath().equals(key)) {
|
||||
info.setReturnValue(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"package": "ru.bclib.mixin.common",
|
||||
"compatibilityLevel": "JAVA_16",
|
||||
"mixins": [
|
||||
"SimpleReloadableResourceManagerMixin",
|
||||
"WeightedBiomePickerMixin",
|
||||
"ComposterBlockAccessor",
|
||||
"PotionBrewingAccessor",
|
||||
|
|
Loading…
Reference in a new issue