Search in sources :

Example 26 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class CoreCommands method spawnBlock.

/**
 * Spawns a block in front of the player
 * @param sender Sender of command
 * @param blockName String containing name of block to spawn
 * @return String containg final message
 */
@Command(shortDescription = "Spawns a block in front of the player", helpText = "Spawns the specified block as a " + "item in front of the player. You can simply pick it up.", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnBlock(@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(3);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    EntityRef blockItem = blockItemFactory.newInstance(block);
    blockItem.send(new DropItemEvent(spawnPos));
    return "Spawned block.";
}
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 27 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class NetClient method setColor.

public void setColor(Color color) {
    this.color = color;
    ClientComponent client = getEntity().getComponent(ClientComponent.class);
    if (client != null) {
        ColorComponent colorInfo = client.clientInfo.getComponent(ColorComponent.class);
        if (colorInfo != null) {
            colorInfo.color = color;
            client.clientInfo.saveComponent(colorInfo);
        }
    }
}
Also used : ColorComponent(org.terasology.network.ColorComponent) ClientComponent(org.terasology.network.ClientComponent)

Example 28 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class HealthCommands method healthMax.

@Command(shortDescription = "Restores your health to max", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String healthMax(@Sender EntityRef clientEntity) {
    ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
    clientComp.character.send(new DoHealEvent(100000, clientComp.character));
    return "Health fully restored";
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 29 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class HealthCommands method showHealth.

@Command(shortDescription = "Show your health", requiredPermission = PermissionManager.NO_PERMISSION)
public String showHealth(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    if (health != null) {
        return "Your health:" + health.currentHealth + " max:" + health.maxHealth + " regen:" + health.regenRate;
    }
    return "I guess you're dead?";
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 30 with ClientComponent

use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.

the class HealthCommands method damageWithType.

@Command(shortDescription = "Reduce the player's health by an amount by a specific type of damage", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String damageWithType(@Sender EntityRef client, @CommandParam("damageType") String damageType, @CommandParam("amount") int amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    Prefab damageTypePrefab = prefabManager.getPrefab(damageType);
    if (damageTypePrefab != null) {
        clientComp.character.send(new DoDamageEvent(amount, damageTypePrefab, clientComp.character));
        return "Inflicted " + amount + " damage of type " + damageType;
    } else {
        return "Specified damage type does not exist.";
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Prefab(org.terasology.entitySystem.prefab.Prefab) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Aggregations

ClientComponent (org.terasology.network.ClientComponent)64 Command (org.terasology.logic.console.commandSystem.annotations.Command)37 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 LocationComponent (org.terasology.logic.location.LocationComponent)13 Vector3f (org.terasology.math.geom.Vector3f)13 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)5 Prefab (org.terasology.entitySystem.prefab.Prefab)5 LocalPlayer (org.terasology.logic.players.LocalPlayer)4 Quat4f (org.terasology.math.geom.Quat4f)4 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Client (org.terasology.network.Client)3 ResourceUrn (org.terasology.assets.ResourceUrn)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)2 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)2