@ReceiveEvent public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent locationComponent, CharacterSoundComponent characterSounds) { List<StaticSound> footstepSounds = characterSounds.footstepSounds; // Check if the block the character is standing on has footstep sounds Vector3i blockPos = new Vector3i(locationComponent.getLocalPosition()); blockPos.y--; // The block *below* the character's feet is interesting to us Block block = worldProvider.getBlock(blockPos); if (block != null) { if (block.getSounds() == null) { logger.error("Block '{}' has no sounds", block.getURI()); } else if (!block.getSounds().getStepSounds().isEmpty()) { footstepSounds = block.getSounds().getStepSounds(); } } if (footstepSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) { StaticSound sound = random.nextItem(footstepSounds); entity.send(new PlaySoundEvent(entity, sound, characterSounds.footstepVolume)); characterSounds.lastSoundTime = time.getGameTimeInMs(); entity.saveComponent(characterSounds); } }
private void onPlayBlockDamageCommon(BlockFamily family, Vector3f location, EntityRef entityRef) { createBlockParticleEffect(family, location); BlockSounds sounds = family.getArchetypeBlock().getSounds(); if (!sounds.getDigSounds().isEmpty()) { StaticSound sound = random.nextItem(sounds.getDigSounds()); entityRef.send(new PlaySoundEvent(sound, 1f)); } }
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)); } } }