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;
}
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();
}
}
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")));
}
}
}
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;
}
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;
}
Aggregations