use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandPreview method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
EntityPlayer player = getCommandSenderAsPlayer(commandSender);
RCEntityInfo RCEntityInfo = RCCommands.getStructureEntityInfo(player, null);
Operation.PreviewType previewType = parameters.get(0).map(Operation.PreviewType::find, s -> RecurrentComplex.translations.commandException("commands.rcpreview.invalid")).require();
RCEntityInfo.setPreviewType(previewType);
RCEntityInfo.sendPreviewTypeToClients(player);
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcpreview.success", previewType.key));
}
use of net.minecraft.command.CommandException 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 net.minecraft.command.CommandException 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 net.minecraft.command.CommandException 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();
}
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandDelete 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).require();
Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
Collection<String> ids = Lists.newArrayList(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());
for (String id : ids) {
if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
continue;
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);
}
}
Aggregations