use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class LightMerger method merge.
private void merge(Chunk chunk) {
Chunk[] localChunks = assembleLocalChunks(chunk);
localChunks[CENTER_INDEX] = chunk;
List<BatchPropagator> propagators = Lists.newArrayList();
propagators.add(new StandardBatchPropagator(new LightPropagationRules(), new LocalChunkView(localChunks, lightRules)));
PropagatorWorldView regenWorldView = new LocalChunkView(localChunks, sunlightRegenRules);
PropagationRules sunlightRules = new SunlightPropagationRules(regenWorldView);
PropagatorWorldView sunlightWorldView = new LocalChunkView(localChunks, sunlightRules);
BatchPropagator sunlightPropagator = new StandardBatchPropagator(sunlightRules, sunlightWorldView);
propagators.add(new SunlightRegenBatchPropagator(sunlightRegenRules, regenWorldView, sunlightPropagator, sunlightWorldView));
propagators.add(sunlightPropagator);
for (BatchPropagator propagator : propagators) {
// Propagate Inwards
for (Side side : Side.values()) {
Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
LitChunk adjChunk = chunkProvider.getChunkUnready(adjChunkPos);
if (adjChunk != null) {
propagator.propagateBetween(adjChunk, chunk, side.reverse(), false);
}
}
// Propagate Outwards
for (Side side : Side.values()) {
Vector3i adjChunkPos = side.getAdjacentPos(chunk.getPosition());
LitChunk adjChunk = chunkProvider.getChunk(adjChunkPos);
if (adjChunk != null) {
propagator.propagateBetween(chunk, adjChunk, side, true);
}
}
}
for (BatchPropagator propagator : propagators) {
propagator.process();
}
chunk.deflateSunlight();
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onStartSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i startPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
blockSelectionComponent.startPosition = startPosition;
Vector3i endPosition = startPosition;
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onEndSelectionAtEntity.
@ReceiveEvent(components = { LocationComponent.class })
public void onEndSelectionAtEntity(SetBlockSelectionEndingPointEvent event, EntityRef entity) {
LocationComponent locationComponent = entity.getComponent(LocationComponent.class);
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3f worldPosition = locationComponent.getWorldPosition();
Vector3i endPosition = new Vector3i(worldPosition.x, worldPosition.y, worldPosition.z);
Vector3i startPosition = blockSelectionComponent.startPosition;
if (null == startPosition) {
startPosition = endPosition;
}
blockSelectionComponent.currentSelection = Region3i.createBounded(startPosition, endPosition);
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class SubSampledNoise method determineRequiredRegion.
private Region3i determineRequiredRegion(Region3i region) {
int newMinX = region.minX() - IntMath.mod(region.minX(), sampleRate);
int newMinY = region.minY() - IntMath.mod(region.minY(), sampleRate);
int newMinZ = region.minZ() - IntMath.mod(region.minZ(), sampleRate);
int newMaxX = region.maxX() + 4 - IntMath.mod(region.maxX(), sampleRate) - 1;
int newMaxY = region.maxY() + 4 - IntMath.mod(region.maxY(), sampleRate) - 1;
int newMaxZ = region.maxZ() + 4 - IntMath.mod(region.maxZ(), sampleRate) - 1;
return Region3i.createFromMinMax(new Vector3i(newMinX, newMinY, newMinZ), new Vector3i(newMaxX, newMaxY, newMaxZ));
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class BlockEntitySystem method defaultDropsHandling.
@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void defaultDropsHandling(CreateBlockDropsEvent event, EntityRef entity, BlockComponent blockComponent) {
Vector3i location = blockComponent.getPosition();
commonDefaultDropsHandling(event, entity, location, blockComponent.getBlock());
}
Aggregations