use of org.terasology.world.block.BlockPart in project Terasology by MovingBlocks.
the class BlockMeshGeneratorSingleShape method generateMesh.
private void generateMesh() {
Tessellator tessellator = new Tessellator();
for (BlockPart dir : BlockPart.values()) {
BlockMeshPart part = block.getPrimaryAppearance().getPart(dir);
if (part != null) {
if (block.isDoubleSided()) {
tessellator.addMeshPartDoubleSided(part);
} else {
tessellator.addMeshPart(part);
}
}
}
mesh = tessellator.generateMesh(new ResourceUrn("engine", "blockmesh", block.getURI().toString()));
}
use of org.terasology.world.block.BlockPart in project Terasology by MovingBlocks.
the class BlockBuilder method createAppearance.
private BlockAppearance createAppearance(BlockShape shape, Map<BlockPart, BlockTile> tiles, Rotation rot) {
Map<BlockPart, BlockMeshPart> meshParts = Maps.newEnumMap(BlockPart.class);
Map<BlockPart, Vector2f> textureAtlasPositions = Maps.newEnumMap(BlockPart.class);
for (BlockPart part : BlockPart.values()) {
// TODO: Need to be more sensible with the texture atlas. Because things like block particles read from a part that may not exist, we're being fairly lenient
Vector2f atlasPos;
if (tiles.get(part) == null) {
atlasPos = new Vector2f();
} else {
atlasPos = worldAtlas.getTexCoords(tiles.get(part), shape.getMeshPart(part) != null);
}
BlockPart targetPart = part.rotate(rot);
textureAtlasPositions.put(targetPart, atlasPos);
if (shape.getMeshPart(part) != null) {
meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.getQuat4f()).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize()));
}
}
return new BlockAppearance(meshParts, textureAtlasPositions);
}
use of org.terasology.world.block.BlockPart 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.BlockPart in project Terasology by MovingBlocks.
the class BlockBuilder method applyLoweredShape.
private void applyLoweredShape(Block block, BlockShape shape, Map<BlockPart, BlockTile> tiles) {
for (Side side : Side.values()) {
BlockPart part = BlockPart.fromSide(side);
BlockTile blockTile = tiles.get(part);
if (blockTile != null) {
BlockMeshPart meshPart = shape.getMeshPart(part).rotate(Rotation.none().getQuat4f()).mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize());
block.setLoweredLiquidMesh(part.getSide(), meshPart);
}
}
}
use of org.terasology.world.block.BlockPart in project Terasology by MovingBlocks.
the class BlockBuilder method setBlockFullSides.
private void setBlockFullSides(Block block, BlockShape shape, Rotation rot) {
for (Side side : Side.values()) {
BlockPart targetPart = BlockPart.fromSide(rot.rotate(side));
block.setFullSide(targetPart.getSide(), shape.isBlockingSide(side));
}
}
Aggregations