use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandEditStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(commandSender);
Parameters parameters = Parameters.of(args, expect()::declare);
ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
String structureID = parameters.get("id").optional().orElse(parameters.get(0).require());
GenericStructure base = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
GenericStructure from = parameters.get("from").to(p -> RCP.genericStructure(p, false)).optional().orElse(base);
if (base != from) {
from = from.copyAsGenericStructure();
from.worldDataCompound = base.worldDataCompound.copy();
}
PacketEditStructureHandler.openEditStructure(entityPlayerMP, from, entityPlayerMP.getPosition(), structureID, directory);
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandLookupStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
String id = parameters.get(0).require();
GenericStructure structure = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
Metadata metadata = structure.metadata;
boolean hasWeblink = !metadata.weblink.trim().isEmpty();
ITextComponent weblink = hasWeblink ? new TextComponentString(RCStrings.abbreviateFormatted(metadata.weblink, 30)) : RecurrentComplex.translations.format("commands.rclookup.reply.nolink");
if (hasWeblink) {
weblink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, metadata.weblink));
weblink.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(metadata.weblink)));
}
ITextComponent level = new TextComponentString(StructureRegistry.INSTANCE.status(id).getLevel().toString());
level.getStyle().setColor(TextFormatting.YELLOW);
commandSender.sendMessage(RecurrentComplex.translations.format(StructureRegistry.INSTANCE.hasActive(id) ? "commands.rclookup.reply.generates" : "commands.rclookup.reply.silent", id, RCTextStyle.users(metadata.authors), level, weblink));
if (!metadata.comment.trim().isEmpty())
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rclookup.reply.comment", metadata.comment));
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandSanity method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
boolean sane = true;
if (RecurrentComplex.isLite()) {
commandSender.sendMessage(new TextComponentString("Recurrent Complex is in lightweight mode!"));
}
if (StructureRegistry.INSTANCE.ids().isEmpty()) {
commandSender.sendMessage(new TextComponentString("No registered structures!"));
sane = false;
}
if (!Files.isReadable(ResourceDirectory.getCustomDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from custom directory"));
sane = false;
}
for (ModContainer mod : Loader.instance().getModList()) {
String domain = mod.getModId();
Path path = null;
try {
path = RCFiles.pathFromResourceLocation(new ResourceLocation(domain.toLowerCase(), ""));
if (path != null && !Files.isReadable(path)) {
commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
sane = false;
}
} catch (RCFiles.ResourceLocationLoadException e) {
RecurrentComplex.logger.error(e);
commandSender.sendMessage(new TextComponentString("Error reading files from mod " + mod.getModId() + ": "));
commandSender.sendMessage(new TextComponentString(RCCommands.reason(e)));
sane = false;
} finally {
if (path != null)
RCFiles.closeQuietly(path.getFileSystem());
}
}
if (!Files.isReadable(ResourceDirectory.getServerDirectory().toPath())) {
commandSender.sendMessage(new TextComponentString("Can't read files from server directory"));
sane = false;
}
if (!parameters.has("short")) {
sane &= addStructureLog(commandSender, (s, structure) -> !structure.generationTypes(GenerationType.class).isEmpty(), "Missing generation type");
sane &= addGenericStructureLog(commandSender, (s, structure) -> !structure.metadata.authors.isEmpty(), "No author");
sane &= addGenericStructureLog(commandSender, (s, structure) -> structure.transformer.getTransformers().stream().allMatch(t -> t.id().length() > 0), "Transformer has empty ID");
sane &= addGenerationLog(commandSender, GenerationType.class, (structure, gen) -> gen.id().length() > 0, "Generation type has empty ID");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Natural generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any known dimensions");
sane &= addGenerationLog(commandSender, NaturalGeneration.class, (structure, gen) -> gen.getActiveGenerationWeight() > 0, "Natural generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> gen.biomeExpression.test(b)), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Vanilla structure generation type has no weight");
sane &= addGenerationLog(commandSender, VanillaGeneration.class, (structure, gen) -> gen.minBaseLimit > 0 || gen.maxBaseLimit > 0 || gen.maxScaledLimit > 0 || gen.minScaledLimit > 0, "Vanilla structure is always limited to zero instances");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> values(Biome.REGISTRY).anyMatch(b -> StructureSelector.generationWeightInBiome(gen.biomeWeights, b) > 0), "Vanilla structure generation type won't accept any known biomes");
sane &= addGenerationLog(commandSender, VanillaDecorationGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> StructureSelector.generationWeightInDimension(gen.dimensionWeights, d.provider) > 0), "Natural generation type won't accept any dimensions");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> gen.getWeight() > 0, "Maze generation type has no weight");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.getMazeID().trim().isEmpty(), "Maze generation type has maze id");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.rooms.isEmpty(), "Maze generation type has no rooms");
sane &= addGenerationLog(commandSender, MazeGeneration.class, (structure, gen) -> !gen.mazeComponent.exitPaths.isEmpty() || !gen.mazeComponent.defaultConnector.id.equals(ConnectorStrategy.DEFAULT_WALL), "Maze generation type has no walkable exits");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> !gen.listID.trim().isEmpty(), "List generation has no list id");
sane &= addGenerationLog(commandSender, ListGeneration.class, (structure, gen) -> gen.getWeight() > 0, "List generation has no weight");
sane &= addGenerationLog(commandSender, SaplingGeneration.class, (structure, gen) -> gen.getActiveWeight() > 0, "Sapling generation has no weight");
sane &= addGenerationLog(commandSender, StaticGeneration.class, (structure, gen) -> dimensions(server).anyMatch(d -> gen.dimensionExpression.test(d.provider)), "Static generation won't accept any known dimensions");
}
if (sane && !parameters.has("silent"))
commandSender.sendMessage(new TextComponentString("No problems identified!"));
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandPreview method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
EntityPlayer player = getCommandSenderAsPlayer(commandSender);
RCEntityInfo RCEntityInfo = RCCommands.getStructureEntityInfo(player, null);
Operation.PreviewType previewType = parameters.get(0).map(Operation.PreviewType::find, s -> RecurrentComplex.translations.commandException("commands.rcpreview.invalid")).require();
RCEntityInfo.setPreviewType(previewType);
RCEntityInfo.sendPreviewTypeToClients(player);
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcpreview.success", previewType.key));
}
use of ivorius.mcopts.commands.parameters.expect.Expect in project RecurrentComplex by Ivorforce.
the class CommandDecorate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
BlockSurfaceArea area = new BlockSurfaceArea(parameters.get(0).to(IvP.surfacePos(commandSender.getPosition(), false)).require(), parameters.get(2).to(IvP.surfacePos(commandSender.getPosition(), false)).require());
BlockSurfaceArea chunkArea = new BlockSurfaceArea(getChunkPos(area.getPoint1()), getChunkPos(area.getPoint2()));
Predicate<Structure> structurePredicate = parameters.get("exp").to(RCP::structurePredicate).optional().orElse(structureInfo -> true);
WorldServer world = (WorldServer) commandSender.getEntityWorld();
if (parameters.has("one")) {
BlockSurfacePos lower = area.getLowerCorner();
int[] size = area.areaSize();
BlockPos pos = new BlockPos(lower.x + world.rand.nextInt(size[0]), 0, lower.z + world.rand.nextInt(size[1]));
if (!WorldGenStructures.generateOneStructureInChunk(world.rand, new ChunkPos(pos), world, world.getBiome(pos)))
throw RecurrentComplex.translations.commandException("commands.rcdecorateone.none");
} else
chunkArea.forEach(coord -> WorldGenStructures.decorate(world, world.rand, new ChunkPos(coord.x, coord.z), structurePredicate));
}
Aggregations