Search in sources :

Example 1 with OnBlockToItem

use of org.terasology.engine.world.block.items.OnBlockToItem 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)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 BlockDamageModifierComponent (org.terasology.engine.world.block.entity.damage.BlockDamageModifierComponent)1 OnBlockToItem (org.terasology.engine.world.block.items.OnBlockToItem)1