Search in sources :

Example 1 with BlockDamageModifierComponent

use of org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDefaultDropsHandling.

public void commonDefaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, Vector3ic location, Block block) {
    BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
    float chanceOfBlockDrop = 1;
    if (blockDamageModifierComponent != null) {
        chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance;
    }
    if (random.nextFloat() < chanceOfBlockDrop) {
        EntityRef item = blockItemFactory.newInstance(block.getBlockFamily(), entity);
        entity.send(new OnBlockToItem(item));
        if (shouldDropToWorld(event, block, blockDamageModifierComponent, item)) {
            float impulsePower = 0;
            if (blockDamageModifierComponent != null) {
                impulsePower = blockDamageModifierComponent.impulsePower;
            }
            processDropping(item, location, impulsePower);
        }
    }
}
Also used : BlockDamageModifierComponent(org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent) OnBlockToItem(org.terasology.engine.world.block.items.OnBlockToItem) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 2 with BlockDamageModifierComponent

use of org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDestroyed.

private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
    entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
    BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
    // TODO: Configurable via block definition
    if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
        // dust particle effect
        if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
            // TODO: particle system stuff should be split out better - this is effectively a stealth dependency on
            // 'CoreAssets' from the engine
            EntityBuilder dustBuilder = entityManager.newBuilder("CoreAssets:dustEffect");
            if (dustBuilder.hasComponent(LocationComponent.class)) {
                dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition(new Vector3f()));
                dustBuilder.build();
            }
        }
        // sound to play for destroyed block
        BlockSounds sounds = block.getSounds();
        if (!sounds.getDestroySounds().isEmpty()) {
            StaticSound sound = random.nextItem(sounds.getDestroySounds());
            entity.send(new PlaySoundEvent(sound, 0.6f));
        }
    }
}
Also used : BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) StaticSound(org.terasology.engine.audio.StaticSound) Vector3f(org.joml.Vector3f) PlaySoundEvent(org.terasology.engine.audio.events.PlaySoundEvent) BlockDamageModifierComponent(org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Aggregations

BlockDamageModifierComponent (org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent)2 Vector3f (org.joml.Vector3f)1 StaticSound (org.terasology.engine.audio.StaticSound)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 OnBlockToItem (org.terasology.engine.world.block.items.OnBlockToItem)1 BlockSounds (org.terasology.engine.world.block.sounds.BlockSounds)1