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());
}
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());
}
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());
}
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;
}
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;
}
Aggregations