diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomPlatform.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomPlatform.java index 3e778039d..e85edbee1 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomPlatform.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/MinestomPlatform.java @@ -17,14 +17,20 @@ import com.dfsek.terra.minestom.entity.MinestomEntityType; import com.dfsek.terra.minestom.item.MinestomItemHandle; +import com.dfsek.terra.minestom.world.MinestomChunkGeneratorWrapper; import com.dfsek.terra.minestom.world.MinestomWorldHandle; +import net.minestom.server.MinecraftServer; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; +import java.util.ArrayList; public final class MinestomPlatform extends AbstractPlatform { + private static final Logger LOGGER = LoggerFactory.getLogger(MinestomPlatform.class); private static MinestomPlatform INSTANCE = null; private final MinestomWorldHandle worldHandle = new MinestomWorldHandle(); private final MinestomItemHandle itemHandle = new MinestomItemHandle(); @@ -45,7 +51,20 @@ public void register(TypeRegistry registry) { @Override public boolean reload() { - return false; + getTerraConfig().load(this); + getRawConfigRegistry().clear(); + boolean succeed = getRawConfigRegistry().loadAll(this); + + MinecraftServer.getInstanceManager().getInstances().forEach(world -> { + if(world.generator() instanceof MinestomChunkGeneratorWrapper wrapper) { + getConfigRegistry().get(wrapper.getPack().getRegistryKey()).ifPresent(pack -> { + wrapper.setPack(pack); + LOGGER.info("Replaced pack in chunk generator for instance {}", world.getUniqueId()); + }); + } + }); + + return succeed; } @Override diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomExample.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomExample.java index 159a9562a..20dd10bbd 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomExample.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/TerraMinestomExample.java @@ -1,19 +1,11 @@ package com.dfsek.terra.minestom; -import com.dfsek.terra.minestom.api.filter.ChunkFilter; -import com.dfsek.terra.minestom.api.filter.EvenChunkFilter; -import com.dfsek.terra.minestom.api.filter.NoFeaturesFilter; -import com.dfsek.terra.minestom.api.filter.NoTerrainFilter; -import com.dfsek.terra.minestom.api.filter.SpecificChunkFilter; -import com.dfsek.terra.minestom.api.filter.XFilter; -import com.dfsek.terra.minestom.api.filter.ZFilter; import com.dfsek.terra.minestom.world.TerraMinestomWorld; import com.dfsek.terra.minestom.world.TerraMinestomWorldBuilder; import net.kyori.adventure.text.Component; import net.minestom.server.MinecraftServer; import net.minestom.server.command.builder.Command; -import net.minestom.server.command.builder.arguments.ArgumentLiteral; import net.minestom.server.command.builder.arguments.number.ArgumentInteger; import net.minestom.server.coordinate.Pos; import net.minestom.server.entity.GameMode; @@ -21,7 +13,6 @@ import net.minestom.server.event.player.PlayerSpawnEvent; import net.minestom.server.instance.Instance; import net.minestom.server.instance.LightingChunk; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,11 +31,9 @@ public void createNewInstance() { instance.setChunkSupplier(LightingChunk::new); } - public void attachTerra(ChunkFilter filter) { + public void attachTerra() { world = TerraMinestomWorldBuilder.from(instance) .defaultPack() -// .seed(0) - .filtered(filter) .attach(); } @@ -117,7 +106,7 @@ public void bind() { public static void main(String[] args) { TerraMinestomExample example = new TerraMinestomExample(); example.createNewInstance(); - example.attachTerra(null); + example.attachTerra(); example.preloadWorldAndMeasure(); example.addScheduler(); example.addListeners(); @@ -128,27 +117,13 @@ public static void main(String[] args) { public class RegenerateCommand extends Command { public RegenerateCommand() { super("regenerate"); - - ArgumentInteger cx = new ArgumentInteger("cx"); - ArgumentInteger cz = new ArgumentInteger("cz"); - - setDefaultExecutor((sender, context) -> regenerate(null)); - addSyntax((sender, context) -> regenerate(new NoFeaturesFilter()), new ArgumentLiteral("noFeatures")); - addSyntax((sender, context) -> regenerate(new NoTerrainFilter()), new ArgumentLiteral("noTerrain")); - addSyntax((sender, context) -> regenerate(new EvenChunkFilter()), new ArgumentLiteral("evenChunks")); - addSyntax((sender, context) -> regenerate(new SpecificChunkFilter(context.get(cx), context.get(cz))), new ArgumentLiteral("chunk"), cx, cz); - addSyntax((sender, context) -> regenerate(new XFilter(context.get(cx))), new ArgumentLiteral("x"), cx); - addSyntax((sender, context) -> regenerate(new ZFilter(context.get(cz))), new ArgumentLiteral("z"), cz); + setDefaultExecutor((sender, context) -> regenerate()); } - private void regenerate(@Nullable ChunkFilter filter) { - if (filter == null) { - instance.sendMessage(Component.text("Regenerating world without filter ")); - } else { - instance.sendMessage(Component.text("Regenerating world with filter " + filter.getClass().getSimpleName())); - } + private void regenerate() { + instance.sendMessage(Component.text("Regenerating world")); createNewInstance(); - attachTerra(filter); + attachTerra(); preloadWorldAndMeasure(); MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(player -> player.setInstance(instance, new Pos(0, 100, 0)) diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ChunkFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ChunkFilter.java deleted file mode 100644 index a72ebcc6d..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ChunkFilter.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -/** - * This interface defines a filter for determining whether terrain and features - * should be placed during chunk generation. Implementations of this interface - * can apply custom logic to selectively control terrain and feature placement - * in specific chunks for debugging purposes. - */ -public interface ChunkFilter { - boolean shouldPlaceTerrain(int x, int z); - boolean shouldPlaceFeatures(int x, int z); -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/EvenChunkFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/EvenChunkFilter.java deleted file mode 100644 index f97507ed1..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/EvenChunkFilter.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class EvenChunkFilter implements ChunkFilter { - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return x % 2 == 0 && z % 2 == 0; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return x % 2 == 0 && z % 2 == 0; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoFeaturesFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoFeaturesFilter.java deleted file mode 100644 index dbbdeb94d..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoFeaturesFilter.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class NoFeaturesFilter implements ChunkFilter { - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return true; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return false; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoTerrainFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoTerrainFilter.java deleted file mode 100644 index 671c746bd..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/NoTerrainFilter.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class NoTerrainFilter implements ChunkFilter { - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return false; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return true; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/SpecificChunkFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/SpecificChunkFilter.java deleted file mode 100644 index cd1670188..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/SpecificChunkFilter.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class SpecificChunkFilter implements ChunkFilter { - private final int x; - private final int z; - - public SpecificChunkFilter(int x, int z) { - this.x = x; - this.z = z; - } - - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return this.x == x && this.z == z; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return this.x == x && this.z == z; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/XFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/XFilter.java deleted file mode 100644 index c282bc2a3..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/XFilter.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class XFilter implements ChunkFilter { - private final int x; - - public XFilter(int x) { this.x = x; } - - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return this.x == x; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return this.x == x; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ZFilter.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ZFilter.java deleted file mode 100644 index 39dfb054e..000000000 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/api/filter/ZFilter.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.dfsek.terra.minestom.api.filter; - -public class ZFilter implements ChunkFilter { - private final int z; - - public ZFilter(int z) { this.z = z; } - - @Override - public boolean shouldPlaceTerrain(int x, int z) { - return this.z == z; - } - - @Override - public boolean shouldPlaceFeatures(int x, int z) { - return this.z == z; - } -} diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkGeneratorWrapper.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkGeneratorWrapper.java index 9daf2b60f..5fbe9da90 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkGeneratorWrapper.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/MinestomChunkGeneratorWrapper.java @@ -1,9 +1,9 @@ package com.dfsek.terra.minestom.world; +import com.dfsek.terra.api.config.ConfigPack; import com.dfsek.terra.api.world.chunk.generation.ChunkGenerator; import com.dfsek.terra.api.world.chunk.generation.stage.GenerationStage; -import com.dfsek.terra.minestom.api.filter.ChunkFilter; import com.dfsek.terra.minestom.chunk.CachedChunk; import com.dfsek.terra.minestom.chunk.GeneratedChunkCache; @@ -15,14 +15,14 @@ public class MinestomChunkGeneratorWrapper implements Generator { private final GeneratedChunkCache cache; - private final ChunkGenerator generator; + private ChunkGenerator generator; private final TerraMinestomWorld world; - private final ChunkFilter filter; + private ConfigPack pack; - public MinestomChunkGeneratorWrapper(ChunkGenerator generator, TerraMinestomWorld world, ChunkFilter filter) { + public MinestomChunkGeneratorWrapper(ChunkGenerator generator, TerraMinestomWorld world, ConfigPack pack) { this.generator = generator; this.world = world; - this.filter = filter; + this.pack = pack; this.cache = new GeneratedChunkCache(world.getDimensionType(), generator, world); } @@ -36,18 +36,24 @@ public void generate(@NotNull GenerationUnit unit) { int x = start.chunkX(); int z = start.chunkZ(); CachedChunk chunk = cache.at(x, z); - if(filter == null || filter.shouldPlaceTerrain(x, z)) - chunk.writeRelative(unit.modifier()); - - if(filter == null || filter.shouldPlaceFeatures(x, z)) { - unit.fork(setter -> { - MinestomProtoWorld protoWorld = new MinestomProtoWorld(cache, x, z, world, setter); - - for(GenerationStage stage : world.getPack().getStages()) { - stage.populate(protoWorld); - } - }); - } + chunk.writeRelative(unit.modifier()); + + unit.fork(setter -> { + MinestomProtoWorld protoWorld = new MinestomProtoWorld(cache, x, z, world, setter); + + for(GenerationStage stage : world.getPack().getStages()) { + stage.populate(protoWorld); + } + }); + } + + public ConfigPack getPack() { + return pack; + } + + public void setPack(ConfigPack pack) { + this.pack = pack; + this.generator = pack.getGeneratorProvider().newInstance(pack); } public void displayStats() { diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorld.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorld.java index e5cf73410..0cce989cf 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorld.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorld.java @@ -16,7 +16,6 @@ import com.dfsek.terra.minestom.api.BlockEntityFactory; import com.dfsek.terra.minestom.api.EntityFactory; import com.dfsek.terra.minestom.block.MinestomBlockState; -import com.dfsek.terra.minestom.api.filter.ChunkFilter; import com.dfsek.terra.minestom.entity.MinestomEntity; import net.minestom.server.MinecraftServer; @@ -43,7 +42,6 @@ public TerraMinestomWorld( ConfigPack pack, long seed, EntityFactory entityFactory, - ChunkFilter filter, BlockEntityFactory blockEntityFactory ) { this.instance = instance; @@ -56,7 +54,7 @@ public TerraMinestomWorld( this.wrapper = new MinestomChunkGeneratorWrapper( pack.getGeneratorProvider().newInstance(pack), this, - filter + pack ); this.entityFactory = entityFactory; diff --git a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorldBuilder.java b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorldBuilder.java index 86ff34c41..7d04d6c9c 100644 --- a/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorldBuilder.java +++ b/platforms/minestom/src/main/java/com/dfsek/terra/minestom/world/TerraMinestomWorldBuilder.java @@ -7,12 +7,10 @@ import com.dfsek.terra.minestom.MinestomPlatform; import com.dfsek.terra.minestom.api.BlockEntityFactory; import com.dfsek.terra.minestom.api.EntityFactory; -import com.dfsek.terra.minestom.api.filter.ChunkFilter; import com.dfsek.terra.minestom.block.DefaultBlockEntityFactory; import com.dfsek.terra.minestom.entity.DefaultEntityFactory; import net.minestom.server.MinecraftServer; import net.minestom.server.instance.Instance; -import org.jetbrains.annotations.Nullable; import java.util.Random; import java.util.function.Function; @@ -23,7 +21,6 @@ public class TerraMinestomWorldBuilder { private ConfigPack pack; private long seed = new Random().nextLong(); private EntityFactory entityFactory = new DefaultEntityFactory(); - private ChunkFilter filter; private BlockEntityFactory blockEntityFactory = new DefaultBlockEntityFactory(); private TerraMinestomWorldBuilder(Instance instance) { this.instance = instance; } @@ -75,12 +72,7 @@ public TerraMinestomWorldBuilder blockEntityFactory(BlockEntityFactory factory) return this; } - public TerraMinestomWorldBuilder filtered(@Nullable ChunkFilter filter) { - this.filter = filter; - return this; - } - public TerraMinestomWorld attach() { - return new TerraMinestomWorld(instance, pack, seed, entityFactory, filter, blockEntityFactory); + return new TerraMinestomWorld(instance, pack, seed, entityFactory, blockEntityFactory); } }