Jump to content

Recommended Posts

Posted

I've been grepping for a while, and I can't find where Minecraft determines the reduced brightness of a block based on the time (with sunset starting at about 12000 and sunrise ending at about 0). As far as I can tell, the block's brightness is looked up in a table from a WorldProvider based on the 0-15 light level, but I can't find where the time factors in.

Posted

I don't have a problem accessing the world time. What I'm trying to do is find where Minecraft accesses the world time and calculates how much a block should be dimmed based on the time. Plugging in numbers and recompiling/testing a bajillion times isn't the way I want to figure out its coefficients.

Posted

Best answer I can give would be to ask the guy behind ccSensors or such about testing for light and how he did it, that may point you in the right direction.

Posted

No, the actual light level of the block is a separate value stored in the world data. It's used to render a shadow on the block based on how much sunlight is getting through. It's not the same thing as the dimness of the block as far as I can tell.

Posted

You're looking for getBlockLightValue in Chunk.java, reproduced below with some comments to explain the vague names. Every tick, calculateSkylightSubtracted from World.java is called, which determines the brightness based on getCelestialAngle, getRainStrength, and getWeightedThunderStrength. The skylightSubtracted variable is changed in tick() of WorldServer.java. Look at getBlockLightingValue_do in World.java for example usage.


    /**

    * Gets the amount of light on a block taking into account sunlight

    * par1: local x coordinate

    * par2: world y coordinate

    * par3: local z coordinate

    * par4: skylightSubtracted for a given World

    */

    public int getBlockLightValue(int par1, int par2, int par3, int par4)

    {

        // Get 16x16 x,z plane of blocks at the local y value (par2)

        // storageArrays is a 16x16x16 cube

        ExtendedBlockStorage var5 = this.storageArrays[par2 >> 4];

 

     

        // Invalid chunk plane - return default light value minus provided LightSubtracted (par4) due to weather/night

        if (var5 == null)

        {

            return !this.worldObj.provider.hasNoSky && par4 < EnumSkyBlock.Sky.defaultLightValue ? EnumSkyBlock.Sky.defaultLightValue - par4 : 0;

        }

        else

        {

            // If this chunk's world has a sky, return the skylight value at local x,y,z (y is at most 6 bits, z is at most 4 bits)

            int var6 = this.worldObj.provider.hasNoSky ? 0 : var5.getExtSkylightValue(par1, par2 & 15, par3);

 

            if (var6 > 0)

            {

                isLit = true;

            }

 

            // Modify skylight value by LightSubtracted due to weather/night

            var6 -= par4;

            int var7 = var5.getExtBlocklightValue(par1, par2 & 15, par3);

 

            // If the block is lit more than the natural lighting, use the block's lighting value (makes torches work)

            if (var7 > var6)

            {

                var6 = var7;

            }

 

            return var6;

        }

    }

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.

×
×
  • Create New...