Search in sources :

Example 1 with Expect

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);
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) PacketEditStructureHandler(ivorius.reccomplex.network.PacketEditStructureHandler) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RCP(ivorius.reccomplex.commands.parameters.RCP) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)

Example 2 with Expect

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));
}
Also used : GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) TextFormatting(net.minecraft.util.text.TextFormatting) ClickEvent(net.minecraft.util.text.event.ClickEvent) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) RCStrings(ivorius.reccomplex.utils.RCStrings) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) HoverEvent(net.minecraft.util.text.event.HoverEvent) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) HoverEvent(net.minecraft.util.text.event.HoverEvent) ClickEvent(net.minecraft.util.text.event.ClickEvent) Metadata(ivorius.reccomplex.world.gen.feature.structure.generic.Metadata) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with Expect

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!"));
}
Also used : Path(java.nio.file.Path) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) CommandSearchStructure(ivorius.reccomplex.commands.structure.CommandSearchStructure) ivorius.reccomplex.world.gen.feature.structure.generic.generation(ivorius.reccomplex.world.gen.feature.structure.generic.generation) Loader(net.minecraftforge.fml.common.Loader) PriorityQueue(java.util.PriorityQueue) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) RCConfig(ivorius.reccomplex.RCConfig) BiPredicate(java.util.function.BiPredicate) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RCFiles(ivorius.reccomplex.files.RCFiles) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) StructureSelector(ivorius.reccomplex.world.gen.feature.selector.StructureSelector) Path(java.nio.file.Path) DimensionManager(net.minecraftforge.common.DimensionManager) Files(java.nio.file.Files) World(net.minecraft.world.World) IRegistry(net.minecraft.util.registry.IRegistry) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) ConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.ConnectorStrategy) TextComponentString(net.minecraft.util.text.TextComponentString) Expect(ivorius.mcopts.commands.parameters.expect.Expect) Stream(java.util.stream.Stream) ICommandSender(net.minecraft.command.ICommandSender) ResourceLocation(net.minecraft.util.ResourceLocation) ModContainer(net.minecraftforge.fml.common.ModContainer) Parameters(ivorius.mcopts.commands.parameters.Parameters) Biome(net.minecraft.world.biome.Biome) Parameters(ivorius.mcopts.commands.parameters.Parameters) ModContainer(net.minecraftforge.fml.common.ModContainer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) ResourceLocation(net.minecraft.util.ResourceLocation) RCFiles(ivorius.reccomplex.files.RCFiles)

Example 4 with Expect

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));
}
Also used : CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) Operation(ivorius.reccomplex.operation.Operation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) RCCommands(ivorius.reccomplex.commands.RCCommands) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) ivorius.mcopts.commands.parameters(ivorius.mcopts.commands.parameters) RCConfig(ivorius.reccomplex.RCConfig) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) EntityPlayer(net.minecraft.entity.player.EntityPlayer) RCEntityInfo(ivorius.reccomplex.capability.RCEntityInfo) Operation(ivorius.reccomplex.operation.Operation)

Example 5 with Expect

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));
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) MCE(ivorius.mcopts.commands.parameters.expect.MCE) Predicate(java.util.function.Predicate) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) RCConfig(ivorius.reccomplex.RCConfig) RCE(ivorius.reccomplex.commands.parameters.expect.RCE) BlockSurfaceArea(ivorius.ivtoolkit.blocks.BlockSurfaceArea) RCP(ivorius.reccomplex.commands.parameters.RCP) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) IvP(ivorius.reccomplex.commands.parameters.IvP) WorldGenStructures(ivorius.reccomplex.world.gen.feature.WorldGenStructures) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) WorldServer(net.minecraft.world.WorldServer) Nonnull(javax.annotation.Nonnull) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) BlockSurfaceArea(ivorius.ivtoolkit.blocks.BlockSurfaceArea) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) RCP(ivorius.reccomplex.commands.parameters.RCP)

Aggregations

CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 RCConfig (ivorius.reccomplex.RCConfig)10 CommandException (net.minecraft.command.CommandException)10 ICommandSender (net.minecraft.command.ICommandSender)10 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)9 MinecraftServer (net.minecraft.server.MinecraftServer)9 RCP (ivorius.reccomplex.commands.parameters.RCP)8 Parameters (ivorius.mcopts.commands.parameters.Parameters)7 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 RCCommands (ivorius.reccomplex.commands.RCCommands)5 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)5 NaP (ivorius.mcopts.commands.parameters.NaP)4 MCE (ivorius.mcopts.commands.parameters.expect.MCE)4 RCTextStyle (ivorius.reccomplex.commands.RCTextStyle)4 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)4 StructureRegistry (ivorius.reccomplex.world.gen.feature.structure.StructureRegistry)4 LeveledRegistry (ivorius.reccomplex.files.loading.LeveledRegistry)3 RawResourceLocation (ivorius.reccomplex.utils.RawResourceLocation)3 ResourceExpression (ivorius.reccomplex.utils.expression.ResourceExpression)3