use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.
the class StandardBatchPropagator method push.
/**
* Propagates a value from a position out into all adjacent blocks.
* <p>
* If the value spreading into a block is larger than the current value there, set it and queue it for propagating
* again If the value is smaller than the current value, do nothing
*
* @param pos The initial position
* @param value The value to propagate
*/
private void push(Vector3ic pos, byte value) {
Block block = world.getBlockAt(pos);
Vector3i adjPos = new Vector3i();
for (Side side : Side.values()) {
byte propagatedValue = rules.propagateValue(value, side, block, scale);
if (rules.canSpreadOutOf(block, side)) {
side.getAdjacentPos(pos, adjPos);
byte adjValue = world.getValueAt(adjPos);
if (adjValue < propagatedValue && adjValue != PropagatorWorldView.UNAVAILABLE) {
Block adjBlock = world.getBlockAt(adjPos);
if (rules.canSpreadInto(adjBlock, side.reverse())) {
increase(adjPos, propagatedValue);
}
}
}
}
}
use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.
the class StandardBatchPropagator method reviewChange.
/**
* Handles a single block being changed to a different type.
*
* @param blockChange The change that was made
*/
private void reviewChange(BlockChange blockChange) {
Vector3ic blockChangePosition = blockChange.getPosition();
byte newValue = rules.getFixedValue(blockChange.getTo(), blockChangePosition);
byte existingValue = world.getValueAt(blockChangePosition);
/* Handle if the block has an higher fixed value */
if (newValue > existingValue) {
increase(blockChangePosition, newValue);
}
/* Handle if the block has a lower fixed value */
byte oldValue = rules.getFixedValue(blockChange.getFrom(), blockChangePosition);
if (newValue < oldValue) {
reduce(blockChangePosition, oldValue);
}
/* Process propagation out to other blocks */
Vector3i adjPos = new Vector3i();
for (Side side : Side.values()) {
PropagationComparison comparison = rules.comparePropagation(blockChange.getTo(), blockChange.getFrom(), side);
if (comparison.isRestricting() && existingValue > 0) {
/* If the propagation of the new value is going to be lower/reduced */
reduce(blockChangePosition, existingValue);
side.getAdjacentPos(blockChangePosition, adjPos);
byte adjValue = world.getValueAt(adjPos);
if (adjValue == rules.propagateValue(existingValue, side, blockChange.getFrom(), scale)) {
reduce(adjPos, adjValue);
}
} else if (comparison.isPermitting()) {
/* If the propagation of the new value is going to be more allowing */
if (existingValue > 0) {
/* Spread this potentially higher value out */
queueSpreadValue(blockChangePosition, existingValue);
}
/* Spread it out to the block on the side */
side.getAdjacentPos(blockChangePosition, adjPos);
byte adjValue = world.getValueAt(adjPos);
if (adjValue != PropagatorWorldView.UNAVAILABLE) {
queueSpreadValue(adjPos, adjValue);
}
}
}
}
use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.
the class NeighbourBlockFamilyUpdateSystem method processUpdateForBlockLocation.
private void processUpdateForBlockLocation(Vector3ic blockLocation) {
for (Side side : Side.values()) {
Vector3i neighborLocation = blockLocation.add(side.direction(), new Vector3i());
if (worldProvider.isBlockRelevant(neighborLocation)) {
Block neighborBlock = worldProvider.getBlock(neighborLocation);
final BlockFamily blockFamily = neighborBlock.getBlockFamily();
if (blockFamily instanceof UpdatesWithNeighboursFamily) {
UpdatesWithNeighboursFamily neighboursFamily = (UpdatesWithNeighboursFamily) blockFamily;
Block neighborBlockAfterUpdate = neighboursFamily.getBlockForNeighborUpdate(neighborLocation, neighborBlock);
if (neighborBlock != neighborBlockAfterUpdate) {
worldProvider.setBlock(neighborLocation, neighborBlockAfterUpdate);
}
}
}
}
}
use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.
the class CeilingSupportingHorizontalFamily method getBlockForPlacement.
@Override
public Block getBlockForPlacement(BlockPlacementData data) {
boolean upsideDownPlacement = data.attachmentSide == Side.BOTTOM || data.attachmentSide != Side.TOP && data.relativeAttachmentPosition.y() > 0.5;
final Side mainSide = upsideDownPlacement ? Side.BOTTOM : Side.TOP;
Side blockDirection = Side.inDirection(-data.viewingDirection.x(), 0, -data.viewingDirection.z());
return blocks.get(ExtendedSide.getExtendedSideFor(mainSide, blockDirection));
}
use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.
the class MultiConnectFamily method registerBlock.
/**
* @param root The root block URI of the family
* @param definition The definition of the block family as passed down from the engine
* @param blockBuilder The block builder to make the blocks in the family
* @param sides A byte representing the sides which should be connected for this block
* @param rotations All of the ways the block should be rotated
* @return All of the rotations possible for the block with the given sides
*/
public Set<Block> registerBlock(BlockUri root, BlockFamilyDefinition definition, final BlockBuilderHelper blockBuilder, byte sides, Iterable<Rotation> rotations) {
Set<Block> result = Sets.newLinkedHashSet();
for (Rotation rotation : rotations) {
byte sideBits = 0;
for (Side side : SideBitFlag.getSides(sides)) {
sideBits |= SideBitFlag.getSide(rotation.rotate(side));
}
BlockUri uri = new BlockUri(root, new Name(String.valueOf(sideBits)));
Block block = blockBuilder.constructTransformedBlock(definition, rotation, uri, this);
block.setUri(uri);
blocks.put(sideBits, block);
result.add(block);
}
return result;
}
Aggregations