Package org.terasology.entitySystem.entity

Examples of org.terasology.entitySystem.entity.EntityRef


        entity.send(new InventorySlotChangedEvent(slot, oldItem, item));
    }

    static void adjustStackSize(EntityRef entity, int slot, int newCount) {
        InventoryComponent inventory = entity.getComponent(InventoryComponent.class);
        EntityRef item = inventory.itemSlots.get(slot);
        ItemComponent itemComponent = item.getComponent(ItemComponent.class);
        byte oldSize = itemComponent.stackCount;
        itemComponent.stackCount = (byte) newCount;
        item.saveComponent(itemComponent);
        entity.send(new InventorySlotStackSizeChangedEvent(slot, oldSize, newCount));
    }
View Full Code Here


        }
        return EntityRef.NULL;
    }

    public boolean isValid() {
        EntityRef characterEntity = getCharacterEntity();
        return characterEntity.exists() && characterEntity.hasComponent(LocationComponent.class) && characterEntity.hasComponent(CharacterComponent.class)
               && characterEntity.hasComponent(CharacterMovementComponent.class);
    }
View Full Code Here

    @In
    private NUIManager nuiManager;

    @ReceiveEvent(components = {InteractionTargetComponent.class}, netFilter = RegisterMode.AUTHORITY)
    public void onActivate(ActivateEvent event, EntityRef target) {
        EntityRef instigator = event.getInstigator();

        CharacterComponent characterComponent = instigator.getComponent(CharacterComponent.class);
        if (characterComponent == null) {
            logger.error("Interaction start request instigator has no character component");
            return;
        }
        if (characterComponent.authorizedInteractionTarget.exists()) {
            logger.error("Interaction wasn't finished at start of next interaction");
            instigator.send(new InteractionEndEvent(characterComponent.authorizedInteractionId));
        }

        characterComponent.authorizedInteractionTarget = target;
        characterComponent.authorizedInteractionId = event.getActivationId();
        instigator.saveComponent(characterComponent);

    }
View Full Code Here

     *
     * @param usedOwnedEntity if it does not exist it is not an item usage.
     * @return true if an activation request got sent. Returns always true if usedItem exists.
     */
    private boolean activateTargetOrOwnedEntity(EntityRef usedOwnedEntity) {
        EntityRef character = getCharacterEntity();
        LocationComponent location = character.getComponent(LocationComponent.class);
        CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
        Vector3f direction = characterComponent.getLookDirection();
        Vector3f originPos = location.getWorldPosition();
        originPos.y += characterComponent.eyeOffset;
        boolean ownedEntityUsage = usedOwnedEntity.exists();
        int activationId = nextActivationId++;
        Physics physics = CoreRegistry.get(Physics.class);
        HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, filter);
        boolean eventWithTarget = result.isHit();
        if (eventWithTarget) {
            EntityRef activatedObject = usedOwnedEntity.exists() ? usedOwnedEntity : result.getEntity();
            activatedObject.send(new ActivationPredicted(character, result.getEntity(), originPos, direction,
                    result.getHitPoint(), result.getHitNormal(), activationId));
            character.send(new ActivationRequest(character, ownedEntityUsage, usedOwnedEntity, eventWithTarget, result.getEntity(),
                    originPos, direction, result.getHitPoint(), result.getHitNormal(), activationId));
            return true;
        } else if (ownedEntityUsage) {
View Full Code Here

    }

    @ReceiveEvent(components = {InteractionTargetComponent.class})
    public void onActivationPredicted(ActivationPredicted event, EntityRef target) {
        EntityRef character = event.getInstigator();
        CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
        if (characterComponent == null) {
            return;
        }
        if (characterComponent.predictedInteractionTarget.exists()) {
            InteractionUtil.cancelInteractionAsClient(character);
        }
        if (target.exists()) {
            characterComponent.predictedInteractionTarget = target;
            characterComponent.predictedInteractionId = event.getActivationId();
            character.saveComponent(characterComponent);
            target.send(new InteractionStartPredicted(character));
        }
    }
View Full Code Here


    @ReceiveEvent(components = {InteractionScreenComponent.class})
    public void onInteractionStartPredicted(InteractionStartPredicted event, EntityRef container,
                                   InteractionScreenComponent interactionScreenComponent) {
        EntityRef investigator = event.getInstigator();
        CharacterComponent characterComponent = investigator.getComponent(CharacterComponent.class);
        if (characterComponent == null) {
            logger.error("Interaction start predicted for entity without character component");
            return;
        }
        ClientComponent controller = characterComponent.controller.getComponent(ClientComponent.class);
View Full Code Here

     *
     * When it happens then it cancels the interaction.
     */
    @ReceiveEvent(components = {ClientComponent.class})
    public void onScreenLayerClosed(ScreenLayerClosedEvent event, EntityRef container, ClientComponent clientComponent) {
        EntityRef character = clientComponent.character;
        AssetUri activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);

        if ((activeInteractionScreenUri != null) && (activeInteractionScreenUri.equals(event.getClosedScreenUri()))) {
            InteractionUtil.cancelInteractionAsClient(clientComponent.character);
        }
View Full Code Here

    public void onToggleInventory(InventoryButton event, EntityRef entity, ClientComponent clientComponent) {
        if (event.getState() != ButtonState.DOWN) {
            return;
        }

        EntityRef character = clientComponent.character;
        AssetUri activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
        if (activeInteractionScreenUri != null) {
            InteractionUtil.cancelInteractionAsClient(character);
            // do not consume the event, so that the inventory will still open
        }
View Full Code Here

    }

    @Test
    public void clientSentNetInitialForNewNetworkEntity() {
        connectClient();
        EntityRef entity = entityManager.create(new NetworkComponent());
        networkSystem.registerNetworkEntity(entity);
        assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
        verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }
View Full Code Here

        verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }

    @Test
    public void clientSentNetInitialForExistingNetworkEntityOnConnect() {
        EntityRef entity = entityManager.create(new NetworkComponent());
        networkSystem.registerNetworkEntity(entity);
        connectClient();
        assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
        verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }
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.