Search in sources :

Example 1 with BoxShape

use of org.terasology.physics.shapes.BoxShape in project Terasology by MovingBlocks.

the class ItemPickupAuthoritySystem method updateExtentsOnBlockItemBoxShape.

@ReceiveEvent
public void updateExtentsOnBlockItemBoxShape(OnAddedComponent event, EntityRef itemEntity, BlockItemComponent blockItemComponent, BoxShapeComponent boxShapeComponent) {
    BlockFamily blockFamily = blockItemComponent.blockFamily;
    if (blockFamily == null) {
        LOGGER.warn("Prefab " + itemEntity.getParentPrefab().getName() + " does not have a block family");
        return;
    }
    if (blockFamily.getArchetypeBlock().getCollisionShape() instanceof BoxShape) {
        BoxShape collisionShape = (BoxShape) blockFamily.getArchetypeBlock().getCollisionShape();
        Vector3f extents = collisionShape.getHalfExtentsWithoutMargin();
        extents.scale(2.0f);
        extents.x = Math.max(extents.x, 0.5f);
        extents.y = Math.max(extents.y, 0.5f);
        extents.z = Math.max(extents.z, 0.5f);
        boxShapeComponent.extents.set(extents);
        itemEntity.saveComponent(boxShapeComponent);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BlockFamily(org.terasology.world.block.family.BlockFamily) BoxShape(org.terasology.physics.shapes.BoxShape) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 Vector3f (org.terasology.math.geom.Vector3f)1 BoxShape (org.terasology.physics.shapes.BoxShape)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1