jakj Posted September 26, 2012 Posted September 26, 2012 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.
okamikk Posted September 26, 2012 Posted September 26, 2012 just a note from someone who knows almost nothing about coding, what if the lighting is based on the sun movement, with each coordinate being assigned a value?
jakj Posted September 26, 2012 Author Posted September 26, 2012 I tried that, but getCelestialAngle is used only when drawing the skybox as far as I can tell.
Lethosos Posted September 27, 2012 Posted September 27, 2012 getCelestialAngle Private or public? I suspect it's a private function from your comment, but it can't be called on otherwise?
jakj Posted September 27, 2012 Author Posted September 27, 2012 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.
Lethosos Posted September 27, 2012 Posted September 27, 2012 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.
jakj Posted September 27, 2012 Author Posted September 27, 2012 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.
phoenix987 Posted September 27, 2012 Posted September 27, 2012 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; } }
jakj Posted September 27, 2012 Author Posted September 27, 2012 Damn, how'd I miss that? You're a genius.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now