mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
Merge pull request #533 from everbuild-org/fix/minestom-platform-fixes
Minestom 1.21.8/9/10 & Metapack support
This commit is contained in:
@@ -96,6 +96,6 @@ object Versions {
|
||||
}
|
||||
|
||||
object Minestom {
|
||||
const val minestom = "1_21_6-a40d7115d4"
|
||||
const val minestom = "2025.10.04-1.21.8"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ dependencies {
|
||||
shadedApi("com.github.ben-manes.caffeine", "caffeine", Versions.Libraries.caffeine)
|
||||
shadedImplementation("com.google.guava", "guava", Versions.Libraries.Internal.guava)
|
||||
|
||||
compileOnly("net.minestom", "minestom-snapshots", Versions.Minestom.minestom)
|
||||
compileOnly("net.minestom", "minestom", Versions.Minestom.minestom)
|
||||
}
|
||||
|
||||
tasks.named("jar") {
|
||||
|
||||
@@ -7,7 +7,7 @@ val javaMainClass = "com.dfsek.terra.minestom.TerraMinestomExample"
|
||||
dependencies {
|
||||
shadedApi(project(":platforms:minestom"))
|
||||
|
||||
implementation("net.minestom", "minestom-snapshots", Versions.Minestom.minestom)
|
||||
implementation("net.minestom", "minestom", Versions.Minestom.minestom)
|
||||
implementation("org.slf4j", "slf4j-simple", Versions.Libraries.slf4j)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
||||
import net.minestom.server.event.player.PlayerSpawnEvent;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.LightingChunk;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -43,7 +44,7 @@ public class TerraMinestomExample {
|
||||
|
||||
public void attachTerra() {
|
||||
world = platform.worldBuilder(instance)
|
||||
.defaultPack()
|
||||
.packByDefaultMeta(DimensionType.OVERWORLD)
|
||||
.attach();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,12 @@ package com.dfsek.terra.minestom;
|
||||
|
||||
import com.dfsek.tectonic.api.TypeRegistry;
|
||||
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;
|
||||
@@ -9,6 +15,7 @@ import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.world.biome.BiomeEffects;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -45,19 +52,22 @@ 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 MinestomUserDefinedBiomePool biomePool;
|
||||
|
||||
public TerraMinestomPlatform(WorldHandle worldHandle, ItemHandle itemHandle, TypeLoader<PlatformBiome> biomeTypeLoader,
|
||||
BaseAddon... extraAddons) {
|
||||
BiomeFactory biomeFactory, BaseAddon... extraAddons) {
|
||||
this.worldHandle = worldHandle;
|
||||
this.itemHandle = itemHandle;
|
||||
this.biomeTypeLoader = biomeTypeLoader;
|
||||
this.biomePool = new MinestomUserDefinedBiomePool(biomeFactory);
|
||||
this.platformAddons.addAll(List.of(extraAddons));
|
||||
load();
|
||||
getEventManager().callEvent(new PlatformInitializationEvent());
|
||||
initializeRegistry(); // Needs to be called before minecraft server bind
|
||||
}
|
||||
|
||||
public TerraMinestomPlatform() {
|
||||
this(new MinestomWorldHandle(), new MinestomItemHandle(), new MinestomBiomeLoader());
|
||||
this(new MinestomWorldHandle(), new MinestomItemHandle(), new MinestomBiomeLoader(), new MinestomUserDefinedBiomeFactory());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +104,10 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
return succeed;
|
||||
}
|
||||
|
||||
public void initializeRegistry() {
|
||||
getRawConfigRegistry()
|
||||
.forEach(pack -> biomePool.preloadBiomes(pack, pack.getBiomeProvider().getBiomes()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull WorldHandle getWorldHandle() {
|
||||
@@ -125,10 +139,62 @@ public final class TerraMinestomPlatform extends AbstractPlatform {
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder worldBuilder(Instance instance) {
|
||||
return new TerraMinestomWorldBuilder(this, instance);
|
||||
return new TerraMinestomWorldBuilder(this, instance, biomePool);
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder worldBuilder() {
|
||||
return new TerraMinestomWorldBuilder(this, MinecraftServer.getInstanceManager().createInstanceContainer());
|
||||
return worldBuilder(MinecraftServer.getInstanceManager().createInstanceContainer());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private @Nullable WorldHandle worldHandle;
|
||||
private @Nullable ItemHandle itemHandle;
|
||||
private @Nullable TypeLoader<PlatformBiome> biomeTypeLoader;
|
||||
private @Nullable BiomeFactory biomeFactory;
|
||||
private final List<BaseAddon> platformAddons = new ArrayList<>();
|
||||
|
||||
public Builder worldHandle(@Nullable WorldHandle worldHandle) {
|
||||
this.worldHandle = worldHandle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder itemHandle(@Nullable ItemHandle itemHandle) {
|
||||
this.itemHandle = itemHandle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder biomeTypeLoader(@Nullable TypeLoader<PlatformBiome> biomeTypeLoader) {
|
||||
this.biomeTypeLoader = biomeTypeLoader;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder addPlatformAddon(BaseAddon addon) {
|
||||
this.platformAddons.add(addon);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder biomeFactory(BiomeFactory biomeFactory) {
|
||||
this.biomeFactory = biomeFactory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerraMinestomPlatform build() {
|
||||
if(worldHandle == null) worldHandle = new MinestomWorldHandle();
|
||||
if(itemHandle == null) itemHandle = new MinestomItemHandle();
|
||||
if(biomeTypeLoader == null) biomeTypeLoader = new MinestomBiomeLoader();
|
||||
if(biomeFactory == null) biomeFactory = new MinestomUserDefinedBiomeFactory();
|
||||
|
||||
return new TerraMinestomPlatform(
|
||||
worldHandle,
|
||||
itemHandle,
|
||||
biomeTypeLoader,
|
||||
biomeFactory,
|
||||
platformAddons.toArray(new BaseAddon[0])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,25 +10,29 @@ 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;
|
||||
|
||||
import net.minestom.server.registry.RegistryKey;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
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 = new MinestomUserDefinedBiomeFactory();
|
||||
|
||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance) {
|
||||
public TerraMinestomWorldBuilder(TerraMinestomPlatform platform, Instance instance, MinestomUserDefinedBiomePool biomePool) {
|
||||
this.platform = platform;
|
||||
this.instance = instance;
|
||||
this.blockEntityFactory = new DefaultBlockEntityFactory(instance);
|
||||
this.biomePool = biomePool;
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder pack(ConfigPack pack) {
|
||||
@@ -36,10 +42,22 @@ public class TerraMinestomWorldBuilder {
|
||||
|
||||
public TerraMinestomWorldBuilder packById(String id) {
|
||||
this.pack = platform.getConfigRegistry().getByID(id).orElseThrow();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder packByMeta(String metaPack, RegistryKey<@NonNull DimensionType> dimensionType) {
|
||||
this.pack = platform.getMetaConfigRegistry()
|
||||
.getByID(metaPack)
|
||||
.orElseThrow(() -> new RuntimeException("MetaPack " + metaPack + " could not be found"))
|
||||
.packs()
|
||||
.get(dimensionType.key().asString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder packByDefaultMeta(RegistryKey<@NonNull DimensionType> dimensionType) {
|
||||
return packByMeta("DEFAULT", dimensionType);
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder findPack(Function<CheckedRegistry<ConfigPack>, ConfigPack> fn) {
|
||||
this.pack = fn.apply(platform.getConfigRegistry());
|
||||
return this;
|
||||
@@ -64,12 +82,7 @@ public class TerraMinestomWorldBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TerraMinestomWorldBuilder biomeFactory(BiomeFactory factory) {
|
||||
this.biomeFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
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())) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.dfsek.terra.api.block.state.properties.Property;
|
||||
|
||||
public class MinestomBlockState implements BlockState {
|
||||
private final Block block;
|
||||
public static final MinestomBlockState AIR = new MinestomBlockState(Block.AIR);
|
||||
|
||||
public MinestomBlockState(Block block) {
|
||||
if(block == null) {
|
||||
|
||||
@@ -32,7 +32,9 @@ public class CachedChunk implements ProtoChunk {
|
||||
public void setBlock(int x, int y, int z, @NotNull BlockState blockState) {
|
||||
Block block = (Block) blockState.getHandle();
|
||||
if(block == null) return;
|
||||
blocks[getIndex(x, y, z)] = block;
|
||||
int index = getIndex(x, y, z);
|
||||
if (index > blocks.length || index < 0) return;
|
||||
blocks[index] = block;
|
||||
}
|
||||
|
||||
private int getIndex(int x, int y, int z) {
|
||||
@@ -42,7 +44,9 @@ public class CachedChunk implements ProtoChunk {
|
||||
|
||||
@Override
|
||||
public @NotNull BlockState getBlock(int x, int y, int z) {
|
||||
return new MinestomBlockState(blocks[getIndex(x, y, z)]);
|
||||
int index = getIndex(x, y, z);
|
||||
if (index > blocks.length || index < 0) return MinestomBlockState.AIR;
|
||||
return new MinestomBlockState(blocks[index]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,8 +3,18 @@ package com.dfsek.terra.minestom.config;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Default;
|
||||
import com.dfsek.tectonic.api.config.template.annotations.Value;
|
||||
import com.dfsek.tectonic.api.config.template.object.ObjectTemplate;
|
||||
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
import net.kyori.adventure.nbt.TagStringIO;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.arguments.minecraft.registry.ArgumentParticle;
|
||||
import net.minestom.server.particle.Particle;
|
||||
import net.minestom.server.world.biome.BiomeEffects;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeEffects.Particle> {
|
||||
@@ -22,9 +32,16 @@ public class BiomeParticleConfigTemplate implements ObjectTemplate<BiomeEffects.
|
||||
return null;
|
||||
}
|
||||
|
||||
String[] parts = particle.split("\\{");
|
||||
Particle parsedParticle = Particle.fromKey(parts[0]);
|
||||
if (parts.length > 1) {
|
||||
LoggerFactory.getLogger(BiomeParticleConfigTemplate.class).warn("Particle {} has additional data, particle will be ignored.", particle);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new BiomeEffects.Particle(
|
||||
probability,
|
||||
Particle.fromKey(particle)
|
||||
parsedParticle
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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