mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-22 02:25:48 +01:00
Updated Server setup (markdown)
parent
e49847b48d
commit
e4b392e08c
@ -27,4 +27,80 @@ _Please check the [instances](https://github.com/Minestom/Minestom/wiki/Instance
|
||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||
event.setSpawningInstance(YOUR_SPAWNING_INSTANCE);
|
||||
});
|
||||
```
|
||||
|
||||
Here is an example of a working Minestom server
|
||||
```java
|
||||
package your.package;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.event.player.PlayerLoginEvent;
|
||||
import net.minestom.server.event.player.PlayerSpawnEvent;
|
||||
import net.minestom.server.instance.*;
|
||||
import net.minestom.server.instance.batch.ChunkBatch;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.utils.Position;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainDemo {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Initialization
|
||||
MinecraftServer minecraftServer = MinecraftServer.init();
|
||||
|
||||
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
|
||||
// Create the instance
|
||||
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
|
||||
// Set the ChunkGenerator
|
||||
instanceContainer.setChunkGenerator(new GeneratorDemo());
|
||||
// Enable the auto chunk loading (when players come close)
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
|
||||
// Add event listeners
|
||||
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
||||
connectionManager.addPlayerInitialization(player -> {
|
||||
// Set the spawning instance
|
||||
player.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||
event.setSpawningInstance(instanceContainer);
|
||||
});
|
||||
|
||||
// Teleport the player at spawn
|
||||
player.addEventCallback(PlayerSpawnEvent.class, event -> {
|
||||
player.teleport(new Position(0, 45, 0));
|
||||
});
|
||||
});
|
||||
|
||||
// Start the server
|
||||
minecraftServer.start("localhost", 55555);
|
||||
}
|
||||
|
||||
public static class GeneratorDemo extends ChunkGenerator {
|
||||
|
||||
@Override
|
||||
public void generateChunkData(ChunkBatch batch, int chunkX, int chunkZ) {
|
||||
// Set chunk blocks
|
||||
for (byte x = 0; x < Chunk.CHUNK_SIZE_X; x++)
|
||||
for (byte z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
|
||||
for (byte y = 0; y < 40; y++) {
|
||||
batch.setBlock(x, y, z, Block.STONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
|
||||
Arrays.fill(biomes, Biome.PLAINS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ChunkPopulator> getPopulators() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
Loading…
Reference in New Issue
Block a user