Search in sources :

Example 16 with BlockFamily

use of org.terasology.world.block.family.BlockFamily 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

BlockFamily (org.terasology.world.block.family.BlockFamily)16 Block (org.terasology.world.block.Block)7 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Command (org.terasology.logic.console.commandSystem.annotations.Command)4 LocationComponent (org.terasology.logic.location.LocationComponent)4 Vector3f (org.terasology.math.geom.Vector3f)4 ClientComponent (org.terasology.network.ClientComponent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 BlockItemFactory (org.terasology.world.block.items.BlockItemFactory)3 Iterator (java.util.Iterator)2 ModuleManager (org.terasology.engine.module.ModuleManager)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 Side (org.terasology.math.Side)2 Vector3i (org.terasology.math.geom.Vector3i)2 Module (org.terasology.module.Module)2 WorldProvider (org.terasology.world.WorldProvider)2 Biome (org.terasology.world.biomes.Biome)2 BlockComponent (org.terasology.world.block.BlockComponent)2