Store registryaccess Object
This commit is contained in:
parent
3e41a4630d
commit
2168787ac2
3 changed files with 64 additions and 71 deletions
|
@ -35,6 +35,11 @@ public class LifeCycleAPI {
|
|||
private final static List<LevelLoadCall> onLoadLevel = new ArrayList<>(2);
|
||||
private final static List<BeforeLevelLoadCall> beforeLoadLevel = new ArrayList<>(2);
|
||||
|
||||
|
||||
private static void worldCreationStarted(RegistryAccess access) {
|
||||
BiomeAPI.initRegistry(access);
|
||||
}
|
||||
|
||||
public static void newWorldSetup(LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
WorldGenSettings settings) {
|
||||
DataExchangeAPI.prepareServerside();
|
||||
|
@ -61,24 +66,15 @@ public class LifeCycleAPI {
|
|||
_runBeforeLevelLoad();
|
||||
}
|
||||
|
||||
public static WorldGenSettings worldLoadStarted(WorldGenSettings settings,
|
||||
Optional<RegistryOps<Tag>> registryOps) {
|
||||
public static WorldGenSettings worldLoadStarted(WorldGenSettings settings, Optional<RegistryOps<Tag>> registryOps) {
|
||||
if (registryOps.orElse(null) instanceof RegistryOpsAccessor acc) {
|
||||
BiomeAPI.initRegistry(acc.bcl_getRegistryAccess()
|
||||
.registry(Registry.BIOME_REGISTRY)
|
||||
.orElse(null));
|
||||
BiomeAPI.initRegistry(acc.bcl_getRegistryAccess());
|
||||
}
|
||||
settings = WorldGenUtil.fixSettingsInCurrentWorld(registryOps, settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static void worldCreationStarted(RegistryAccess access) {
|
||||
BiomeAPI.initRegistry(access
|
||||
.registry(Registry.BIOME_REGISTRY)
|
||||
.orElse(null));
|
||||
}
|
||||
|
||||
public static void worldCreationStarted(RegistryOps<Tag> regOps) {
|
||||
if (regOps instanceof RegistryOpsAccessor acc) {
|
||||
worldCreationStarted(acc.bcl_getRegistryAccess());
|
||||
|
@ -90,44 +86,10 @@ public class LifeCycleAPI {
|
|||
worldCreationStarted(worldGenSettingsComponent.registryHolder());
|
||||
|
||||
if (levelStorageAccess.isPresent()) {
|
||||
newWorldSetup(levelStorageAccess.get(),
|
||||
worldGenSettingsComponent.settings().worldGenSettings());
|
||||
newWorldSetup(levelStorageAccess.get(), worldGenSettingsComponent.settings().worldGenSettings());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface BeforeLevelLoadCall {
|
||||
void beforeLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface LevelLoadBiomesCall {
|
||||
void onLoad(ServerLevel world, long seed, Registry<Biome> registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface LevelLoadCall {
|
||||
void onLoad(
|
||||
ServerLevel world,
|
||||
MinecraftServer minecraftServer,
|
||||
Executor executor,
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
ServerLevelData serverLevelData,
|
||||
ResourceKey<Level> resourceKey,
|
||||
ChunkProgressListener chunkProgressListener,
|
||||
boolean bl,
|
||||
long l,
|
||||
List<CustomSpawner> list,
|
||||
boolean bl2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a callback that is called before a level is loaded or created,
|
||||
* but after the {@link WorldDataAPI} was initialized and patches from
|
||||
|
@ -191,22 +153,51 @@ public class LifeCycleAPI {
|
|||
long l,
|
||||
List<CustomSpawner> list,
|
||||
boolean bl2) {
|
||||
onLoadLevel.forEach(c -> c.onLoad(
|
||||
world,
|
||||
minecraftServer,
|
||||
executor,
|
||||
levelStorageAccess,
|
||||
serverLevelData,
|
||||
resourceKey,
|
||||
chunkProgressListener,
|
||||
bl,
|
||||
l,
|
||||
list,
|
||||
bl2)
|
||||
);
|
||||
onLoadLevel.forEach(c -> c.onLoad(world,
|
||||
minecraftServer,
|
||||
executor,
|
||||
levelStorageAccess,
|
||||
serverLevelData,
|
||||
resourceKey,
|
||||
chunkProgressListener,
|
||||
bl,
|
||||
l,
|
||||
list,
|
||||
bl2));
|
||||
|
||||
final long seed = world.getSeed();
|
||||
final Registry<Biome> biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
onLoadLevelBiomes.forEach(c -> c.onLoad(world, seed, biomeRegistry));
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface BeforeLevelLoadCall {
|
||||
void beforeLoad();
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface LevelLoadBiomesCall {
|
||||
void onLoad(ServerLevel world, long seed, Registry<Biome> registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* A callback function that is used for each new ServerLevel instance
|
||||
*/
|
||||
public interface LevelLoadCall {
|
||||
void onLoad(ServerLevel world,
|
||||
MinecraftServer minecraftServer,
|
||||
Executor executor,
|
||||
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
ServerLevelData serverLevelData,
|
||||
ResourceKey<Level> resourceKey,
|
||||
ChunkProgressListener chunkProgressListener,
|
||||
boolean bl,
|
||||
long l,
|
||||
List<CustomSpawner> list,
|
||||
boolean bl2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package org.betterx.bclib.api.biomes;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.*;
|
||||
import net.minecraft.data.BuiltinRegistries;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -115,7 +112,8 @@ public class BiomeAPI {
|
|||
|
||||
private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap();
|
||||
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
|
||||
public static Registry<Biome> biomeRegistry;
|
||||
private static Registry<Biome> biomeRegistry;
|
||||
private static RegistryAccess registryAccess;
|
||||
|
||||
private static final Map<Holder<PlacedFeature>, Integer> FEATURE_ORDER = Maps.newHashMap();
|
||||
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
|
||||
|
@ -165,12 +163,17 @@ public class BiomeAPI {
|
|||
/**
|
||||
* Initialize registry for current server.
|
||||
*
|
||||
* @param biomeRegistry - {@link Registry} for {@link Biome}.
|
||||
* @param access - The new, active {@link RegistryAccess} for the current session.
|
||||
*/
|
||||
public static void initRegistry(Registry<Biome> biomeRegistry) {
|
||||
if (biomeRegistry != BiomeAPI.biomeRegistry) {
|
||||
BiomeAPI.biomeRegistry = biomeRegistry; //12819
|
||||
CLIENT.clear();
|
||||
public static void initRegistry(RegistryAccess access) {
|
||||
if (access != registryAccess) {
|
||||
BiomeAPI.registryAccess = access;
|
||||
Registry<Biome> biomeRegistry = access.registry(Registry.BIOME_REGISTRY).orElse(null);
|
||||
|
||||
if (biomeRegistry != BiomeAPI.biomeRegistry) {
|
||||
BiomeAPI.biomeRegistry = biomeRegistry;
|
||||
CLIENT.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package org.betterx.bclib.mixin.client;
|
|||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.WorldLoader;
|
||||
|
@ -39,7 +38,7 @@ public class CreateWorldScreenMixin {
|
|||
DataPackConfig dataPackConfig,
|
||||
WorldGenSettingsComponent worldGenSettingsComponent,
|
||||
CallbackInfo ci) {
|
||||
BiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder().registryOrThrow(Registry.BIOME_REGISTRY));
|
||||
BiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder());
|
||||
}
|
||||
|
||||
//Change the WorldPreset that is selected by default on the Create World Screen
|
||||
|
|
Loading…
Reference in a new issue