use of org.terasology.rendering.world.selection.BlockSelectionRenderer in project Terasology by MovingBlocks.
the class BlockDamageRenderer method renderOverlay.
@Override
public void renderOverlay() {
if (blockSelectionRenderer == null) {
Texture texture = Assets.getTextureRegion("core:blockdamageeffects#1").get().getTexture();
blockSelectionRenderer = new BlockSelectionRenderer(texture);
}
// group the entities into what texture they will use so that there is less recreating meshes (changing a texture region on the BlockSelectionRenderer
// will recreate the mesh to use the different UV coordinates). Also this allows
Multimap<Integer, Vector3i> groupedEntitiesByEffect = ArrayListMultimap.create();
for (EntityRef entity : entityManager.getEntitiesWith(HealthComponent.class, BlockComponent.class)) {
HealthComponent health = entity.getComponent(HealthComponent.class);
if (health.currentHealth == health.maxHealth) {
continue;
}
BlockComponent blockComponent = entity.getComponent(BlockComponent.class);
groupedEntitiesByEffect.put(getEffectsNumber(health), blockComponent.getPosition());
}
for (EntityRef entity : entityManager.getEntitiesWith(BlockRegionComponent.class, HealthComponent.class)) {
HealthComponent health = entity.getComponent(HealthComponent.class);
if (health.currentHealth == health.maxHealth) {
continue;
}
BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
for (Vector3i blockPos : blockRegion.region) {
groupedEntitiesByEffect.put(getEffectsNumber(health), blockPos);
}
}
// we know that the texture will be the same for each block effect, just differnt UV coordinates. Bind the texture already
blockSelectionRenderer.beginRenderOverlay();
for (Integer effectsNumber : groupedEntitiesByEffect.keySet()) {
Optional<TextureRegionAsset> texture = Assets.getTextureRegion("core:blockdamageeffects#" + effectsNumber);
if (texture.isPresent()) {
blockSelectionRenderer.setEffectsTexture(texture.get());
for (Vector3i position : groupedEntitiesByEffect.get(effectsNumber)) {
blockSelectionRenderer.renderMark(position);
}
}
}
blockSelectionRenderer.endRenderOverlay();
}
Aggregations