Search in sources :

Example 46 with Command

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

the class CoreCommands method reloadScreen.

/**
 * Reloads ui screen
 * @param ui String containing ui screen name
 * @return String containing Success if UI was reloaded or No unique resource found if more screens were found
 */
@Command(shortDescription = "Reloads a ui screen")
public String reloadScreen(@CommandParam("ui") String ui) {
    Set<ResourceUrn> urns = assetManager.resolve(ui, UIElement.class);
    if (urns.size() == 1) {
        ResourceUrn urn = urns.iterator().next();
        boolean wasOpen = nuiManager.isOpen(urn);
        if (wasOpen) {
            nuiManager.closeScreen(urn);
        }
        if (wasOpen) {
            nuiManager.pushScreen(urn);
        }
        return "Success";
    } else {
        return "No unique resource found";
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 47 with Command

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

the class CoreCommands method editScreen.

/**
 * Opens the NUI editor for a ui screen
 * @param uri String containing ui screen name
 * @return String containing final message
 */
@Command(shortDescription = "Opens the NUI editor for a ui screen", requiredPermission = PermissionManager.NO_PERMISSION)
public String editScreen(@CommandParam(value = "uri", suggester = ScreenSuggester.class) String uri) {
    if (!nuiEditorSystem.isEditorActive()) {
        nuiEditorSystem.toggleEditor();
    }
    Set<ResourceUrn> urns = assetManager.resolve(uri, UIElement.class);
    switch(urns.size()) {
        case 0:
            return String.format("No asset found for screen '%s'", uri);
        case 1:
            ResourceUrn urn = urns.iterator().next();
            ((NUIEditorScreen) nuiManager.getScreen(NUIEditorScreen.ASSET_URI)).selectAsset(urn);
            return "Success";
        default:
            return String.format("Multiple matches for screen '%s': {%s}", uri, Arrays.toString(urns.toArray()));
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) NUIEditorScreen(org.terasology.rendering.nui.editor.layers.NUIEditorScreen) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 48 with Command

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

the class CoreCommands method bowlingPrep.

@Command(shortDescription = "Sets up a typical bowling pin arrangement in front of the player. ", helpText = "Spawns the specific block in a regular bowling pin pattern, Throw something at it!", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bowlingPrep(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition();
    Vector3f offset = characterLocation.getWorldDirection();
    offset.scale(5);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    Vector3f startPos = new Vector3f(spawnPos);
    // delta x is the distance between the pins in the rows.
    float deltax = 0.5f;
    // delta z is the distance between the rows.
    float deltaz = 1.0f;
    // the height of the drop (to be modified to keep the bowlingPin upright)
    float vectorY = 0.0f;
    // rownumber loop is for selecting row
    for (int rownumber = 0; rownumber < 4; rownumber++) {
        // Spawn starting position for Rownumber
        startPos.add(deltax * (4 - rownumber), vectorY, deltaz);
        // pinPosx loop is for vectorx position of bowling pin  in  a particular row
        for (int pinPosx = 0; pinPosx <= rownumber; pinPosx++) {
            EntityRef blockItem = blockItemFactory.newInstance(block);
            blockItem.send(new DropItemEvent(startPos));
            if (pinPosx < rownumber) {
                // drift of position in vector x coordinate, for the last pin stop drifting
                startPos.add(2 * deltax, 0, 0);
            }
        }
        // returns to start position
        startPos.add(-deltax * (rownumber + 4), 0, 0);
    }
    return "prepared 10 " + blockName + " in a bowling pin pattern :)";
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) BlockItemFactory(org.terasology.world.block.items.BlockItemFactory) BlockFamily(org.terasology.world.block.family.BlockFamily) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 49 with Command

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

the class CoreCommands method spawnPrefab.

/**
 * Spawns an instance of a prefab in the world
 * @param sender Sender of command
 * @param prefabName String containing prefab name
 * @return String containing final message
 */
@Command(shortDescription = "Spawns an instance of a prefab in the world", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnPrefab(@Sender EntityRef sender, @CommandParam("prefabId") String prefabName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition();
    Vector3f offset = new Vector3f(characterLocation.getWorldDirection());
    offset.scale(2);
    spawnPos.add(offset);
    Vector3f dir = new Vector3f(characterLocation.getWorldDirection());
    dir.y = 0;
    if (dir.lengthSquared() > 0.001f) {
        dir.normalize();
    } else {
        dir.set(Direction.FORWARD.getVector3f());
    }
    Quat4f rotation = Quat4f.shortestArcQuat(Direction.FORWARD.getVector3f(), dir);
    Optional<Prefab> prefab = Assets.getPrefab(prefabName);
    if (prefab.isPresent() && prefab.get().getComponent(LocationComponent.class) != null) {
        entityManager.create(prefab.get(), spawnPos, rotation);
        return "Done";
    } else if (!prefab.isPresent()) {
        return "Unknown prefab";
    } else {
        return "Prefab cannot be spawned (no location component)";
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) Prefab(org.terasology.entitySystem.prefab.Prefab) Quat4f(org.terasology.math.geom.Quat4f) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 50 with Command

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

the class CoreCommands method bulkDrop.

@Command(shortDescription = "Mass-drops the desired block however many times the player indicates", helpText = "First parameter indicates which block to drop, second parameter how many", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bulkDrop(@Sender EntityRef sender, @CommandParam("blockName") String blockName, @CommandParam("value") int value) {
    // This is a loop which gives the particular amount of block the player wants to spawn
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition();
    Vector3f offset = characterLocation.getWorldDirection();
    offset.scale(3);
    spawnPos.add(5, 10, 0);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    if (value > 5000) {
        return "Value exceeds the maximum limit of 5000 blocks. your value: " + value + " blocks";
    }
    for (int i = 0; i < value; i++) {
        EntityRef blockItem = blockItemFactory.newInstance(block);
        blockItem.send(new DropItemEvent(spawnPos));
    }
    // this returns the block you have spawned and the amount
    return "Dropped " + value + " " + blockName + " Blocks :)";
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) BlockItemFactory(org.terasology.world.block.items.BlockItemFactory) BlockFamily(org.terasology.world.block.family.BlockFamily) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

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