Search in sources :

Example 21 with LocationComponent

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

the class SectorUtil method getWatchedChunks.

/**
 * Watched chunks are defined as the union of:
 * <ul>
 *     <li>The chunk in which the {@link LocationComponent#getWorldPosition(Vector3f)} resides, if any</li>
 *     <li>The set of chunks in {@link SectorRegionComponent#chunks}, if any</li>
 * </ul>
 *
 * @param entity the entity to query the watched chunks of
 * @return the set of positions of this entity's watched chunks
 */
public static Set<Vector3i> getWatchedChunks(EntityRef entity) {
    Set<Vector3i> chunks = new HashSet<>();
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    Vector3f position = loc.getWorldPosition(new Vector3f());
    if (position.isFinite()) {
        chunks.add(Chunks.toChunkPos(position, new Vector3i()));
    }
    SectorRegionComponent regionComponent = entity.getComponent(SectorRegionComponent.class);
    if (regionComponent != null) {
        // potential leaky abstraction. component exposes its internal vectors
        chunks.addAll(regionComponent.chunks);
    }
    return chunks;
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) LocationComponent(org.terasology.engine.logic.location.LocationComponent) HashSet(java.util.HashSet)

Example 22 with LocationComponent

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

the class ParticleEmitterComponent method copyFrom.

@Override
public void copyFrom(ParticleEmitterComponent other) {
    this.maxParticles = other.maxParticles;
    this.particleCollision = other.particleCollision;
    this.spawnRateMax = other.spawnRateMax;
    this.spawnRateMin = other.spawnRateMin;
    this.enabled = other.enabled;
    this.lifeTime = other.lifeTime;
    this.particleSpawnsLeft = other.particleSpawnsLeft;
    this.destroyEntityWhenDead = other.destroyEntityWhenDead;
    this.ownerEntity = other.ownerEntity;
    this.particlePool = other.particlePool;
    this.generatorFunctionMap.clear();
    this.generatorFunctionMap.putAll(other.generatorFunctionMap);
    this.affectorFunctionMap.clear();
    this.affectorFunctionMap.putAll(other.affectorFunctionMap);
    this.locationComponent = new LocationComponent();
    // TODO check this
    this.locationComponent.copyFrom(other.locationComponent);
    this.nextEmission = other.nextEmission;
    this.collisionUpdateIteration = other.collisionUpdateIteration;
}
Also used : LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 23 with LocationComponent

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

the class AbstractStorageManager method getEntitiesOfChunk.

protected Collection<EntityRef> getEntitiesOfChunk(Chunk chunk) {
    List<EntityRef> entitiesToStore = Lists.newArrayList();
    AABBfc aabb = chunk.getAABB();
    for (EntityRef entity : getEntityManager().getEntitiesWith(LocationComponent.class)) {
        if (!entity.getOwner().exists() && !entity.isAlwaysRelevant() && !entity.hasComponent(ClientComponent.class)) {
            LocationComponent loc = entity.getComponent(LocationComponent.class);
            if (loc == null) {
                continue;
            }
            Vector3f pos = loc.getWorldPosition(new Vector3f());
            if (pos.isFinite()) {
                if (aabb.containsPoint(loc.getWorldPosition(new Vector3f()))) {
                    entitiesToStore.add(entity);
                }
            }
        }
    }
    return entitiesToStore;
}
Also used : AABBfc(org.terasology.joml.geom.AABBfc) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 24 with LocationComponent

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

the class NetClient method sendNewChunks.

private void sendNewChunks(NetData.NetMessage.Builder message) {
    if (!readyChunks.isEmpty()) {
        chunkSendCounter += chunkSendRate * NET_TICK_RATE * networkSystem.getBandwidthPerClient();
        if (chunkSendCounter > 1.0f) {
            chunkSendCounter -= 1.0f;
            Vector3i center = new Vector3i();
            LocationComponent loc = getEntity().getComponent(ClientComponent.class).character.getComponent(LocationComponent.class);
            if (loc != null) {
                Vector3f target = loc.getWorldPosition(new Vector3f());
                if (target.isFinite()) {
                    // use center as temporary variable
                    center.set(target, RoundingMode.HALF_UP);
                    // update center to chunkPos
                    Chunks.toChunkPos(center, center);
                }
            }
            Vector3i pos = null;
            long distance = Integer.MAX_VALUE;
            for (Vector3i chunkPos : readyChunks.keySet()) {
                long chunkDistance = chunkPos.distanceSquared(center);
                if (pos == null || chunkDistance < distance) {
                    pos = chunkPos;
                    distance = chunkDistance;
                }
            }
            Chunk chunk = readyChunks.remove(pos);
            relevantChunks.add(pos);
            message.addChunkInfo(chunk.encode());
        }
    } else {
        chunkSendCounter = 1.0f;
    }
}
Also used : Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 25 with LocationComponent

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

the class CoreCommands method bowlingPrep.

@Command(shortDescription = "Sets up a typical bowling pin arrangement in front of the player. ", helpText = "Spawns the specific block in a regular bowling pin pattern, Throw something at it!", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String bowlingPrep(@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(5);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "Sorry, your block is not found";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    Vector3f startPos = new Vector3f(spawnPos);
    // delta x is the distance between the pins in the rows.
    float deltax = 0.5f;
    // delta z is the distance between the rows.
    float deltaz = 1.0f;
    // the height of the drop (to be modified to keep the bowlingPin upright)
    float vectorY = 0.0f;
    // rownumber loop is for selecting row
    for (int rownumber = 0; rownumber < 4; rownumber++) {
        // Spawn starting position for Rownumber
        startPos.add(deltax * (4 - rownumber), vectorY, deltaz);
        // pinPosx loop is for vectorx position of bowling pin  in  a particular row
        for (int pinPosx = 0; pinPosx <= rownumber; pinPosx++) {
            EntityRef blockItem = blockItemFactory.newInstance(block);
            blockItem.send(new DropItemEvent(startPos));
            if (pinPosx < rownumber) {
                // drift of position in vector x coordinate, for the last pin stop drifting
                startPos.add(2 * deltax, 0, 0);
            }
        }
        // returns to start position
        startPos.add(-deltax * (rownumber + 4), 0, 0);
    }
    return "prepared 10 " + blockName + " in a bowling pin pattern :)";
}
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)

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