Search in sources :

Example 1 with VoxelComponentSignText

use of io.xol.chunkstories.core.voxel.components.VoxelComponentSignText in project chunkstories-core by Hugobros3.

the class Sign method translateSignText.

private void translateSignText(VoxelComponent target, MinecraftChunk minecraftChunk, int x, int y, int z) {
    NBTCompound root = minecraftChunk.getRootTag();
    if (root == null)
        return;
    NBTList entitiesList = (NBTList) root.getTag("Level.TileEntities");
    // Check it exists and is of the right kind
    if (target != null && target instanceof VoxelComponentSignText) {
        VoxelComponentSignText signTextComponent = (VoxelComponentSignText) target;
        signTextComponent.setSignText("<corresponding sign not found :(>");
        for (NBTag element : entitiesList.elements) {
            NBTCompound entity = (NBTCompound) element;
            NBTString entityId = (NBTString) entity.getTag("id");
            int tileX = ((NBTInt) entity.getTag("x")).data;
            int tileY = ((NBTInt) entity.getTag("y")).data;
            int tileZ = ((NBTInt) entity.getTag("z")).data;
            if (entityId.data.toLowerCase().equals("sign") || entityId.data.toLowerCase().equals("minecraft:sign")) {
                // System.out.println("Looking up sign data for B:"+x+":"+y+":"+z);
                if ((tileX & 0xF) != x || tileY != y || (tileZ & 0xF) != z) {
                    continue;
                }
                String text1 = SignParseUtil.parseSignData(((NBTString) entity.getTag("Text1")).data);
                String text2 = SignParseUtil.parseSignData(((NBTString) entity.getTag("Text2")).data);
                String text3 = SignParseUtil.parseSignData(((NBTString) entity.getTag("Text3")).data);
                String text4 = SignParseUtil.parseSignData(((NBTString) entity.getTag("Text4")).data);
                String textComplete = text1 + "\n" + text2 + "\n" + text3 + "\n" + text4;
                signTextComponent.setSignText(textComplete);
                System.out.println("OK: " + textComplete);
                break;
            // ((EntitySign) ((VoxelSign) voxel).getEntity(exported.peekSafely(csCoordinatesX, csCoordinatesY, csCoordinatesZ))).setText(textComplete);
            }
        // else
        // System.out.println("Found "+entityId.data);
        }
    }
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText) NBTList(io.xol.enklume.nbt.NBTList) NBTCompound(io.xol.enklume.nbt.NBTCompound) NBTString(io.xol.enklume.nbt.NBTString) NBTag(io.xol.enklume.nbt.NBTag) NBTString(io.xol.enklume.nbt.NBTString) NBTInt(io.xol.enklume.nbt.NBTInt)

Example 2 with VoxelComponentSignText

use of io.xol.chunkstories.core.voxel.components.VoxelComponentSignText in project chunkstories-core by Hugobros3.

the class SignRenderer method renderVoxels.

@Override
public void renderVoxels(RenderingInterface renderingContext, IterableIterator<ChunkCell> renderableEntitiesIterator) {
    setupRender(renderingContext);
    renderingContext.setObjectMatrix(null);
    for (// .getElementsInFrustrumOnly())
    ChunkCell context : // .getElementsInFrustrumOnly())
    renderableEntitiesIterator) {
        if (renderingContext.getCamera().getCameraPosition().distance(context.getLocation()) > 32)
            continue;
        Texture2D diffuse = renderingContext.textures().getTexture("./models/sign.png");
        diffuse.setLinearFiltering(false);
        renderingContext.bindAlbedoTexture(diffuse);
        renderingContext.bindNormalTexture(renderingContext.textures().getTexture("./textures/normalnormal.png"));
        renderingContext.currentShader().setUniform2f("worldLightIn", context.getBlocklight(), context.getSunlight());
        boolean isPost = context.getVoxel().getName().endsWith("_post");
        int facing = context.getMetaData();
        Matrix4f mutrix = new Matrix4f();
        mutrix.translate(new Vector3f(0.5f, 0.0f, 0.5f));
        Location loc = context.getLocation();
        mutrix.translate((float) loc.x, (float) loc.y, (float) loc.z);
        mutrix.rotate((float) Math.PI * 2.0f * (-facing) / 16f, new Vector3f(0, 1, 0));
        if (!isPost)
            mutrix.translate(new Vector3f(0.0f, 0.0f, -0.5f));
        renderingContext.setObjectMatrix(mutrix);
        if (!isPost)
            renderingContext.meshes().getRenderableMeshByName("./models/sign_post.obj").render(renderingContext);
        else
            renderingContext.meshes().getRenderableMeshByName("./models/sign.obj").render(renderingContext);
        VoxelComponentSignText signTextComponent = (VoxelComponentSignText) context.components().get("signData");
        if (signTextComponent == null)
            continue;
        // bake sign mesh
        if (signTextComponent.cachedText == null || !signTextComponent.cachedText.equals(signTextComponent.getSignText())) {
            // entitySign.renderData = new TextMeshObject(entitySign.signText.getSignText());
            signTextComponent.cachedText = signTextComponent.getSignText();
            signTextComponent.renderData = renderingContext.getFontRenderer().newTextMeshObject(renderingContext.getFontRenderer().defaultFont(), signTextComponent.cachedText);
        }
        // signTextComponent.setSignText("fuck");
        // System.out.println("cachedText:"+signTextComponent.getSignText());
        // Display it
        mutrix.translate(new Vector3f(0.0f, 1.15f, 0.055f));
        renderingContext.setObjectMatrix(mutrix);
        signTextComponent.renderData.render(renderingContext);
    }
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText) Texture2D(io.xol.chunkstories.api.rendering.textures.Texture2D) Matrix4f(org.joml.Matrix4f) Vector3f(org.joml.Vector3f) ChunkCell(io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell) Location(io.xol.chunkstories.api.Location)

Example 3 with VoxelComponentSignText

use of io.xol.chunkstories.core.voxel.components.VoxelComponentSignText in project chunkstories-core by Hugobros3.

the class VoxelSign method whenPlaced.

@Override
public void whenPlaced(FreshChunkCell cell) {
    VoxelComponentSignText signTextComponent = new VoxelComponentSignText(cell.components());
    cell.registerComponent("signData", signTextComponent);
}
Also used : VoxelComponentSignText(io.xol.chunkstories.core.voxel.components.VoxelComponentSignText)

Aggregations

VoxelComponentSignText (io.xol.chunkstories.core.voxel.components.VoxelComponentSignText)3 Location (io.xol.chunkstories.api.Location)1 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)1 ChunkCell (io.xol.chunkstories.api.world.chunk.Chunk.ChunkCell)1 NBTCompound (io.xol.enklume.nbt.NBTCompound)1 NBTInt (io.xol.enklume.nbt.NBTInt)1 NBTList (io.xol.enklume.nbt.NBTList)1 NBTString (io.xol.enklume.nbt.NBTString)1 NBTag (io.xol.enklume.nbt.NBTag)1 Matrix4f (org.joml.Matrix4f)1 Vector3f (org.joml.Vector3f)1