Search in sources :

Example 51 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent 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(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(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.engine.logic.inventory.events.DropItemEvent) Vector3f(org.joml.Vector3f) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 52 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent 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(new Vector3f());
    Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
    offset.mul(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.engine.logic.inventory.events.DropItemEvent) Vector3f(org.joml.Vector3f) BlockItemFactory(org.terasology.engine.world.block.items.BlockItemFactory) BlockFamily(org.terasology.engine.world.block.family.BlockFamily) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 53 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class ThirdPersonRemoteClientSystem method linkHeldItemLocationForRemotePlayer.

/**
 * Changes held item entity.
 * <p>
 * Detaches old held item and removes its components. Adds components to new held item and attaches it to the mount
 * point entity.
 */
private void linkHeldItemLocationForRemotePlayer(EntityRef newItem, EntityRef player) {
    if (relatesToLocalPlayer(player)) {
        logger.debug("linkHeldItemLocationForRemotePlayer called with an entity that relates to the local player," + " ignoring{}", player);
        return;
    }
    // Find out if there is a current held item that maps to this player
    EntityRef currentHeldItem = EntityRef.NULL;
    for (EntityRef heldItemCandidate : entityManager.getEntitiesWith(ItemIsRemotelyHeldComponent.class)) {
        EntityRef remotePlayerCandidate = heldItemCandidate.getComponent(ItemIsRemotelyHeldComponent.class).remotePlayer;
        logger.debug("For held item candidate {} got its player candidate as {}", heldItemCandidate, remotePlayerCandidate);
        if (remotePlayerCandidate.equals(player)) {
            logger.debug("Thinking we found a match with player {} so counting this held item as relevant for " + "processing", player);
            currentHeldItem = heldItemCandidate;
            // need to remove the old item
            if (newItem.equals(EntityRef.NULL)) {
                logger.debug("Found an existing held item but the new request was to no longer hold anything so " + "destroying {}", currentHeldItem);
                currentHeldItem.destroy();
                return;
            }
            break;
        }
    }
    // In the case of an actual change of item other than an empty hand we need to hook up a new held item entity
    if (newItem != null && !newItem.equals(EntityRef.NULL) && !newItem.equals(currentHeldItem)) {
        RemotePersonHeldItemMountPointComponent mountPointComponent = player.getComponent(RemotePersonHeldItemMountPointComponent.class);
        if (mountPointComponent != null) {
            // currentHeldItem is at this point the old item
            if (currentHeldItem != EntityRef.NULL) {
                currentHeldItem.destroy();
            }
            currentHeldItem = entityManager.create();
            logger.debug("linkHeldItemLocationForRemotePlayer is now creating a new held item {}", currentHeldItem);
            // add the visually relevant components
            for (Component component : newItem.iterateComponents()) {
                if (component instanceof VisualComponent && !(component instanceof FirstPersonHeldItemTransformComponent)) {
                    currentHeldItem.addComponent(component);
                }
            }
            // ensure world location is set
            currentHeldItem.addComponent(new LocationComponent());
            // Map this held item to the player it is held by
            ItemIsRemotelyHeldComponent itemIsRemotelyHeldComponent = new ItemIsRemotelyHeldComponent();
            itemIsRemotelyHeldComponent.remotePlayer = player;
            currentHeldItem.addComponent(itemIsRemotelyHeldComponent);
            RemotePersonHeldItemTransformComponent heldItemTransformComponent = currentHeldItem.getComponent(RemotePersonHeldItemTransformComponent.class);
            if (heldItemTransformComponent == null) {
                heldItemTransformComponent = new RemotePersonHeldItemTransformComponent();
                currentHeldItem.addComponent(heldItemTransformComponent);
            }
            Location.attachChild(mountPointComponent.mountPointEntity, currentHeldItem, heldItemTransformComponent.translate, new Quaternionf().rotationYXZ(Math.toRadians(heldItemTransformComponent.rotateDegrees.y), Math.toRadians(heldItemTransformComponent.rotateDegrees.x), Math.toRadians(heldItemTransformComponent.rotateDegrees.z)), heldItemTransformComponent.scale);
        }
    } else {
        logger.info("Somehow ended up in the else during linkHeldItemLocationForRemotePlayer - current item was " + "{} and new item {}", currentHeldItem, newItem);
    }
}
Also used : VisualComponent(org.terasology.engine.rendering.logic.VisualComponent) Quaternionf(org.joml.Quaternionf) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) CharacterHeldItemComponent(org.terasology.engine.logic.characters.CharacterHeldItemComponent) Component(org.terasology.gestalt.entitysystem.component.Component) VisualComponent(org.terasology.engine.rendering.logic.VisualComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent) OnActivatedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent) OnChangedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 54 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class FirstPersonClientSystem method linkHeldItemLocationForLocalPlayer.

/**
 * Changes held item entity.
 *
 * <p>Detaches old held item and removes it's components. Adds components to new held item and
 * attaches it to the mount point entity.</p>
 */
private void linkHeldItemLocationForLocalPlayer(EntityRef newItem) {
    if (!newItem.equals(currentHeldItem)) {
        EntityRef camera = localPlayer.getCameraEntity();
        FirstPersonHeldItemMountPointComponent mountPointComponent = camera.getComponent(FirstPersonHeldItemMountPointComponent.class);
        if (mountPointComponent != null) {
            // currentHeldItem is at this point the old item
            if (currentHeldItem != EntityRef.NULL) {
                currentHeldItem.destroy();
            }
            // use the hand if there is no new item
            EntityRef newHeldItem;
            if (newItem == EntityRef.NULL) {
                newHeldItem = getHandEntity();
            } else {
                newHeldItem = newItem;
            }
            // create client side held item entity
            currentHeldItem = entityManager.create();
            // add the visually relevant components
            for (Component component : newHeldItem.iterateComponents()) {
                if (component instanceof VisualComponent) {
                    currentHeldItem.addComponent(component);
                }
            }
            // ensure world location is set
            currentHeldItem.addComponent(new LocationComponent());
            currentHeldItem.addComponent(new ItemIsHeldComponent());
            FirstPersonHeldItemTransformComponent heldItemTransformComponent = currentHeldItem.getComponent(FirstPersonHeldItemTransformComponent.class);
            if (heldItemTransformComponent == null) {
                heldItemTransformComponent = new FirstPersonHeldItemTransformComponent();
                currentHeldItem.addComponent(heldItemTransformComponent);
            }
            Location.attachChild(mountPointComponent.mountPointEntity, currentHeldItem, heldItemTransformComponent.translate, new Quaternionf().rotationYXZ(TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * heldItemTransformComponent.rotateDegrees.z), heldItemTransformComponent.scale);
        }
    }
}
Also used : VisualComponent(org.terasology.engine.rendering.logic.VisualComponent) Quaternionf(org.joml.Quaternionf) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) CharacterHeldItemComponent(org.terasology.engine.logic.characters.CharacterHeldItemComponent) Component(org.terasology.gestalt.entitysystem.component.Component) VisualComponent(org.terasology.engine.rendering.logic.VisualComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent) OnActivatedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent) OnChangedComponent(org.terasology.engine.entitySystem.entity.lifecycleEvents.OnChangedComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 55 with LocationComponent

use of org.terasology.engine.logic.location.LocationComponent in project Terasology by MovingBlocks.

the class MovementDebugCommands method teleportPlayerToMe.

@Command(shortDescription = "Teleport player to you", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String teleportPlayerToMe(@Sender EntityRef sender, @CommandParam("username") String username) {
    for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
        EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
        if (username.equalsIgnoreCase(name.name)) {
            LocationComponent locationComponent = sender.getComponent(LocationComponent.class);
            if (locationComponent != null) {
                Vector3f vLocation = locationComponent.getWorldPosition(new Vector3f());
                ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
                if (clientComp != null) {
                    clientComp.character.send(new CharacterTeleportEvent(vLocation));
                    return "Teleporting " + username + " to you at " + vLocation.x + " " + vLocation.y + " " + vLocation.z;
                }
            }
        }
    }
    throw new IllegalArgumentException("No such user '" + username + "'");
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) CharacterTeleportEvent(org.terasology.engine.logic.characters.CharacterTeleportEvent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) LocationComponent(org.terasology.engine.logic.location.LocationComponent) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Aggregations

LocationComponent (org.terasology.engine.logic.location.LocationComponent)65 Vector3f (org.joml.Vector3f)46 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)40 Quaternionf (org.joml.Quaternionf)18 ClientComponent (org.terasology.engine.network.ClientComponent)17 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)9 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)9 Matrix4f (org.joml.Matrix4f)7 Vector3i (org.joml.Vector3i)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)5 Vector3fc (org.joml.Vector3fc)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)4 CharacterHeldItemComponent (org.terasology.engine.logic.characters.CharacterHeldItemComponent)4 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)4 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)4 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 Bone (org.terasology.engine.rendering.assets.skeletalmesh.Bone)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Component (org.terasology.gestalt.entitysystem.component.Component)4