use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project SpongeCommon by SpongePowered.
the class MixinWorldInfo method onConstruction.
// public WorldInfo(WorldSettings settings, String name)
@Inject(method = "<init>*", at = @At("RETURN"))
public void onConstruction(WorldSettings settings, String name, CallbackInfo ci) {
if (name.equals("MpServer") || name.equals("sponge$dummy_world")) {
this.isValid = false;
this.isConstructed = true;
return;
}
onConstructionCommon();
final WorldArchetype archetype = (WorldArchetype) (Object) settings;
setDimensionType(archetype.getDimensionType());
createWorldConfig();
setEnabled(archetype.isEnabled());
setLoadOnStartup(archetype.loadOnStartup());
if (((IMixinWorldSettings) (Object) settings).internalKeepSpawnLoaded() != null) {
setKeepSpawnLoaded(archetype.doesKeepSpawnLoaded());
}
setGenerateSpawnOnLoad(archetype.doesGenerateSpawnOnLoad());
setDifficulty(archetype.getDifficulty());
Collection<WorldGeneratorModifier> modifiers = this.getGeneratorModifiers();
if (modifiers.isEmpty()) {
setGeneratorModifiers(archetype.getGeneratorModifiers());
} else {
// use config modifiers
setGeneratorModifiers(modifiers);
}
setDoesGenerateBonusChest(archetype.doesGenerateBonusChest());
setSerializationBehavior(archetype.getSerializationBehavior());
this.getOrCreateWorldConfig().save();
this.isConstructed = true;
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project SpongeCommon by SpongePowered.
the class MixinWorldServer method updateWorldGenerator.
@Override
public void updateWorldGenerator() {
// Get the default generator for the world type
DataContainer generatorSettings = this.getProperties().getGeneratorSettings();
SpongeWorldGenerator newGenerator = createWorldGenerator(generatorSettings);
// by the base generation populator
if (newGenerator.getBaseGenerationPopulator() instanceof IChunkGenerator) {
// from a mod chunk provider extending a provider that we mixed into
if (WorldGenConstants.isValid((IChunkGenerator) newGenerator.getBaseGenerationPopulator(), IPopulatorProvider.class)) {
((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
}
} else if (newGenerator.getBaseGenerationPopulator() instanceof IPopulatorProvider) {
// If its not a chunk provider but is a populator provider then we call it as well
((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
}
for (WorldGeneratorModifier modifier : this.getProperties().getGeneratorModifiers()) {
modifier.modifyWorldGenerator(this.getProperties(), generatorSettings, newGenerator);
}
this.spongegen = createChunkGenerator(newGenerator);
this.spongegen.setGenerationPopulators(newGenerator.getGenerationPopulators());
this.spongegen.setPopulators(newGenerator.getPopulators());
this.spongegen.setBiomeOverrides(newGenerator.getBiomeSettings());
ChunkProviderServer chunkProviderServer = this.getChunkProvider();
chunkProviderServer.chunkGenerator = this.spongegen;
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project Skree by Skelril.
the class WorldSystem method buildArchetype.
private void buildArchetype(ArchetypeConfig archetypeConfig) throws Throwable {
GameRegistry registry = Sponge.getRegistry();
Optional<WorldArchetype> optTargetArchetype = registry.getType(WorldArchetype.class, archetypeConfig.getId());
if (optTargetArchetype.isPresent()) {
return;
}
WorldArchetype.Builder archeTypeBuilder = obtainAutoloadingWorld();
String dimensionName = archetypeConfig.getDimension();
DimensionType dimension = registry.getType(DimensionType.class, dimensionName).orElseThrow((Supplier<Throwable>) () -> {
List<String> valid = registry.getAllOf(DimensionType.class).stream().map(DimensionType::getId).collect(Collectors.toList());
return new RuntimeException("No dimension type: " + dimensionName + "; Valid dimension types: " + Joiner.on(", ").join(valid));
});
archeTypeBuilder.dimension(dimension);
String generatorName = archetypeConfig.getGenerator();
GeneratorType generator = registry.getType(GeneratorType.class, generatorName).orElseThrow((Supplier<Throwable>) () -> {
List<String> valid = registry.getAllOf(GeneratorType.class).stream().map(GeneratorType::getId).collect(Collectors.toList());
return new RuntimeException("No generator type: " + generatorName + "; Valid generator types: " + Joiner.on(", ").join(valid));
});
archeTypeBuilder.generator(generator);
boolean usesMapFeatures = archetypeConfig.usesMapFeatures();
archeTypeBuilder.usesMapFeatures(usesMapFeatures);
List<WorldGeneratorModifier> modifiers = new ArrayList<>();
for (String modifierId : archetypeConfig.getModifiers()) {
modifiers.add(registry.getType(WorldGeneratorModifier.class, modifierId).orElseThrow((Supplier<Throwable>) () -> {
return new RuntimeException("No world generator modifier: " + modifierId);
}));
}
archeTypeBuilder.generatorModifiers(modifiers.toArray(new WorldGeneratorModifier[modifiers.size()]));
archeTypeBuilder.build(archetypeConfig.getId(), archetypeConfig.getName());
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project ProjectWorlds by trentech.
the class CommandCreate method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("create")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
String worldName;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
if (Sponge.getServer().getWorldProperties(worldName).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " already exists"), false);
}
WorldArchetype.Builder builder = WorldArchetype.builder();
List<WorldGeneratorModifier> modifiers = new ArrayList<>();
if (args.length > 2) {
boolean skip = false;
for (int i = 1; i < args.length - 1; i++) {
if (skip) {
skip = false;
continue;
}
String arg = args[i];
String value;
try {
value = args[i + 1];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-dimension")) {
Optional<DimensionType> optionalDimension = Sponge.getRegistry().getType(DimensionType.class, value);
if (!optionalDimension.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid DimensionType"));
throw new CommandException(getHelp().getUsageText());
}
builder.dimension(optionalDimension.get());
} else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("-generator")) {
String[] split = value.split("\\{");
Optional<GeneratorType> optionalGenerator = Sponge.getRegistry().getType(GeneratorType.class, split[0]);
if (!optionalGenerator.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid GeneratorType"));
throw new CommandException(getHelp().getUsageText());
}
builder.generator(optionalGenerator.get());
if (split.length == 2) {
builder.generatorSettings(DataContainer.createNew().set(DataQuery.of("customSettings"), split[1].replace("\\}", "")));
}
} else if (arg.equalsIgnoreCase("-gm") || arg.equalsIgnoreCase("-gamemode")) {
Optional<GameMode> optionalGamemode = Optional.empty();
try {
optionalGamemode = Gamemode.get(Integer.parseInt(value));
} catch (Exception e) {
optionalGamemode = Gamemode.get(value);
}
if (!optionalGamemode.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid GameMode"));
throw new CommandException(getHelp().getUsageText());
}
builder.gameMode(optionalGamemode.get());
} else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("-modifier")) {
Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, value);
if (!optionalModifier.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid WorldGeneratorModifier"));
throw new CommandException(getHelp().getUsageText());
}
modifiers.add(optionalModifier.get());
} else if (arg.equalsIgnoreCase("-s") || arg.equalsIgnoreCase("-seed")) {
try {
Long s = Long.parseLong(value);
builder.seed(s);
} catch (Exception e) {
builder.seed(value.hashCode());
}
} else if (arg.equalsIgnoreCase("-df") || arg.equalsIgnoreCase("-difficulty")) {
Optional<Difficulty> optionalDifficulty = Sponge.getRegistry().getType(Difficulty.class, value);
if (!optionalDifficulty.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Difficulty"));
throw new CommandException(getHelp().getUsageText());
}
builder.difficulty(optionalDifficulty.get());
} else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup")) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
builder.loadsOnStartup(Boolean.valueOf(value));
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
} else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded")) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
builder.keepsSpawnLoaded(Boolean.valueOf(value));
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
} else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands")) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
builder.commandsAllowed(Boolean.valueOf(value));
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
} else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest")) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
builder.generateBonusChest(Boolean.valueOf(value));
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
} else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
builder.usesMapFeatures(Boolean.valueOf(value));
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
throw new CommandException(getHelp().getUsageText());
}
} else {
source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Flag"));
throw new CommandException(getHelp().getUsageText());
}
skip = true;
}
}
WorldArchetype settings = builder.enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true).build(worldName, worldName);
WorldProperties properties;
try {
properties = Sponge.getServer().createWorldProperties(worldName, settings);
properties.setGeneratorModifiers(modifiers);
} catch (IOException e) {
e.printStackTrace();
throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
}
Sponge.getServer().saveWorldProperties(properties);
worlds.add(worldName);
source.sendMessage(Text.of(TextColors.DARK_GREEN, worldName, " created successfully"));
return CommandResult.success();
}
use of org.spongepowered.api.world.gen.WorldGeneratorModifier in project ProjectWorlds by trentech.
the class CommandModifier method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("modifier")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
for (WorldGeneratorModifier modifier : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(modifier.getId());
}
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
}
if (args.length >= 2) {
for (WorldGeneratorModifier modifier : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
if (modifier.getId().equalsIgnoreCase(args[1])) {
return list;
}
if (modifier.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(modifier.getId());
}
}
}
return list;
}
Aggregations