Skip to content

Instantly share code, notes, and snippets.

@keir-nellyer
Created October 21, 2015 16:51
Show Gist options
  • Save keir-nellyer/52cd4c645e54c7d4fe5c to your computer and use it in GitHub Desktop.
Save keir-nellyer/52cd4c645e54c7d4fe5c to your computer and use it in GitHub Desktop.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<String> worldName = args.getOne("world-name");
src.sendMessage(Texts.of("Starting world build..."));
if (worldName.isPresent()) {
Optional<World> worldOptional = game.getRegistry().createWorldBuilder()
.name(worldName.get())
.enabled(true)
.loadsOnStartup(false)
.keepsSpawnLoaded(false)
.dimensionType(DimensionTypes.OVERWORLD)
.generator(GeneratorTypes.OVERWORLD)
.gameMode(GameModes.CREATIVE)
.build();
if (worldOptional.isPresent()) {
World world = worldOptional.get();
net.minecraft.world.World nmsWorld = (net.minecraft.world.World) world;
Location<World> location = world.getSpawnLocation();
ChunkIOExecutor.queueChunkLoad(nmsWorld,
(AnvilChunkLoader) nmsWorld.getSaveHandler().getChunkLoader(nmsWorld.provider),
(ChunkProviderServer) nmsWorld.getChunkProvider(),
location.getBlockX(),
location.getBlockZ(),
() -> { // presume this is run when chunk is meant to be loaded?
if (src instanceof Player) {
((Player) src).setLocationSafely(world.getSpawnLocation());
}
}
);
src.sendMessage(Texts.of("World created and queued for loading."));
} else {
src.sendMessage(Texts.of("World couldn't be created for some reason."));
return CommandResult.empty();
}
} else {
src.sendMessage(Texts.of("Missing world name."));
return CommandResult.empty();
}
return CommandResult.success();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment