use of org.terasology.world.block.Block 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.world.block.Block in project Terasology by MovingBlocks.
the class SymmetricBlockFamilyFactory 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");
}
Block block = blockBuilder.constructSimpleBlock(definition, shape);
BlockUri uri;
if (CUBE_SHAPE_URN.equals(shape.getUrn())) {
uri = new BlockUri(definition.getUrn());
} else {
uri = new BlockUri(definition.getUrn(), shape.getUrn());
}
return new SymmetricFamily(uri, block, definition.getCategories());
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class UpdatesWithNeighboursFamilyFactory method createBlockFamily.
@Override
public BlockFamily createBlockFamily(BlockFamilyDefinition definition, BlockBuilderHelper blockBuilder) {
TByteObjectMap<String>[] basicBlocks = new TByteObjectMap[7];
TByteObjectMap<Block> blocksForConnections = new TByteObjectHashMap<>();
addConnections(basicBlocks, 0, NO_CONNECTIONS);
addConnections(basicBlocks, 1, ONE_CONNECTION);
addConnections(basicBlocks, 2, TWO_CONNECTIONS_LINE);
addConnections(basicBlocks, 2, TWO_CONNECTIONS_CORNER);
addConnections(basicBlocks, 3, THREE_CONNECTIONS_CORNER);
addConnections(basicBlocks, 3, THREE_CONNECTIONS_T);
addConnections(basicBlocks, 4, FOUR_CONNECTIONS_CROSS);
addConnections(basicBlocks, 4, FOUR_CONNECTIONS_SIDE);
addConnections(basicBlocks, 5, FIVE_CONNECTIONS);
addConnections(basicBlocks, 6, SIX_CONNECTIONS);
BlockUri blockUri = new BlockUri(definition.getUrn());
// Now make sure we have all combinations based on the basic set (above) and rotations
for (byte connections = 0; connections < 64; connections++) {
// Only the allowed connections should be created
if ((connections & connectionSides) == connections) {
Block block = constructBlockForConnections(connections, blockBuilder, definition, basicBlocks);
if (block == null) {
throw new IllegalStateException("Unable to find correct block definition for connections: " + connections);
}
block.setUri(new BlockUri(blockUri, new Name(String.valueOf(connections))));
blocksForConnections.put(connections, block);
}
}
final Block archetypeBlock = blocksForConnections.get(SideBitFlag.getSides(Side.RIGHT, Side.LEFT));
return new UpdatesWithNeighboursFamily(connectionCondition, blockUri, definition.getCategories(), archetypeBlock, blocksForConnections, connectionSides);
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockBuilder method constructCustomBlock.
@Override
public Block constructCustomBlock(String defaultName, BlockShape shape, Rotation rotation, SectionDefinitionData section) {
Block block = createRawBlock(defaultName, section);
block.setDirection(rotation.rotate(Side.FRONT));
block.setPrimaryAppearance(createAppearance(shape, section.getBlockTiles(), rotation));
setBlockFullSides(block, shape, rotation);
block.setCollision(shape.getCollisionOffset(rotation), shape.getCollisionShape(rotation));
for (BlockPart part : BlockPart.values()) {
block.setColorSource(part, section.getColorSources().get(part));
block.setColorOffset(part, section.getColorOffsets().get(part));
}
return block;
}
use of org.terasology.world.block.Block in project Terasology by MovingBlocks.
the class BlockBuilder method createRawBlock.
private Block createRawBlock(String defaultName, SectionDefinitionData def) {
Block block = new Block();
block.setLiquid(def.isLiquid());
block.setWater(def.isWater());
block.setLava(def.isLava());
block.setGrass(def.isGrass());
block.setIce(def.isIce());
block.setHardness(def.getHardness());
block.setAttachmentAllowed(def.isAttachmentAllowed());
block.setReplacementAllowed(def.isReplacementAllowed());
block.setSupportRequired(def.isSupportRequired());
block.setPenetrable(def.isPenetrable());
block.setTargetable(def.isTargetable());
block.setClimbable(def.isClimbable());
block.setTranslucent(def.isTranslucent());
block.setDoubleSided(def.isDoubleSided());
block.setShadowCasting(def.isShadowCasting());
block.setWaving(def.isWaving());
block.setLuminance(def.getLuminance());
block.setTint(def.getTint());
if (Strings.isNullOrEmpty(def.getDisplayName())) {
block.setDisplayName(properCase(defaultName));
} else {
block.setDisplayName(def.getDisplayName());
}
block.setSounds(def.getSounds());
block.setMass(def.getMass());
block.setDebrisOnDestroy(def.isDebrisOnDestroy());
block.setFriction(def.getFriction());
block.setRestitution(def.getRestitution());
if (def.getEntity() != null) {
block.setPrefab(def.getEntity().getPrefab());
block.setKeepActive(def.getEntity().isKeepActive());
}
if (def.getInventory() != null) {
block.setStackable(def.getInventory().isStackable());
block.setDirectPickup(def.getInventory().isDirectPickup());
}
return block;
}
Aggregations