Search in sources :

Example 1 with ScaleToRequest

use of org.terasology.engine.logic.characters.events.ScaleToRequest in project Terasology by MovingBlocks.

the class MovementDebugCommands method playerHeight.

@Command(shortDescription = "Sets the height of the player", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String playerHeight(@Sender EntityRef entity, @CommandParam("height") float newHeight) {
    if (newHeight > 0.5 && newHeight <= 20) {
        ClientComponent client = entity.getComponent(ClientComponent.class);
        if (client != null) {
            EntityRef character = client.character;
            CharacterMovementComponent movement = client.character.getComponent(CharacterMovementComponent.class);
            if (movement != null) {
                float currentHeight = movement.height;
                ScaleToRequest scaleRequest = new ScaleToRequest(newHeight);
                character.send(scaleRequest);
                return "Height of player set to " + newHeight + " (was " + currentHeight + ")";
            }
        }
    } else {
        return "Invalid input. Accepted values: [1 to 25]";
    }
    return "";
}
Also used : CharacterMovementComponent(org.terasology.engine.logic.characters.CharacterMovementComponent) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ScaleToRequest(org.terasology.engine.logic.characters.events.ScaleToRequest) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 2 with ScaleToRequest

use of org.terasology.engine.logic.characters.events.ScaleToRequest in project Terasology by MovingBlocks.

the class LocalPlayerSystem method onPlayerSpawn.

@ReceiveEvent
public void onPlayerSpawn(OnPlayerSpawnedEvent event, EntityRef character) {
    if (character.equals(localPlayer.getCharacterEntity())) {
        // update character height as given in player settings
        ScaleToRequest scaleRequest = new ScaleToRequest(playerConfig.height.get());
        localPlayer.getCharacterEntity().send(scaleRequest);
        // Trigger updating the player camera position as soon as the local player is spawned.
        // This is not done while the game is still loading, since systems are not updated.
        // RenderableWorldImpl pre-generates chunks around the player camera and therefore needs
        // the correct location.
        lookYaw = 0f;
        lookPitch = 0f;
        update(0);
    }
}
Also used : ScaleToRequest(org.terasology.engine.logic.characters.events.ScaleToRequest) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ScaleToRequest (org.terasology.engine.logic.characters.events.ScaleToRequest)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)1 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)1 ClientComponent (org.terasology.engine.network.ClientComponent)1