mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-19 19:12:33 +00:00
refactor: remove fine-grained biome controls and adjust biome handling
Removed the deprecated `doFineGrainedBiomes` option from `TerraMinestomWorldBuilder` and associated classes. Updated biome management to use `IdentityHashMap` and added additional tracking for created biomes. Upgraded Minestom version to `1_21_6-a40d7115d4`.
This commit is contained in:
parent
923cb08b37
commit
89cbab071f
@ -89,6 +89,6 @@ object Versions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Minestom {
|
object Minestom {
|
||||||
const val minestom = "1_21_6-c3ccee696b"
|
const val minestom = "1_21_6-a40d7115d4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ public class TerraMinestomExample {
|
|||||||
public void attachTerra() {
|
public void attachTerra() {
|
||||||
world = platform.worldBuilder(instance)
|
world = platform.worldBuilder(instance)
|
||||||
.defaultPack()
|
.defaultPack()
|
||||||
.doFineGrainedBiomes(false)
|
|
||||||
.attach();
|
.attach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ public class TerraMinestomWorldBuilder {
|
|||||||
private EntityFactory entityFactory = new DefaultEntityFactory();
|
private EntityFactory entityFactory = new DefaultEntityFactory();
|
||||||
private BlockEntityFactory blockEntityFactory;
|
private BlockEntityFactory blockEntityFactory;
|
||||||
private BiomeFactory biomeFactory = new MinestomUserDefinedBiomeFactory();
|
private BiomeFactory biomeFactory = new MinestomUserDefinedBiomeFactory();
|
||||||
private boolean doFineGrainedBiomes = true;
|
|
||||||
|
|
||||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance) {
|
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance) {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
@ -70,20 +69,7 @@ public class TerraMinestomWorldBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Due to a current bug with the minestom biome encoder, sometimes, the client gets kicked when decoding a chunk
|
|
||||||
* packet with more than one biome. Until this is fixed in minestom, one can disable fine-grained biomes to prevent
|
|
||||||
* this issue.
|
|
||||||
*
|
|
||||||
* @deprecated Scheduled for removal once Minestom rolls out a fix
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public TerraMinestomWorldBuilder doFineGrainedBiomes(boolean doFineGrainedBiomes) {
|
|
||||||
this.doFineGrainedBiomes = doFineGrainedBiomes;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TerraMinestomWorld attach() {
|
public TerraMinestomWorld attach() {
|
||||||
return new TerraMinestomWorld(platform, instance, pack, seed, entityFactory, blockEntityFactory, biomeFactory, doFineGrainedBiomes);
|
return new TerraMinestomWorld(platform, instance, pack, seed, entityFactory, blockEntityFactory, biomeFactory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.dfsek.terra.minestom.biome;
|
package com.dfsek.terra.minestom.biome;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
|
|
||||||
import com.dfsek.terra.api.config.ConfigPack;
|
import com.dfsek.terra.api.config.ConfigPack;
|
||||||
import com.dfsek.terra.api.world.biome.Biome;
|
import com.dfsek.terra.api.world.biome.Biome;
|
||||||
@ -8,7 +10,8 @@ import com.dfsek.terra.minestom.api.BiomeFactory;
|
|||||||
|
|
||||||
|
|
||||||
public class MinestomUserDefinedBiomePool {
|
public class MinestomUserDefinedBiomePool {
|
||||||
private final HashMap<String, UserDefinedBiome> biomes = new HashMap<>();
|
private final IdentityHashMap<Biome, UserDefinedBiome> biomes = new IdentityHashMap<>();
|
||||||
|
private final HashSet<String> createdBiomes = new HashSet<>();
|
||||||
private final BiomeFactory factory;
|
private final BiomeFactory factory;
|
||||||
private final ConfigPack configPack;
|
private final ConfigPack configPack;
|
||||||
|
|
||||||
@ -18,18 +21,21 @@ public class MinestomUserDefinedBiomePool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public UserDefinedBiome getBiome(Biome source) {
|
public UserDefinedBiome getBiome(Biome source) {
|
||||||
UserDefinedBiome userDefinedBiome = biomes.get(source.getID());
|
UserDefinedBiome userDefinedBiome = biomes.get(source);
|
||||||
if(userDefinedBiome != null) return userDefinedBiome;
|
if(userDefinedBiome != null) return userDefinedBiome;
|
||||||
userDefinedBiome = factory.create(configPack, source);
|
userDefinedBiome = factory.create(configPack, source);
|
||||||
biomes.put(source.getID(), userDefinedBiome);
|
biomes.put(source, userDefinedBiome);
|
||||||
|
createdBiomes.add(source.getID());
|
||||||
return userDefinedBiome;
|
return userDefinedBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preloadBiomes(Iterable<Biome> biomesToLoad) {
|
public void preloadBiomes(Iterable<Biome> biomesToLoad) {
|
||||||
biomesToLoad
|
biomesToLoad
|
||||||
.forEach(biome -> {
|
.forEach(biome -> {
|
||||||
if(!this.biomes.containsKey(biome.getID())) {
|
if(!this.createdBiomes.contains(biome.getID())) {
|
||||||
this.biomes.put(biome.getID(), factory.create(configPack, biome));
|
UserDefinedBiome udf = factory.create(configPack, biome);
|
||||||
|
this.biomes.put(biome, udf);
|
||||||
|
this.createdBiomes.add(biome.getID());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,49 @@
|
|||||||
package com.dfsek.terra.minestom.biome;
|
package com.dfsek.terra.minestom.biome;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.registry.DynamicRegistry;
|
||||||
import net.minestom.server.registry.RegistryKey;
|
import net.minestom.server.registry.RegistryKey;
|
||||||
import net.minestom.server.world.biome.Biome;
|
import net.minestom.server.world.biome.Biome;
|
||||||
|
|
||||||
|
|
||||||
public record UserDefinedBiome(Key key, RegistryKey<Biome> registry, String id, Biome biome) {
|
public class UserDefinedBiome {
|
||||||
|
private static final DynamicRegistry<Biome> BIOME_REGISTRY = MinecraftServer.getBiomeRegistry();
|
||||||
|
|
||||||
|
private final Key key;
|
||||||
|
private final RegistryKey<Biome> registry;
|
||||||
|
private final String id;
|
||||||
|
private final Biome biome;
|
||||||
|
|
||||||
|
private int registryId = -1;
|
||||||
|
|
||||||
|
public UserDefinedBiome(Key key, RegistryKey<Biome> registry, String id, Biome biome) {
|
||||||
|
this.key = key;
|
||||||
|
this.registry = registry;
|
||||||
|
this.id = id;
|
||||||
|
this.biome = biome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Key key() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RegistryKey<Biome> registryKey() {
|
||||||
|
return registry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String id() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Biome biome() {
|
||||||
|
return biome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int registryId() {
|
||||||
|
if(registryId == -1) {
|
||||||
|
registryId = BIOME_REGISTRY.getId(registry);
|
||||||
|
}
|
||||||
|
return registryId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package com.dfsek.terra.minestom.world;
|
package com.dfsek.terra.minestom.world;
|
||||||
|
|
||||||
import net.minestom.server.coordinate.Point;
|
import net.minestom.server.coordinate.Point;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
import net.minestom.server.instance.generator.GenerationUnit;
|
import net.minestom.server.instance.generator.GenerationUnit;
|
||||||
import net.minestom.server.instance.generator.Generator;
|
import net.minestom.server.instance.generator.Generator;
|
||||||
|
import net.minestom.server.instance.generator.GeneratorImpl.AreaModifierImpl;
|
||||||
|
import net.minestom.server.instance.generator.GeneratorImpl.SectionModifierImpl;
|
||||||
import net.minestom.server.instance.generator.UnitModifier;
|
import net.minestom.server.instance.generator.UnitModifier;
|
||||||
|
import net.minestom.server.instance.palette.Palette;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import com.dfsek.terra.api.Platform;
|
import com.dfsek.terra.api.Platform;
|
||||||
@ -22,25 +26,21 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
|||||||
private final GeneratedChunkCache cache;
|
private final GeneratedChunkCache cache;
|
||||||
private final TerraMinestomWorld world;
|
private final TerraMinestomWorld world;
|
||||||
private final BiomeProvider biomeProvider;
|
private final BiomeProvider biomeProvider;
|
||||||
private final boolean doFineGrainedBiomes;
|
|
||||||
private final MinestomUserDefinedBiomePool biomePool;
|
private final MinestomUserDefinedBiomePool biomePool;
|
||||||
private ChunkGenerator generator;
|
private ChunkGenerator generator;
|
||||||
private ConfigPack pack;
|
private ConfigPack pack;
|
||||||
|
|
||||||
public MinestomChunkGeneratorWrapper(
|
public MinestomChunkGeneratorWrapper(
|
||||||
Platform platform,
|
|
||||||
ChunkGenerator generator,
|
ChunkGenerator generator,
|
||||||
TerraMinestomWorld world,
|
TerraMinestomWorld world,
|
||||||
ConfigPack pack,
|
ConfigPack pack,
|
||||||
MinestomUserDefinedBiomePool biomePool,
|
MinestomUserDefinedBiomePool biomePool
|
||||||
boolean doFineGrainedBiomes
|
|
||||||
) {
|
) {
|
||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.pack = pack;
|
this.pack = pack;
|
||||||
this.biomePool = biomePool;
|
this.biomePool = biomePool;
|
||||||
this.biomeProvider = pack.getBiomeProvider();
|
this.biomeProvider = pack.getBiomeProvider();
|
||||||
this.doFineGrainedBiomes = doFineGrainedBiomes;
|
|
||||||
this.cache = new GeneratedChunkCache(world.getDimensionType(), generator, world, biomeProvider);
|
this.cache = new GeneratedChunkCache(world.getDimensionType(), generator, world, biomeProvider);
|
||||||
preloadBiomes();
|
preloadBiomes();
|
||||||
}
|
}
|
||||||
@ -49,6 +49,7 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
|||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
@Override
|
@Override
|
||||||
public void generate(@NotNull GenerationUnit unit) {
|
public void generate(@NotNull GenerationUnit unit) {
|
||||||
Point start = unit.absoluteStart();
|
Point start = unit.absoluteStart();
|
||||||
@ -56,27 +57,33 @@ public class MinestomChunkGeneratorWrapper implements Generator, GeneratorWrappe
|
|||||||
int z = start.chunkZ();
|
int z = start.chunkZ();
|
||||||
int blockX = start.blockX();
|
int blockX = start.blockX();
|
||||||
int blockZ = start.blockZ();
|
int blockZ = start.blockZ();
|
||||||
int minY = world.getMinHeight();
|
|
||||||
int maxY = world.getMaxHeight();
|
|
||||||
CachedChunk chunk = cache.at(x, z);
|
CachedChunk chunk = cache.at(x, z);
|
||||||
UnitModifier modifier = unit.modifier();
|
UnitModifier modifier = unit.modifier();
|
||||||
chunk.writeRelative(modifier);
|
chunk.writeRelative(modifier);
|
||||||
|
|
||||||
if(doFineGrainedBiomes) {
|
AreaModifierImpl areaModifiers = (AreaModifierImpl) modifier;
|
||||||
for(int y = minY; y < maxY; y++) {
|
for(GenerationUnit section : areaModifiers.sections()) {
|
||||||
for(int absoluteX = blockX; absoluteX < blockX + 16; absoluteX++) {
|
SectionModifierImpl sectionModifier = (SectionModifierImpl) section.modifier();
|
||||||
for(int absoluteZ = blockZ; absoluteZ < blockZ + 16; absoluteZ++) {
|
Palette biomes = sectionModifier.genSection().biomes();
|
||||||
UserDefinedBiome userDefinedBiome = biomePool.getBiome(
|
int minY = section.absoluteStart().blockY();
|
||||||
biomeProvider.getBiome(absoluteX, y, absoluteZ, world.getSeed())
|
for(int relativeX = 0; relativeX < 16; relativeX += 1) {
|
||||||
);
|
int absoluteX = blockX + relativeX;
|
||||||
modifier.setBiome(absoluteX, y, absoluteZ, userDefinedBiome.registry());
|
for(int relativeZ = 0; relativeZ < 16; relativeZ += 1) {
|
||||||
|
int absoluteZ = blockZ + relativeZ;
|
||||||
|
for(int relativeY = 0; relativeY < 16; relativeY += 1) {
|
||||||
|
int absoluteY = minY + relativeY;
|
||||||
|
|
||||||
|
if (relativeX % 4 == 0 && relativeY % 4 == 0 && relativeZ % 4 == 0) {
|
||||||
|
UserDefinedBiome userDefinedBiome = biomePool.getBiome(
|
||||||
|
biomeProvider.getBiome(absoluteX, absoluteY, absoluteZ, world.getSeed())
|
||||||
|
);
|
||||||
|
|
||||||
|
int registryId = userDefinedBiome.registryId();
|
||||||
|
biomes.set(relativeX / 4, relativeY / 4, relativeZ / 4, registryId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// TODO: remove with feature flag once minestom fixed biome encoding
|
|
||||||
UserDefinedBiome userDefinedBiome = biomePool.getBiome(biomeProvider.getBiome(blockX, 100, blockZ, world.getSeed()));
|
|
||||||
modifier.fillBiome(userDefinedBiome.registry());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unit.fork(setter -> {
|
unit.fork(setter -> {
|
||||||
|
@ -44,8 +44,7 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
|||||||
long seed,
|
long seed,
|
||||||
EntityFactory entityFactory,
|
EntityFactory entityFactory,
|
||||||
BlockEntityFactory blockEntityFactory,
|
BlockEntityFactory blockEntityFactory,
|
||||||
BiomeFactory factory,
|
BiomeFactory factory
|
||||||
boolean doFineGrainedBiomes
|
|
||||||
) {
|
) {
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
this.pack = pack;
|
this.pack = pack;
|
||||||
@ -55,12 +54,10 @@ public final class TerraMinestomWorld implements ServerWorld, WorldProperties {
|
|||||||
this.blockEntityFactory = blockEntityFactory;
|
this.blockEntityFactory = blockEntityFactory;
|
||||||
|
|
||||||
this.wrapper = new MinestomChunkGeneratorWrapper(
|
this.wrapper = new MinestomChunkGeneratorWrapper(
|
||||||
platform,
|
|
||||||
pack.getGeneratorProvider().newInstance(pack),
|
pack.getGeneratorProvider().newInstance(pack),
|
||||||
this,
|
this,
|
||||||
pack,
|
pack,
|
||||||
new MinestomUserDefinedBiomePool(pack, factory),
|
new MinestomUserDefinedBiomePool(pack, factory)
|
||||||
doFineGrainedBiomes
|
|
||||||
);
|
);
|
||||||
this.entityFactory = entityFactory;
|
this.entityFactory = entityFactory;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user