Search in sources :

Example 61 with Block

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

the class WorldProviderCoreStub method setBlocks.

@Override
public Map<Vector3i, Block> setBlocks(Map<Vector3i, Block> blocksToPlace) {
    Map<Vector3i, Block> result = new HashMap<>(blocks.size());
    for (Map.Entry<Vector3i, Block> entry : blocksToPlace.entrySet()) {
        Block b = setBlock(entry.getKey(), entry.getValue());
        result.put(entry.getKey(), b);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) HashMap(java.util.HashMap) Map(java.util.Map)

Example 62 with Block

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

the class BlockPlacementBenchmark method runStep.

@Override
public void runStep() {
    if (useSetBlocksInsteadOfSetBlock) {
        Map<Vector3i, Block> blocksToPlace = new HashMap<>();
        for (Vector3i v : region3i) {
            blocksToPlace.put(v, blockToPlace);
        }
        worldProvider.setBlocks(blocksToPlace);
    } else {
        for (Vector3i v : region3i) {
            worldProvider.setBlock(v, blockToPlace);
        }
    }
    if (blockToPlace == stone) {
        blockToPlace = air;
    } else {
        blockToPlace = stone;
    }
}
Also used : HashMap(java.util.HashMap) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 63 with Block

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

the class DoorSystem method canAttachTo.

private boolean canAttachTo(Vector3i doorPos, Side side) {
    Vector3i adjacentBlockPos = new Vector3i(doorPos);
    adjacentBlockPos.add(side.getVector3i());
    Block adjacentBlock = worldProvider.getBlock(adjacentBlockPos);
    return adjacentBlock.isAttachmentAllowed();
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block)

Example 64 with Block

use of org.terasology.world.block.Block 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;
}
Also used : Side(org.terasology.math.Side) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Block(org.terasology.world.block.Block) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 65 with Block

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

the class ArrowAction method onActivate.

@ReceiveEvent
public void onActivate(ActivateEvent event, EntityRef entity, ArrowActionComponent arrowActionComponent) {
    if (time.getGameTime() > lastTime + 1.0f / arrowActionComponent.arrowsPerSecond) {
        Vector3f target = event.getHitNormal();
        Vector3i blockPos = new Vector3i(target);
        Vector3f position = new Vector3f(event.getOrigin());
        Vector3f dir = new Vector3f(event.getDirection());
        HitResult result;
        result = physicsRenderer.rayTrace(position, dir, arrowActionComponent.maxDistance, filter);
        Block currentBlock = worldProvider.getBlock(blockPos);
        if (currentBlock.isDestructible()) {
            EntityBuilder builder = entityManager.newBuilder("Core:defaultBlockParticles");
            builder.getComponent(LocationComponent.class).setWorldPosition(target);
            builder.build();
        }
        EntityRef blockEntity = result.getEntity();
        blockEntity.send(new DoDamageEvent(arrowActionComponent.damageAmount, arrowActionComponent.damageType));
        lastTime = time.getGameTime();
    }
}
Also used : HitResult(org.terasology.physics.HitResult) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) DoDamageEvent(org.terasology.logic.health.DoDamageEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

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