Reverted changes to BiomeModification API

This commit is contained in:
Frank 2021-12-03 09:48:55 +01:00
parent fb79201b51
commit 26fa4bb3fd
4 changed files with 9 additions and 75 deletions

View file

@ -82,16 +82,7 @@ public class BiomeAPI {
* @param server - {@link MinecraftServer}
*/
public static void initRegistry(MinecraftServer server) {
initRegistry(server.registryAccess());
}
/**
* Initialize registry for current server.
*
* @param access - {@link RegistryAccess}
*/
public static void initRegistry(RegistryAccess access) {
biomeRegistry = access.registryOrThrow(Registry.BIOME_REGISTRY);
biomeRegistry = server.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
CLIENT.clear();
}
@ -401,45 +392,14 @@ public class BiomeAPI {
* @param level
*/
public static void applyModifications(ServerLevel level) {
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
Set<Biome> biomes = source.possibleBiomes();
applyModifications(biomes, level.dimension());
}
private static final Set<ResourceLocation> modifiedBiomes = new HashSet<>();
/**
* 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())
.filter(b -> modifiedBiomes.add(getBiomeID(b)))
.collect(Collectors.toSet());
applyModifications(
biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.NETHER)).collect(Collectors.toSet()),
Level.NETHER
);
applyModifications(
biomes.stream().filter(b->!b.getBiomeCategory().equals(BiomeCategory.NETHER) && !b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()),
Level.OVERWORLD
);
applyModifications(
biomes.stream().filter(b->b.getBiomeCategory().equals(BiomeCategory.THEEND)).collect(Collectors.toSet()),
Level.END
);
}
private static void applyModifications(Set<Biome> biomes, ResourceKey<Level> dimension) {
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(dimension);
List<BiConsumer<ResourceLocation, Biome>> modifications = MODIFICATIONS.get(level.dimension());
if (modifications == null) {
return;
}
BiomeSource source = level.getChunkSource().getGenerator().getBiomeSource();
Set<Biome> biomes = source.possibleBiomes();
biomes.forEach(biome -> {
ResourceLocation biomeID = getBiomeID(biome);
boolean modify = isDatapackBiome(biomeID);

View file

@ -1,24 +0,0 @@
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 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);
}
}

View file

@ -38,9 +38,8 @@ public abstract class ServerLevelMixin extends Level {
ServerLevel world = ServerLevel.class.cast(this);
LifeCycleAPI._runLevelLoad(world, server, executor, levelStorageAccess, serverLevelData, resourceKey, dimensionType, chunkProgressListener, chunkGenerator, bl, l, list, bl2);
//called from RegistryReadOpsMixin for now
// BiomeAPI.initRegistry(server);
// BiomeAPI.applyModifications(ServerLevel.class.cast(this));
BiomeAPI.initRegistry(server);
BiomeAPI.applyModifications(ServerLevel.class.cast(this));
if (bclib_lastWorld != null && bclib_lastWorld.equals(levelStorageAccess.getLevelId())) {
return;

View file

@ -33,8 +33,7 @@
"AnvilBlockMixin",
"AnvilMenuMixin",
"TagLoaderMixin",
"MainMixin",
"RegistryReadOpsMixin"
"MainMixin"
],
"injectors": {
"defaultRequire": 1