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);
}
}
}
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));
}
}
}
Aggregations