Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Custom Block Render Issues: Brightness is incorrect
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
Draco18s

Custom Block Render Issues: Brightness is incorrect

By Draco18s, June 10, 2013 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 10, 2013

We'll start with a picture of what I have

 

width=800 height=449http://s11.postimg.org/k3dpbpw83/2013_06_10_17_42_07.png[/img]

 

The block itself actually exists in a different place than its rendering.  One block down and one block "in" (the block attaches to a solid surface, like a ladder, and renders 1 block below that in order to cover an open space, for tripwire hooks).

 

Problem is, I can't get it to render at the correct brightness.  The getMixedBrightnessForBlock function seems to return full sun despite the fact that that space is not under full sun (if I cover things over it still renders too bright, although it does dim as the light value is reduced).

 

How can I fix this?

 

Render code:

package draco18s.traps.client;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class RenderCoverPlate implements ISimpleBlockRenderingHandler {
private int renderType;

public RenderCoverPlate(int r) {
	renderType = r;
}

@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {

}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
        
	Tessellator tessellator = Tessellator.instance;
        int l = world.getBlockMetadata(x, y, z);
        //gets the texture based on block location, the block blends in to neighbors, grabbing their texture
        Icon icon = block.getBlockTexture(world, x, y, z, 2);

        double f = 1F/64;
        
        switch(l) {
        case 2:
        	z++;
        	break;
        case 3:
        	z--;
        	break;
        case 4:
        	x++;
        	break;
        case 5:
        	x--;
        	break;
        }
        y--;
        int brightness = block.getMixedBrightnessForBlock(world, x, y, z);
        tessellator.setBrightness(brightness);
        tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
        
        double d0 = (double)icon.getMinU();
        double d1 = (double)icon.getMinV();
        double d2 = (double)icon.getMaxU();
        double d3 = (double)icon.getMaxV();
        double d5 = (double)(x + 1);
        double d7 = (double)(x);
        double d9 = (double)(z);
        double d11 = (double)(z + 1);
        double d13 = (double)(y + 1);
        double d15 = (double)(y);
        
        tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
        tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d5, d15, d9, d0, d3);
        tessellator.addVertexWithUV(d5, d13, d9, d0, d1);

        tessellator.addVertexWithUV(d5, d13, d9, d2, d1);
        tessellator.addVertexWithUV(d5, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d5, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d5, d13, d11, d0, d1);

        tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
        tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d7, d13, d9, d2, d1);

        tessellator.addVertexWithUV(d5, d13, d11, d2, d1);
        tessellator.addVertexWithUV(d5, d15, d11, d2, d3);
        tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d7, d13, d11, d0, d1);

        //gets the little "hole" texture from the blocks registered texture, renders ever so slightly in front to avoid z-fighting
        icon = block.getIcon(0, 0);
        d0 = (double)icon.getMinU();
        d1 = (double)icon.getMinV();
        d2 = (double)icon.getMaxU();
        d3 = (double)icon.getMaxV();
        d5 = (double)(x + 1 + f);
        d7 = (double)(x - f);
        d9 = (double)(z - f);
        d11 = (double)(z + 1 + f);
        d13 = (double)(y + 1);
        d15 = (double)(y);
        
        tessellator.addVertexWithUV(d7, d13, d9, d2, d1);
        tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d5, d15, d9, d0, d3);
        tessellator.addVertexWithUV(d5, d13, d9, d0, d1);

        tessellator.addVertexWithUV(d5, d13, d9, d2, d1);
        tessellator.addVertexWithUV(d5, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d5, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d5, d13, d11, d0, d1);

        tessellator.addVertexWithUV(d7, d13, d11, d0, d1);
        tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d7, d15, d9, d2, d3);
        tessellator.addVertexWithUV(d7, d13, d9, d2, d1);

        tessellator.addVertexWithUV(d5, d13, d11, d2, d1);
        tessellator.addVertexWithUV(d5, d15, d11, d2, d3);
        tessellator.addVertexWithUV(d7, d15, d11, d0, d3);
        tessellator.addVertexWithUV(d7, d13, d11, d0, d1);

	return false;
}

@Override
public boolean shouldRender3DInInventory() {
	return true;
}

@Override
public int getRenderId() {
	return renderType;
}
}

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

ObsequiousNewt    84

ObsequiousNewt

ObsequiousNewt    84

  • Dragon Slayer
  • ObsequiousNewt
  • Forge Modder
  • 84
  • 751 posts
Posted June 10, 2013

Try world.getBlockLightValue().

  • Quote

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 11, 2013

Try world.getBlockLightValue().

 

I shall try that.  Ty.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 11, 2013

That seems to be working better, but...

 

2013_06_10_22_25_52.png

 

:\

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 11, 2013

Still need help with this.  Brightness integers are weird.

I solved the alpha problem (seems that bits 9 to 16 effect the alpha, 21 to 24 are brightness, and the lowest 8 are color; 17 to 20 appear unused) but now I have an absolute brightness issue and color problem.

 

I'm actually stripping out the 3rd bit of the absolute brightness to tone it down some (helps, but not enough in some cases; 4th bit too much in all cases).

 

And this is what it looks like under various conditions:

 

Full sun.  Color is off.  Absolute brightness perfect.

Near-full darkness.  Very slight color difference.  Absolute brightness perfect.

Torch light.  Color perfect.  Absolute brightness out of whack.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

ObsequiousNewt    84

ObsequiousNewt

ObsequiousNewt    84

  • Dragon Slayer
  • ObsequiousNewt
  • Forge Modder
  • 84
  • 751 posts
Posted June 11, 2013

The problem is, brightness works differently for specially rendered blocks and normal blocks. I'm afraid I don't know how to fix your problem. :/

  • Quote

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 11, 2013

The problem is, brightness works differently for specially rendered blocks and normal blocks.

 

Dafuk.

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
Share on other sites

Draco18s    2416

Draco18s

Draco18s    2416

  • Reality Controller
  • Draco18s
  • Members
  • 2416
  • 16012 posts
Posted June 11, 2013

Did this:

int brightness = Block.blocksList[block.stone.blockID].getMixedBrightnessForBlock(world, x, y, z);

Instead of this:

int brightness = block.getMixedBrightnessForBlock(world, x, y, z);

 

And it got better.  Only "flaw" is that it has the brightness/color of the top face rather than the side face of that location (specifically, the brightness/color of the top face of the block below where I'm rendering).

  • Quote

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • LessyDoggy
      Forge 1.12.2 Installing Bug

      By LessyDoggy · Posted 1 hour ago

      So I used forge 1.16.5 but now I cant change it too 1.12.2 no mather what. I have tried Installing client, Installing server and extract but nothing works. I even removed forge 1.16.5 from my computer but I still have that verison on and idk how to change it.
    • Yourskillx2
      !!Keeps crashing during launch!!

      By Yourskillx2 · Posted 1 hour ago

      I have a decent sized mod pack with around 90 mods and every time I go to launch the game, it loads some stuff then crashes with exit code 0, I cannot figure out if its a mod in the pack doing it, like maybe not a release version or if it just doesn't work with Mc like its supposed to.
    • IMaironI
      server error

      By IMaironI · Posted 8 hours ago

      2021-03-06-8.log
    • diesieben07
      server error

      By diesieben07 · Posted 8 hours ago

      Like I already said: The logs folder.
    • prototype204
      Attacking/Hitting issue

      By prototype204 · Posted 8 hours ago

      I am no longer able to attack animals or mobs in the game, however they are still able to attack me. I checked to verify that the mods I downloaded weren't the issue. I think they might be an error code in forge 1.16.5 however if anyone knows what I could do to fix this. P.S. I could still break bricks. 
  • Topics

    • LessyDoggy
      0
      Forge 1.12.2 Installing Bug

      By LessyDoggy
      Started 1 hour ago

    • Yourskillx2
      0
      !!Keeps crashing during launch!!

      By Yourskillx2
      Started 1 hour ago

    • IMaironI
      13
      server error

      By IMaironI
      Started 12 hours ago

    • prototype204
      0
      Attacking/Hitting issue

      By prototype204
      Started 8 hours ago

    • BeardlessBrady
      3
      [1.16.5] Adding arguments to DeferredRegister and RegistryObject

      By BeardlessBrady
      Started 12 hours ago

  • Who's Online (See full list)

    • Kreepydude
    • VecsonON
    • zlappedx3
    • DavidM
    • troublemaker_47
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Custom Block Render Issues: Brightness is incorrect
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community