Package org.terasology.logic.location

Examples of org.terasology.logic.location.LocationComponent


        return false;
    }

    @ReceiveEvent(components = ClientComponent.class)
    public void onConnect(ConnectedEvent connected, EntityRef entity) {
        LocationComponent loc = entity.getComponent(LocationComponent.class);
        loc.setWorldPosition(connected.getPlayerStore().getRelevanceLocation());
        entity.saveComponent(loc);
        addRelevanceEntity(entity, ViewDistance.LEGALLY_BLIND.getChunkDistance(), networkSystem.getOwner(entity));
        if (connected.getPlayerStore().hasCharacter()) {
            if (worldProvider.isBlockRelevant(connected.getPlayerStore().getRelevanceLocation())) {
                restoreCharacter(entity, connected.getPlayerStore());
            } else {
                SpawningClientInfo spawningClientInfo = new SpawningClientInfo(entity, connected.getPlayerStore().getRelevanceLocation(), connected.getPlayerStore());
                clientsPreparingToSpawn.add(spawningClientInfo);
            }
        } else {
            Vector3i pos = Vector3i.zero();
            if (worldProvider.isBlockRelevant(pos)) {
                spawnPlayer(entity, getSafeSpawnPosition());
            } else {
                // Move the player (before it's spawned) to the spawn-position to make sure the relevance
                // loads the chunk at some point
                Vector3f spawnPosition = getSafeSpawnPosition().toVector3f();
                loc.setWorldPosition(spawnPosition);
                entity.saveComponent(loc);
               
                SpawningClientInfo spawningClientInfo = new SpawningClientInfo(entity,
                        spawnPosition);
                clientsPreparingToSpawn.add(spawningClientInfo);
View Full Code Here


        if (!client.character.exists()) {
            Vector3i pos = Vector3i.zero();
            if (worldProvider.isBlockRelevant(pos)) {
                spawnPlayer(entity, getSafeSpawnPosition());
            } else {
                LocationComponent loc = entity.getComponent(LocationComponent.class);
                loc.setWorldPosition(getSafeSpawnPosition().toVector3f());
                entity.saveComponent(loc);
                updateRelevanceEntity(entity, ViewDistance.LEGALLY_BLIND.getChunkDistance());

                SpawningClientInfo info = new SpawningClientInfo(entity, getSafeSpawnPosition().toVector3f());
                clientsPreparingToSpawn.add(info);
View Full Code Here

             * Note: Entities with owners get saved with the owner. Entities that are always relevant don't get stored
             * in chunk as the chunk is not always loaded
             */
            if (entity.isPersistent() && !entity.getOwner().exists() && !entity.hasComponent(ClientComponent.class)
                    && !entity.isAlwaysRelevant()) {
                LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
                if (locationComponent != null) {
                    Vector3f loc = locationComponent.getWorldPosition();
                    Vector3i chunkPos = TeraMath.calcChunkPos((int) loc.x, (int) loc.y, (int) loc.z);
                    Collection<EntityRef> collection = chunkPosToEntitiesMap.get(chunkPos);
                    if (collection == null) {
                        collection = Lists.newArrayList();
                        chunkPosToEntitiesMap.put(chunkPos, collection);
View Full Code Here

        if (character.exists()) {
            playerStore.setCharacter(character);
        }

        boolean hasCharacter = character.exists();
        LocationComponent location = character.getComponent(LocationComponent.class);
        Vector3f relevanceLocation;
        if (location != null) {
            relevanceLocation = location.getWorldPosition();
        } else {
            relevanceLocation = new Vector3f();
        }

        EntityData.PlayerStore.Builder playerEntityStore = EntityData.PlayerStore.newBuilder();
View Full Code Here

        List<EntityRef> entitiesToStore = Lists.newArrayList();

        AABB aabb = chunk.getAABB();
        for (EntityRef entity : entityManager.getEntitiesWith(LocationComponent.class)) {
            if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) {
                LocationComponent loc = entity.getComponent(LocationComponent.class);
                if (loc != null) {
                    if (aabb.contains(loc.getWorldPosition())) {
                        entitiesToStore.add(entity);
                    }
                }
            }
        }
View Full Code Here

            if (!character.equals(event.getItem().getOwner())) {
                return;
            }
        }

        LocationComponent location = character.getComponent(LocationComponent.class);
        CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
        Vector3f direction = characterComponent.getLookDirection();
        Vector3f originPos = location.getWorldPosition();
        originPos.y += characterComponent.eyeOffset;

        HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, filter);

        if (result.isHit()) {
View Full Code Here

        }
        return displayNameComponent.name;
    }

    private boolean isPredictionOfEventCorrect(EntityRef character, ActivationRequest event) {
        LocationComponent location = character.getComponent(LocationComponent.class);
        CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
        Vector3f direction = characterComponent.getLookDirection();
        if (!(vectorsAreAboutEqual(event.getDirection(), direction))) {
            logger.error("Direction at client {} was different than direction at server {}", event.getDirection(), direction);
        }
        // Assume the exact same value in case there are rounding mistakes:
        direction = event.getDirection();

        Vector3f originPos = location.getWorldPosition();
        originPos.y += characterComponent.eyeOffset;
        if (!(vectorsAreAboutEqual(event.getOrigin(), originPos))) {
            logger.info("Player {} seems to have cheated: It stated that it performed an action from {} but the predicted position is {}", getPlayerNameFromCharacter(character), event.getOrigin(), originPos);
            return false;
        }
View Full Code Here

        for (EntityRef characterEntity: characterEntities) {
            CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
            if (characterComponent == null) {
                continue; // could have changed during events below
            }
            LocationComponent characterLocation = characterEntity.getComponent(LocationComponent.class);
            if (characterLocation == null) {
                continue; // could have changed during events below
            }
            EntityRef target = characterComponent.authorizedInteractionTarget;
            if (target.isActive()) {

                LocationComponent targetLocation = target.getComponent(LocationComponent.class);
                if (targetLocation == null) {
                    continue; // could have changed during events below
                }
                float maxInteractionRange = characterComponent.interactionRange;
                if (isDistanceToLarge(characterLocation, targetLocation, maxInteractionRange)) {
View Full Code Here

        CharacterStateEvent.setToState(entity, newState);
    }

    private CharacterStateEvent createInitialState(EntityRef entity) {
        LocationComponent location = entity.getComponent(LocationComponent.class);
        return new CharacterStateEvent(time.getGameTimeInMs(), 0, location.getWorldPosition(), location.getWorldRotation(), new Vector3f(), 0, 0, MovementMode.WALKING, false);
    }
View Full Code Here

        List<Component> components = Lists.newArrayList();
        for (Component component : prefab.iterateComponents()) {
            Component newComp = componentLibrary.copy(component);
            components.add(newComp);
            if (newComp instanceof LocationComponent) {
                LocationComponent loc = (LocationComponent) newComp;
                loc.setWorldPosition(position);
                loc.setWorldRotation(rotation);
            }
        }
        components.add(new EntityInfoComponent(prefab.getName(), prefab.isPersisted(), prefab.isAlwaysRelevant()));
        return create(components);
    }
View Full Code Here

TOP

Related Classes of org.terasology.logic.location.LocationComponent

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.