Search in sources :

Example 1 with Rotation

use of org.terasology.math.Rotation in project Terasology by MovingBlocks.

the class AttachedToSurfaceFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
    Map<Side, Block> blockMap = Maps.newEnumMap(Side.class);
    if (definition.getData().hasSection("top")) {
        Block block = blockBuilder.constructSimpleBlock(definition, "top");
        block.setDirection(Side.TOP);
        blockMap.put(Side.TOP, block);
    }
    if (definition.getData().hasSection("front")) {
        for (Rotation rot : Rotation.horizontalRotations()) {
            Side side = rot.rotate(Side.FRONT);
            blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot));
        }
    }
    if (definition.getData().hasSection("bottom")) {
        Block block = blockBuilder.constructSimpleBlock(definition, "bottom");
        block.setDirection(Side.BOTTOM);
        blockMap.put(Side.BOTTOM, block);
    }
    return new AttachedToSurfaceFamily(new BlockUri(definition.getUrn()), blockMap, definition.getCategories());
}
Also used : Side(org.terasology.math.Side) BlockUri(org.terasology.world.block.BlockUri) Block(org.terasology.world.block.Block) Rotation(org.terasology.math.Rotation)

Example 2 with Rotation

use of org.terasology.math.Rotation in project Terasology by MovingBlocks.

the class HorizontalBlockFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
    if (definition.isFreeform()) {
        throw new IllegalStateException("A shape must be provided when creating a family for a freeform block family definition");
    }
    Map<Side, Block> blockMap = Maps.newHashMap();
    for (Rotation rot : Rotation.horizontalRotations()) {
        Side side = rot.rotate(Side.FRONT);
        blockMap.put(side, blockBuilder.constructTransformedBlock(definition, side.toString().toLowerCase(Locale.ENGLISH), rot));
    }
    return new HorizontalBlockFamily(new BlockUri(definition.getUrn()), getArchetypeSide(), blockMap, definition.getCategories());
}
Also used : Side(org.terasology.math.Side) BlockUri(org.terasology.world.block.BlockUri) Block(org.terasology.world.block.Block) Rotation(org.terasology.math.Rotation)

Example 3 with Rotation

use of org.terasology.math.Rotation in project Terasology by MovingBlocks.

the class HorizontalBlockFamilyFactory method createBlockFamily.

@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockShape shape, BlockBuilderHelper blockBuilder) {
    if (!definition.isFreeform()) {
        throw new IllegalStateException("A shape cannot be provided when creating a family for a non-freeform block family definition");
    }
    Map<Side, Block> blockMap = Maps.newHashMap();
    for (Rotation rot : Rotation.horizontalRotations()) {
        Side side = rot.rotate(Side.FRONT);
        blockMap.put(side, blockBuilder.constructTransformedBlock(definition, shape, side.toString().toLowerCase(Locale.ENGLISH), rot));
    }
    BlockUri uri;
    if (CUBE_SHAPE_URN.equals(shape.getUrn())) {
        uri = new BlockUri(definition.getUrn());
    } else {
        uri = new BlockUri(definition.getUrn(), shape.getUrn());
    }
    return new HorizontalBlockFamily(uri, getArchetypeSide(), blockMap, definition.getCategories());
}
Also used : Side(org.terasology.math.Side) BlockUri(org.terasology.world.block.BlockUri) Block(org.terasology.world.block.Block) Rotation(org.terasology.math.Rotation)

Example 4 with Rotation

use of org.terasology.math.Rotation in project Terasology by MovingBlocks.

the class UpdatesWithNeighboursFamilyFactory method constructBlockForConnections.

private Block constructBlockForConnections(final byte connections, final BlockBuilderHelper blockBuilder, BlockFamilyDefinition definition, TByteObjectMap<String>[] basicBlocks) {
    int connectionCount = SideBitFlag.getSides(connections).size();
    TByteObjectMap<String> possibleBlockDefinitions = basicBlocks[connectionCount];
    final TByteObjectIterator<String> blockDefinitionIterator = possibleBlockDefinitions.iterator();
    while (blockDefinitionIterator.hasNext()) {
        blockDefinitionIterator.advance();
        final byte originalConnections = blockDefinitionIterator.key();
        final String section = blockDefinitionIterator.value();
        Rotation rot = getRotationToAchieve(originalConnections, connections);
        if (rot != null) {
            return blockBuilder.constructTransformedBlock(definition, section, rot);
        }
    }
    return null;
}
Also used : Rotation(org.terasology.math.Rotation)

Example 5 with Rotation

use of org.terasology.math.Rotation in project Terasology by MovingBlocks.

the class UpdatesWithNeighboursFamilyFactory method getRotationToAchieve.

private Rotation getRotationToAchieve(byte source, byte target) {
    Collection<Side> originalSides = SideBitFlag.getSides(source);
    Iterable<Rotation> rotations = horizontalOnly ? Rotation.horizontalRotations() : Rotation.values();
    for (Rotation rot : rotations) {
        Set<Side> transformedSides = Sets.newHashSet();
        transformedSides.addAll(originalSides.stream().map(rot::rotate).collect(Collectors.toList()));
        byte transformedSide = SideBitFlag.getSides(transformedSides);
        if (transformedSide == target) {
            return rot;
        }
    }
    return null;
}
Also used : Side(org.terasology.math.Side) Rotation(org.terasology.math.Rotation)

Aggregations

Rotation (org.terasology.math.Rotation)6 Side (org.terasology.math.Side)4 Block (org.terasology.world.block.Block)3 BlockUri (org.terasology.world.block.BlockUri)3 CollisionShape (org.terasology.physics.shapes.CollisionShape)1