use of org.terasology.particles.components.generators.TextureOffsetGeneratorComponent in project Terasology by MovingBlocks.
the class BlockDamageAuthoritySystem method createBlockParticleEffect.
/**
* Creates a new entity for the block damage particle effect.
*
* If the terrain texture of the damaged block is available, the particles will have the block texture. Otherwise,
* the default sprite (smoke) is used.
*
* @param family the {@link BlockFamily} of the damaged block
* @param location the location of the damaged block
*/
private void createBlockParticleEffect(BlockFamily family, Vector3f location) {
EntityBuilder builder = entityManager.newBuilder("core:defaultBlockParticles");
builder.getComponent(LocationComponent.class).setWorldPosition(location);
Optional<Texture> terrainTexture = Assets.getTexture("engine:terrain");
if (terrainTexture.isPresent() && terrainTexture.get().isLoaded()) {
final BlockAppearance blockAppearance = family.getArchetypeBlock().getPrimaryAppearance();
final float relativeTileSize = worldAtlas.getRelativeTileSize();
final float particleScale = 0.25f;
final float spriteSize = relativeTileSize * particleScale;
ParticleDataSpriteComponent spriteComponent = builder.getComponent(ParticleDataSpriteComponent.class);
spriteComponent.texture = terrainTexture.get();
spriteComponent.textureSize.set(spriteSize, spriteSize);
final List<Vector2f> offsets = computeOffsets(blockAppearance, particleScale);
TextureOffsetGeneratorComponent textureOffsetGeneratorComponent = builder.getComponent(TextureOffsetGeneratorComponent.class);
textureOffsetGeneratorComponent.validOffsets.addAll(offsets);
}
builder.build();
}
Aggregations