Different mixin for BiomeModification call
This commit is contained in:
parent
f5ee249bbb
commit
7b64221b55
4 changed files with 63 additions and 13 deletions
|
@ -10,6 +10,7 @@ import net.fabricmc.fabric.impl.biome.NetherBiomeData;
|
||||||
import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
|
import net.fabricmc.fabric.impl.biome.TheEndBiomeData;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
import net.minecraft.data.BuiltinRegistries;
|
import net.minecraft.data.BuiltinRegistries;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -40,6 +41,7 @@ import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BiomeAPI {
|
public class BiomeAPI {
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +80,16 @@ public class BiomeAPI {
|
||||||
* @param server - {@link MinecraftServer}
|
* @param server - {@link MinecraftServer}
|
||||||
*/
|
*/
|
||||||
public static void initRegistry(MinecraftServer server) {
|
public static void initRegistry(MinecraftServer server) {
|
||||||
biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
initRegistry(server.registryAccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize registry for current server.
|
||||||
|
*
|
||||||
|
* @param access - {@link RegistryAccess}
|
||||||
|
*/
|
||||||
|
public static void initRegistry(RegistryAccess access) {
|
||||||
|
biomeRegistry = access.registryOrThrow(Registry.BIOME_REGISTRY);
|
||||||
CLIENT.clear();
|
CLIENT.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,13 +399,30 @@ public class BiomeAPI {
|
||||||
* @param level
|
* @param level
|
||||||
*/
|
*/
|
||||||
public static void applyModifications(ServerLevel level) {
|
public static void applyModifications(ServerLevel level) {
|
||||||
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
|
|
||||||
if (modifications == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
|
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
|
||||||
Set<Biome> biomes = source.possibleBiomes();
|
Set<Biome> biomes = source.possibleBiomes();
|
||||||
|
|
||||||
|
applyModifications(biomes, level.dimension());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will apply biome modifications to world, internal usage only.
|
||||||
|
* @param registryAccess
|
||||||
|
*/
|
||||||
|
public static void applyModifications(RegistryAccess registryAccess) {
|
||||||
|
Registry<Biome> biomeReg = registryAccess.registryOrThrow(Registry.BIOME_REGISTRY);
|
||||||
|
Set<Biome> biomes = biomeReg.entrySet().stream().map(e -> e.getValue()).collect(Collectors.toSet());
|
||||||
|
|
||||||
|
applyModifications(biomes, Level.NETHER);
|
||||||
|
applyModifications(biomes, Level.OVERWORLD);
|
||||||
|
applyModifications(biomes, Level.END);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyModifications(Set<Biome> biomes, ResourceKey<Level> dimension) {
|
||||||
|
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(dimension);
|
||||||
|
if (modifications == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
biomes.forEach(biome -> {
|
biomes.forEach(biome -> {
|
||||||
ResourceLocation biomeID = getBiomeID(biome);
|
ResourceLocation biomeID = getBiomeID(biome);
|
||||||
boolean modify = isDatapackBiome(biomeID);
|
boolean modify = isDatapackBiome(biomeID);
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ru.bclib.mixin.common;
|
||||||
|
|
||||||
|
import com.mojang.serialization.DynamicOps;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.resources.RegistryReadOps;
|
||||||
|
import net.minecraft.resources.RegistryResourceAccess;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import ru.bclib.api.biomes.BiomeAPI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fabrics BiomeModifications API is called at this point. We have to ensure that BCLibs Modification API
|
||||||
|
* runs before Fabric, so we need to hook into the same class.
|
||||||
|
*/
|
||||||
|
@Mixin(RegistryReadOps.class)
|
||||||
|
public class RegistryReadOpsMixin {
|
||||||
|
@Inject(method = "createAndLoad(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/resources/RegistryResourceAccess;Lnet/minecraft/core/RegistryAccess;)Lnet/minecraft/resources/RegistryReadOps;", at = @At("RETURN"))
|
||||||
|
private static <T> void foo(DynamicOps<T> dynamicOps, RegistryResourceAccess registryResourceAccess, RegistryAccess registryAccess, CallbackInfoReturnable<RegistryReadOps<T>> cir){
|
||||||
|
BiomeAPI.initRegistry(registryAccess);
|
||||||
|
BiomeAPI.applyModifications(registryAccess);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,8 +38,9 @@ public abstract class ServerLevelMixin extends Level {
|
||||||
ServerLevel world = ServerLevel.class.cast(this);
|
ServerLevel world = ServerLevel.class.cast(this);
|
||||||
LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2);
|
LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2);
|
||||||
|
|
||||||
BiomeAPI.initRegistry(server);
|
//called from RegistryReadOpsMixin for now
|
||||||
BiomeAPI.applyModifications(ServerLevel.class.cast(this));
|
// BiomeAPI.initRegistry(server);
|
||||||
|
// BiomeAPI.applyModifications(ServerLevel.class.cast(this));
|
||||||
|
|
||||||
if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) {
|
if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -13,8 +13,6 @@
|
||||||
"shears.MushroomCowMixin",
|
"shears.MushroomCowMixin",
|
||||||
"ComposterBlockAccessor",
|
"ComposterBlockAccessor",
|
||||||
"PotionBrewingAccessor",
|
"PotionBrewingAccessor",
|
||||||
"PotionBrewingAccessor",
|
|
||||||
"RecipeManagerAccessor",
|
|
||||||
"RecipeManagerAccessor",
|
"RecipeManagerAccessor",
|
||||||
"shears.SnowGolemMixin",
|
"shears.SnowGolemMixin",
|
||||||
"EnchantmentMenuMixin",
|
"EnchantmentMenuMixin",
|
||||||
|
@ -24,21 +22,19 @@
|
||||||
"TheEndBiomeDataMixin",
|
"TheEndBiomeDataMixin",
|
||||||
"ChunkGeneratorMixin",
|
"ChunkGeneratorMixin",
|
||||||
"WorldGenRegionMixin",
|
"WorldGenRegionMixin",
|
||||||
"WorldGenRegionMixin",
|
|
||||||
"DimensionTypeMixin",
|
"DimensionTypeMixin",
|
||||||
"RecipeManagerMixin",
|
"RecipeManagerMixin",
|
||||||
"RecipeManagerMixin",
|
"RecipeManagerMixin",
|
||||||
"BoneMealItemMixin",
|
"BoneMealItemMixin",
|
||||||
"CraftingMenuMixin",
|
"CraftingMenuMixin",
|
||||||
"CraftingMenuMixin",
|
|
||||||
"shears.SheepMixin",
|
|
||||||
"shears.SheepMixin",
|
"shears.SheepMixin",
|
||||||
"PortalShapeMixin",
|
"PortalShapeMixin",
|
||||||
"ServerLevelMixin",
|
"ServerLevelMixin",
|
||||||
"AnvilBlockMixin",
|
"AnvilBlockMixin",
|
||||||
"AnvilMenuMixin",
|
"AnvilMenuMixin",
|
||||||
"TagLoaderMixin",
|
"TagLoaderMixin",
|
||||||
"MainMixin"
|
"MainMixin",
|
||||||
|
"RegistryReadOpsMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue