Search in sources :

Example 31 with Command

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

the class HealthCommands method damage.

@Command(shortDescription = "Reduce the player's health by an amount", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String damage(@Sender EntityRef client, @CommandParam("amount") int amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    clientComp.character.send(new DoDamageEvent(amount, EngineDamageTypes.DIRECT.get(), clientComp.character));
    return "Inflicted damage of " + amount;
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 32 with Command

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

the class BlockCommands method listShapes.

@Command(shortDescription = "Lists all available shapes\nYou can filter by adding the beginning of words after the" + "commands, e.g.: \"listShapes engine: core:\" will list all shapes from the engine and core module", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listShapes(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("Shapes");
    stringBuilder.append(Console.NEW_LINE);
    stringBuilder.append("-----------");
    stringBuilder.append(Console.NEW_LINE);
    List<ResourceUrn> sortedUris = sortItems(Assets.list(BlockShape.class));
    for (ResourceUrn uri : sortedUris) {
        if (!uriStartsWithAnyString(uri.toString(), startsWith)) {
            continue;
        }
        stringBuilder.append(uri.toString());
        stringBuilder.append(Console.NEW_LINE);
    }
    return stringBuilder.toString();
}
Also used : BlockShape(org.terasology.world.block.shapes.BlockShape) ResourceUrn(org.terasology.assets.ResourceUrn) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 33 with Command

use of org.terasology.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 core module", 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.world.block.BlockUri) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 34 with Command

use of org.terasology.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(), gazeLocation.getWorldDirection(), 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.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) BlockComponent(org.terasology.world.block.BlockComponent) Iterator(java.util.Iterator) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) ResourceUrn(org.terasology.assets.ResourceUrn) BlockFamilyDefinition(org.terasology.world.block.loader.BlockFamilyDefinition) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 35 with Command

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

the class AudioSystem method playTestSound.

/**
 * Plays a test dig sound at an offset from the player in the x and z axis.
 *
 * @param sender The entity sending the sound request
 * @param xOffset The x axis offset from the player to play the sound at.
 * @param zOffset The z axis offset from the player to play the sound at.
 */
@Command(shortDescription = "Plays a test sound")
public void playTestSound(@Sender EntityRef sender, @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) {
    Vector3f position = localPlayer.getPosition();
    position.x += xOffset;
    position.z += zOffset;
    audioManager.playSound(Assets.getSound("engine:dig").get(), position);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

Command (org.terasology.logic.console.commandSystem.annotations.Command)76 ClientComponent (org.terasology.network.ClientComponent)48 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)16 Vector3f (org.terasology.math.geom.Vector3f)14 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)10 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)9 ResourceUrn (org.terasology.assets.ResourceUrn)8 Prefab (org.terasology.entitySystem.prefab.Prefab)6 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 SimpleUri (org.terasology.engine.SimpleUri)5 BlockFamily (org.terasology.world.block.family.BlockFamily)4 Map (java.util.Map)3 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2