Package org.terasology.entitySystem.entity

Examples of org.terasology.entitySystem.entity.EntityRef


    private long lastTimeThrowInteraction;

    @ReceiveEvent
    public void onSlotChangeRequested(SelectItemRequest request, EntityRef character, CharacterComponent characterComp) {
        if (request.getSlot() >= 0 && request.getSlot() < 10 && request.getSlot() != characterComp.selectedItem) {
            EntityRef oldItem = InventoryUtils.getItemAt(character, characterComp.selectedItem);
            EntityRef newItem = InventoryUtils.getItemAt(character, request.getSlot());
            characterComp.selectedItem = request.getSlot();
            character.saveComponent(characterComp);
            character.send(new SelectedItemChangedEvent(oldItem, newItem));
        }
    }
View Full Code Here


        if (!event.isDown() || time.getGameTimeInMs() - lastInteraction < 200) {
            return;
        }

        CharacterComponent character = entity.getComponent(CharacterComponent.class);
        EntityRef selectedItemEntity = InventoryUtils.getItemAt(entity, character.selectedItem);

        entity.send(new AttackRequest(selectedItemEntity));

        lastInteraction = time.getGameTimeInMs();
        character.handAnimation = 0.5f;
View Full Code Here

    }

    @ReceiveEvent(components = {CharacterComponent.class, InventoryComponent.class})
    public void onDropItemRequest(DropItemButton event, EntityRef entity) {
        CharacterComponent character = entity.getComponent(CharacterComponent.class);
        EntityRef selectedItemEntity = InventoryUtils.getItemAt(entity, character.selectedItem);

        if (selectedItemEntity.equals(EntityRef.NULL)) {
            return;
        }
        //if this is our first time throwing, set the timer to something sensible, we can return since
        // this is a repeating event.
        if (event.isDown() && lastTimeThrowInteraction == 0) {
View Full Code Here

        ItemComponent itemComp = itemEntity.getComponent(ItemComponent.class);
        if (itemComp == null || !itemComp.pickupPrefab.exists()) {
            return EntityRef.NULL;
        }

        EntityRef pickupItem = itemEntity;
        EntityRef owner = itemEntity.getOwner();
        if (owner.hasComponent(InventoryComponent.class)) {
            if (dropAll) {
                final EntityRef removedItem = CoreRegistry.get(InventoryManager.class).removeItem(owner, EntityRef.NULL, pickupItem, false);
                if (removedItem != null) {
                    pickupItem = removedItem;
                }
            } else {
                final EntityRef removedItem = CoreRegistry.get(InventoryManager.class).removeItem(owner, EntityRef.NULL, pickupItem, false, 1);
                if (removedItem != null) {
                    pickupItem = removedItem;
                }
            }
        }
View Full Code Here

    public EntityRef newInstance(Vector3f spawnPosition, EntityRef controller) {
        EntityBuilder builder = entityManager.newBuilder("engine:player");
        builder.getComponent(LocationComponent.class).setWorldPosition(spawnPosition);
        builder.setOwner(controller);
        EntityRef transferSlot = entityManager.create("engine:transferSlot");

        ClientComponent clientComp = controller.getComponent(ClientComponent.class);
        if (clientComp != null) {
            ColorComponent colorComp = clientComp.clientInfo.getComponent(ColorComponent.class);
           
            MeshComponent meshComp = builder.getComponent(MeshComponent.class);
            meshComp.color = colorComp.color;
        }
       
        CharacterComponent playerComponent = builder.getComponent(CharacterComponent.class);
        playerComponent.spawnPosition.set(spawnPosition);
        playerComponent.movingItem = transferSlot;
        playerComponent.controller = controller;

        EntityRef player = builder.build();

        player.send(new SelectedItemChangedEvent(EntityRef.NULL, InventoryUtils.getItemAt(player, 0)));

        return player;
    }
View Full Code Here

        Vector3i spawnPos = getSafeSpawnPosition(initialSpawnPosition);

        ClientComponent client = clientEntity.getComponent(ClientComponent.class);
        if (client != null) {
            PlayerFactory playerFactory = new PlayerFactory(entityManager);
            EntityRef playerCharacter = playerFactory.newInstance(new Vector3f(spawnPos.x, spawnPos.y + 1.5f, spawnPos.z), clientEntity);
            Location.attachChild(playerCharacter, clientEntity, new Vector3f(), new Quat4f(0, 0, 0, 1));

            Client clientListener = networkSystem.getOwner(clientEntity);
            Vector3i distance = clientListener.getViewDistance().getChunkDistance();
            updateRelevanceEntity(clientEntity, distance);
            client.character = playerCharacter;
            clientEntity.saveComponent(client);
            playerCharacter.send(new OnPlayerSpawnedEvent());
        }
    }
View Full Code Here

    }

    private void refreshPrefabs() {
        Collection<Prefab> prefabs = prefabManager.listPrefabs(BehaviorNodeComponent.class);
        for (Prefab prefab : prefabs) {
            EntityRef entityRef = entityManager.create(prefab);
            entityRef.setPersistent(false);
            BehaviorNodeComponent component = entityRef.getComponent(BehaviorNodeComponent.class);
            ClassMetadata<? extends Node, ?> classMetadata = nodesClassLibrary.resolve(component.type);
            if (classMetadata != null) {
                if (classMetadata.isConstructable()) {
                    nodes.put(classMetadata, component);
                    logger.debug("Found behavior node for class " + component.type + " name=" + component.name);
View Full Code Here

                        if (ref.exists()) {
                            outEntityList.add(ref);
                        }
                    }
                } else if (value instanceof EntityRef) {
                    EntityRef ref = (EntityRef) value;
                    if (ref.exists()) {
                        outEntityList.add(ref);
                    }
                }
            }
        }
View Full Code Here

        containerInventory = find("container", InventoryGrid.class);
        containerInventory.bindTargetEntity(new ReadOnlyBinding<EntityRef>() {
            @Override
            public EntityRef get() {
                EntityRef characterEntity = localPlayer.getCharacterEntity();
                CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
                return characterComponent.predictedInteractionTarget;
            }
        });
    }
View Full Code Here

    public void onPlaced(ActivateEvent event, EntityRef itemEntity) {
        if (event.getTargetLocation() == null) {
            return;
        }

        EntityRef targetLocationEntity = event.getTarget();

        this.blockSelectionComponentEntity = itemEntity;
        BlockSelectionComponent blockSelectionComponent = itemEntity.getComponent(BlockSelectionComponent.class);

        if (null == blockSelectionComponent.startPosition) {
            // on the first item click, we start selecting blocks
            targetLocationEntity.send(new SetBlockSelectionStartingPointEvent(itemEntity));

            blockSelectionComponent.shouldRender = true;
        } else {
            // on the second item click, we will set the ending selection point and send an ApplyBlockSelectionEvent
            targetLocationEntity.send(new SetBlockSelectionEndingPointEvent(itemEntity));

            localPlayer.getCharacterEntity().send(new ApplyBlockSelectionEvent(itemEntity, blockSelectionComponent.currentSelection));
            blockSelectionComponent.shouldRender = false;
            blockSelectionComponent.currentSelection = null;
            blockSelectionComponent.startPosition = null;
View Full Code Here

TOP

Related Classes of org.terasology.entitySystem.entity.EntityRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.