mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
feat: actually do biome preloading
This commit is contained in:
@@ -6,6 +6,8 @@ import com.dfsek.tectonic.api.loader.type.TypeLoader;
|
||||
import com.dfsek.terra.minestom.api.BiomeFactory;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomeFactory;
|
||||
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
@@ -50,14 +52,14 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
private final ItemHandle itemHandle;
|
||||
private final TypeLoader<PlatformBiome> biomeTypeLoader;
|
||||
private final ArrayList<BaseAddon> platformAddons = new ArrayList<>(List.of(new MinestomAddon(this)));
|
||||
private final BiomeFactory biomeFactory;
|
||||
private final MinestomUserDefinedBiomePool biomePool;
|
||||
|
||||
public TerraMinestomPlatform(WorldHandle worldHandle, ItemHandle itemHandle, TypeLoader<PlatformBiome> biomeTypeLoader,
|
||||
BiomeFactory biomeFactory, BaseAddon... extraAddons) {
|
||||
this.worldHandle = worldHandle;
|
||||
this.itemHandle = itemHandle;
|
||||
this.biomeTypeLoader = biomeTypeLoader;
|
||||
this.biomeFactory = biomeFactory;
|
||||
this.biomePool = new MinestomUserDefinedBiomePool(biomeFactory);
|
||||
this.platformAddons.addAll(List.of(extraAddons));
|
||||
load();
|
||||
getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
@@ -104,11 +106,7 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
|
||||
public void initializeRegistry() {
|
||||
getRawConfigRegistry()
|
||||
.forEach(pack -> {
|
||||
pack.getBiomeProvider().getBiomes().forEach(biome -> {
|
||||
|
||||
});
|
||||
});
|
||||
.forEach(pack -> biomePool.preloadBiomes(pack, pack.getBiomeProvider().getBiomes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -141,7 +139,7 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder worldBuilder(Instance instance) {
|
||||
return new TerraMinestomWorldBuilder(this, instance, biomeFactory);
|
||||
return new TerraMinestomWorldBuilder(this, instance, biomePool);
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder worldBuilder() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.minestom.api;
|
||||
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomePool;
|
||||
|
||||
import net.minestom.server.instance.Instance;
|
||||
|
||||
import java.util.Random;
|
||||
@@ -8,7 +10,6 @@ import java.util.function.Function;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.minestom.TerraMinestomPlatform;
|
||||
import com.dfsek.terra.minestom.biome.MinestomUserDefinedBiomeFactory;
|
||||
import com.dfsek.terra.minestom.block.DefaultBlockEntityFactory;
|
||||
import com.dfsek.terra.minestom.entity.DefaultEntityFactory;
|
||||
import com.dfsek.terra.minestom.world.TerraMinestomWorld;
|
||||
@@ -21,17 +22,17 @@ import org.jspecify.annotations.NonNull;
|
||||
public class TerraMinestomWorldBuilder {
|
||||
private final TerraMinestomPlatform platform;
|
||||
private final Instance instance;
|
||||
private final MinestomUserDefinedBiomePool biomePool;
|
||||
private ConfigPack pack;
|
||||
private long seed = new Random().nextLong();
|
||||
private EntityFactory entityFactory = new DefaultEntityFactory();
|
||||
private BlockEntityFactory blockEntityFactory;
|
||||
private BiomeFactory biomeFactory;
|
||||
|
||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance, BiomeFactory biomeFactory) {
|
||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance, MinestomUserDefinedBiomePool biomePool) {
|
||||
this.platform = platform;
|
||||
this.instance = instance;
|
||||
this.blockEntityFactory = new DefaultBlockEntityFactory(instance);
|
||||
this.biomeFactory = biomeFactory;
|
||||
this.biomePool = biomePool;
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder pack(ConfigPack pack) {
|
||||
@@ -82,6 +83,6 @@ public class TerraMinestomWorldBuilder {
|
||||
}
|
||||
|
||||
public TerraMinestomWorld attach() {
|
||||
return new TerraMinestomWorld(platform, instance, pack, seed, entityFactory, blockEntityFactory, biomeFactory);
|
||||
return new TerraMinestomWorld(platform, instance, pack, seed, entityFactory, blockEntityFactory, biomePool);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,12 @@ public class MinestomUserDefinedBiomePool {
|
||||
private final IdentityHashMap<Biome, UserDefinedBiome> biomes = new IdentityHashMap<>();
|
||||
private final HashSet<String> createdBiomes = new HashSet<>();
|
||||
private final BiomeFactory factory;
|
||||
private final ConfigPack configPack;
|
||||
|
||||
public MinestomUserDefinedBiomePool(ConfigPack configPack, BiomeFactory factory) {
|
||||
this.configPack = configPack;
|
||||
public MinestomUserDefinedBiomePool(BiomeFactory factory) {
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
public UserDefinedBiome getBiome(Biome source) {
|
||||
public UserDefinedBiome getBiome(ConfigPack configPack, Biome source) {
|
||||
UserDefinedBiome userDefinedBiome = biomes.get(source);
|
||||
if(userDefinedBiome != null) return userDefinedBiome;
|
||||
userDefinedBiome = factory.create(configPack, source);
|
||||
@@ -28,7 +26,7 @@ public class MinestomUserDefinedBiomePool {
|
||||
return userDefinedBiome;
|
||||
}
|
||||
|
||||
public void preloadBiomes(Iterable<Biome> biomesToLoad) {
|
||||
public void preloadBiomes(ConfigPack configPack, Iterable<Biome> biomesToLoad) {
|
||||
biomesToLoad
|
||||
.forEach(biome -> {
|
||||
if(!this.createdBiomes.contains(biome.getID())) {
|
||||
|
||||
@@ -40,7 +40,6 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
||||
this.biomePool = biomePool;
|
||||
this.biomeProvider = pack.getBiomeProvider();
|
||||
this.cache = new GeneratedChunkCache(world.getDimensionType(), generator, world, biomeProvider);
|
||||
preloadBiomes();
|
||||
}
|
||||
|
||||
public ChunkGenerator getGenerator() {
|
||||
@@ -73,6 +72,7 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
||||
|
||||
if(relativeX % 4 == 0 && relativeY % 4 == 0 && relativeZ % 4 == 0) {
|
||||
UserDefinedBiome userDefinedBiome = biomePool.getBiome(
|
||||
pack,
|
||||
biomeProvider.getBiome(absoluteX, absoluteY, absoluteZ, world.getSeed())
|
||||
);
|
||||
|
||||
@@ -101,11 +101,6 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
||||
this.pack = pack;
|
||||
this.generator = pack.getGeneratorProvider().newInstance(pack);
|
||||
this.biomePool.invalidate();
|
||||
preloadBiomes();
|
||||
}
|
||||
|
||||
private void preloadBiomes() {
|
||||
this.biomePool.preloadBiomes(world.getBiomeProvider().getBiomes());
|
||||
}
|
||||
|
||||
public void displayStats() {
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
||||
long seed,
|
||||
EntityFactory entityFactory,
|
||||
BlockEntityFactory blockEntityFactory,
|
||||
BiomeFactory factory
|
||||
MinestomUserDefinedBiomePool biomePool
|
||||
) {
|
||||
this.instance = instance;
|
||||
this.pack = pack;
|
||||
@@ -57,7 +57,7 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
||||
pack.getGeneratorProvider().newInstance(pack),
|
||||
this,
|
||||
pack,
|
||||
new MinestomUserDefinedBiomePool(pack, factory)
|
||||
biomePool
|
||||
);
|
||||
this.entityFactory = entityFactory;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user