feat: implemented default module for easy start
This commit is contained in:
parent
bf8f4042b4
commit
761015b6a8
@ -1,10 +1,15 @@
|
|||||||
package ru.dragonestia.msb3.api;
|
package ru.dragonestia.msb3.api;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import ru.dragonestia.msb3.api.module.FlatWorldModule;
|
||||||
|
|
||||||
public class Bootstrap {
|
public class Bootstrap {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
var boot = new ServerBootstrap();
|
var boot = new ServerBootstrap();
|
||||||
|
|
||||||
|
FlatWorldModule.init(GameMode.ADVENTURE);
|
||||||
|
|
||||||
boot.start("0.0.0.0", 25565);
|
boot.start("0.0.0.0", 25565);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,8 @@ public class ServerBootstrap {
|
|||||||
|
|
||||||
server = MinecraftServer.init();
|
server = MinecraftServer.init();
|
||||||
|
|
||||||
|
MinecraftServer.setBrandName("Dragonestia");
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,69 @@
|
|||||||
|
package ru.dragonestia.msb3.api.module;
|
||||||
|
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
|
import net.minestom.server.coordinate.Pos;
|
||||||
|
import net.minestom.server.entity.GameMode;
|
||||||
|
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
||||||
|
import net.minestom.server.instance.Chunk;
|
||||||
|
import net.minestom.server.instance.DynamicChunk;
|
||||||
|
import net.minestom.server.instance.IChunkLoader;
|
||||||
|
import net.minestom.server.instance.Instance;
|
||||||
|
import net.minestom.server.instance.block.Block;
|
||||||
|
import net.minestom.server.world.DimensionType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class FlatWorldModule {
|
||||||
|
|
||||||
|
private static boolean used = false;
|
||||||
|
|
||||||
|
private FlatWorldModule() {}
|
||||||
|
|
||||||
|
public static synchronized void init(GameMode gameMode) {
|
||||||
|
if (used) return;
|
||||||
|
used = true;
|
||||||
|
|
||||||
|
var dimension = MinecraftServer.getDimensionTypeRegistry().register("msb3:full_bright", DimensionType.builder()
|
||||||
|
.ambientLight(2f)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
var instance = MinecraftServer.getInstanceManager().createInstanceContainer(dimension, new IChunkLoader() {
|
||||||
|
@Override
|
||||||
|
public @NotNull CompletableFuture<@Nullable Chunk> loadChunk(@NotNull Instance instance, int chunkX, int chunkZ) {
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
var chunk = new DynamicChunk(instance, chunkX, chunkZ);
|
||||||
|
for (int x = 0; x < 16; x++) {
|
||||||
|
for (int z = 0; z < 16; z++) {
|
||||||
|
for (int y = 0; y <= 10; y++) {
|
||||||
|
var block = switch (y) {
|
||||||
|
case 10 -> Block.GRASS_BLOCK;
|
||||||
|
case 9, 8, 7 -> Block.DIRT;
|
||||||
|
case 0 -> Block.BEDROCK;
|
||||||
|
default -> Block.STONE;
|
||||||
|
};
|
||||||
|
chunk.setBlock(x, y, z, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chunk;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull CompletableFuture<Void> saveChunk(@NotNull Chunk chunk) {
|
||||||
|
return new CompletableFuture<>();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MinecraftServer.getGlobalEventHandler().addListener(AsyncPlayerConfigurationEvent.class, event -> {
|
||||||
|
var player = event.getPlayer();
|
||||||
|
|
||||||
|
player.setRespawnPoint(new Pos(0, 11, 0));
|
||||||
|
player.setGameMode(gameMode);
|
||||||
|
|
||||||
|
event.setSpawningInstance(instance);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user