Search in sources :

Example 1 with BlockPart

use of org.terasology.engine.world.block.BlockPart in project Terasology by MovingBlocks.

the class AutoBlockProvider method getAssetData.

@Override
public Optional<BlockFamilyDefinitionData> getAssetData(ResourceUrn urn) throws IOException {
    Optional<BlockTile> blockTile = assetManager.getAsset(urn, BlockTile.class);
    if (blockTile.isPresent() && blockTile.get().isAutoBlock()) {
        BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
        for (BlockPart part : BlockPart.values()) {
            data.getBaseSection().getBlockTiles().put(part, blockTile.get());
        }
        data.getBaseSection().setSounds(assetManager.getAsset("engine:default", BlockSounds.class).get());
        data.setBlockFamily(FreeformFamily.class);
        return Optional.of(data);
    }
    return Optional.empty();
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) BlockTile(org.terasology.engine.world.block.tiles.BlockTile)

Example 2 with BlockPart

use of org.terasology.engine.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.engine.math.Side) BlockPart(org.terasology.engine.world.block.BlockPart)

Example 3 with BlockPart

use of org.terasology.engine.world.block.BlockPart in project Terasology by MovingBlocks.

the class BlockMeshShapeGenerator method getStandaloneMesh.

@Override
public Mesh getStandaloneMesh() {
    if (mesh == null || mesh.isDisposed()) {
        Block block = getBlock();
        StandardMeshData meshData = new StandardMeshData();
        int nextIndex = 0;
        Vector3f light0 = new Vector3f(1, 1, 1);
        for (BlockPart dir : BlockPart.allParts()) {
            BlockMeshPart part = block.getPrimaryAppearance().getPart(dir);
            if (part != null) {
                for (int i = 0; i < part.size(); i++) {
                    meshData.position.put(part.getVertex(i));
                    meshData.color0.put(Color.white);
                    meshData.normal.put(part.getNormal(i));
                    meshData.uv0.put(part.getTexCoord(i));
                    meshData.light0.put(light0);
                }
                for (int i = 0; i < part.indicesSize(); ++i) {
                    meshData.indices.put(nextIndex + part.getIndex(i));
                }
                if (block.isDoubleSided()) {
                    for (int i = 0; i < part.indicesSize(); i += 3) {
                        meshData.indices.put(nextIndex + part.getIndex(i + 1));
                        meshData.indices.put(nextIndex + part.getIndex(i));
                        meshData.indices.put(nextIndex + part.getIndex(i + 2));
                    }
                }
                nextIndex += part.size();
            }
        }
        mesh = Assets.generateAsset(new ResourceUrn(getBaseUrn(), block.getURI().toString()), meshData, Mesh.class);
    }
    return mesh;
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) StandardMeshData(org.terasology.engine.rendering.assets.mesh.StandardMeshData) Vector3f(org.joml.Vector3f) Block(org.terasology.engine.world.block.Block) Mesh(org.terasology.engine.rendering.assets.mesh.Mesh) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BlockMeshPart(org.terasology.engine.world.block.shapes.BlockMeshPart)

Example 4 with BlockPart

use of org.terasology.engine.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;
        int frameCount;
        BlockTile tile = tiles.get(part);
        if (tile == null) {
            atlasPos = new Vector2f();
            frameCount = 1;
        } else {
            atlasPos = worldAtlas.getTexCoords(tile, shape.getMeshPart(part) != null);
            frameCount = tile.getLength();
        }
        BlockPart targetPart = part.rotate(rot);
        textureAtlasPositions.put(targetPart, atlasPos);
        if (shape.getMeshPart(part) != null) {
            meshParts.put(targetPart, shape.getMeshPart(part).rotate(rot.orientation().get(new Quaternionf())).mapTexCoords(atlasPos, worldAtlas.getRelativeTileSize(), frameCount));
        }
    }
    return new BlockAppearance(meshParts, textureAtlasPositions);
}
Also used : BlockPart(org.terasology.engine.world.block.BlockPart) BlockAppearance(org.terasology.engine.world.block.BlockAppearance) Vector2f(org.joml.Vector2f) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) Quaternionf(org.joml.Quaternionf) BlockMeshPart(org.terasology.engine.world.block.shapes.BlockMeshPart)

Example 5 with BlockPart

use of org.terasology.engine.world.block.BlockPart in project Terasology by MovingBlocks.

the class BlockBuilder method applyLiquidShapes.

private void applyLiquidShapes(Block block, Map<BlockPart, BlockTile> tiles) {
    for (Side side : Side.values()) {
        BlockPart part = BlockPart.fromSide(side);
        BlockTile blockTile = tiles.get(part);
        if (blockTile != null) {
            BlockMeshPart lowMeshPart = lowShape.getMeshPart(part).mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize(), blockTile.getLength());
            block.setLowLiquidMesh(part.getSide(), lowMeshPart);
            BlockMeshPart topMeshPart = topShape.getMeshPart(part).mapTexCoords(worldAtlas.getTexCoords(blockTile, true), worldAtlas.getRelativeTileSize(), blockTile.getLength());
            block.setTopLiquidMesh(part.getSide(), topMeshPart);
        }
    }
}
Also used : Side(org.terasology.engine.math.Side) BlockPart(org.terasology.engine.world.block.BlockPart) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) BlockMeshPart(org.terasology.engine.world.block.shapes.BlockMeshPart)

Aggregations

BlockPart (org.terasology.engine.world.block.BlockPart)7 Side (org.terasology.engine.math.Side)3 BlockMeshPart (org.terasology.engine.world.block.shapes.BlockMeshPart)3 BlockTile (org.terasology.engine.world.block.tiles.BlockTile)3 Block (org.terasology.engine.world.block.Block)2 Quaternionf (org.joml.Quaternionf)1 Vector2f (org.joml.Vector2f)1 Vector3f (org.joml.Vector3f)1 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)1 StandardMeshData (org.terasology.engine.rendering.assets.mesh.StandardMeshData)1 BlockAppearance (org.terasology.engine.world.block.BlockAppearance)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1 Color (org.terasology.nui.Color)1