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