Created
November 5, 2021 10:55
-
-
Save edewit/15f25b87b74b540b37e0b37f7683ccbf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//REPOS mavenCentral,sponge=https://repo.spongepowered.org/maven,jitpack=https://jitpack.io | |
//DEPS com.github.Minestom:Minestom:master-SNAPSHOT | |
import static java.lang.System.*; | |
import net.minestom.server.MinecraftServer; | |
public class server { | |
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()); | |
// Add an event callback to specify the spawning instance (and the spawn position) | |
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); | |
globalEventHandler.addListener(PlayerLoginEvent.class, event -> { | |
final Player player = event.getPlayer(); | |
event.setSpawningInstance(instanceContainer); | |
player.setRespawnPoint(new Pos(0, 42, 0)); | |
}); | |
// Start the server on port 25565 | |
minecraftServer.start("0.0.0.0", 25565); | |
} | |
private static class GeneratorDemo implements 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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment