Search in sources :

Example 11 with Side

use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.

the class CeilingSupportingHorizontalFamily method populateBlockMaps.

/**
 * Populates the map with all 8 rotations of the block that are possible.
 * <p>
 * These are all four 90 degree rotations about the Y-axis (YAW) for each case where the TOP side is
 * - facing upwards
 * - facing downwards
 *
 * @param blockBuilder The block builder to use to produce blocks
 * @param shape        The shape the block should be made in
 * @param definition   The definition for the family
 * @param uri          The base URI for the block
 */
private void populateBlockMaps(BlockBuilderHelper blockBuilder, BlockShape shape, BlockFamilyDefinition definition, BlockUri uri) {
    for (Rotation rotation : Rotation.horizontalRotations()) {
        Side horizontalSide = rotation.rotate(Side.FRONT);
        ExtendedSide extendedSideTop = ExtendedSide.getExtendedSideFor(Side.TOP, horizontalSide);
        blocks.put(extendedSideTop, transformBlock(blockBuilder, shape, definition, new BlockUri(uri, new Name(extendedSideTop.name())), rotation, extendedSideTop));
        ExtendedSide extendedSideBottom = ExtendedSide.getExtendedSideFor(Side.BOTTOM, horizontalSide);
        Yaw yaw = Rotation.horizontalRotations().get((rotation.getYaw().getIndex() + 2) % 4).getYaw();
        blocks.put(extendedSideBottom, transformBlock(blockBuilder, shape, definition, new BlockUri(uri, new Name(extendedSideBottom.name())), Rotation.rotate(yaw, Pitch.CLOCKWISE_180, Roll.NONE), extendedSideBottom));
    }
}
Also used : Side(org.terasology.engine.math.Side) BlockUri(org.terasology.engine.world.block.BlockUri) Rotation(org.terasology.engine.math.Rotation) Yaw(org.terasology.engine.math.Yaw) Name(org.terasology.gestalt.naming.Name)

Example 12 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 name The name of the section of the block to be registered, ex: "no_connections"
 * @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, BlockBuilderHelper blockBuilder, String name, 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));
        }
        Block block = blockBuilder.constructTransformedBlock(definition, name, rotation, new BlockUri(root, new Name(String.valueOf(sideBits))), this);
        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)

Example 13 with Side

use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.

the class BlockShapeImpl method doReload.

@Override
protected void doReload(BlockShapeData data) {
    collisionShape.clear();
    displayName = data.getDisplayName();
    for (BlockPart part : BlockPart.values()) {
        this.meshParts.put(part, data.getMeshPart(part));
    }
    for (Side side : Side.values()) {
        this.fullSide[side.ordinal()] = data.isBlockingSide(side);
    }
    this.baseCollisionShape = data.getCollisionShape();
    this.baseCollisionOffset.set(data.getCollisionOffset());
    collisionShape.put(Rotation.none(), baseCollisionShape);
    yawSymmetric = data.isYawSymmetric();
    pitchSymmetric = data.isPitchSymmetric();
    rollSymmetric = data.isRollSymmetric();
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) Side(org.terasology.engine.math.Side)

Example 14 with Side

use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.

the class StandardBatchPropagator method purge.

/**
 * Reset a position to only it's fixed values
 *
 * @param pos The position to reset
 * @param oldValue The value present before reset
 */
private void purge(Vector3ic pos, byte oldValue) {
    increaseQueues[rules.getMaxValue() - oldValue].remove(pos);
    /* Clear the value and re-propagate it if it's a positive value */
    Block block = world.getBlockAt(pos);
    byte fixedValue = rules.getFixedValue(block, pos);
    if (fixedValue > 0) {
        increase(pos, fixedValue);
    } else {
        world.setValueAt(pos, NO_VALUE);
    }
    Vector3i adjPos = new Vector3i();
    for (Side side : Side.values()) {
        /* Handle this value being reset to the default by updating sides as needed */
        byte expectedValue = rules.propagateValue(oldValue, side, block, scale);
        if (rules.canSpreadOutOf(block, side)) {
            side.getAdjacentPos(pos, adjPos);
            byte adjValue = world.getValueAt(adjPos);
            if (adjValue == expectedValue) {
                Block adjBlock = world.getBlockAt(adjPos);
                if (rules.canSpreadInto(adjBlock, side.reverse())) {
                    reduce(adjPos, expectedValue);
                }
            } else if (adjValue > 0) {
                queueSpreadValue(adjPos, adjValue);
            }
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) Vector3i(org.joml.Vector3i) Block(org.terasology.engine.world.block.Block)

Example 15 with Side

use of org.terasology.engine.math.Side in project Terasology by MovingBlocks.

the class LightMerger method merge.

/**
 * Merge light for chunk.
 *
 * @param localChunks nearest chunks with target chunk
 * @throws IllegalArgumentException if {@code localChunks.length != LOCAL_CHUNKS_ARRAY_LENGTH} or {@code
 *         chunk} not in center of {@code localChunks}
 */
public static Chunk merge(Chunk[] localChunks) {
    Preconditions.checkArgument(localChunks.length == LOCAL_CHUNKS_ARRAY_LENGTH, "Length of parameter [localChunks] must be equals [" + LOCAL_CHUNKS_ARRAY_LENGTH + "]");
    Preconditions.checkArgument(Arrays.stream(localChunks).noneMatch(Objects::isNull), "Parameter [localChunks] " + "must not contains nulls");
    Arrays.sort(localChunks, Comparator.<Chunk>comparingInt(c -> c.getPosition().x()).thenComparingInt(c -> c.getPosition().y()).thenComparing(c -> c.getPosition().z()));
    Chunk chunk = localChunks[CENTER_INDEX];
    List<BatchPropagator> propagators = Lists.newArrayList();
    propagators.add(new StandardBatchPropagator(new LightPropagationRules(), new LocalChunkView(localChunks, LIGHT_RULES)));
    PropagatorWorldView regenWorldView = new LocalChunkView(localChunks, SUNLIGHT_REGEN_RULES);
    PropagationRules sunlightRules = new SunlightPropagationRules(regenWorldView);
    PropagatorWorldView sunlightWorldView = new LocalChunkView(localChunks, sunlightRules);
    BatchPropagator sunlightPropagator = new StandardBatchPropagator(sunlightRules, sunlightWorldView);
    propagators.add(new SunlightRegenBatchPropagator(SUNLIGHT_REGEN_RULES, regenWorldView, sunlightPropagator, sunlightWorldView));
    propagators.add(sunlightPropagator);
    for (BatchPropagator propagator : propagators) {
        // Propagate Inwards
        for (Side side : Side.allSides()) {
            Chunk adjChunk = localChunks[indexOf(side)];
            if (adjChunk != null) {
                propagator.propagateBetween(adjChunk, chunk, side.reverse(), false);
            }
        }
        // Propagate Outwards
        for (Side side : Side.allSides()) {
            Chunk adjChunk = localChunks[indexOf(side)];
            if (adjChunk != null) {
                propagator.propagateBetween(chunk, adjChunk, side, true);
            }
        }
    }
    for (BatchPropagator propagator : propagators) {
        propagator.process();
    }
    chunk.deflateSunlight();
    return chunk;
}
Also used : Arrays(java.util.Arrays) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) Objects(java.util.Objects) LocalChunkView(org.terasology.engine.world.propagation.LocalChunkView) List(java.util.List) Lists(com.google.common.collect.Lists) Vector3ic(org.joml.Vector3ic) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) Vector3i(org.joml.Vector3i) Chunk(org.terasology.engine.world.chunks.Chunk) Preconditions(com.google.common.base.Preconditions) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) Side(org.terasology.engine.math.Side) Comparator(java.util.Comparator) PropagatorWorldView(org.terasology.engine.world.propagation.PropagatorWorldView) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) Side(org.terasology.engine.math.Side) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) StandardBatchPropagator(org.terasology.engine.world.propagation.StandardBatchPropagator) BatchPropagator(org.terasology.engine.world.propagation.BatchPropagator) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) SunlightRegenBatchPropagator(org.terasology.engine.world.propagation.SunlightRegenBatchPropagator) PropagatorWorldView(org.terasology.engine.world.propagation.PropagatorWorldView) LocalChunkView(org.terasology.engine.world.propagation.LocalChunkView) PropagationRules(org.terasology.engine.world.propagation.PropagationRules) Chunk(org.terasology.engine.world.chunks.Chunk)

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