Search in sources :

Example 1 with MockWorld

use of ivorius.ivtoolkit.world.MockWorld in project RecurrentComplex by Ivorforce.

the class CommandMapAllStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    ResourceExpression expression = new ResourceExpression(StructureRegistry.INSTANCE::has);
    IvOptional.ifAbsent(parameters.rc("exp").expression(expression).optional(), () -> expression.setExpression(""));
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    CommandVirtual virtual = parameters.rc().virtualCommand(server).require();
    int saved = 0, failed = 0, skipped = 0;
    for (String id : StructureRegistry.INSTANCE.ids()) {
        if (!expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id)))
            continue;
        Structure<?> info = StructureRegistry.INSTANCE.get(id);
        if (!(info instanceof GenericStructure)) {
            skipped++;
            continue;
        }
        GenericStructure structure = (GenericStructure) info;
        IvWorldData worldData = structure.constructWorldData();
        MockWorld world = new MockWorld.WorldData(worldData);
        try {
            virtual.execute(world, new CommandSelecting.SelectingSender(commandSender, BlockPos.ORIGIN, worldData.blockCollection.area().getHigherCorner()), parameters.get().move(1).varargs());
        } catch (MockWorld.VirtualWorldException ex) {
            throw ServerTranslations.commandException("commands.rcmap.nonvirtual.arguments");
        }
        structure.worldDataCompound = worldData.createTagCompound();
        if (PacketSaveStructureHandler.write(commandSender, structure, id, directory, true, false))
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(ServerTranslations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) IvWorldData(ivorius.ivtoolkit.tools.IvWorldData) CommandSelecting(ivorius.reccomplex.commands.CommandSelecting) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) MockWorld(ivorius.ivtoolkit.world.MockWorld) GenericStructure(ivorius.reccomplex.world.gen.feature.structure.generic.GenericStructure) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression)

Example 2 with MockWorld

use of ivorius.ivtoolkit.world.MockWorld in project RecurrentComplex by Ivorforce.

the class CommandSelectFill 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().move(1).metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    String shape = parameters.get("shape").first().optional().orElse("cube");
    BlockArea area = selectionOwner.getSelection();
    BlockPos p1 = area.getPoint1();
    BlockPos p2 = area.getPoint2();
    switch(shape) {
        case "cube":
            for (BlockPos pos : area) {
                IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                world.setBlockState(pos, state, 2);
            }
            break;
        case "sphere":
            {
                double[] spheroidOrigin = new double[] { (p1.getX() + p2.getX()) * 0.5, (p1.getY() + p2.getY()) * 0.5, (p1.getZ() + p2.getZ()) * 0.5 };
                int[] areaSize = area.areaSize();
                double[] spheroidSize = new double[] { areaSize[0] * 0.5, areaSize[1] * 0.5, areaSize[2] * 0.5 };
                for (BlockPos coord : area) {
                    double[] coordPoint = new double[] { coord.getX(), coord.getY(), coord.getZ() };
                    if (IvShapeHelper.isPointInSpheroid(coordPoint, spheroidOrigin, spheroidSize)) {
                        IBlockState state = dst.get(world.rand().nextInt(dst.size()));
                        world.setBlockState(coord, state, 2);
                    }
                }
                break;
            }
        default:
            throw new WrongUsageException(getUsage(commandSender));
    }
}
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) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) 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) WrongUsageException(net.minecraft.command.WrongUsageException) IvShapeHelper(ivorius.ivtoolkit.math.IvShapeHelper) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) BlockArea(ivorius.ivtoolkit.blocks.BlockArea) WrongUsageException(net.minecraft.command.WrongUsageException) IBlockState(net.minecraft.block.state.IBlockState) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with MockWorld

use of ivorius.ivtoolkit.world.MockWorld 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 4 with MockWorld

use of ivorius.ivtoolkit.world.MockWorld 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 5 with MockWorld

use of ivorius.ivtoolkit.world.MockWorld in project RecurrentComplex by Ivorforce.

the class CommandSelectFlood method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    PreloadedBooleanExpression<EnumFacing> facingExpression = PreloadedBooleanExpression.with(exp -> {
        exp.addConstants(EnumFacing.values());
        exp.addEvaluators(axis -> facing -> facing.getAxis() == axis, EnumFacing.Axis.values());
        exp.addEvaluator("horizontal", f -> f.getHorizontalIndex() >= 0);
        exp.addEvaluator("vertical", f -> f.getHorizontalIndex() < 0);
    });
    facingExpression.setExpression(parameters.get().move(2).text().optional().orElse(""));
    List<EnumFacing> available = Arrays.stream(EnumFacing.values()).filter(facingExpression).collect(Collectors.toList());
    List<BlockPos> dirty = Lists.newArrayList(selectionOwner.getSelection());
    Set<BlockPos> visited = Sets.newHashSet(dirty);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc().move(1).metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    while (!dirty.isEmpty()) {
        BlockPos pos = dirty.remove(dirty.size() - 1);
        for (EnumFacing facing : available) {
            BlockPos offset = pos.offset(facing);
            if (RCBlockLogic.isAir(world, offset) && visited.add(offset))
                dirty.add(offset);
        }
        if (visited.size() > MAX_FLOOD)
            throw new CommandException("Area too big to flood!");
    }
    for (BlockPos pos : visited) {
        IBlockState state = dst.get(world.rand().nextInt(dst.size()));
        world.setBlockState(pos, state, 2);
    }
}
Also used : SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) PreloadedBooleanExpression(ivorius.reccomplex.utils.expression.PreloadedBooleanExpression) IntStream(java.util.stream.IntStream) java.util(java.util) RCCommands(ivorius.reccomplex.commands.RCCommands) EnumFacing(net.minecraft.util.EnumFacing) 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) Sets(com.google.common.collect.Sets) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) RCBlockLogic(ivorius.reccomplex.utils.RCBlockLogic) ICommandSender(net.minecraft.command.ICommandSender) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) CommandException(net.minecraft.command.CommandException) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

MockWorld (ivorius.ivtoolkit.world.MockWorld)6 CommandVirtual (ivorius.reccomplex.commands.CommandVirtual)6 RCParameters (ivorius.reccomplex.commands.parameters.RCParameters)6 RCConfig (ivorius.reccomplex.RCConfig)4 SelectionOwner (ivorius.reccomplex.capability.SelectionOwner)4 RCCommands (ivorius.reccomplex.commands.RCCommands)4 RCExpect (ivorius.reccomplex.commands.parameters.RCExpect)4 ServerTranslations (ivorius.reccomplex.utils.ServerTranslations)4 Collectors (java.util.stream.Collectors)4 Nullable (javax.annotation.Nullable)4 CommandException (net.minecraft.command.CommandException)4 ICommandSender (net.minecraft.command.ICommandSender)4 MinecraftServer (net.minecraft.server.MinecraftServer)4 BlockPos (net.minecraft.util.math.BlockPos)4 BlockStates (ivorius.ivtoolkit.blocks.BlockStates)3 List (java.util.List)3 IntStream (java.util.stream.IntStream)3 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 IvWorldData (ivorius.ivtoolkit.tools.IvWorldData)2