Search in sources :

Example 66 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class BlockDamageAuthoritySystem method beforeDamagedEnsureHealthPresent.

@ReceiveEvent
public void beforeDamagedEnsureHealthPresent(BeforeDamagedEvent event, EntityRef blockEntity, BlockComponent blockComponent) {
    if (!blockEntity.hasComponent(HealthComponent.class)) {
        Block type = blockComponent.getBlock();
        if (type.isDestructible()) {
            HealthComponent healthComponent = new HealthComponent(type.getHardness(), type.getHardness() / BLOCK_REGEN_SECONDS, 1.0f);
            healthComponent.destroyEntityOnNoHealth = true;
            blockEntity.addComponent(healthComponent);
        }
    }
}
Also used : Block(org.terasology.world.block.Block) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 67 with Block

use of org.terasology.world.block.Block in project Terasology by MovingBlocks.

the class TreeTests method computeAABB.

private Vector3i computeAABB(TreeGenerator treeGen, long seed) {
    Vector3i pos = new Vector3i(ChunkConstants.SIZE_X / 2, 0, ChunkConstants.SIZE_Z / 2);
    final Vector3i min = new Vector3i(pos);
    final Vector3i max = new Vector3i(pos);
    Rect2i chunks = Rect2i.createFromMinAndMax(-1, -1, 1, 1);
    for (BaseVector2i chunkPos : chunks.contents()) {
        Chunk chunk = new ChunkImpl(chunkPos.getX(), 0, chunkPos.getY(), blockManager, biomeManager) {

            @Override
            public Block setBlock(int x, int y, int z, Block block) {
                Vector3i world = chunkToWorldPosition(x, y, z);
                minimize(min, world);
                maximize(max, world);
                return null;
            }
        };
        Random random = new MersenneRandom(seed);
        BlockManager blockManagerLocal = CoreRegistry.get(BlockManager.class);
        Vector3i relPos = chunk.chunkToWorldPosition(0, 0, 0).sub(pos).invert();
        treeGen.generate(blockManagerLocal, chunk, random, relPos.x, relPos.y, relPos.z);
    }
    Vector3i ext = new Vector3i(max).sub(min);
    return ext;
}
Also used : Rect2i(org.terasology.math.geom.Rect2i) MersenneRandom(org.terasology.utilities.random.MersenneRandom) Random(org.terasology.utilities.random.Random) MersenneRandom(org.terasology.utilities.random.MersenneRandom) ChunkImpl(org.terasology.world.chunks.internal.ChunkImpl) BlockManager(org.terasology.world.block.BlockManager) Vector3i(org.terasology.math.geom.Vector3i) BaseVector2i(org.terasology.math.geom.BaseVector2i) Block(org.terasology.world.block.Block) Chunk(org.terasology.world.chunks.Chunk)

Aggregations

Block (org.terasology.world.block.Block)67 Vector3i (org.terasology.math.geom.Vector3i)32 EntityRef (org.terasology.entitySystem.entity.EntityRef)16 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)11 Side (org.terasology.math.Side)11 Vector3f (org.terasology.math.geom.Vector3f)9 LocationComponent (org.terasology.logic.location.LocationComponent)7 BlockUri (org.terasology.world.block.BlockUri)7 BlockFamily (org.terasology.world.block.family.BlockFamily)7 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)6 OnChangedBlock (org.terasology.world.OnChangedBlock)6 BlockComponent (org.terasology.world.block.BlockComponent)5 BlockManager (org.terasology.world.block.BlockManager)5 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Before (org.junit.Before)3 ResourceUrn (org.terasology.assets.ResourceUrn)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)3