Search in sources :

Example 1 with Side

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);
                }
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 2 with Side

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);
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) Vector3ic(org.joml.Vector3ic) Vector3i(org.joml.Vector3i)

Example 3 with Side

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);
                }
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) UpdatesWithNeighboursFamily(org.terasology.engine.world.block.family.UpdatesWithNeighboursFamily) Vector3i(org.joml.Vector3i) OnChangedBlock(org.terasology.engine.world.OnChangedBlock) Block(org.terasology.engine.world.block.Block) BlockFamily(org.terasology.engine.world.block.family.BlockFamily)

Example 4 with Side

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));
}
Also used : Side(org.terasology.engine.math.Side)

Example 5 with Side

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;
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Block(org.terasology.engine.world.block.Block) Rotation(org.terasology.engine.math.Rotation) Name(org.terasology.gestalt.naming.Name)

Aggregations

Side (org.terasology.engine.math.Side)15 Block (org.terasology.engine.world.block.Block)7 Vector3i (org.joml.Vector3i)6 Vector3ic (org.joml.Vector3ic)3 Rotation (org.terasology.engine.math.Rotation)3 BlockPart (org.terasology.engine.world.block.BlockPart)3 BlockUri (org.terasology.engine.world.block.BlockUri)3 Name (org.terasology.gestalt.naming.Name)3 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)2 BlockMeshPart (org.terasology.engine.world.block.shapes.BlockMeshPart)2 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Objects (java.util.Objects)1 Vector2f (org.joml.Vector2f)1 Test (org.junit.jupiter.api.Test)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1