Search in sources :

Example 16 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandSelectReplace method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc("metadata").metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    PositionedBlockExpression matcher = parameters.rc().move(1).expression(new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos coord : selectionOwner.getSelection()) {
        if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, coord))) {
            IBlockState state = dst.get(world.rand().nextInt(dst.size()));
            world.setBlockState(coord, state, 3);
        }
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IntStream(java.util.stream.IntStream) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) Block(net.minecraft.block.Block) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) IBlockState(net.minecraft.block.state.IBlockState) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 17 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandSetProperty method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    PositionedBlockExpression matcher = new PositionedBlockExpression(RecurrentComplex.specialRegistry);
    IvOptional.ifAbsent(parameters.rc("exp").expression(matcher).optional(), () -> matcher.setExpression(""));
    String propertyName = parameters.get().first().require();
    String propertyValue = parameters.get().at(1).require();
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    for (BlockPos pos : BlockAreas.mutablePositions(selectionOwner.getSelection())) {
        PositionedBlockExpression.Argument at = PositionedBlockExpression.Argument.at(world, pos);
        if (matcher.test(at))
            TransformerProperty.withProperty(at.state, propertyName, propertyValue).ifPresent(state -> world.setBlockState(pos, state, 3));
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) TransformerProperty(ivorius.reccomplex.world.gen.feature.structure.generic.transformers.TransformerProperty) RCCommands(ivorius.reccomplex.commands.RCCommands) BlockAreas(ivorius.ivtoolkit.blocks.BlockAreas) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IvOptional(ivorius.reccomplex.utils.optional.IvOptional) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PositionedBlockExpression(ivorius.reccomplex.utils.expression.PositionedBlockExpression) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) BlockPos(net.minecraft.util.math.BlockPos)

Example 18 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandNaturalSpace method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    BlockArea area = selectionOwner.getSelection();
    RCParameters parameters = RCParameters.of(args);
    int floorDistance = parameters.get("distance-to-floor").intAt(0).optional().orElse(0) + 1;
    int maxClosedSides = parameters.get("max-closed-sides").intAt(1).optional().orElse(3);
    placeNaturalAir(world, area, floorDistance, maxClosedSides);
}
Also used : BlockArea(ivorius.ivtoolkit.blocks.BlockArea) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner)

Example 19 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandNaturalFloor method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    BlockArea area = RCCommands.getSelectionOwner(commandSender, null, true).getSelection();
    double expandFloor = parameters.get("expansion").doubleAt(0).optional().orElse(1.);
    placeNaturalFloor(world, area, expandFloor);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) BlockArea(ivorius.ivtoolkit.blocks.BlockArea)

Example 20 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters in project RecurrentComplex by Ivorforce.

the class CommandSanity method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args, "silent", "short");
    boolean sane = true;
    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(), ""));
        } 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;
        }
        if (path != null && !Files.isReadable(path)) {
            commandSender.sendMessage(new TextComponentString("Can't read files from mod: " + mod.getModId()));
            sane = false;
        }
    }
    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 &= 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 specific problems found!"));
}
Also used : Path(java.nio.file.Path) 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) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) RCConfig(ivorius.reccomplex.RCConfig) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) 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) Nullable(javax.annotation.Nullable) Files(java.nio.file.Files) World(net.minecraft.world.World) IRegistry(net.minecraft.util.registry.IRegistry) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) ConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.ConnectorStrategy) TextComponentString(net.minecraft.util.text.TextComponentString) List(java.util.List) Stream(java.util.stream.Stream) ICommandSender(net.minecraft.command.ICommandSender) ResourceLocation(net.minecraft.util.ResourceLocation) ModContainer(net.minecraftforge.fml.common.ModContainer) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Biome(net.minecraft.world.biome.Biome) ModContainer(net.minecraftforge.fml.common.ModContainer) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ResourceLocation(net.minecraft.util.ResourceLocation) RCFiles(ivorius.reccomplex.files.RCFiles)

Aggregations

RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)39 BlockPos (net.minecraft.util.math.BlockPos)17 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)14 GenericStructure (ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure)11 RCConfig (ivorius.reccomplex.RCConfig)8 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)8 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)8 Nullable (javax.annotation.Nullable)8 CommandException (net.minecraft.command.CommandException)8 ICommandSender (net.minecraft.command.ICommandSender)8 MinecraftServer (net.minecraft.server.MinecraftServer)8 BlockArea (ivorius.ivtoolkit.blocks.BlockArea)7 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)7 ResourceDirectory (ivorius.reccomplex.files.loading.ResourceDirectory)7 List (java.util.List)7 WorldServer (net.minecraft.world.WorldServer)7 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)6 MockWorld (ivorius.ivtoolkit.world.MockWorld)6 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)6 RCCommands (ivorius.reccomplex.commands.RCCommands)6