Search in sources :

Example 76 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BlockPositionIterator method next.

@Override
public Vector3i next() {
    Vector3i result = new Vector3i(nextResult);
    iterate();
    return result;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 77 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class BlockItemSystem method onPlaceBlock.

@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
    if (!event.getTarget().exists()) {
        event.consume();
        return;
    }
    BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
    BlockFamily type = blockItem.blockFamily;
    Side surfaceSide = Side.inDirection(event.getHitNormal());
    Side secondaryDirection = ChunkMath.getSecondaryPlacementDirection(event.getDirection(), event.getHitNormal());
    BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
    if (blockComponent == null) {
        // If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
        event.consume();
        return;
    }
    Vector3i targetBlock = blockComponent.getPosition();
    Vector3i placementPos = new Vector3i(targetBlock);
    placementPos.add(surfaceSide.getVector3i());
    Block block = type.getBlockForPlacement(worldProvider, blockEntityRegistry, placementPos, surfaceSide, secondaryDirection);
    if (canPlaceBlock(block, targetBlock, placementPos)) {
        // TODO: Fix this for changes.
        if (networkSystem.getMode().isAuthority()) {
            PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
            worldProvider.getWorldEntity().send(placeBlocks);
            if (!placeBlocks.isConsumed()) {
                item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos)));
            } else {
                event.consume();
            }
        }
        recordBlockPlaced(event, type);
        event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
    } else {
        event.consume();
    }
}
Also used : Side(org.terasology.math.Side) BlockComponent(org.terasology.world.block.BlockComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) BlockFamily(org.terasology.world.block.family.BlockFamily) PlaceBlocks(org.terasology.world.block.entity.placement.PlaceBlocks) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 78 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class SideBlockSupportRequired method checkForSupport.

@ReceiveEvent
public void checkForSupport(DelayedActionTriggeredEvent event, EntityRef entity, BlockComponent block, SideBlockSupportRequiredComponent supportRequired) {
    if (event.getActionId().equals(SUPPORT_CHECK_ACTION_ID)) {
        if (!isSufficientlySupported(block.getPosition(), null, Collections.<Vector3i, Block>emptyMap(), supportRequired)) {
            PrefabManager prefabManager = CoreRegistry.get(PrefabManager.class);
            entity.send(new DestroyEvent(entity, EntityRef.NULL, prefabManager.getPrefab("engine:supportRemovedDamage")));
        }
    }
}
Also used : DestroyEvent(org.terasology.logic.health.DestroyEvent) PrefabManager(org.terasology.entitySystem.prefab.PrefabManager) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 79 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class TreeTests method estimateExtent.

private Vector3i estimateExtent(TreeGenerator treeGen) {
    Vector3i maxExt = new Vector3i();
    for (int i = 0; i < 100; i++) {
        Vector3i ext = computeAABB(treeGen, i * 37);
        maximize(maxExt, ext);
    }
    return maxExt;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i)

Example 80 with Vector3i

use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.

the class HeadlessWorldRenderer method updateChunksInProximity.

/**
 * Updates the list of chunks around the player.
 *
 * @param force Forces the update
 * @return True if the list was changed
 */
public boolean updateChunksInProximity(boolean force) {
    Vector3i newChunkPos = calcCamChunkOffset();
    // TODO: This should actually be done based on events from the ChunkProvider on new chunk availability/old chunk removal
    boolean chunksCurrentlyPending = false;
    if (!newChunkPos.equals(chunkPos) || force || pendingChunks) {
        Vector3i viewingDistance = config.getRendering().getViewDistance().getChunkDistance();
        Region3i viewRegion = Region3i.createFromCenterExtents(newChunkPos, new Vector3i(viewingDistance.x / 2, viewingDistance.y / 2, viewingDistance.z / 2));
        if (chunksInProximity.size() == 0 || force || pendingChunks) {
            // just add all visible chunks
            chunksInProximity.clear();
            for (Vector3i chunkPosition : viewRegion) {
                RenderableChunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition()) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        } else {
            Region3i oldRegion = Region3i.createFromCenterExtents(chunkPos, new Vector3i(viewingDistance.x / 2, viewingDistance.y / 2, viewingDistance.z / 2));
            Iterator<Vector3i> chunksForRemove = oldRegion.subtract(viewRegion);
            // remove
            while (chunksForRemove.hasNext()) {
                Vector3i r = chunksForRemove.next();
                RenderableChunk c = chunkProvider.getChunk(r);
                if (c != null) {
                    chunksInProximity.remove(c);
                    c.disposeMesh();
                }
            }
            // add
            for (Vector3i chunkPosition : viewRegion) {
                RenderableChunk c = chunkProvider.getChunk(chunkPosition);
                if (c != null && worldProvider.getLocalView(c.getPosition()) != null) {
                    chunksInProximity.add(c);
                } else {
                    chunksCurrentlyPending = true;
                }
            }
        }
        chunkPos.set(newChunkPos);
        pendingChunks = chunksCurrentlyPending;
        Collections.sort(chunksInProximity, new ChunkFrontToBackComparator());
        return true;
    }
    return false;
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) RenderableChunk(org.terasology.world.chunks.RenderableChunk) Region3i(org.terasology.math.Region3i)

Aggregations

Vector3i (org.terasology.math.geom.Vector3i)246 Test (org.junit.Test)91 EntityRef (org.terasology.entitySystem.entity.EntityRef)34 Block (org.terasology.world.block.Block)32 Chunk (org.terasology.world.chunks.Chunk)30 Vector3f (org.terasology.math.geom.Vector3f)21 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)17 ChunkImpl (org.terasology.world.chunks.internal.ChunkImpl)17 Region3i (org.terasology.math.Region3i)15 BaseVector3i (org.terasology.math.geom.BaseVector3i)15 LocationComponent (org.terasology.logic.location.LocationComponent)14 BlockComponent (org.terasology.world.block.BlockComponent)10 Side (org.terasology.math.Side)9 ChunkViewCoreImpl (org.terasology.world.internal.ChunkViewCoreImpl)8 Before (org.junit.Before)7 Biome (org.terasology.world.biomes.Biome)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 CoreChunk (org.terasology.world.chunks.CoreChunk)6 RenderableChunk (org.terasology.world.chunks.RenderableChunk)6