Search in sources :

Example 26 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method renderModelTESR.

public static void renderModelTESR(List<BakedQuad> quads, VertexBuffer renderer, int brightness) {
    int l1 = (brightness >> 0x10) & 0xFFFF;
    int l2 = brightness & 0xFFFF;
    for (BakedQuad quad : quads) {
        int[] vData = quad.getVertexData();
        VertexFormat format = quad.getFormat();
        int size = format.getIntegerSize();
        int uv = format.getUvOffsetById(0) / 4;
        for (int i = 0; i < 4; ++i) {
            renderer.pos(Float.intBitsToFloat(vData[size * i]), Float.intBitsToFloat(vData[size * i + 1]), Float.intBitsToFloat(vData[size * i + 2])).color(255, 255, 255, 255).tex(Float.intBitsToFloat(vData[size * i + uv]), Float.intBitsToFloat(vData[size * i + uv + 1])).lightmap(l1, l2).endVertex();
        }
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) VertexFormat(net.minecraft.client.renderer.vertex.VertexFormat)

Example 27 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method createBakedQuad.

public static BakedQuad createBakedQuad(VertexFormat format, Vector3f[] vertices, EnumFacing facing, TextureAtlasSprite sprite, double[] uvs, float[] colour, boolean invert, float[] alpha, boolean smartLighting, BlockPos basePos) {
    UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format);
    builder.setQuadOrientation(facing);
    builder.setTexture(sprite);
    Normal faceNormal = new Normal(facing.getDirectionVec().getX(), facing.getDirectionVec().getY(), facing.getDirectionVec().getZ());
    int vId = invert ? 3 : 0;
    int u = vId > 1 ? 2 : 0;
    putVertexData(format, builder, vertices[vId], faceNormal, uvs[u], uvs[1], sprite, colour, alpha[invert ? 3 : 0]);
    vId = invert ? 2 : 1;
    u = vId > 1 ? 2 : 0;
    putVertexData(format, builder, vertices[invert ? 2 : 1], faceNormal, uvs[u], uvs[3], sprite, colour, alpha[invert ? 2 : 1]);
    vId = invert ? 1 : 2;
    u = vId > 1 ? 2 : 0;
    putVertexData(format, builder, vertices[invert ? 1 : 2], faceNormal, uvs[u], uvs[3], sprite, colour, alpha[invert ? 1 : 2]);
    vId = invert ? 1 : 3;
    u = vId > 1 ? 2 : 0;
    putVertexData(format, builder, vertices[invert ? 0 : 3], faceNormal, uvs[u], uvs[1], sprite, colour, alpha[invert ? 0 : 3]);
    BakedQuad tmp = builder.build();
    return smartLighting ? new SmartLightingQuad(tmp.getVertexData(), -1, facing, sprite, format, basePos) : tmp;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) SmartLightingQuad(blusunrize.immersiveengineering.client.models.SmartLightingQuad) Normal(net.minecraftforge.client.model.obj.OBJModel.Normal)

Example 28 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class TileRenderAutoWorkbench method getBlueprintDrawable.

public static BlueprintLines getBlueprintDrawable(ItemStack stack, World world) {
    if (stack == null)
        return null;
    EntityPlayer player = ClientUtils.mc().thePlayer;
    ArrayList<BufferedImage> images = new ArrayList<>();
    try {
        IBakedModel ibakedmodel = ClientUtils.mc().getRenderItem().getItemModelWithOverrides(stack, world, player);
        HashSet<String> textures = new HashSet();
        Collection<BakedQuad> quads = ibakedmodel.getQuads(null, null, 0);
        for (BakedQuad quad : quads) if (quad != null && quad.getSprite() != null)
            textures.add(quad.getSprite().getIconName());
        for (String s : textures) {
            ResourceLocation rl = new ResourceLocation(s);
            rl = new ResourceLocation(rl.getResourceDomain(), String.format("%s/%s%s", "textures", rl.getResourcePath(), ".png"));
            IResource resource = ClientUtils.mc().getResourceManager().getResource(rl);
            BufferedImage bufferedImage = TextureUtil.readBufferedImage(resource.getInputStream());
            if (bufferedImage != null)
                images.add(bufferedImage);
        }
    } catch (Exception e) {
    }
    if (images.isEmpty())
        return null;
    ArrayList<Pair<TexturePoint, TexturePoint>> lines = new ArrayList();
    HashSet testSet = new HashSet();
    HashMultimap<Integer, TexturePoint> area = HashMultimap.create();
    int wMax = 0;
    for (BufferedImage bufferedImage : images) {
        Set<Pair<TexturePoint, TexturePoint>> temp_lines = new HashSet<>();
        int w = bufferedImage.getWidth();
        int h = bufferedImage.getHeight();
        if (h > w)
            h = w;
        if (w > wMax)
            wMax = w;
        for (int hh = 0; hh < h; hh++) for (int ww = 0; ww < w; ww++) {
            int argb = bufferedImage.getRGB(ww, hh);
            float r = (argb >> 16 & 255) / 255f;
            float g = (argb >> 8 & 255) / 255f;
            float b = (argb & 255) / 255f;
            float intesity = (r + b + g) / 3f;
            int alpha = (argb >> 24) & 255;
            if (alpha > 0) {
                boolean added = false;
                //Check colour sets for similar colour to shade it later
                TexturePoint tp = new TexturePoint(ww, hh, w);
                if (!testSet.contains(tp)) {
                    for (Integer key : area.keySet()) {
                        for (Point p : area.get(key)) {
                            int pColour = bufferedImage.getRGB(p.x, p.y);
                            float dR = (r - (pColour >> 16 & 255) / 255f);
                            float dG = (g - (pColour >> 8 & 255) / 255f);
                            float dB = (b - (pColour & 255) / 255f);
                            double delta = Math.sqrt(dR * dR + dG * dG + dB * dB);
                            if (delta < .25) {
                                area.put(key, tp);
                                added = true;
                                break;
                            }
                        }
                        if (added)
                            break;
                    }
                    if (!added)
                        area.put(argb, tp);
                    testSet.add(tp);
                }
                //Compare to direct neighbour
                for (int i = 0; i < 4; i++) {
                    int xx = (i == 0 ? -1 : i == 1 ? 1 : 0);
                    int yy = (i == 2 ? -1 : i == 3 ? 1 : 0);
                    int u = ww + xx;
                    int v = hh + yy;
                    int neighbour = 0;
                    float delta = 1;
                    boolean notTransparent = false;
                    if (u >= 0 && u < w && v >= 0 && v < h) {
                        neighbour = bufferedImage.getRGB(u, v);
                        notTransparent = ((neighbour >> 24) & 255) > 0;
                        if (notTransparent) {
                            float neighbourIntesity = ((neighbour >> 16 & 255) + (neighbour >> 8 & 255) + (neighbour & 255)) / 765f;
                            float intesityDelta = Math.max(0, Math.min(1, Math.abs(intesity - neighbourIntesity)));
                            float rDelta = Math.max(0, Math.min(1, Math.abs(r - (neighbour >> 16 & 255) / 255f)));
                            float gDelta = Math.max(0, Math.min(1, Math.abs(g - (neighbour >> 8 & 255) / 255f)));
                            float bDelta = Math.max(0, Math.min(1, Math.abs(b - (neighbour & 255) / 255f)));
                            delta = Math.max(intesityDelta, Math.max(rDelta, Math.max(gDelta, bDelta)));
                            delta = delta < .25 ? 0 : delta > .4 ? 1 : delta;
                        }
                    }
                    if (delta > 0) {
                        Pair<TexturePoint, TexturePoint> l = Pair.of(new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 0), hh + (i == 2 ? 0 : i == 3 ? 1 : 0), w), new TexturePoint(ww + (i == 0 ? 0 : i == 1 ? 1 : 1), hh + (i == 2 ? 0 : i == 3 ? 1 : 1), w));
                        temp_lines.add(l);
                    }
                }
            }
        }
        lines.addAll(temp_lines);
    }
    ArrayList<Integer> lumiSort = new ArrayList<>(area.keySet());
    Collections.sort(lumiSort, (rgb1, rgb2) -> Double.compare(getLuminance(rgb1), getLuminance(rgb2)));
    HashMultimap<ShadeStyle, Point> complete_areaMap = HashMultimap.create();
    int lineNumber = 2;
    int lineStyle = 0;
    for (Integer i : lumiSort) {
        complete_areaMap.putAll(new ShadeStyle(lineNumber, lineStyle), area.get(i));
        ++lineStyle;
        lineStyle %= 3;
        if (lineStyle == 0)
            lineNumber += 1;
    }
    Set<Pair<Point, Point>> complete_lines = new HashSet<>();
    for (Pair<TexturePoint, TexturePoint> line : lines) {
        TexturePoint p1 = line.getKey();
        TexturePoint p2 = line.getValue();
        complete_lines.add(Pair.of(new Point((int) (p1.x / (float) p1.scale * wMax), (int) (p1.y / (float) p1.scale * wMax)), new Point((int) (p2.x / (float) p2.scale * wMax), (int) (p2.y / (float) p2.scale * wMax))));
    }
    return new BlueprintLines(wMax, complete_lines, complete_areaMap);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) BufferedImage(java.awt.image.BufferedImage) ResourceLocation(net.minecraft.util.ResourceLocation) Pair(org.apache.commons.lang3.tuple.Pair) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IResource(net.minecraft.client.resources.IResource)

Example 29 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ConveyorCovered method modifyQuads.

@Override
@SideOnly(Side.CLIENT)
public List<BakedQuad> modifyQuads(List<BakedQuad> baseModel, @Nullable TileEntity tile, EnumFacing facing) {
    ItemStack cover = this.cover != null ? this.cover : defaultCover;
    Block b = Block.getBlockFromItem(cover.getItem());
    IBlockState state = b != null ? b.getStateFromMeta(cover.getMetadata()) : Blocks.STONE.getDefaultState();
    IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state);
    if (model != null) {
        TextureAtlasSprite sprite = model.getParticleTexture();
        HashMap<EnumFacing, TextureAtlasSprite> sprites = new HashMap<>();
        ConveyorDirection conDir = this.getConveyorDirection();
        for (EnumFacing f : EnumFacing.VALUES) for (BakedQuad q : model.getQuads(state, f, 0)) if (q != null && q.getSprite() != null)
            sprites.put(f, q.getSprite());
        for (BakedQuad q : model.getQuads(state, null, 0)) if (q != null && q.getSprite() != null && q.getFace() != null)
            sprites.put(q.getFace(), q.getSprite());
        Function<EnumFacing, TextureAtlasSprite> getSprite = f -> sprites.containsKey(f) ? sprites.get(f) : sprite;
        Function<EnumFacing, TextureAtlasSprite> getSpriteHorizontal = f -> f.getAxis() == Axis.Y ? null : sprites.containsKey(f) ? sprites.get(f) : sprite;
        float[] colour = { 1, 1, 1, 1 };
        Matrix4 matrix = new Matrix4(facing);
        boolean wallLeft = tile == null || this.renderWall(tile, facing, 0);
        boolean wallRight = tile == null || this.renderWall(tile, facing, 1);
        Function<Vector3f[], Vector3f[]> vertexTransformer = conDir == ConveyorDirection.HORIZONTAL ? vertices -> vertices : vertices -> {
            Vector3f[] ret = new Vector3f[vertices.length];
            for (int i = 0; i < ret.length; i++) ret[i] = new Vector3f(vertices[i].x, vertices[i].y + (vertices[i].z == (conDir == ConveyorDirection.UP ? 0 : 1) ? 1 : 0), vertices[i].z);
            return ret;
        };
        baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .75f, 0), new Vector3f(1, 1, 1), matrix, facing, vertexTransformer, getSprite, colour));
        if (wallLeft)
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, 0), new Vector3f(.0625f, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(0, .1875f, .9375f), new Vector3f(.0625f, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
        if (wallRight)
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, 1), matrix, facing, vertexTransformer, getSpriteHorizontal, colour));
        else {
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, 0), new Vector3f(1, .75f, .0625f), matrix, facing, getSpriteHorizontal, colour));
            baseModel.addAll(ClientUtils.createBakedBox(new Vector3f(.9375f, .1875f, .9375f), new Vector3f(1, .75f, 1), matrix, facing, getSpriteHorizontal, colour));
        }
    }
    return baseModel;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) IEContent(blusunrize.immersiveengineering.common.IEContent) Blocks(net.minecraft.init.Blocks) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) HashMap(java.util.HashMap) Function(java.util.function.Function) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) OreDictionary(net.minecraftforge.oredict.OreDictionary) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Nullable(javax.annotation.Nullable) BlockTypes_WoodenDecoration(blusunrize.immersiveengineering.common.blocks.wooden.BlockTypes_WoodenDecoration) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EntityItem(net.minecraft.entity.item.EntityItem) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Entity(net.minecraft.entity.Entity) Utils(blusunrize.immersiveengineering.common.util.Utils) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) EnumFacing(net.minecraft.util.EnumFacing) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) Vector3f(org.lwjgl.util.vector.Vector3f) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntity(net.minecraft.tileentity.TileEntity) BlockTypes_MetalDecoration1(blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_MetalDecoration1) Axis(net.minecraft.util.EnumFacing.Axis) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4) Vector3f(org.lwjgl.util.vector.Vector3f) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ConveyorDirection(blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 30 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project BetterWithAddons by DaedalusGame.

the class ModelToolShardInner method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, java.util.function.Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Optional<TRSRTransformation> transform = state.apply(Optional.empty());
    for (int i = 0; i < textures.size(); i++) {
        ResourceLocation tex = textures.get(i);
        if (tex.toString().equals("minecraft:missingno"))
            continue;
        TextureAtlasSprite sprite = bakedTextureGetter.apply(tex);
        String breakLocation = new ResourceLocation(Reference.MOD_ID, "items/breakmask").toString();
        TextureAtlasSprite breakTemplate = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(breakLocation);
        builder.addAll(getQuadsForSprite(i, breakTemplate, sprite, format, transform));
    // builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, breakTemplate, sprite, NORTH_Z + Z_OFFSET * i, EnumFacing.NORTH, 0xffffffff));
    // builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, breakTemplate, sprite, SOUTH_Z - Z_OFFSET * i, EnumFacing.SOUTH, 0xffffffff));
    }
    TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
    ImmutableMap<ItemCameraTransforms.TransformType, TRSRTransformation> map = PerspectiveMapWrapper.getTransforms(state);
    return new BakedItemModel(builder.build(), particle, map, null);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)30 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)13 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)8 EnumFacing (net.minecraft.util.EnumFacing)8 Tessellator (net.minecraft.client.renderer.Tessellator)6 Vec3i (net.minecraft.util.math.Vec3i)6 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)5 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)5 Vector3f (org.lwjgl.util.vector.Vector3f)5 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)4 ImmutableList (com.google.common.collect.ImmutableList)4 IBlockState (net.minecraft.block.state.IBlockState)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 BlockPos (net.minecraft.util.math.BlockPos)4 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 HashMap (java.util.HashMap)3 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2