use of org.terasology.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.
the class EntityAwareWorldProvider method onBlockRegionChanged.
@ReceiveEvent(components = { BlockRegionComponent.class })
public void onBlockRegionChanged(OnChangedComponent event, EntityRef entity) {
Region3i oldRegion = blockRegions.get(entity);
for (Vector3i pos : oldRegion) {
blockRegionLookup.remove(pos);
}
BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
blockRegions.put(entity, regionComp.region);
for (Vector3i pos : regionComp.region) {
blockRegionLookup.put(pos, entity);
}
}
use of org.terasology.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.
the class DoorSystem method openDoor.
@ReceiveEvent
public void openDoor(OpenDoorEvent event, EntityRef player) {
EntityRef entity = event.getDoorEntity();
DoorComponent door = entity.getComponent(DoorComponent.class);
Side newSide = door.openSide;
BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
Block bottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.min(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.min(), bottomBlock);
Block topBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.max(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.max(), topBlock);
if (door.openSound != null) {
entity.send(new PlaySoundEvent(door.openSound, 1f));
}
door.isOpen = true;
}
use of org.terasology.world.block.regions.BlockRegionComponent 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