use of ivorius.reccomplex.capability.SelectionOwner in project RecurrentComplex by Ivorforce.
the class ItemBlockSelector method onClientEvent.
@Override
public void onClientEvent(String context, ByteBuf payload, EntityPlayer sender, ItemStack stack, int itemSlot) {
if ("select".equals(context)) {
BlockPos coord = BlockPositions.maybeReadFromBuffer(payload);
boolean secondary = payload.readBoolean();
SelectionOwner selectionOwner = SelectionOwner.getOwner(sender, null);
if (selectionOwner != null) {
if (secondary)
selectionOwner.setSelectedPoint2(coord);
else
selectionOwner.setSelectedPoint1(coord);
}
}
}
use of ivorius.reccomplex.capability.SelectionOwner 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);
}
}
Aggregations