Search in sources :

Example 76 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ExplosionAuthoritySystem method doExplosion.

void doExplosion(ExplosionActionComponent explosionComp, Vector3f origin, EntityRef instigatingBlockEntity) {
    EntityBuilder builder = entityManager.newBuilder("core:smokeExplosion");
    builder.getComponent(LocationComponent.class).setWorldPosition(origin);
    EntityRef smokeEntity = builder.build();
    smokeEntity.send(new PlaySoundEvent(getRandomExplosionSound(), 1f));
    Vector3i blockPos = new Vector3i();
    for (int i = 0; i < explosionComp.maxRange; i++) {
        Vector3f direction = random.nextVector3f(1.0f);
        for (int j = 0; j < 4; j++) {
            Vector3f target = new Vector3f(origin);
            target.x += direction.x * j;
            target.y += direction.y * j;
            target.z += direction.z * j;
            blockPos.set((int) target.x, (int) target.y, (int) target.z);
            Block currentBlock = worldProvider.getBlock(blockPos);
            /* PHYSICS */
            if (currentBlock.isDestructible()) {
                EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos);
                // allow explosions to chain together,  but do not chain on the instigating block
                if (!blockEntity.equals(instigatingBlockEntity) && blockEntity.hasComponent(ExplosionActionComponent.class)) {
                    doExplosion(blockEntity.getComponent(ExplosionActionComponent.class), blockPos.toVector3f(), blockEntity);
                } else {
                    blockEntity.send(new DoDamageEvent(explosionComp.damageAmount, explosionComp.damageType));
                }
            }
        }
    }
}
Also used : PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) DoDamageEvent(org.terasology.logic.health.DoDamageEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 77 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ExplosionAuthoritySystem method onDelayedExplosion.

@ReceiveEvent
public void onDelayedExplosion(DelayedActionTriggeredEvent event, EntityRef entityRef, ExplosionActionComponent explosionActionComponent) {
    if (event.getActionId().equals(DELAYED_EXPLOSION_ACTION_ID)) {
        // check if the exploding entity is a block or not
        if (entityRef.hasComponent(BlockComponent.class)) {
            BlockComponent blockComponent = entityRef.getComponent(BlockComponent.class);
            // always destroy the block that caused the explosion
            worldProvider.setBlock(blockComponent.getPosition(), blockManager.getBlock(BlockManager.AIR_ID));
            // create the explosion from the block's location
            doExplosion(explosionActionComponent, blockComponent.getPosition().toVector3f(), entityRef);
        } else if (entityRef.hasComponent(LocationComponent.class)) {
            // get the position of the non-block entity to make it explode from there
            Vector3f position = entityRef.getComponent(LocationComponent.class).getWorldPosition();
            // destroy the non-block entity
            entityRef.destroy();
            // create the explosion from the non-block entity location
            doExplosion(explosionActionComponent, position, EntityRef.NULL);
        }
    }
}
Also used : BlockComponent(org.terasology.world.block.BlockComponent) Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 78 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ExplosionAuthoritySystem method onActivate.

@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ExplosionActionComponent explosionComp) {
    Vector3f origin = null;
    switch(explosionComp.relativeTo) {
        case Self:
            LocationComponent loc = entity.getComponent(LocationComponent.class);
            if (loc != null) {
                origin = loc.getWorldPosition();
            }
            break;
        case Instigator:
            origin = event.getInstigatorLocation();
            break;
        default:
            origin = event.getTargetLocation();
            break;
    }
    if (origin == null) {
        return;
    }
    doExplosion(explosionComp, origin, EntityRef.NULL);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 79 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class TunnelAction method onActivate.

@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, TunnelActionComponent tunnelActionComponent) {
    Vector3f dir = new Vector3f(event.getDirection());
    dir.scale(4.0f);
    Vector3f origin = new Vector3f(event.getOrigin());
    origin.add(dir);
    Vector3i blockPos = new Vector3i();
    int particleEffects = 0;
    int blockCounter = tunnelActionComponent.maxDestroyedBlocks;
    for (int s = 0; s <= tunnelActionComponent.maxTunnelDepth; s++) {
        origin.add(dir);
        if (!worldProvider.isBlockRelevant(origin)) {
            break;
        }
        for (int i = 0; i < tunnelActionComponent.maxRaysCast; i++) {
            Vector3f direction = random.nextVector3f();
            Vector3f impulse = new Vector3f(direction);
            impulse.scale(tunnelActionComponent.explosiveForce);
            for (int j = 0; j < 3; j++) {
                Vector3f target = new Vector3f(origin);
                target.x += direction.x * j;
                target.y += direction.y * j;
                target.z += direction.z * j;
                blockPos.set((int) target.x, (int) target.y, (int) target.z);
                Block currentBlock = worldProvider.getBlock(blockPos);
                if (currentBlock.isDestructible()) {
                    if (particleEffects < tunnelActionComponent.maxParticalEffects) {
                        EntityBuilder builder = entityManager.newBuilder("Core:smokeExplosion");
                        builder.getComponent(LocationComponent.class).setWorldPosition(target);
                        builder.build();
                        particleEffects++;
                    }
                    if (random.nextFloat() < tunnelActionComponent.thoroughness) {
                        EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos);
                        blockEntity.send(new DoDamageEvent(tunnelActionComponent.damageAmount, tunnelActionComponent.damageType));
                    }
                    blockCounter--;
                }
                if (blockCounter <= 0) {
                    return;
                }
            }
        }
    }
    // No blocks were destroyed, so cancel the event
    if (blockCounter == tunnelActionComponent.maxDestroyedBlocks) {
        event.consume();
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) DoDamageEvent(org.terasology.logic.health.DoDamageEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 80 with Vector3f

use of org.terasology.math.geom.Vector3f in project Terasology by MovingBlocks.

the class ChunkImpl method getAABB.

@Override
public AABB getAABB() {
    if (aabb == null) {
        Vector3f min = getChunkWorldOffset().toVector3f();
        Vector3f max = ChunkConstants.CHUNK_SIZE.toVector3f();
        max.add(min);
        aabb = AABB.createMinMax(min, max);
    }
    return aabb;
}
Also used : Vector3f(org.terasology.math.geom.Vector3f)

Aggregations

Vector3f (org.terasology.math.geom.Vector3f)194 LocationComponent (org.terasology.logic.location.LocationComponent)45 EntityRef (org.terasology.entitySystem.entity.EntityRef)44 Quat4f (org.terasology.math.geom.Quat4f)33 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)26 Vector3i (org.terasology.math.geom.Vector3i)21 Test (org.junit.Test)20 ClientComponent (org.terasology.network.ClientComponent)15 Command (org.terasology.logic.console.commandSystem.annotations.Command)14 Matrix4f (org.terasology.math.geom.Matrix4f)13 BaseVector3f (org.terasology.math.geom.BaseVector3f)9 Block (org.terasology.world.block.Block)9 Vector2f (org.terasology.math.geom.Vector2f)8 HitResult (org.terasology.physics.HitResult)8 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)7 IOException (java.io.IOException)6 FloatBuffer (java.nio.FloatBuffer)6 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 AABB (org.terasology.math.AABB)5 ChunkMesh (org.terasology.rendering.primitives.ChunkMesh)5