use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setLiquid.
@Override
public boolean setLiquid(int x, int y, int z, LiquidData newState, LiquidData oldState) {
Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
LiquidData liquidState = chunk.getLiquid(blockPos);
if (liquidState.equals(oldState)) {
chunk.setLiquid(blockPos, newState);
return true;
}
}
return false;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method getLight.
@Override
public byte getLight(int x, int y, int z) {
Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
LitChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
return chunk.getLight(blockPos);
}
return 0;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method setBlock.
@Override
public Block setBlock(Vector3i worldPos, Block type) {
/*
* Hint: This method has a benchmark available in the BenchmarkScreen, The screen can be opened ingame via the
* command "showSCreen BenchmarkScreen".
*/
Vector3i chunkPos = ChunkMath.calcChunkPos(worldPos);
CoreChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(worldPos);
Block oldBlockType = chunk.setBlock(blockPos, type);
if (oldBlockType != type) {
BlockChange oldChange = blockChanges.get(worldPos);
if (oldChange == null) {
blockChanges.put(worldPos, new BlockChange(worldPos, oldBlockType, type));
} else {
oldChange.setTo(type);
}
for (Vector3i pos : ChunkMath.getChunkRegionAroundWorldPos(worldPos, 1)) {
RenderableChunk dirtiedChunk = chunkProvider.getChunk(pos);
if (dirtiedChunk != null) {
dirtiedChunk.setDirty(true);
}
}
notifyBlockChanged(worldPos, type, oldBlockType);
}
return oldBlockType;
}
return null;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class WorldProviderCoreImpl method getTotalLight.
@Override
public byte getTotalLight(int x, int y, int z) {
Vector3i chunkPos = ChunkMath.calcChunkPos(x, y, z);
LitChunk chunk = chunkProvider.getChunk(chunkPos);
if (chunk != null) {
Vector3i blockPos = ChunkMath.calcBlockPos(x, y, z);
return (byte) Math.max(chunk.getSunlight(blockPos), chunk.getLight(blockPos));
}
return 0;
}
use of org.terasology.math.geom.Vector3i in project Terasology by MovingBlocks.
the class StandardBatchPropagator method reviewChange.
private void reviewChange(BlockChange blockChange) {
byte newValue = rules.getFixedValue(blockChange.getTo(), blockChange.getPosition());
byte existingValue = world.getValueAt(blockChange.getPosition());
if (newValue > existingValue) {
increase(blockChange.getPosition(), newValue);
}
byte oldValue = rules.getFixedValue(blockChange.getFrom(), blockChange.getPosition());
if (newValue < oldValue) {
reduce(blockChange.getPosition(), oldValue);
}
for (Side side : Side.values()) {
PropagationComparison comparison = rules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), side);
if (comparison.isRestricting() && existingValue > 0) {
reduce(blockChange.getPosition(), existingValue);
Vector3i adjPos = side.getAdjacentPos(blockChange.getPosition());
byte adjValue = world.getValueAt(adjPos);
if (adjValue == rules.propagateValue(existingValue, side, blockChange.getFrom())) {
reduce(adjPos, adjValue);
}
} else if (comparison.isPermitting()) {
if (existingValue > 0) {
queueSpreadValue(blockChange.getPosition(), existingValue);
}
Vector3i adjPos = side.getAdjacentPos(blockChange.getPosition());
byte adjValue = world.getValueAt(adjPos);
if (adjValue != PropagatorWorldView.UNAVAILABLE) {
queueSpreadValue(adjPos, adjValue);
}
}
}
}
Aggregations