Search in sources :

Example 1 with OnBlockToItem

use of org.terasology.world.block.items.OnBlockToItem in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDefaultDropsHandling.

public void commonDefaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, Vector3i 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.world.block.entity.damage.BlockDamageModifierComponent) OnBlockToItem(org.terasology.world.block.items.OnBlockToItem) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

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