Search in sources :

Example 1 with BlockPart

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()));
}
Also used : BlockPart(org.terasology.world.block.BlockPart) ResourceUrn(org.terasology.assets.ResourceUrn) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 2 with BlockPart

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);
}
Also used : BlockPart(org.terasology.world.block.BlockPart) BlockAppearance(org.terasology.world.block.BlockAppearance) Vector2f(org.terasology.math.geom.Vector2f) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 3 with BlockPart

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;
}
Also used : BlockPart(org.terasology.world.block.BlockPart) Block(org.terasology.world.block.Block)

Example 4 with BlockPart

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);
        }
    }
}
Also used : Side(org.terasology.math.Side) BlockPart(org.terasology.world.block.BlockPart) BlockTile(org.terasology.world.block.tiles.BlockTile) BlockMeshPart(org.terasology.world.block.shapes.BlockMeshPart)

Example 5 with BlockPart

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));
    }
}
Also used : Side(org.terasology.math.Side) BlockPart(org.terasology.world.block.BlockPart)

Aggregations

BlockPart (org.terasology.world.block.BlockPart)7 Side (org.terasology.math.Side)3 BlockMeshPart (org.terasology.world.block.shapes.BlockMeshPart)3 BlockTile (org.terasology.world.block.tiles.BlockTile)2 ResourceUrn (org.terasology.assets.ResourceUrn)1 Vector2f (org.terasology.math.geom.Vector2f)1 Block (org.terasology.world.block.Block)1 BlockAppearance (org.terasology.world.block.BlockAppearance)1