Search in sources :

Example 1 with BlockRegionComponent

use of org.terasology.engine.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class EntityAwareWorldProvider method onBlockRegionActivated.

@ReceiveEvent(components = BlockRegionComponent.class)
public void onBlockRegionActivated(OnActivatedComponent event, EntityRef entity) {
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3ic pos : regionComp.region) {
        blockRegionLookup.put(new Vector3i(pos), entity);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3i(org.joml.Vector3i) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 2 with BlockRegionComponent

use of org.terasology.engine.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class BlockEntitySystem method defaultDropsHandling.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, ActAsBlockComponent blockComponent) {
    if (blockComponent.block != null) {
        if (entity.hasComponent(BlockRegionComponent.class)) {
            BlockRegionComponent blockRegion = entity.getComponent(BlockRegionComponent.class);
            if (blockComponent.dropBlocksInRegion) {
                // loop through all the blocks in this region and drop them
                for (Vector3ic location : blockRegion.region) {
                    Block blockInWorld = worldProvider.getBlock(location);
                    commonDefaultDropsHandling(event, entity, location, blockInWorld.getBlockFamily().getArchetypeBlock());
                }
            } else {
                // just drop the ActAsBlock block
                Vector3i location = new Vector3i(blockRegion.region.center(new Vector3f()), RoundingMode.HALF_UP);
                commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
            }
        } else if (entity.hasComponent(LocationComponent.class)) {
            LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
            Vector3i location = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.HALF_UP);
            commonDefaultDropsHandling(event, entity, location, blockComponent.block.getArchetypeBlock());
        }
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with BlockRegionComponent

use of org.terasology.engine.world.block.regions.BlockRegionComponent in project Terasology by MovingBlocks.

the class LocalPlayerSystem method onTargetChanged.

@ReceiveEvent
public void onTargetChanged(PlayerTargetChangedEvent event, EntityRef entity) {
    EntityRef target = event.getNewTarget();
    hasTarget = target.exists();
    if (hasTarget) {
        LocationComponent location = target.getComponent(LocationComponent.class);
        if (location != null) {
            BlockComponent blockComp = target.getComponent(BlockComponent.class);
            BlockRegionComponent blockRegion = target.getComponent(BlockRegionComponent.class);
            if (blockComp != null || blockRegion != null) {
                Vector3f blockPos = location.getWorldPosition(new Vector3f());
                Block block = worldProvider.getBlock(blockPos);
                aabb.set(block.getBounds(blockPos));
            } else {
                MeshComponent mesh = target.getComponent(MeshComponent.class);
                if (mesh != null && mesh.mesh != null) {
                    aabb.set(mesh.mesh.getAABB());
                    aabb.transform(new Matrix4f().translationRotateScale(location.getWorldPosition(new Vector3f()), location.getWorldRotation(new Quaternionf()), location.getWorldScale()));
                }
            }
        }
    }
}
Also used : BlockComponent(org.terasology.engine.world.block.BlockComponent) MeshComponent(org.terasology.engine.rendering.logic.MeshComponent) Matrix4f(org.joml.Matrix4f) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3f(org.joml.Vector3f) Block(org.terasology.engine.world.block.Block) Quaternionf(org.joml.Quaternionf) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with BlockRegionComponent

use of org.terasology.engine.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) {
    BlockRegion oldRegion = blockRegions.get(entity);
    for (Vector3ic pos : oldRegion) {
        blockRegionLookup.remove(pos);
    }
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    blockRegions.put(entity, regionComp.region);
    for (Vector3ic pos : regionComp.region) {
        blockRegionLookup.put(new Vector3i(pos), entity);
    }
}
Also used : Vector3ic(org.joml.Vector3ic) BlockRegionComponent(org.terasology.engine.world.block.regions.BlockRegionComponent) Vector3i(org.joml.Vector3i) BlockRegion(org.terasology.engine.world.block.BlockRegion) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)4 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)4 Vector3i (org.joml.Vector3i)3 Vector3ic (org.joml.Vector3ic)3 Vector3f (org.joml.Vector3f)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 Block (org.terasology.engine.world.block.Block)2 Matrix4f (org.joml.Matrix4f)1 Quaternionf (org.joml.Quaternionf)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 MeshComponent (org.terasology.engine.rendering.logic.MeshComponent)1 BlockComponent (org.terasology.engine.world.block.BlockComponent)1 BlockRegion (org.terasology.engine.world.block.BlockRegion)1