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