use of org.terasology.world.block.entity.damage.BlockDamageModifierComponent 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);
}
}
}
use of org.terasology.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()) {
EntityBuilder dustBuilder = entityManager.newBuilder("core:dustEffect");
// TODO: particle system stuff should be split out better - this is effectively a stealth dependency on Core from the engine
if (dustBuilder.hasComponent(LocationComponent.class)) {
dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition());
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));
}
}
}
use of org.terasology.world.block.entity.damage.BlockDamageModifierComponent in project Terasology by MovingBlocks.
the class BlockDropGrammarSystem method onDestroyed.
@ReceiveEvent
public void onDestroyed(DoDestroyEvent event, EntityRef entity, BlockDropGrammarComponent blockDrop, LocationComponent locationComp) {
BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
float chanceOfBlockDrop = 1;
if (blockDamageModifierComponent != null) {
chanceOfBlockDrop = 1 - blockDamageModifierComponent.blockAnnihilationChance;
}
if (random.nextFloat() < chanceOfBlockDrop) {
List<String> blockDrops = blockDrop.blockDrops;
List<String> itemDrops = blockDrop.itemDrops;
if (blockDamageModifierComponent != null && blockDrop.droppedWithTool != null) {
for (String toolType : blockDamageModifierComponent.materialDamageMultiplier.keySet()) {
if (blockDrop.droppedWithTool.containsKey(toolType)) {
BlockDropGrammarComponent.DropDefinition dropDefinition = blockDrop.droppedWithTool.get(toolType);
blockDrops = dropDefinition.blockDrops;
itemDrops = dropDefinition.itemDrops;
break;
}
}
}
if (blockDrops != null) {
for (String drop : blockDrops) {
String dropResult = drop;
boolean dropping = true;
int pipeIndex = dropResult.indexOf('|');
if (pipeIndex > -1) {
float chance = Float.parseFloat(dropResult.substring(0, pipeIndex));
if (random.nextFloat() >= chance) {
dropping = false;
}
dropResult = dropResult.substring(pipeIndex + 1);
}
if (dropping) {
DropParser dropParser = new DropParser(random, dropResult).invoke();
EntityRef dropItem = blockItemFactory.newInstance(blockManager.getBlockFamily(dropParser.getDrop()), dropParser.getCount());
if (shouldDropToWorld(event, blockDamageModifierComponent, dropItem)) {
createDrop(dropItem, locationComp.getWorldPosition(), true);
}
}
}
}
if (itemDrops != null) {
for (String drop : itemDrops) {
String dropResult = drop;
boolean dropping = true;
int pipeIndex = dropResult.indexOf('|');
if (pipeIndex > -1) {
float chance = Float.parseFloat(dropResult.substring(0, pipeIndex));
if (random.nextFloat() >= chance) {
dropping = false;
}
dropResult = dropResult.substring(pipeIndex + 1);
}
if (dropping) {
DropParser dropParser = new DropParser(random, dropResult).invoke();
EntityBuilder dropEntity = entityManager.newBuilder(dropParser.getDrop());
if (dropParser.getCount() > 1) {
ItemComponent itemComponent = dropEntity.getComponent(ItemComponent.class);
itemComponent.stackCount = (byte) dropParser.getCount();
}
EntityRef dropItem = dropEntity.build();
if (shouldDropToWorld(event, blockDamageModifierComponent, dropItem)) {
createDrop(dropItem, locationComp.getWorldPosition(), false);
}
}
}
}
}
}
use of org.terasology.world.block.entity.damage.BlockDamageModifierComponent in project Terasology by MovingBlocks.
the class BlockDamageAuthoritySystem method onDamagedCommon.
private void onDamagedCommon(OnDamagedEvent event, BlockFamily blockFamily, Vector3f location, EntityRef entityRef) {
BlockDamageModifierComponent blockDamageSettings = event.getType().getComponent(BlockDamageModifierComponent.class);
boolean skipDamageEffects = false;
if (blockDamageSettings != null) {
skipDamageEffects = blockDamageSettings.skipPerBlockEffects;
}
if (!skipDamageEffects) {
onPlayBlockDamageCommon(blockFamily, location, entityRef);
}
}
Aggregations