Package org.terasology.entitySystem.entity

Examples of org.terasology.entitySystem.entity.EntityRef


    @Test
    public void clientNoInitialEntityIfNotOwnedAndReplicateToOwner() {
        connectClient();
        NetworkComponent netComp = new NetworkComponent();
        netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
        EntityRef entity = entityManager.create(netComp);

        networkSystem.registerNetworkEntity(entity);

        assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);

        verify(client, times(0)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }
View Full Code Here


        connectClient();
        EntityBuilder builder = entityManager.newBuilder();
        NetworkComponent netComp = builder.addComponent(new NetworkComponent());
        netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
        builder.setOwner(clientEntity);
        EntityRef entity = builder.build();

        networkSystem.registerNetworkEntity(entity);

        assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
        verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }
View Full Code Here

    public void clientSentInitialOnlyOnce() {
        EntityBuilder builder = entityManager.newBuilder();
        NetworkComponent netComp = builder.addComponent(new NetworkComponent());
        netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
        builder.setOwner(clientEntity);
        EntityRef entity = builder.build();

        networkSystem.registerNetworkEntity(entity);
        connectClient();
        networkSystem.updateOwnership(entity);

        verify(client, times(1)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
    }
View Full Code Here

    @Test
    public void clientSentInitialForOwnershipChain() {
        NetworkComponent netCompA = new NetworkComponent();
        netCompA.replicateMode = NetworkComponent.ReplicateMode.OWNER;
        EntityRef entityA = entityManager.create(netCompA);

        EntityBuilder builder = entityManager.newBuilder();
        NetworkComponent netCompB = builder.addComponent(new NetworkComponent());
        netCompB.replicateMode = NetworkComponent.ReplicateMode.OWNER;
        builder.setOwner(entityA);
        EntityRef entityB = builder.build();

        networkSystem.registerNetworkEntity(entityA);
        networkSystem.registerNetworkEntity(entityB);
        connectClient();
        verify(client, times(0)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
        verify(client, times(0)).setNetInitial(entityB.getComponent(NetworkComponent.class).getNetworkId());
        entityA.setOwner(clientEntity);
        networkSystem.updateOwnership(entityA);

        verify(client, times(1)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
        verify(client, times(1)).setNetInitial(entityB.getComponent(NetworkComponent.class).getNetworkId());
    }
View Full Code Here

    public void clientSendInitialForRelevantOwnedItems() {
        EntityBuilder builder = entityManager.newBuilder();
        NetworkComponent netCompA = builder.addComponent(new NetworkComponent());
        netCompA.replicateMode = NetworkComponent.ReplicateMode.RELEVANT;
        builder.setOwner(clientEntity);
        EntityRef entityA = builder.build();

        networkSystem.registerNetworkEntity(entityA);
        connectClient();
        verify(client, times(1)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());

    }
View Full Code Here

    @Override
    public void restoreEntities() {
        if (entityStore != null) {
            EntityRestorer restorer = new EntityRestorer(entityManager);
            Map<String, EntityRef> refMap = restorer.restore(entityStore, externalRefs);
            EntityRef loadedCharacter = refMap.get(CHARACTER);
            if (loadedCharacter != null) {
                this.character = loadedCharacter;
            }
            entityStore = null;
        }
View Full Code Here

    @Command(shortDescription = "Adds an item to your inventory", runOnServer = true)
    public String giveItem(@CommandParam("prefabId or blockName") String itemPrefabName, EntityRef client) {
        Prefab prefab = prefabManager.getPrefab(itemPrefabName);
        if (prefab != null && prefab.getComponent(ItemComponent.class) != null) {
            EntityRef item = entityManager.create(prefab);
            EntityRef playerEntity = client.getComponent(ClientComponent.class).character;
            if (!inventoryManager.giveItem(playerEntity, playerEntity, item)) {
                item.destroy();
            }
            return "You received an item of " + prefab.getName();
        } else {
View Full Code Here

        if (characterComponent == null) {
            logger.error("Interaction instigator has no character component");
            return;
        }

        EntityRef oldTarget = characterComponent.predictedInteractionTarget;
        if (oldTarget.exists()) {
            characterComponent.predictedInteractionTarget = EntityRef.NULL;
            character.saveComponent(characterComponent);
            oldTarget.send(new InteractionEndPredicted(character));
            if (notifyServer) {
                character.send(new InteractionEndRequest());
            }
        }
    }
View Full Code Here

        if (characterComponent == null) {
            logger.error("Interaction end request instigator has no character component");
            return;
        }
        int oldInteractionId = characterComponent.authorizedInteractionId;
        EntityRef oldTarget = characterComponent.authorizedInteractionTarget;
        if (oldTarget.exists()) {
            characterComponent.authorizedInteractionTarget =EntityRef.NULL;
            character.saveComponent(characterComponent);
        }

        character.send(new InteractionEndEvent(oldInteractionId));
View Full Code Here

    public static AssetUri getActiveInteractionScreenUri(EntityRef character) {
        CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
        if (characterComponent == null) {
            return null;
        }
        EntityRef interactionTarget = characterComponent.predictedInteractionTarget;
        if (!interactionTarget.exists()) {
            return null;
        }
        InteractionScreenComponent screenComponent = interactionTarget.getComponent(InteractionScreenComponent.class);
        if (screenComponent == null) {
            return null;
        }
        return new AssetUri(AssetType.UI_ELEMENT, screenComponent.screen);
    }
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.