Search in sources :

Example 1 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class BakedRenderable method render.

@Override
public void render(PoseStack poseStack, MultiBufferSource bufferSource, Function<ResourceLocation, RenderType> renderTypeFunction, int lightmapCoord, int overlayCoord, float partialTicks, IModelData renderValues) {
    var rt = renderTypeFunction.apply(InventoryMenu.BLOCK_ATLAS);
    VertexConsumer bb = bufferSource.getBuffer(rt);
    for (Direction direction : MODEL_FACINGS) {
        for (BakedQuad quad : model.getQuads(null, direction, rand, renderValues)) {
            bb.putBulkData(poseStack.last(), quad, 1, 1, 1, 1, lightmapCoord, overlayCoord, true);
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) Direction(net.minecraft.core.Direction)

Example 2 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class ForgeBlockModelRenderer method render.

public static boolean render(VertexLighterFlat lighter, BlockAndTintGetter world, BakedModel model, BlockState state, BlockPos pos, PoseStack matrixStack, boolean checkSides, Random rand, long seed, IModelData modelData) {
    lighter.setWorld(world);
    lighter.setState(state);
    lighter.setBlockPos(pos);
    boolean empty = true;
    rand.setSeed(seed);
    List<BakedQuad> quads = model.getQuads(state, null, rand, modelData);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (Direction side : Direction.values()) {
        rand.setSeed(seed);
        quads = model.getQuads(state, side, rand, modelData);
        if (!quads.isEmpty()) {
            if (!checkSides || Block.shouldRenderFace(state, world, pos, side, pos.relative(side))) {
                if (empty)
                    lighter.updateBlockInfo();
                empty = false;
                for (BakedQuad quad : quads) {
                    quad.pipe(lighter);
                }
            }
        }
    }
    lighter.resetBlockInfo();
    return !empty;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Direction(net.minecraft.core.Direction)

Example 3 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class OBJModel method makeQuad.

private Pair<BakedQuad, Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, TextureAtlasSprite texture, Transformation transform) {
    boolean needsNormalRecalculation = false;
    for (int[] ints : indices) {
        needsNormalRecalculation |= ints.length < 3;
    }
    Vector3f faceNormal = new Vector3f(0, 0, 0);
    if (needsNormalRecalculation) {
        Vector3f a = positions.get(indices[0][0]);
        Vector3f ab = positions.get(indices[1][0]);
        Vector3f ac = positions.get(indices[2][0]);
        Vector3f abs = ab.copy();
        abs.sub(a);
        Vector3f acs = ac.copy();
        acs.sub(a);
        abs.cross(acs);
        abs.normalize();
        faceNormal = abs;
    }
    Vector4f[] pos = new Vector4f[4];
    Vector3f[] norm = new Vector3f[4];
    BakedQuadBuilder builder = new BakedQuadBuilder(texture);
    builder.setQuadTint(tintIndex);
    Vec2 uv2 = new Vec2(0, 0);
    if (ambientToFullbright) {
        int fakeLight = (int) ((ambientColor.x() + ambientColor.y() + ambientColor.z()) * 15 / 3.0f);
        uv2 = new Vec2((fakeLight << 4) / 32767.0f, (fakeLight << 4) / 32767.0f);
        builder.setApplyDiffuseLighting(fakeLight == 0);
    } else {
        builder.setApplyDiffuseLighting(diffuseLighting);
    }
    boolean hasTransform = !transform.isIdentity();
    // The incoming transform is referenced on the center of the block, but our coords are referenced on the corner
    Transformation transformation = hasTransform ? transform.blockCenterToCorner() : transform;
    for (int i = 0; i < 4; i++) {
        int[] index = indices[Math.min(i, indices.length - 1)];
        Vector3f pos0 = positions.get(index[0]);
        Vector4f position = new Vector4f(pos0);
        Vec2 texCoord = index.length >= 2 && texCoords.size() > 0 ? texCoords.get(index[1]) : DEFAULT_COORDS[i];
        Vector3f norm0 = !needsNormalRecalculation && index.length >= 3 && normals.size() > 0 ? normals.get(index[2]) : faceNormal;
        Vector3f normal = norm0;
        Vector4f color = index.length >= 4 && colors.size() > 0 ? colors.get(index[3]) : COLOR_WHITE;
        if (hasTransform) {
            normal = norm0.copy();
            transformation.transformPosition(position);
            transformation.transformNormal(normal);
        }
        ;
        Vector4f tintedColor = new Vector4f(color.x() * colorTint.x(), color.y() * colorTint.y(), color.z() * colorTint.z(), color.w() * colorTint.w());
        putVertexData(builder, position, texCoord, normal, tintedColor, uv2, texture);
        pos[i] = position;
        norm[i] = normal;
    }
    builder.setQuadOrientation(Direction.getNearest(norm[0].x(), norm[0].y(), norm[0].z()));
    Direction cull = null;
    if (detectCullableFaces) {
        if (// vertex.position.x
        Mth.equal(pos[0].x(), 0) && Mth.equal(pos[1].x(), 0) && Mth.equal(pos[2].x(), 0) && Mth.equal(pos[3].x(), 0) && // vertex.normal.x
        norm[0].x() < 0) {
            cull = Direction.WEST;
        } else if (// vertex.position.x
        Mth.equal(pos[0].x(), 1) && Mth.equal(pos[1].x(), 1) && Mth.equal(pos[2].x(), 1) && Mth.equal(pos[3].x(), 1) && // vertex.normal.x
        norm[0].x() > 0) {
            cull = Direction.EAST;
        } else if (// vertex.position.z
        Mth.equal(pos[0].z(), 0) && Mth.equal(pos[1].z(), 0) && Mth.equal(pos[2].z(), 0) && Mth.equal(pos[3].z(), 0) && // vertex.normal.z
        norm[0].z() < 0) {
            // can never remember
            cull = Direction.NORTH;
        } else if (// vertex.position.z
        Mth.equal(pos[0].z(), 1) && Mth.equal(pos[1].z(), 1) && Mth.equal(pos[2].z(), 1) && Mth.equal(pos[3].z(), 1) && // vertex.normal.z
        norm[0].z() > 0) {
            cull = Direction.SOUTH;
        } else if (// vertex.position.y
        Mth.equal(pos[0].y(), 0) && Mth.equal(pos[1].y(), 0) && Mth.equal(pos[2].y(), 0) && Mth.equal(pos[3].y(), 0) && // vertex.normal.z
        norm[0].y() < 0) {
            // can never remember
            cull = Direction.DOWN;
        } else if (// vertex.position.y
        Mth.equal(pos[0].y(), 1) && Mth.equal(pos[1].y(), 1) && Mth.equal(pos[2].y(), 1) && Mth.equal(pos[3].y(), 1) && // vertex.normal.y
        norm[0].y() > 0) {
            cull = Direction.UP;
        }
    }
    return Pair.of(builder.build(), cull);
}
Also used : Transformation(com.mojang.math.Transformation) Vector4f(com.mojang.math.Vector4f) Vec2(net.minecraft.world.phys.Vec2) Vector3f(com.mojang.math.Vector3f) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder) Direction(net.minecraft.core.Direction)

Example 4 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class BlockInfo method updateFlatLighting.

public void updateFlatLighting() {
    full = Block.isShapeFullBlock(state.getCollisionShape(level, blockPos));
    packed[0] = LevelRenderer.getLightColor(level, blockPos);
    for (Direction side : SIDES) {
        int i = side.ordinal() + 1;
        packed[i] = LevelRenderer.getLightColor(level, blockPos.relative(side));
    }
}
Also used : Direction(net.minecraft.core.Direction)

Example 5 with Direction

use of net.minecraft.core.Direction in project MinecraftForge by MinecraftForge.

the class BlockInfo method updateLightMatrix.

public void updateLightMatrix() {
    for (int x = 0; x <= 2; x++) {
        for (int y = 0; y <= 2; y++) {
            for (int z = 0; z <= 2; z++) {
                BlockPos pos = blockPos.offset(x - 1, y - 1, z - 1);
                BlockState state = level.getBlockState(pos);
                t[x][y][z] = state.getLightBlock(level, pos) < 15;
                int brightness = LevelRenderer.getLightColor(level, pos);
                s[x][y][z] = LightTexture.sky(brightness);
                b[x][y][z] = LightTexture.block(brightness);
                ao[x][y][z] = state.getShadeBrightness(level, pos);
            }
        }
    }
    for (Direction side : SIDES) {
        BlockPos pos = blockPos.relative(side);
        BlockState state = level.getBlockState(pos);
        BlockState thisStateShape = this.state.canOcclude() && this.state.useShapeForLightOcclusion() ? this.state : Blocks.AIR.defaultBlockState();
        BlockState otherStateShape = state.canOcclude() && state.useShapeForLightOcclusion() ? state : Blocks.AIR.defaultBlockState();
        if (state.getLightBlock(level, pos) == 15 || Shapes.faceShapeOccludes(thisStateShape.getFaceOcclusionShape(level, blockPos, side), otherStateShape.getFaceOcclusionShape(level, pos, side.getOpposite()))) {
            int x = side.getStepX() + 1;
            int y = side.getStepY() + 1;
            int z = side.getStepZ() + 1;
            s[x][y][z] = Math.max(s[1][1][1] - 1, s[x][y][z]);
            b[x][y][z] = Math.max(b[1][1][1] - 1, b[x][y][z]);
        }
    }
    for (int x = 0; x < 2; x++) {
        for (int y = 0; y < 2; y++) {
            for (int z = 0; z < 2; z++) {
                int x1 = x * 2;
                int y1 = y * 2;
                int z1 = z * 2;
                int sxyz = s[x1][y1][z1];
                int bxyz = b[x1][y1][z1];
                boolean txyz = t[x1][y1][z1];
                int sxz = s[x1][1][z1], sxy = s[x1][y1][1], syz = s[1][y1][z1];
                int bxz = b[x1][1][z1], bxy = b[x1][y1][1], byz = b[1][y1][z1];
                boolean txz = t[x1][1][z1], txy = t[x1][y1][1], tyz = t[1][y1][z1];
                int sx = s[x1][1][1], sy = s[1][y1][1], sz = s[1][1][z1];
                int bx = b[x1][1][1], by = b[1][y1][1], bz = b[1][1][z1];
                boolean tx = t[x1][1][1], ty = t[1][y1][1], tz = t[1][1][z1];
                skyLight[0][x][y][z] = combine(sx, sxz, sxy, txz || txy ? sxyz : sx, tx, txz, txy, txz || txy ? txyz : tx);
                blockLight[0][x][y][z] = combine(bx, bxz, bxy, txz || txy ? bxyz : bx, tx, txz, txy, txz || txy ? txyz : tx);
                skyLight[1][x][y][z] = combine(sy, sxy, syz, txy || tyz ? sxyz : sy, ty, txy, tyz, txy || tyz ? txyz : ty);
                blockLight[1][x][y][z] = combine(by, bxy, byz, txy || tyz ? bxyz : by, ty, txy, tyz, txy || tyz ? txyz : ty);
                skyLight[2][x][y][z] = combine(sz, syz, sxz, tyz || txz ? sxyz : sz, tz, tyz, txz, tyz || txz ? txyz : tz);
                blockLight[2][x][y][z] = combine(bz, byz, bxz, tyz || txz ? bxyz : bz, tz, tyz, txz, tyz || txz ? txyz : tz);
            }
        }
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction)

Aggregations

Direction (net.minecraft.core.Direction)17 BlockPos (net.minecraft.core.BlockPos)4 Nonnull (javax.annotation.Nonnull)3 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)3 ItemStack (net.minecraft.world.item.ItemStack)3 Level (net.minecraft.world.level.Level)2 BellBlock (net.minecraft.world.level.block.BellBlock)2 DispenserBlockEntity (net.minecraft.world.level.block.entity.DispenserBlockEntity)2 org.bukkit.block (org.bukkit.block)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 Transformation (com.mojang.math.Transformation)1 Vector3f (com.mojang.math.Vector3f)1 Vector4f (com.mojang.math.Vector4f)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 BlockElementFace (net.minecraft.client.renderer.block.model.BlockElementFace)1