use of org.spongepowered.api.world.GeneratorType 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.GeneratorType in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onCreateSpawnPosition.
@Inject(method = "createSpawnPosition(Lnet/minecraft/world/WorldSettings;)V", at = @At("HEAD"), cancellable = true)
private void onCreateSpawnPosition(WorldSettings settings, CallbackInfo ci) {
GeneratorType generatorType = (GeneratorType) settings.getTerrainType();
// Allow bonus chest generation for non-Overworld worlds
if (!this.provider.canRespawnHere() && this.getProperties().doesGenerateBonusChest()) {
this.createBonusChest();
}
if ((generatorType != null && generatorType.equals(GeneratorTypes.THE_END)) || ((((WorldServer) (Object) this)).getChunkProvider().chunkGenerator instanceof ChunkGeneratorEnd)) {
this.worldInfo.setSpawn(new BlockPos(100, 50, 0));
ci.cancel();
}
}
use of org.spongepowered.api.world.GeneratorType in project ProjectWorlds by trentech.
the class CommandCreate method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("create")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length <= 1) {
return list;
}
String arg = args[args.length - 1];
if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-dimension")) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
list.add(type.getId());
}
} else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("-generator")) {
for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
list.add(type.getId());
}
} else if (arg.equalsIgnoreCase("-gm") || arg.equalsIgnoreCase("-gamemode")) {
for (Gamemode type : Gamemode.values()) {
list.add(Integer.toString(type.getIndex()));
list.add(type.getGameMode().getName());
}
} else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("-modifier")) {
for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(type.getId());
}
} else if (arg.equalsIgnoreCase("-df") || arg.equalsIgnoreCase("-difficulty")) {
for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
list.add(type.getId());
}
} else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
list.add("true");
list.add("false");
} else {
String parent = args[args.length - 2];
if (parent.equalsIgnoreCase("-d") || parent.equalsIgnoreCase("-dimension")) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
list.add(type.getId());
}
}
} else if (parent.equalsIgnoreCase("-g") || parent.equalsIgnoreCase("-generator")) {
for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
list.add(type.getId());
}
}
} else if (parent.equalsIgnoreCase("-gm") || parent.equalsIgnoreCase("-gamemode")) {
for (Gamemode type : Gamemode.values()) {
if (type.getGameMode().getName().toLowerCase().startsWith(arg.toLowerCase())) {
list.add(type.getGameMode().getName());
}
}
} else if (parent.equalsIgnoreCase("-m") || parent.equalsIgnoreCase("-modifier")) {
for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
list.add(type.getId());
}
}
} else if (parent.equalsIgnoreCase("-df") || parent.equalsIgnoreCase("-difficulty")) {
for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
list.add(type.getId());
}
}
} else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
if ("true".startsWith(arg.toLowerCase())) {
list.add("true");
}
if ("false".startsWith(arg.toLowerCase())) {
list.add("false");
}
}
}
return list;
}
use of org.spongepowered.api.world.GeneratorType in project ProjectWorlds by trentech.
the class CommandImport method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("import")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
list.add(type.getId());
}
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
}
if (args.length == 2) {
for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (GeneratorType genType : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
list.add(genType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
if (args.length == 3) {
for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(modType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
if (args.length >= 4) {
for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
if (type.getId().equalsIgnoreCase(args[1])) {
for (WorldGeneratorModifier modType : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
list.add(modType.getId());
}
return list;
}
if (type.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(type.getId());
}
}
}
return list;
}
use of org.spongepowered.api.world.GeneratorType in project ProjectWorlds by trentech.
the class CommandImport method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("import")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
String worldName;
String genType;
String dimType;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
if (Sponge.getServer().getWorld(worldName).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " is already loaded"), false);
}
WorldData worldData = new WorldData(worldName);
if (!worldData.exists()) {
throw new CommandException(Text.of(TextColors.RED, worldName, " is not a valid world"), false);
}
SpongeData spongeData = new SpongeData(worldName);
if (spongeData.exists()) {
source.sendMessage(Text.of(TextColors.RED, "Sponge world detected"));
source.sendMessage(Text.builder().color(TextColors.YELLOW).onHover(TextActions.showText(Text.of("Click command for more information "))).onClick(TextActions.runCommand("/pjw:world load")).append(Text.of(" /world load")).build());
return CommandResult.success();
}
try {
dimType = args[1];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<DimensionType> optionalDimensionType = Sponge.getRegistry().getType(DimensionType.class, dimType);
if (!optionalDimensionType.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, dimType, " is not a valid DimensionType"));
throw new CommandException(getHelp().getUsageText());
}
DimensionType dimensionType = optionalDimensionType.get();
try {
genType = args[2];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<GeneratorType> optionalGeneratorType = Sponge.getRegistry().getType(GeneratorType.class, genType);
if (!optionalGeneratorType.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, genType, " is not a valid GeneratorType"));
throw new CommandException(getHelp().getUsageText());
}
GeneratorType generatorType = optionalGeneratorType.get();
WorldArchetype.Builder builder = WorldArchetype.builder().dimension(dimensionType).generator(generatorType).enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true);
Collection<WorldGeneratorModifier> modifiers = Collections.<WorldGeneratorModifier>emptyList();
if (args.length >= 4) {
for (int i = 3; i < args.length - 3; i++) {
Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, args[i]);
if (!optionalModifier.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, args[i], " is not a valid WorldGeneratorModifier"));
throw new CommandException(getHelp().getUsageText());
}
modifiers.add(optionalModifier.get());
}
}
WorldArchetype settings = builder.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);
source.sendMessage(Text.of(TextColors.DARK_GREEN, worldName, " imported successfully"));
return CommandResult.success();
}
Aggregations