Jump to content

Recommended Posts

Posted

I have a block in my mod that changes its texture using a custom block model, which is really a re-purposed ladder model. but I'm getting this really strange bug where any other blocks in the same chunk with a y value greater than or equal to that of my block will be displayed with the texture my block is currently using. If there are multiple instances of my block, the affected blocks show the texture of the first one placed.

 

Here are some screenshots of the bug:

 

  Reveal hidden contents

 

 

Here's my code:

 

  Reveal hidden contents

 

Posted

use setTextureFile

Don't override getTextureFile.

Also, multiple calls to getTileEntity is costly, cache its result.

And you are not reverting the texture override. You need to just call Forge's beforeBlockRender and afterBlockRender to have it setup the Tessellator properly.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

Changing to setTextureFile and removing override code for getTextureFile: Check.

Lowering number of calls to getTileEntity: Check.

Implementing beforeBlockRender and afterBlockRender: Check, unless I did it wrong. I just put those at the beginning and end of my renderWorldBlock() method, right? Like this:

public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
	ForgeHooksClient.beforeBlockRender(block, renderer);
	if (modelId == ClientProxySG.GunRackRenderID){
		return renderBlockGunRack(block, x, y, z, renderer);
	}
	return false;
}

public boolean renderBlockGunRack(Block block, int i, int j, int k, RenderBlocks renderblocks){
	//if(block.getRenderType() == ClientProxySG.GunRackRenderID){
		Tessellator var5 = Tessellator.instance;
        //int var6 = block.getBlockTexture(renderblocks.blockAccess, i, j, k, 0);
		int var6 = 128;
		TileEntityNewGunRack ent = (TileEntityNewGunRack) renderblocks.blockAccess.getBlockTileEntity(i, j, k);
        if(ent != null) var6 = ((TileEntityNewGunRack)renderblocks.blockAccess.getBlockTileEntity(i, j, k)).texture;
        renderblocks.overrideBlockTexture = var6;
        var5.setBrightness(block.getMixedBrightnessForBlock(renderblocks.blockAccess, i, j, k));
        float var7 = 1.0F;
        var5.setColorOpaque_F(var7, var7, var7);
        int var22 = (var6 & 15) << 4;
        int var8 = var6 & 240;
        double var9 = (double)((float)var22 / 256.0F);
        double var11 = (double)(((float)var22 + 15.99F) / 256.0F);
        double var13 = (double)((float)var8 / 256.0F);
        double var15 = (double)(((float)var8 + 15.99F) / 256.0F);
        int var17 = renderblocks.blockAccess.getBlockMetadata(i, j, k);
        double var18 = 0.0D;
        double var20 = 0.05000000074505806D;
        ForgeHooksClient.afterBlockRender(block, renderblocks);

        if (var17 == 5)
        {
            var5.addVertexWithUV((double)i + var20, (double)(j + 1) + var18, (double)(k + 1) + var18, var9, var13);
            var5.addVertexWithUV((double)i + var20, (double)(j + 0) - var18, (double)(k + 1) + var18, var9, var15);
            var5.addVertexWithUV((double)i + var20, (double)(j + 0) - var18, (double)(k + 0) - var18, var11, var15);
            var5.addVertexWithUV((double)i + var20, (double)(j + 1) + var18, (double)(k + 0) - var18, var11, var13);
        }

        if (var17 == 4)
        {
            var5.addVertexWithUV((double)(i + 1) - var20, (double)(j + 0) - var18, (double)(k + 1) + var18, var11, var15);
            var5.addVertexWithUV((double)(i + 1) - var20, (double)(j + 1) + var18, (double)(k + 1) + var18, var11, var13);
            var5.addVertexWithUV((double)(i + 1) - var20, (double)(j + 1) + var18, (double)(k + 0) - var18, var9, var13);
            var5.addVertexWithUV((double)(i + 1) - var20, (double)(j + 0) - var18, (double)(k + 0) - var18, var9, var15);
        }

        if (var17 == 3)
        {
            var5.addVertexWithUV((double)(i + 1) + var18, (double)(j + 0) - var18, (double)k + var20, var11, var15);
            var5.addVertexWithUV((double)(i + 1) + var18, (double)(j + 1) + var18, (double)k + var20, var11, var13);
            var5.addVertexWithUV((double)(i + 0) - var18, (double)(j + 1) + var18, (double)k + var20, var9, var13);
            var5.addVertexWithUV((double)(i + 0) - var18, (double)(j + 0) - var18, (double)k + var20, var9, var15);
        }

        if (var17 == 2)
        {
            var5.addVertexWithUV((double)(i + 1) + var18, (double)(j + 1) + var18, (double)(k + 1) - var20, var9, var13);
            var5.addVertexWithUV((double)(i + 1) + var18, (double)(j + 0) - var18, (double)(k + 1) - var20, var9, var15);
            var5.addVertexWithUV((double)(i + 0) - var18, (double)(j + 0) - var18, (double)(k + 1) - var20, var11, var15);
            var5.addVertexWithUV((double)(i + 0) - var18, (double)(j + 1) + var18, (double)(k + 1) - var20, var11, var13);
        }
	//}
        return true;
    }

 

So far, the result is the same.

Posted

Upon closer inspection of afterBlockRender, I discovered that overrideBlockTexture must be -1 for it to work. Added that at the end of renderBlockGunRack and it worked.

Posted

Just a note, your whole override texture is useless.

 

Don't use it.

 

Also, you should really rename your variables it makes it less obvious that you just copy/pasted decompiled code.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.