use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.
the class CommandRetrogen method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
Predicate<Structure> structurePredicate = parameters.get("exp").to(RCP::structurePredicate).optional().orElse(null);
WorldServer world = parameters.get("dimension").to(MCP.dimension(server, commandSender)).require();
long count = retrogen(world, structurePredicate);
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcretro.count", String.valueOf(count)));
}
use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.
the class CommandConvertSchematic method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
EntityPlayerMP player = getCommandSenderAsPlayer(commandSender);
if (args.length < 1)
throw RecurrentComplex.translations.wrongUsageException("commands.rcconvertschematic.usage");
ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
String schematicName = parameters.get(0).require();
String structureID = parameters.get("id").optional().orElse(schematicName);
SchematicFile schematicFile = CommandImportSchematic.parseSchematic(schematicName);
GenericStructure from = parameters.get("from").to(RCP::structureFromBlueprint, commandSender).require();
from.worldDataCompound = CommandExportSchematic.toWorldData(schematicFile).createTagCompound();
PacketEditStructureHandler.openEditStructure(player, from, player.getPosition(), structureID, directory);
}
use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.
the class CommandDecorate method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
BlockSurfaceArea area = new BlockSurfaceArea(parameters.get(0).to(IvP.surfacePos(commandSender.getPosition(), false)).require(), parameters.get(2).to(IvP.surfacePos(commandSender.getPosition(), false)).require());
BlockSurfaceArea chunkArea = new BlockSurfaceArea(getChunkPos(area.getPoint1()), getChunkPos(area.getPoint2()));
Predicate<Structure> structurePredicate = parameters.get("exp").to(RCP::structurePredicate).optional().orElse(structureInfo -> true);
WorldServer world = (WorldServer) commandSender.getEntityWorld();
if (parameters.has("one")) {
BlockSurfacePos lower = area.getLowerCorner();
int[] size = area.areaSize();
BlockPos pos = new BlockPos(lower.x + world.rand.nextInt(size[0]), 0, lower.z + world.rand.nextInt(size[1]));
if (!WorldGenStructures.generateOneStructureInChunk(world.rand, new ChunkPos(pos), world, world.getBiome(pos)))
throw RecurrentComplex.translations.commandException("commands.rcdecorateone.none");
} else
chunkArea.forEach(coord -> WorldGenStructures.decorate(world, world.rand, new ChunkPos(coord.x, coord.z), structurePredicate));
}
use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.
the class CommandWrite method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
String adapterID = parameters.get(0).require();
if (!RecurrentComplex.saver.has(adapterID))
throw RecurrentComplex.translations.commandException("commands.rcsave.noregistry");
ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(ResourceDirectory.ACTIVE);
Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
Set<String> ids = adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet());
ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get(1).rest(NaP::join).require());
int saved = 0, failed = 0;
for (String id : ids) {
if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
continue;
boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
if (success)
saved++;
else
failed++;
}
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcsaveall.result", saved, RCTextStyle.path(directory), failed));
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
use of ivorius.reccomplex.commands.parameters.RCP in project RecurrentComplex by Ivorforce.
the class CommandFill method execute.
@Override
public void execute(MockWorld world, ICommandSender sender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
Block dstBlock = parameters.get(0).to(MCP::block, sender).require();
int[] dstMeta = parameters.get("metadata").to(RCP::metadatas).optional().orElse(new int[1]);
List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
RCP.Shape shape = parameters.get("shape").to(RCP::shape).optional().orElse(RCP.Shape.cube);
PositionedBlockExpression matcher = parameters.get(1).rest(NaP::join).orElse("").to(RCP::expression, new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(sender, null, true);
RCCommands.assertSize(sender, selectionOwner);
if (parameters.has("flood")) {
List<EnumFacing> directions = parameters.get("flood").orElse("").to(RCP::directions).require();
List<BlockPos> dirty = new ArrayList<>();
Set<BlockPos> visited = Sets.newHashSet(dirty);
runShape(shape, selectionOwner.getSelection(), dirty::add);
while (!dirty.isEmpty()) {
BlockPos pos = dirty.remove(dirty.size() - 1);
for (EnumFacing facing : directions) {
BlockPos offset = pos.offset(facing);
if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, offset)) && visited.add(offset))
dirty.add(offset);
}
if (visited.size() > MAX_FLOOD)
throw new CommandException("Area too big to flood!");
}
visited.forEach(p -> setFrom(world, dst, p));
} else {
// TODO Can't freeze because the lighting update won't get sent
// HeightMapFreezer freezer = HeightMapFreezer.freeze(BlockAreas.toBoundingBox(selectionOwner.getSelection()), sender.getEntityWorld());
runShape(shape, selectionOwner.getSelection(), pos -> {
if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, pos))) {
setFrom(world, dst, pos);
// freezer.markBlock(pos, state);
}
});
// freezer.melt();
}
}
Aggregations