Search in sources :

Example 6 with Command

use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class BlockCommands method listFreeShapeBlocks.

@Command(shortDescription = "Lists available free shape blocks", helpText = "Lists all the available free shape blocks. These blocks can be created with any shape.\n" + "You can filter by adding the beginning of words after the commands, e.g.: \"listFreeShapeBlocks" + "engine: core\" will list all free shape blocks from the engine and modules starting with 'core'", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listFreeShapeBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Free Shape Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("-----------------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> sortedUris = sortItems(blockExplorer.getFreeformBlockFamilies());
    for (BlockUri uri : sortedUris) {
        if (!uriStartsWithAnyString(uri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(uri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 7 with Command

use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class BlockCommands method listBlocks.

@Command(shortDescription = "List all available blocks\nYou can filter by adding the beginning of words after the" + " commands, e.g.: \"listBlocks engine: core\" will list all blocks from the engine and modules starting with 'core'", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Used Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("-----------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> registeredBlocks = sortItems(blockManager.listRegisteredBlockUris());
    for (BlockUri blockUri : registeredBlocks) {
        if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(blockUri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("Available Blocks");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("----------------");
    stringBuilder.append(Console.NEW_LINE);
    List<BlockUri> availableBlocks = sortItems(blockExplorer.getAvailableBlockFamilies());
    for (BlockUri blockUri : availableBlocks) {
        if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(blockUri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : BlockUri(org.terasology.engine.world.block.BlockUri) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 8 with Command

use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class BlockCommands method replaceBlock.

@Command(shortDescription = "Replaces a block in front of user", helpText = "Replaces a block in front of the user at the specified max distance", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public void replaceBlock(@Sender EntityRef sender, @CommandParam("blockName") String uri, @CommandParam(value = "maxDistance", required = false) Integer maxDistanceParam) {
    int maxDistance = maxDistanceParam != null ? maxDistanceParam : 12;
    EntityRef playerEntity = sender.getComponent(ClientComponent.class).character;
    EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(playerEntity);
    LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
    Set<ResourceUrn> matchingUris = Assets.resolveAssetUri(uri, BlockFamilyDefinition.class);
    targetSystem.updateTarget(gazeLocation.getWorldPosition(new Vector3f()), gazeLocation.getWorldDirection(new Vector3f()), maxDistance);
    EntityRef target = targetSystem.getTarget();
    BlockComponent targetLocation = target.getComponent(BlockComponent.class);
    if (matchingUris.size() == 1) {
        Optional<BlockFamilyDefinition> def = Assets.get(matchingUris.iterator().next(), BlockFamilyDefinition.class);
        if (def.isPresent()) {
            BlockFamily blockFamily = blockManager.getBlockFamily(uri);
            Block block = blockManager.getBlock(blockFamily.getURI());
            world.setBlock(targetLocation.getPosition(), block);
        } else if (matchingUris.size() > 1) {
            StringBuilder builder = new StringBuilder();
            builder.append("Non-unique shape name, possible matches: ");
            Iterator<ResourceUrn> shapeUris = sortItems(matchingUris).iterator();
            while (shapeUris.hasNext()) {
                builder.append(shapeUris.next().toString());
                if (shapeUris.hasNext()) {
                    builder.append(", ");
                }
            }
        }
    }
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) BlockComponent(org.terasology.engine.world.block.BlockComponent) Vector3f(org.joml.Vector3f) Iterator(java.util.Iterator) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 9 with Command

use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class WorldRendererImpl method dagRedirect.

/**
 * Redirect output FBO from one node to another's input
 * <p>
 * Usage: {@code dagRedirect <connectionTypeString> <fromNodeUri> <outputFboId> <toNodeUri> <inputFboId>}
 * <p>
 * Example: dagRedirect fbo blurredAmbientOcclusion 1 BasicRendering:outputToScreenNode 1 dagRedirect bufferpair
 * backdrop 1 AdvancedRendering:intermediateHazeNode 1
 */
@Command(shortDescription = "Debugging command for DAG.", requiredPermission = PermissionManager.NO_PERMISSION)
public void dagRedirect(@CommandParam("fromNodeUri") final String connectionTypeString, @CommandParam("fromNodeUri") final String fromNodeUri, @CommandParam("outputFboId") final int outputFboId, @CommandParam("toNodeUri") final String toNodeUri, @CommandParam(value = "inputFboId") final int inputFboId) {
    RenderGraph.ConnectionType connectionType;
    if (connectionTypeString.equalsIgnoreCase("fbo")) {
        connectionType = RenderGraph.ConnectionType.FBO;
    } else if (connectionTypeString.equalsIgnoreCase("bufferpair")) {
        connectionType = RenderGraph.ConnectionType.BUFFER_PAIR;
    } else {
        throw new RuntimeException(("Unsupported connection type: '" + connectionTypeString + "'. Expected 'fbo' " + "or 'bufferpair'.\n"));
    }
    Node toNode = renderGraph.findNode(toNodeUri);
    if (toNode == null) {
        toNode = renderGraph.findAka(toNodeUri);
        if (toNode == null) {
            throw new RuntimeException(("No node is associated with URI '" + toNodeUri + "'"));
        }
    }
    Node fromNode = renderGraph.findNode(fromNodeUri);
    if (fromNode == null) {
        fromNode = renderGraph.findAka(fromNodeUri);
        if (fromNode == null) {
            throw new RuntimeException(("No node is associated with URI '" + fromNodeUri + "'"));
        }
    }
    renderGraph.reconnectInputToOutput(fromNode, outputFboId, toNode, inputFboId, connectionType, true);
    toNode.clearDesiredStateChanges();
    requestTaskListRefresh();
}
Also used : Node(org.terasology.engine.rendering.dag.Node) RenderGraph(org.terasology.engine.rendering.dag.RenderGraph) MethodCommand(org.terasology.engine.logic.console.commandSystem.MethodCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 10 with Command

use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method help.

/**
 * Prints out short descriptions for all available commands, or a longer help text if a command is provided.
 *
 * @param commandName String containing command for which will be displayed help
 * @return String containing short description of all commands or longer help text if command is provided
 */
@Command(shortDescription = "Prints out short descriptions for all available commands, or a longer help text if a command is provided.", requiredPermission = PermissionManager.NO_PERMISSION)
public String help(@CommandParam(value = "command", required = false, suggester = CommandNameSuggester.class) Name commandName) {
    if (commandName == null) {
        StringBuilder msg = new StringBuilder();
        // Get all commands, with appropriate sorting
        List<ConsoleCommand> commands = Ordering.natural().immutableSortedCopy(console.getCommands());
        for (ConsoleCommand cmd : commands) {
            if (!msg.toString().isEmpty()) {
                msg.append(Console.NEW_LINE);
            }
            msg.append(FontColor.getColored(cmd.getUsage(), ConsoleColors.COMMAND));
            msg.append(" - ");
            msg.append(cmd.getDescription());
        }
        return msg.toString();
    } else {
        ConsoleCommand cmd = console.getCommand(commandName);
        if (cmd == null) {
            return "No help available for command '" + commandName + "'. Unknown command.";
        } else {
            StringBuilder msg = new StringBuilder();
            msg.append("===========================================================================================================");
            msg.append(Console.NEW_LINE);
            msg.append(cmd.getUsage());
            msg.append(Console.NEW_LINE);
            msg.append("===========================================================================================================");
            msg.append(Console.NEW_LINE);
            if (!cmd.getHelpText().isEmpty()) {
                msg.append(cmd.getHelpText());
                msg.append(Console.NEW_LINE);
                msg.append("===========================================================================================================");
                msg.append(Console.NEW_LINE);
            } else if (!cmd.getDescription().isEmpty()) {
                msg.append(cmd.getDescription());
                msg.append(Console.NEW_LINE);
                msg.append("===========================================================================================================");
                msg.append(Console.NEW_LINE);
            }
            if (!cmd.getRequiredPermission().isEmpty()) {
                msg.append("Required permission level - " + cmd.getRequiredPermission());
                msg.append(Console.NEW_LINE);
                msg.append("===========================================================================================================");
                msg.append(Console.NEW_LINE);
            }
            return msg.toString();
        }
    }
}
Also used : ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Aggregations

Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)67 ClientComponent (org.terasology.engine.network.ClientComponent)42 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)35 Vector3f (org.joml.Vector3f)16 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)16 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 LocationComponent (org.terasology.engine.logic.location.LocationComponent)10 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)9 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 Map (java.util.Map)5 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)5 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 List (java.util.List)3 Locale (java.util.Locale)3