Merge branch 'main' of https://github.com/paulevsGitch/BCLib
This commit is contained in:
commit
8a93be6ba6
4 changed files with 142 additions and 7 deletions
|
@ -7,8 +7,8 @@ loom_version=0.8-SNAPSHOT
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://fabricmc.net/versions.html
|
# check these on https://fabricmc.net/versions.html
|
||||||
minecraft_version= 1.17.1
|
minecraft_version= 1.17.1
|
||||||
loader_version= 0.12.4
|
loader_version= 0.12.5
|
||||||
fabric_version = 0.41.3+1.17
|
fabric_version = 0.42.1+1.17
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.5.5
|
mod_version = 0.5.5
|
||||||
|
|
|
@ -38,6 +38,8 @@ import ru.bclib.world.features.BCLFeature;
|
||||||
import ru.bclib.world.generator.BiomePicker;
|
import ru.bclib.world.generator.BiomePicker;
|
||||||
import ru.bclib.world.structures.BCLStructureFeature;
|
import ru.bclib.world.structures.BCLStructureFeature;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -507,7 +509,13 @@ public class BiomeAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends Object> List<T> getMutableList(List<T> input) {
|
private static <T extends Object> List<T> getMutableList(List<T> input) {
|
||||||
if (input instanceof ImmutableList) {
|
if (input!=null) {
|
||||||
|
System.out.println("getMutableList: " + input.getClass().getName());
|
||||||
|
for (Class cl : input.getClass().getInterfaces()){
|
||||||
|
System.out.println(" - " + cl.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (/*input instanceof ImmutableList ||*/ !(input instanceof ArrayList || input instanceof LinkedList)) {
|
||||||
return Lists.newArrayList(input);
|
return Lists.newArrayList(input);
|
||||||
}
|
}
|
||||||
return input;
|
return input;
|
||||||
|
|
121
src/main/java/ru/bclib/api/LifeCycleAPI.java
Normal file
121
src/main/java/ru/bclib/api/LifeCycleAPI.java
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
package ru.bclib.api;
|
||||||
|
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
|
import net.minecraft.resources.ResourceKey;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.server.level.progress.ChunkProgressListener;
|
||||||
|
import net.minecraft.world.level.CustomSpawner;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraft.world.level.biome.Biome;
|
||||||
|
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||||
|
import net.minecraft.world.level.dimension.DimensionType;
|
||||||
|
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||||
|
import net.minecraft.world.level.storage.LevelStorageSource.LevelStorageAccess;
|
||||||
|
import net.minecraft.world.level.storage.ServerLevelData;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides some lifetime hooks for a Minecraft instance
|
||||||
|
*/
|
||||||
|
public class LifeCycleAPI {
|
||||||
|
private final static List<LevelLoadBiomesCall> onLoadLevelBiomes = new ArrayList<>(2);
|
||||||
|
private final static List<LevelLoadCall> onLoadLevel = new ArrayList<>(2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
DimensionType dimensionType,
|
||||||
|
ChunkProgressListener chunkProgressListener,
|
||||||
|
ChunkGenerator chunkGenerator,
|
||||||
|
boolean bl,
|
||||||
|
long l,
|
||||||
|
List<CustomSpawner> list,
|
||||||
|
boolean bl2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback that is called when a new {@code ServerLevel is instantiated}.
|
||||||
|
* This callback will receive the world seed as well as it's biome registry.
|
||||||
|
* @param call The calbback Method
|
||||||
|
*/
|
||||||
|
public static void onLevelLoad(LevelLoadBiomesCall call){
|
||||||
|
onLoadLevelBiomes.add(call);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback that is called when a new {@code ServerLevel is instantiated}.
|
||||||
|
* This callbacl will receiv all parameters that were passed to the ServerLevel's constructor
|
||||||
|
* @param call The calbback Method
|
||||||
|
*/
|
||||||
|
public static void onLevelLoad(LevelLoadCall call){
|
||||||
|
onLoadLevel.add(call);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For internal use, You should not call this method!
|
||||||
|
* @param minecraftServer
|
||||||
|
* @param executor
|
||||||
|
* @param levelStorageAccess
|
||||||
|
* @param serverLevelData
|
||||||
|
* @param resourceKey
|
||||||
|
* @param dimensionType
|
||||||
|
* @param chunkProgressListener
|
||||||
|
* @param chunkGenerator
|
||||||
|
* @param bl
|
||||||
|
* @param l
|
||||||
|
* @param list
|
||||||
|
* @param bl2
|
||||||
|
*/
|
||||||
|
public static void _runLevelLoad(ServerLevel world,
|
||||||
|
MinecraftServer minecraftServer,
|
||||||
|
Executor executor,
|
||||||
|
LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||||
|
ServerLevelData serverLevelData,
|
||||||
|
ResourceKey<Level> resourceKey,
|
||||||
|
DimensionType dimensionType,
|
||||||
|
ChunkProgressListener chunkProgressListener,
|
||||||
|
ChunkGenerator chunkGenerator,
|
||||||
|
boolean bl,
|
||||||
|
long l,
|
||||||
|
List<CustomSpawner> list,
|
||||||
|
boolean bl2){
|
||||||
|
onLoadLevel.forEach(c -> c.onLoad(
|
||||||
|
world,
|
||||||
|
minecraftServer,
|
||||||
|
executor,
|
||||||
|
levelStorageAccess,
|
||||||
|
serverLevelData,
|
||||||
|
resourceKey,
|
||||||
|
dimensionType,
|
||||||
|
chunkProgressListener,
|
||||||
|
chunkGenerator,
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,9 @@
|
||||||
package ru.bclib.mixin.common;
|
package ru.bclib.mixin.common;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
@ -17,10 +21,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import ru.bclib.api.BiomeAPI;
|
import ru.bclib.api.BiomeAPI;
|
||||||
|
import ru.bclib.api.LifeCycleAPI;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executor;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
@Mixin(ServerLevel.class)
|
@Mixin(ServerLevel.class)
|
||||||
public abstract class ServerLevelMixin extends Level {
|
public abstract class ServerLevelMixin extends Level {
|
||||||
|
@ -32,6 +33,9 @@ public abstract class ServerLevelMixin extends Level {
|
||||||
|
|
||||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||||
private void bclib_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey<Level> registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<CustomSpawner> list, boolean bl, CallbackInfo info) {
|
private void bclib_onServerWorldInit(MinecraftServer server, Executor workerExecutor, LevelStorageSource.LevelStorageAccess session, ServerLevelData properties, ResourceKey<Level> registryKey, DimensionType dimensionType, ChunkProgressListener worldGenerationProgressListener, ChunkGenerator chunkGenerator, boolean debugWorld, long l, List<CustomSpawner> list, boolean bl, CallbackInfo info) {
|
||||||
|
ServerLevel world = ServerLevel.class.cast(this);
|
||||||
|
LifeCycleAPI._runLevelLoad(world, server, workerExecutor, session, properties, registryKey, dimensionType, worldGenerationProgressListener, chunkGenerator, debugWorld, l, list, bl);
|
||||||
|
|
||||||
BiomeAPI.initRegistry(server);
|
BiomeAPI.initRegistry(server);
|
||||||
BiomeAPI.applyModifications(ServerLevel.class.cast(this));
|
BiomeAPI.applyModifications(ServerLevel.class.cast(this));
|
||||||
|
|
||||||
|
@ -40,5 +44,7 @@ public abstract class ServerLevelMixin extends Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
bclib_lastWorld = session.getLevelId();
|
bclib_lastWorld = session.getLevelId();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue