[SOLVED]World Builder

K so what i’m trying to do is create a new world using a command…just basic all predetermined in the code like every single one is in the overworld…any one willing to help is amazing… thank you

it is possible to create a world by using the world builder class like this:

public World generateWorld(String name) {
    WorldBuilder builder = this.game.getRegistry().createBuilder(WorldBuilder.class);
    builder.dimensionType(DimensionTypes.OVERWORLD);
    builder.name(name);
    builder.enabled(true);
    builder.hardcore(false);
    builder.keepsSpawnLoaded(true);
    builder.loadsOnStartup(true);
    builder.usesMapFeatures(false);
    builder.generator(GeneratorTypes.DEFAULT);
    Optional<World> optWorld = builder.build();
    if (optWorld.isPresent()) {
        return (optWorld.get());
    }
    return null;
}
1 Like

ok so i see that that would work on it’s own…but how would i get it to tie in with a command? thjis is what i have in a CreateWorld class seperate from the mainClass.

> public class CreateWorld implements CommandExecutor {
>     private Game game;
>     private String name;
>     public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
>             WorldBuilder builder = this.game.getRegistry().createBuilder(WorldBuilder.class);
>             builder.dimensionType(DimensionTypes.OVERWORLD);
>             builder.name(name);
>             builder.enabled(true);
>             builder.hardcore(false);
>             builder.keepsSpawnLoaded(true);
>             builder.loadsOnStartup(true);
>             builder.usesMapFeatures(false);
>             builder.generator(GeneratorTypes.DEFAULT);
>             Optional<World> optWorld = builder.build();
>             if (optWorld.isPresent()) {
>                 return (optWorld.get());
>             }
>             return null;
>         return null;
>     }

}

however i want it to work whenever t;his code is called from the main class :slight_smile: any help is awesome as always :smile:

ok…so i figured if i make a new command and then using the command class that handles it to call a new instance of the world creation it would make a new world… but after i type /mv name i get this in the server logs

[16:42:05] [Server thread/FATAL] [FML/]: Exception caught executing FutureTask: java.util.concurrent.ExecutionException: java.lang.NullPointerException
java.util.concurrent.ExecutionException: java.lang.NullPointerException
	at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_65]
	at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_65]
	at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:715) [FMLCommonHandler.class:?]
	at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:656) [MinecraftServer.class:?]
	at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:364) [po.class:?]
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:598) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478) [MinecraftServer.class:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
Caused by: java.lang.NullPointerException
	at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:81) ~[cl.class:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:812) ~[rj.class:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:791) ~[rj.class:?]
	at net.minecraft.network.play.client.C01PacketChatMessage.func_180757_a(SourceFile:37) ~[lu.class:?]
	at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:9) ~[lu.class:?]
	at net.minecraft.network.PacketThreadUtil$1.onProcessPacket(SourceFile:63) ~[ih.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) ~[ih.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_65]
	at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_65]
	at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) ~[FMLCommonHandler.class:?]
	... 5 more

any and all help with getting this to work correctely would be awesome

You’re returning null in execute which breaks it’s non-null contract.
You need to return an instanceof CommandResult, for example CommandResult.success();

1 Like

Hmmm ok well in eclipse there are no errors on it…however now i’m having other issues…here’s what i have so far

MainClass.java
> package me.Cleardragonf.Multiverse;

> import org.spongepowered.api.event.game.state.GamePreInitializationEvent;

> import org.spongepowered.api.service.config.ConfigDir;
> import org.spongepowered.api.event.network.ClientConnectionEvent.Join;
> import org.spongepowered.api.event.game.state.GameInitializationEvent;

> import java.io.File;

> import ninja.leaping.configurate.commented.CommentedConfigurationNode;
> import ninja.leaping.configurate.loader.ConfigurationLoader;
> import org.spongepowered.api.service.config.DefaultConfig;
> import com.google.inject.Inject;
> import org.spongepowered.api.util.command.spec.CommandSpec;
> import org.spongepowered.api.text.Texts;
> import org.spongepowered.api.event.Listener;
> import org.spongepowered.api.plugin.Plugin;

> @Plugin(id = "ManyVerse", name = "ManyVerse", version = "0.0.1")
> public class MainClass {

>     @Inject @ConfigDir(sharedRoot = false) private File configDir;

>     // this is where the file is located
>     @Inject @DefaultConfig(sharedRoot = false) private File configFile;

>     // this loads the default config
>     @Inject @DefaultConfig(sharedRoot = false) private ConfigurationLoader<CommentedConfigurationNode> configManager;

>     @Listener
>     public void onGamePreInitializationEvent(GamePreInitializationEvent e) {
>         if (!configDir.exists())
>             configDir.mkdir();
>         if (!configFile.exists())
>             ;

>         ConfigManager.getInstance().setup(configFile, configManager);
>     }

>     @Listener
>     public void onGameInitializationEvent(GameInitializationEvent e) {
>         CommandSpec mv = CommandSpec.builder()
>                 .executor(new CreateWorld())
>                 .build();

>         e.getGame().getCommandDispatcher().register(this, mv, "mv", "ManyVerse", "manyverse");
>     }

>     @Listener
>     public void ClientConnectionEvent(Join e) {
>         e.getTargetEntity().sendMessage(Texts.of(ConfigManager.getInstance().getConfig().getNode("MOTD").getString()));
>     }
> }

CreateWorld.java

package me.Cleardragonf.Multiverse;


import java.util.Optional;

import org.spongepowered.api.world.World;
import org.spongepowered.api.world.GeneratorTypes;
import org.spongepowered.api.world.DimensionTypes;
import org.spongepowered.api.world.WorldBuilder;
import org.spongepowered.api.Game;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import org.spongepowered.api.util.command.args.CommandContext;
import org.spongepowered.api.util.command.spec.CommandExecutor;


public class CreateWorld implements CommandExecutor {

private Game game;
private String name;
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
WorldBuilder builder = this.game.getRegistry().createBuilder(WorldBuilder.class);
builder.dimensionType(DimensionTypes.OVERWORLD);
builder.name(name);
builder.hardcore(false);
builder.keepsSpawnLoaded(true);
builder.loadsOnStartup(true);
builder.usesMapFeatures(false);
builder.generator(GeneratorTypes.DEFAULT);
Optional optWorld = builder.build();
if (optWorld.isPresent()) {
return (CommandResult) (optWorld.get());
}
return CommandResult.success();
}
}

and finally there is a config manager but that’s not important can someone point out why i’m still getting issues?

the problem is with the name: you need to make it an argument:

onEnableMethod

createWorldCommand

1 Like

You can’t just say a world object is a command result. Doesn’t make sense to return the world there

ok so I’ve gotten all of it to play nice…however i’m getting this now that the world creation is an arguement like lucdon suggested and now when i type create Test the server comes up with the following nomethod

[20:05:48] [Server thread/ERROR] [Sponge/]: Error occurred while executing command 'create Test' for source EntityPlayerMP['Cleardragonf'/320, l='world', x=55.00, y=117.00, z=153.00]: org.spongepowered.api.GameRegistry.createBuilder(Ljava/lang/Class;)Lorg/spongepowered/api/util/ResettableBuilder;
java.lang.NoSuchMethodError: org.spongepowered.api.GameRegistry.createBuilder(Ljava/lang/Class;)Lorg/spongepowered/api/util/ResettableBuilder;
	at me.Cleardragonf.ManyVerse.WorldCreation.execute(WorldCreation.java:30) ~[WorldCreation.class:?]
	at org.spongepowered.api.util.command.spec.CommandSpec.process(CommandSpec.java:334) ~[CommandSpec.class:1.8-1521-2.1DEV-726+spongeproject-ci-b726.git-bd07085cf983e5024b395e249c647f6465c1295c]
	at org.spongepowered.api.util.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:340) ~[SimpleDispatcher.class:1.8-1521-2.1DEV-726+spongeproject-ci-b726.git-bd07085cf983e5024b395e249c647f6465c1295c]
	at org.spongepowered.api.service.command.SimpleCommandService.process(SimpleCommandService.java:250) [SimpleCommandService.class:1.8-1521-2.1DEV-726+spongeproject-ci-b726.git-bd07085cf983e5024b395e249c647f6465c1295c]
	at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:80) [cl.class:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:812) [rj.class:?]
	at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:791) [rj.class:?]
	at net.minecraft.network.play.client.C01PacketChatMessage.func_180757_a(SourceFile:37) [lu.class:?]
	at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:9) [lu.class:?]
	at net.minecraft.network.PacketThreadUtil$1.onProcessPacket(SourceFile:53) [ih.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [ih.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_65]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_65]
	at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:714) [FMLCommonHandler.class:?]
	at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:656) [MinecraftServer.class:?]
	at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:364) [po.class:?]
	at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:598) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:478) [MinecraftServer.class:?]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_65]
[20:06:16] [Server thread/DEBUG] [mixin/]: Mixing text.MixinTextPlaceholder from mixins.common.api.json into org.spongepowered.api.text.Text$Placeholder

ok but that doesn’t tell me what i need to do to make this work…I understand it doesn’t make sense and i understand that sponge is still being developed as i’ve already made several plugins for my hopefully future server all on sponge…but I do still need some help being a novice as such :slight_smile:

Build 726 is an old build which is why it’s failing. Get the latest version from spongeforge

1 Like

Yes! OMG YES!!! Now I just need to figure out a way to teleport between the two!!! or make a portal… but i’ll take either! thank you I’ll open up another Forum for that I hope these notes will help others Just as you all have helped me on this!!!