Search in sources :

Example 1 with BakedQuad

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

the class ItemLayerModel method getQuadsForSprite.

public static ImmutableList<BakedQuad> getQuadsForSprite(int tint, TextureAtlasSprite sprite, VertexFormat format, Optional<TRSRTransformation> transform) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    int uMax = sprite.getIconWidth();
    int vMax = sprite.getIconHeight();
    BitSet faces = new BitSet((uMax + 1) * (vMax + 1) * 4);
    for (int f = 0; f < sprite.getFrameCount(); f++) {
        int[] pixels = sprite.getFrameTextureData(f)[0];
        boolean ptu;
        boolean[] ptv = new boolean[uMax];
        Arrays.fill(ptv, true);
        for (int v = 0; v < vMax; v++) {
            ptu = true;
            for (int u = 0; u < uMax; u++) {
                boolean t = isTransparent(pixels, uMax, vMax, u, v);
                if (// left - transparent, right - opaque
                ptu && !t) {
                    addSideQuad(builder, faces, format, transform, EnumFacing.WEST, tint, sprite, uMax, vMax, u, v);
                }
                if (// left - opaque, right - transparent
                !ptu && t) {
                    addSideQuad(builder, faces, format, transform, EnumFacing.EAST, tint, sprite, uMax, vMax, u, v);
                }
                if (// up - transparent, down - opaque
                ptv[u] && !t) {
                    addSideQuad(builder, faces, format, transform, EnumFacing.UP, tint, sprite, uMax, vMax, u, v);
                }
                if (// up - opaque, down - transparent
                !ptv[u] && t) {
                    addSideQuad(builder, faces, format, transform, EnumFacing.DOWN, tint, sprite, uMax, vMax, u, v);
                }
                ptu = t;
                ptv[u] = t;
            }
            if (// last - opaque
            !ptu) {
                addSideQuad(builder, faces, format, transform, EnumFacing.EAST, tint, sprite, uMax, vMax, uMax, v);
            }
        }
        // last line
        for (int u = 0; u < uMax; u++) {
            if (!ptv[u]) {
                addSideQuad(builder, faces, format, transform, EnumFacing.DOWN, tint, sprite, uMax, vMax, u, vMax);
            }
        }
    }
    // front
    builder.add(buildQuad(format, transform, EnumFacing.NORTH, sprite, tint, 0, 0, 7.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 0, 1, 7.5f / 16f, sprite.getMinU(), sprite.getMinV(), 1, 1, 7.5f / 16f, sprite.getMaxU(), sprite.getMinV(), 1, 0, 7.5f / 16f, sprite.getMaxU(), sprite.getMaxV()));
    // back
    builder.add(buildQuad(format, transform, EnumFacing.SOUTH, sprite, tint, 0, 0, 8.5f / 16f, sprite.getMinU(), sprite.getMaxV(), 1, 0, 8.5f / 16f, sprite.getMaxU(), sprite.getMaxV(), 1, 1, 8.5f / 16f, sprite.getMaxU(), sprite.getMinV(), 0, 1, 8.5f / 16f, sprite.getMinU(), sprite.getMinV()));
    return builder.build();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) ImmutableList(com.google.common.collect.ImmutableList) BitSet(java.util.BitSet)

Example 2 with BakedQuad

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

the class ForgeBlockModelRenderer method render.

public static boolean render(VertexLighterFlat lighter, IBlockAccess world, IBakedModel model, IBlockState state, BlockPos pos, VertexBuffer wr, boolean checkSides, long rand) {
    lighter.setWorld(world);
    lighter.setState(state);
    lighter.setBlockPos(pos);
    boolean empty = true;
    List<BakedQuad> quads = model.getQuads(state, null, rand);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (EnumFacing side : EnumFacing.values()) {
        quads = model.getQuads(state, side, rand);
        if (!quads.isEmpty()) {
            if (!checkSides || state.shouldSideBeRendered(world, pos, side)) {
                if (empty)
                    lighter.updateBlockInfo();
                empty = false;
                for (BakedQuad quad : quads) {
                    quad.pipe(lighter);
                }
            }
        }
    }
    return !empty;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) EnumFacing(net.minecraft.util.EnumFacing)

Example 3 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project Overloaded by CJ-MC-Mods.

the class ModelUtils method renderQuadsRGB.

public static void renderQuadsRGB(List<BakedQuad> listQuads, float r, float g, float b) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    int i = 0;
    for (int j = listQuads.size(); i < j; ++i) {
        BakedQuad bakedquad = (BakedQuad) listQuads.get(i);
        vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
        vertexbuffer.addVertexData(bakedquad.getVertexData());
        vertexbuffer.putColorRGB_F4(r, g, b);
        Vec3i vec3i = bakedquad.getFace().getDirectionVec();
        vertexbuffer.putNormal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
        tessellator.draw();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Vec3i(net.minecraft.util.math.Vec3i) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 4 with BakedQuad

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

the class TileRenderBelljar method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBelljar tile, double x, double y, double z, float partialTicks, int destroyStage) {
    if (tile.dummy != 0 || !tile.getWorld().isBlockLoaded(tile.getPos(), false))
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    BlockPos blockPos = tile.getPos();
    if (!quads.containsKey(tile.getFacing())) {
        IBlockState state = getWorld().getBlockState(blockPos);
        if (state.getBlock() != IEContent.blockMetalDevice1)
            return;
        state = state.getActualState(getWorld(), blockPos);
        IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
        if (state instanceof IExtendedBlockState)
            state = ((IExtendedBlockState) state).withProperty(Properties.AnimationProperty, new OBJState(Arrays.asList("glass"), true));
        quads.put(tile.getFacing(), model.getQuads(state, null, 0));
    }
    ClientUtils.bindAtlas();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x, y, z);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    if (Minecraft.isAmbientOcclusionEnabled())
        GlStateManager.shadeModel(7425);
    else
        GlStateManager.shadeModel(7424);
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = Tessellator.getInstance().getBuffer();
    GlStateManager.enableCull();
    IPlantHandler plantHandler = tile.getCurrentPlantHandler();
    if (plantHandler != null) {
        GlStateManager.pushMatrix();
        GlStateManager.translate(0, 1.0625, 0);
        GlStateManager.color(1, 1, 1, 1);
        float scale = plantHandler.getRenderSize(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
        GlStateManager.translate((1 - scale) / 2, 0, (1 - scale) / 2);
        GlStateManager.scale(scale, scale, scale);
        if (!plantHandler.overrideRender(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile, blockRenderer)) {
            IBlockState[] states = plantHandler.getRenderedPlant(tile.getInventory()[1], tile.getInventory()[0], tile.renderGrowth, tile);
            if (states == null || states.length < 1)
                return;
            for (IBlockState s : states) {
                List<BakedQuad> plantQuadList = plantQuads.get(s);
                if (plantQuadList == null) {
                    IBakedModel plantModel = blockRenderer.getModelForState(s);
                    plantQuadList = plantModel.getQuads(s, null, 0);
                    for (EnumFacing f : EnumFacing.values()) plantQuadList.addAll(plantModel.getQuads(s, f, 0));
                    plantQuads.put(s, plantQuadList);
                }
                if (plantQuadList != null) {
                    GlStateManager.pushMatrix();
                    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
                    ClientUtils.renderModelTESR(plantQuadList, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
                    Tessellator.getInstance().draw();
                    GlStateManager.popMatrix();
                    GlStateManager.translate(0, 1, 0);
                }
            }
        }
        GlStateManager.popMatrix();
    }
    GlStateManager.depthMask(false);
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    ClientUtils.renderModelTESR(quads.get(tile.getFacing()), worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    Tessellator.getInstance().draw();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.depthMask(true);
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 5 with BakedQuad

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

the class TileRenderBucketWheel method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
    if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    if (model == null) {
        state = state.withProperty(IEProperties.DYNAMICRENDER, true);
        model = blockRenderer.getModelForState(state);
    }
    OBJState objState = null;
    HashMap<String, String> texMap = new HashMap<>();
    if (state instanceof IExtendedBlockState) {
        ArrayList<String> list = Lists.newArrayList("bucketWheel");
        synchronized (tile.digStacks) {
            for (int i = 0; i < tile.digStacks.length; i++) if (tile.digStacks[i] != null) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
                IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.getDefaultState();
                IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
                if (digModel != null && digModel.getParticleTexture() != null)
                    texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
            }
        }
        objState = new OBJState(list, true);
    }
    Tessellator tessellator = Tessellator.getInstance();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    EnumFacing facing = tile.facing;
    if (tile.mirrored) {
        GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
        GlStateManager.disableCull();
    }
    float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
    GlStateManager.rotate(dir, 0, 1, 0);
    float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * f : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = tessellator.getBuffer();
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5, -.5, -.5);
    List<BakedQuad> quads;
    if (model instanceof IESmartObjModel)
        quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
    else
        quads = model.getQuads(state, null, 0);
    ClientUtils.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    worldRenderer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    if (tile.mirrored) {
        GlStateManager.enableCull();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)130 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)43 EnumFacing (net.minecraft.util.EnumFacing)39 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)36 ArrayList (java.util.ArrayList)27 IBlockState (net.minecraft.block.state.IBlockState)24 ResourceLocation (net.minecraft.util.ResourceLocation)23 ImmutableList (com.google.common.collect.ImmutableList)22 MutableQuad (buildcraft.lib.client.model.MutableQuad)19 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)17 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)16 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)15 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)14 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)14 List (java.util.List)13 IModel (net.minecraftforge.client.model.IModel)13 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 Matrix4f (javax.vecmath.Matrix4f)12 Tessellator (net.minecraft.client.renderer.Tessellator)12 ItemLayerModel (net.minecraftforge.client.model.ItemLayerModel)12