Search in sources :

Example 31 with RCParameters

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

the class CommandSelectSetBiome method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    Biome biome = parameters.mc().biome().require();
    byte biomeID = (byte) (Biome.REGISTRY.getIDForObject(biome) & 255);
    World world = commandSender.getEntityWorld();
    // TODO Send to clients somehow
    BlockSurfaceArea.from(RCCommands.getSelectionOwner(commandSender, null, true).getSelection()).forEach(p -> {
        Chunk chunk = world.getChunkFromChunkCoords(p.getX() >> 4, p.getZ() >> 4);
        chunk.getBiomeArray()[biomeArrayIndex(p)] = biomeID;
        chunk.setModified(true);
    });
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Biome(net.minecraft.world.biome.Biome) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk)

Example 32 with RCParameters

use of ivorius.reccomplex.commands.parameters.RCParameters 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)

Example 33 with RCParameters

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

the class CommandDelete method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String adapterID = parameters.get().first().require();
    String id = parameters.get().at(1).require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw ServerTranslations.commandException("commands.rcsave.noregistry");
    if (!RecurrentComplex.saver.registry(adapterID).ids().contains(id))
        throw ServerTranslations.commandException("commands.rcsave.noelement");
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().require();
    RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(directory.toPath(), adapterID, id), commandSender, adapterID, id, directory);
    // Could also predict changes and just reload those for the file but eh.
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory)

Example 34 with RCParameters

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

the class CommandWrite method getTabCompletions.

@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
    RCParameters parameters = RCParameters.of(args);
    RCExpect<?> expect = RCExpect.expectRC();
    // Can't chain because of compiler bug :|
    expect.next(RecurrentComplex.saver.keySet());
    expect.next(args1 -> parameters.get().first().tryGet().map(RecurrentComplex.saver::get).map(a -> a.getRegistry().ids()).orElse(Collections.emptySet()));
    expect.named("dir").resourceDirectory();
    return expect.get(server, sender, args, pos);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) RecurrentComplex(ivorius.reccomplex.RecurrentComplex)

Example 35 with RCParameters

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

the class CommandWrite method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String adapterID = parameters.get().first().require();
    String id = parameters.get().at(1).require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw ServerTranslations.commandException("commands.rcsave.noregistry");
    if (!RecurrentComplex.saver.registry(adapterID).ids().contains(id))
        throw ServerTranslations.commandException("commands.rcsave.noelement");
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    if (RCCommands.informSaveResult(RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id), commandSender, directory, adapterID, id)) {
        RCCommands.informDeleteResult(RecurrentComplex.saver.tryDeleteWithID(directory.opposite().toPath(), adapterID, id), commandSender, adapterID, id, directory);
        // Could also predict changes and just reload those for the file but eh.
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
        RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
    }
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory)

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