Jump to content

net.minecraft.client.renderer.RenderBlocks#getBlockIconFromSideAndMetadata in 1.10.2?


lukas2005

Recommended Posts

im trying to port this bit of code to 1.10.2 (from 1.7.10)

                            IIcon icon = renderer.getBlockIconFromSideAndMetadata(block, 1, meta);
                            double tu0 = (double)icon.getMinUV();
                            double tu1 = (double)icon.getMaxU();
                            double tv0 = (double)icon.getMinV();
                            double tv1 = (double)icon.getMaxV();

 

Link to comment
Share on other sites

What is your overall goal? What feature is this code a part of? We need some more context than a snippet of code.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

That code alone does precisely nothing.

yes i know its because its part of bigger thing

4 minutes ago, Choonster said:

What is your overall goal? What feature is this code a part of? We need some more context than a snippet of code.

im using this to then be able to use tessalator to render some stuff

Edited by lukas2005
Link to comment
Share on other sites

2 minutes ago, lukas2005 said:

im using this to then be able to use tessalator to render some stuff

 

What "stuff"? You're being very vague, which makes it hard to help you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Just now, lukas2005 said:

i just use this little snippet for rendering an i need to know what is repacment for IIcon and RenderBlocks

 

But what are you trying to render? Where are you rendering it?

 

IIcon and RenderBlocks were replaced by the baked model system, but it's hard to tell you what you need to do when we don't actually know what you're trying to do.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

i am trying to make terrain smoother rather than just blocks and i need to know the size of textures for tesselator

 

whole render method: (1.7.10)

 

public static boolean renderChunk(int pass, int cx, int cy, int cz, IBlockAccess cache, RenderBlocks renderer) {
        if(!ModConfig.MOD_ENABLED) {
            return false;
        } else if(pass != 0) {
            return false;
        } else {
            Tessellator tess = Tessellator.getInstance();
            int[] dims = new int[]{16, 16, 16};
            int[] c = new int[]{cx, cy, cz};
            int[] x = new int[3];
            int[] r = new int[]{1, dims[0] + 3, (dims[0] + 3) * (dims[1] + 3)};
            float[] grid = new float[8];
            float[][] buffer = new float[r[2] * 2][3];
            int bufno = 1;

            for(x[2] = 0; x[2] < dims[2] + 1; r[2] = -r[2]) {
                int m = 1 + (dims[0] + 3) * (1 + bufno * (dims[1] + 3));

                for(x[1] = 0; x[1] < dims[1] + 1; m += 2) {
                    for(x[0] = 0; x[0] < dims[0] + 1; ++m) {
                        int mask = 0;
                        int g = 0;

                        for(int k = 0; k < 2; ++k) {
                            for(int j = 0; j < 2; ++j) {
                                for(int i = 0; i < 2; ++g) {
                                    float p = getBlockDensity(c[0] + x[0] + i, c[1] + x[1] + j, c[2] + x[2] + k, cache);
                                    grid[g] = p;
                                    mask |= p > 0.0F?1 << g:0;
                                    ++i;
                                }
                            }
                        }

                        if(mask != 0 && mask != 255) {
                            Block block = Blocks.AIR;
                            int meta = 0;

                            label368:
                            for(int k = -1; k < 2; ++k) {
                                for(int j = -1; j < 2; ++j) {
                                    for(int i = -1; i < 2; ++i) {
                                        IBlockState bs = cache.getBlockState(new BlockPos(c[0] + x[0] + i, c[1] + x[1] + k, c[2] + x[2] + j));
                                        Block b = bs.getBlock();
                                        if(Main.shouldSmooth(b) && block != Blocks.SNOW_LAYER && block != Blocks.GRASS) {
                                            block = b;
                                            meta = b.getMetaFromState(bs);
                                            if(b == Blocks.SNOW_LAYER || b == Blocks.GRASS) {
                                                break label368;
                                            }
                                        }
                                    }
                                }
                            }

                            int[] br = new int[]{c[0] + x[0], c[1] + x[1] + 1, c[2] + x[2]};

                            label594:
                            for(int k = -1; k < 2; ++k) {
                                for(int j = -2; j < 3; ++j) {
                                    for(int i = -1; i < 2; ++i) {
                                        IBlockState bs = cache.getBlockState(new BlockPos(c[0] + x[0] + i, c[1] + x[1] + k, c[2] + x[2] + j));
                                        Block b = bs.getBlock();
                                        if(!b.isOpaqueCube(bs)) {
                                            br[0] = c[0] + x[0] + i;
                                            br[1] = c[1] + x[1] + k;
                                            br[2] = c[2] + x[2] + j;
                                            break label594;
                                        }
                                    }
                                }
                            }

                            IIcon icon = renderer.getBlockIconFromSideAndMetadata(block, 1, meta);
                            double tu0 = (double)icon.getMinUV();
                            double tu1 = (double)icon.getMaxU();
                            double tv0 = (double)icon.getMinV();
                            double tv1 = (double)icon.getMaxV();
                            int edgemask = edge_table[mask];
                            int ecount = 0;
                            float[] v = new float[]{0.0F, 0.0F, 0.0F};

                            for(int i = 0; i < 12; ++i) {
                                if((edgemask & 1 << i) != 0) {
                                    ++ecount;
                                    int e0 = cube_edges[i << 1];
                                    int e1 = cube_edges[(i << 1) + 1];
                                    float g0 = grid[e0];
                                    float g1 = grid[e1];
                                    float t = g0 - g1;
                                    if(Math.abs(t) > 0.0F) {
                                        t = g0 / t;
                                        int j = 0;

                                        for(int k = 1; j < 3; k <<= 1) {
                                            int a = e0 & k;
                                            int b = e1 & k;
                                            if(a != b) {
                                                v[j] += a != 0?1.0F - t:t;
                                            } else {
                                                v[j] += a != 0?1.0F:0.0F;
                                            }

                                            ++j;
                                        }
                                    }
                                }
                            }

                            float s = 1.0F / (float)ecount;

                            for(int i = 0; i < 3; ++i) {
                                v[i] = (float)(c[i] + x[i]) + s * v[i];
                            }

                            int tx = x[0] == 16?0:x[0];
                            int ty = x[1] == 16?0:x[1];
                            int tz = x[2] == 16?0:x[2];
                            long i1 = (long)(tx * 3129871) ^ (long)tz * 116129781L ^ (long)ty;
                            i1 = i1 * i1 * 42317861L + i1 * 11L;
                            v[0] = (float)((double)v[0] - ((double)((float)(i1 >> 16 & 15L) / 15.0F) - 0.5D) * 0.2D);
                            v[1] = (float)((double)v[1] - ((double)((float)(i1 >> 20 & 15L) / 15.0F) - 1.0D) * 0.2D);
                            v[2] = (float)((double)v[2] - ((double)((float)(i1 >> 24 & 15L) / 15.0F) - 0.5D) * 0.2D);
                            buffer[m] = v;

                            for(int i = 0; i < 3; ++i) {
                                if((edgemask & 1 << i) != 0) {
                                    int iu = (i + 1) % 3;
                                    int iv = (i + 2) % 3;
                                    if(x[iu] != 0 && x[iv] != 0) {
                                        int du = r[iu];
                                        int dv = r[iv];
                                        //tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));
                                        //tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2])); dont know what to do with these too
                                        float[] v0 = buffer[m];
                                        float[] v1 = buffer[m - du];
                                        float[] v2 = buffer[m - du - dv];
                                        float[] v3 = buffer[m - dv];
                                        if((mask & 1) != 0) {
                                            tess.addVertexWithUV((double)v0[0], (double)v0[1], (double)v0[2], tu0, tv1);
                                            tess.addVertexWithUV((double)v1[0], (double)v1[1], (double)v1[2], tu1, tv1);
                                            tess.addVertexWithUV((double)v2[0], (double)v2[1], (double)v2[2], tu1, tv0);
                                            tess.addVertexWithUV((double)v3[0], (double)v3[1], (double)v3[2], tu0, tv0);
                                        } else {
                                            tess.addVertexWithUV((double)v0[0], (double)v0[1], (double)v0[2], tu0, tv1);
                                            tess.addVertexWithUV((double)v3[0], (double)v3[1], (double)v3[2], tu1, tv1);
                                            tess.addVertexWithUV((double)v2[0], (double)v2[1], (double)v2[2], tu1, tv0);
                                            tess.addVertexWithUV((double)v1[0], (double)v1[1], (double)v1[2], tu0, tv0);
                                        }
                                    }
                                }
                            }
                        }

                        ++x[0];
                    }

                    ++x[1];
                }

                ++x[2];
                bufno ^= 1;
            }

            return true;
        }
    }

    static {
        int k = 0;

        for(int i = 0; i < 8; ++i) {
            for(int j = 1; j <= 4; j <<= 1) {
                int p = i ^ j;
                if(i <= p) {
                    cube_edges[k++] = i;
                    cube_edges[k++] = p;
                }
            }
        }

        for(int i = 0; i < 256; ++i) {
            int em = 0;

            for(int j = 0; j < 24; j += 2) {
                boolean a = (i & 1 << cube_edges[j]) != 0;
                boolean b = (i & 1 << cube_edges[j + 1]) != 0;
                em |= a != b?1 << (j >> 1):0;
            }

            edge_table[i] = em;
        }

    }

 

Link to comment
Share on other sites

The main problem you'll run into is that blocks no longer have textures, they now have models. An IBakedModel can have any number of BakedQuads, each of which belongs to an EnumFacing (or null) and has a texture.

 

You can use IBakedModel#getQuads to get the BakedQuads for an optional IBlockState and optional EnumFacing. You'll need to work out what to do if the model has either zero or more than one BakedQuads for EnumFacing.UP (probably blacklist that state from being smoothed).

 

Look at BlockRendererDispatcher#renderBlock to see how it gets the actual state from the in-world state, the model from the actual state and the extended state from the actual state before rendering the model.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

3 minutes ago, Choonster said:

The main problem you'll run into is that blocks no longer have textures, they now have models. An IBakedModel can have any number of BakedQuads, each of which belongs to an EnumFacing (or null) and has a texture.

 

You can use IBakedModel#getQuads to get the BakedQuads for an optional IBlockState and optional EnumFacing. You'll need to work out what to do if the model has either zero or more than one BakedQuads for EnumFacing.UP (probably blacklist that state from being smoothed).

 

Look at BlockRendererDispatcher#renderBlock to see how it gets the actual state from the in-world state, the model from the actual state and the extended state from the actual state before rendering the model.

how do i get the IBakedModel from block?

Link to comment
Share on other sites

2 minutes ago, lukas2005 said:

how do i get the IBakedModel from block?

 

As I said, look at BlockRendererDispatcher#renderBlock.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

2 minutes ago, Choonster said:

 

As I said, look at BlockRendererDispatcher#renderBlock.

well it uses non-static method getModelForState then how do i get BlockRendererDispatcher instance?EDIT ok i got it Minecraft.getMinecraft().getBlockRendererDispatcher()

Edited by lukas2005
Link to comment
Share on other sites

Just now, lukas2005 said:

well it uses non-static method getModelForState

 

Yes, you should use it too. Use Minecraft#getBlockRendererDispatcher to get the BlockRenderDispatcher instance.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

4 minutes ago, lukas2005 said:

now in IBakedModel#getQuads teres a strange long at the and called rand what shlou it be? random long?

 

That's a "random" number derived from the BlockPos, use MathHelper.getPositionRandom to calculate it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

ok i have the quads list now what do i do with a quad?]

 

EDIT: i got an object called TextureAtlasSprite from a quad and it seems to have almost same functions as the old IIcon object wich is great

Edited by lukas2005
Link to comment
Share on other sites

1 minute ago, lukas2005 said:

ok i have the quads list now what do i do with a quad?

 

Get its texture with BakedQuad#getSprite. This is a TextureAtlasSprite, a sprite on the block/item texture atlas (like IIcon).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

ok i now have my sizes but there is one more thing what are these?

tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));

tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2]));

Link to comment
Share on other sites

19 minutes ago, lukas2005 said:

ok i now have my sizes but there is one more thing what are these?

tess.setBrightness(block.getMixedBrightnessForBlock(Minecraft.getMinecraft().theWorld, br[0], br[1], br[2]));

tess.setColorOpaque_I(block.colorMultiplier(cache, c[0] + x[0], c[1] + x[1], c[2] + x[2]));

 

I can't really help you with rendering specifics like this, all I can suggest is looking at ForgeBlockModelRenderer#renderModelFlat/ForgeBlockModelRenderer#renderModelSmooth (called by BlockModelRenderer#renderModel) to see how they render block models.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.