Search in sources :

Example 6 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandSightInfo method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    WorldStructureGenerationData generationData = WorldStructureGenerationData.get(sender.getEntityWorld());
    WorldStructureGenerationData.Entry entry = generationData.getEntry(UUID.fromString(parameters.get(0).require()));
    if (entry == null)
        throw RecurrentComplex.translations.commandException("commands.rcsightinfo.unknown");
    else {
        ITextComponent area = RCTextStyle.area(RCBlockAreas.from(entry.getBoundingBox()));
        ITextComponent sight = RCTextStyle.sight(entry, true);
        if (entry instanceof WorldStructureGenerationData.StructureEntry) {
            WorldStructureGenerationData.StructureEntry structureEntry = (WorldStructureGenerationData.StructureEntry) entry;
            sender.sendMessage(new TextComponentTranslation("commands.rcsightinfo.structure", RCTextStyle.structure(structureEntry.getStructureID()), area, RCTextStyle.copy(String.valueOf(structureEntry.getSeed())), sight));
            Structure structure = StructureRegistry.INSTANCE.get(structureEntry.getStructureID());
            if (structure != null) {
                // TODO generateAsSource not accurate
                NBTStorable instanceData = structure.loadInstanceData(new StructureLoadContext(structureEntry.getTransform(), entry.getBoundingBox(), false), structureEntry.getInstanceData(), RCConfig.getUniversalTransformer());
                List<TextComponentBase> list = structure.instanceDataInfo(instanceData);
                for (TextComponentBase s : list) sender.sendMessage(s);
            }
        } else
            sender.sendMessage(new TextComponentTranslation("commands.rcsightinfo.get", entry.description(), area, sight));
    }
}
Also used : StructureLoadContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Parameters(ivorius.mcopts.commands.parameters.Parameters) WorldStructureGenerationData(ivorius.reccomplex.world.gen.feature.WorldStructureGenerationData) ITextComponent(net.minecraft.util.text.ITextComponent) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) TextComponentBase(net.minecraft.util.text.TextComponentBase)

Example 7 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters 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 8 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandSightCheck method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    World world = sender.getEntityWorld();
    BlockPos pos = parameters.get(0).to(MCP.pos(sender.getPosition(), false)).require();
    List<ITextComponent> names = WorldStructureGenerationData.get(world).entriesAt(pos).map(RCTextStyle::sight).collect(Collectors.toCollection(ArrayList::new));
    if (checkAll)
        names.addAll(CommandVanilla.sightNames(world, pos));
    sender.sendMessage(list(names));
}
Also used : Parameters(ivorius.mcopts.commands.parameters.Parameters) ITextComponent(net.minecraft.util.text.ITextComponent) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World)

Example 9 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandConvertSchematic method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
    if (args.length < 1)
        throw RecurrentComplex.translations.wrongUsageException("commands.rcconvertschematic.usage");
    ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
    String schematicName = parameters.get(0).require();
    String structureID = parameters.get("id").optional().orElse(schematicName);
    SchematicFile schematicFile = CommandImportSchematic.parseSchematic(schematicName);
    GenericStructure from = parameters.get("from").to(RCP::structureFromBlueprint, commandSender).require();
    from.worldDataCompound = CommandExportSchematic.toWorldData(schematicFile).createTagCompound();
    PacketEditStructureHandler.openEditStructure(player, from, player.getPosition(), structureID, directory);
}
Also used : SchematicFile(ivorius.reccomplex.world.gen.feature.structure.schematics.SchematicFile) Parameters(ivorius.mcopts.commands.parameters.Parameters) 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 10 with Parameters

use of ivorius.mcopts.commands.parameters.Parameters in project RecurrentComplex by Ivorforce.

the class CommandGenerateStructure method execute.

@Override
@ParametersAreNonnullByDefault
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    String structureID = parameters.get(0).require();
    Structure<?> structure = parameters.get(0).to(RCP::structure).require();
    WorldServer world = parameters.get("dimension").to(MCP.dimension(server, sender)).require();
    AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(null);
    GenerationType generationType = parameters.get("gen").to(RCP::generationType, structure).require();
    BlockSurfacePos pos = parameters.get(IvP.surfacePos("x", "z", sender.getPosition(), false)).require();
    String seed = parameters.get("seed").optional().orElseGet(() -> RandomStringUtils.randomAlphanumeric(20).toUpperCase());
    boolean suggest = parameters.has("suggest");
    Placer placer = generationType.placer();
    StructureGenerator<?> generator = new StructureGenerator<>(structure).world(world).generationInfo(generationType).seed(RCStrings.seed(seed)).structureID(structureID).randomPosition(pos, placer).fromCenter(true).maturity(suggest ? SUGGEST : FIRST).transform(transform);
    if (structure instanceof GenericStructure && world == sender.getEntityWorld()) {
        GenericStructure genericStructureInfo = (GenericStructure) structure;
        // noinspection unchecked
        if (!OperationRegistry.queueOperation(new OperationGenerateStructure(genericStructureInfo, generationType.id(), generator.transform(), generator.lowerCoord().orElse(null), false).withSeed(seed).withStructureID(structureID).prepare((Optional<GenericStructure.InstanceData>) generator.instanceData()), sender))
            return;
    } else {
        StructureGenerator.GenerationResult result = generator.generate();
        if (result instanceof StructureGenerator.GenerationResult.Failure) {
            String reason = ((StructureGenerator.GenerationResult.Failure) result).description;
            throw RecurrentComplex.translations.commandException("commands.strucGen.failure", reason);
        }
    }
    if (parameters.has("select"))
        RCCommands.select(sender, RCBlockAreas.from(generator.boundingBox().get()));
}
Also used : OperationGenerateStructure(ivorius.reccomplex.operation.OperationGenerateStructure) Parameters(ivorius.mcopts.commands.parameters.Parameters) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) Placer(ivorius.reccomplex.world.gen.feature.structure.Placer) WorldServer(net.minecraft.world.WorldServer) GenerationType(ivorius.reccomplex.world.gen.feature.structure.generic.generation.GenerationType) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

Parameters (ivorius.mcopts.commands.parameters.Parameters)18 RCP (ivorius.reccomplex.commands.parameters.RCP)9 BlockPos (net.minecraft.util.math.BlockPos)8 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)7 Expect (ivorius.mcopts.commands.parameters.expect.Expect)7 RCConfig (ivorius.reccomplex.RCConfig)7 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)7 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)7 NaP (ivorius.mcopts.commands.parameters.NaP)6 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)6 CommandException (net.minecraft.command.CommandException)6 ICommandSender (net.minecraft.command.ICommandSender)6 MinecraftServer (net.minecraft.server.MinecraftServer)6 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)5 Structure (ivorius.reccomplex.world.gen.feature.structure.Structure)5 MCE (ivorius.mcopts.commands.parameters.expect.MCE)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 WorldServer (net.minecraft.world.WorldServer)4 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)3 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)3