use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.
the class CommandSelectDuplicate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args, "mirror");
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
BlockArea area = selectionOwner.getSelection();
BlockPos pos = parameters.pos("x", "y", "z", commandSender.getPosition(), false).require();
AxisAlignedTransform2D transform = parameters.transform("rotation", "mirror").optional().orElse(AxisAlignedTransform2D.ORIGINAL);
IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
NBTTagCompound worldDataCompound = worldData.createTagCompound();
GenericStructure structureInfo = GenericStructure.createDefaultStructure();
structureInfo.worldDataCompound = worldDataCompound;
OperationRegistry.queueOperation(new OperationGenerateStructure(structureInfo, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
}
use of ivorius.reccomplex.capability.SelectionOwner 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));
}
}
use of ivorius.reccomplex.capability.SelectionOwner 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);
}
}
}
use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.
the class CommandSelectMove method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
RCCommands.assertSize(commandSender, selectionOwner);
BlockPos move = parameters.get(RCP.pos("x", "y", "z", BlockPos.ORIGIN, false)).require();
AxisAlignedTransform2D transform = parameters.get(IvP.transform("rotation", "mirror")).optional().orElse(AxisAlignedTransform2D.ORIGINAL);
boolean noselect = parameters.has("noselect");
boolean duplicate = parameters.has("duplicate");
int times = parameters.get("times").to(NaP::asInt).optional().orElse(1);
BlockArea area = selectionOwner.getSelection();
IvWorldData worldData = IvWorldData.capture(commandSender.getEntityWorld(), area, true);
NBTTagCompound worldDataCompound = worldData.createTagCompound();
GenericStructure structure = GenericStructure.createDefaultStructure();
structure.worldDataCompound = worldDataCompound;
BlockPos pos = selectionOwner.getSelection().getLowerCorner();
for (int i = 0; i < times; i++) {
pos = pos.add(move);
if (duplicate)
OperationRegistry.queueOperation(new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld()), commandSender);
else
OperationRegistry.queueOperation(new OperationMulti(new OperationClearArea(area), new OperationGenerateStructure(structure, null, transform, pos, true).prepare((WorldServer) commandSender.getEntityWorld())), commandSender);
}
if (!noselect) {
StructureGenerator<GenericStructure.InstanceData> generator = new StructureGenerator<>(structure).transform(transform).lowerCoord(pos);
// noinspection OptionalGetWithoutIsPresent
StructureBoundingBox boundingBox = generator.boundingBox().get();
selectionOwner.setSelection(RCBlockAreas.from(boundingBox));
}
}
use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.
the class CommandSetProperty method execute.
@Override
public void execute(MockWorld world, ICommandSender sender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
PositionedBlockExpression matcher = parameters.get("exp").orElse("").to(RCP::expression, new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
String propertyName = parameters.get(0).require();
String propertyValue = parameters.get(1).require();
RCP.Shape shape = parameters.get("shape").to(RCP::shape).optional().orElse(RCP.Shape.cube);
Consumer<BlockPos> consumer = (BlockPos pos) -> {
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));
};
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(sender, null, true);
RCCommands.assertSize(sender, selectionOwner);
CommandFill.runShape(shape, selectionOwner.getSelection(), consumer);
}
Aggregations