1
0
Fork 0

minor light cleanup

This commit is contained in:
Sen 2025-08-27 20:25:20 +02:00
parent aaad753263
commit 375a67d10f
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
23 changed files with 53 additions and 215 deletions

View file

@ -39,6 +39,7 @@ import client.renderer.tileentity.SpecialRenderer;
import client.world.ChunkClient;
import common.block.Block;
import common.block.Material;
import common.block.artificial.BlockSlab;
import common.block.liquid.BlockDynamicLiquid;
import common.block.liquid.BlockLiquid;
import common.block.liquid.BlockStaticLiquid;
@ -3506,6 +3507,27 @@ public class Renderer {
}
}
private static final int getLightmapValue(IWorldAccess world, BlockPos pos) {
Block block = world.getState(pos).getBlock();
int light = world.getCombinedLight(pos, block.getLight());
if(light == 0 && block instanceof BlockSlab) {
pos = pos.down();
block = world.getState(pos).getBlock();
return world.getCombinedLight(pos, block.getLight());
}
return light;
}
private static final int getLightmapValueLiquid(IWorldAccess world, BlockPos pos) {
int i = world.getCombinedLight(pos, 0);
int j = world.getCombinedLight(pos.up(), 0);
int k = i & 255;
int l = j & 255;
int i1 = i >> 16 & 255;
int j1 = j >> 16 & 255;
return (k > l ? k : l) | (i1 > j1 ? i1 : j1) << 16;
}
public boolean renderModel(IWorldAccess blockAccessIn, IBakedModel modelIn, State blockStateIn, BlockPos blockPosIn, RenderBuffer worldRendererIn, boolean checkSides)
{
Block blockIn = blockStateIn.getBlock();
@ -3522,7 +3544,7 @@ public class Renderer {
if (!checkSides || blockIn.canRender(blockAccessIn, blockpos, enumfacing))
{
int i = blockIn.getLightmapValue(blockAccessIn, blockpos);
int i = getLightmapValue(blockAccessIn, blockpos);
this.renderModelStandardQuads(blockAccessIn, blockIn, blockPosIn, enumfacing, i, false, worldRendererIn, list, bitset);
flag = true;
}
@ -3551,7 +3573,7 @@ public class Renderer {
if (ownBrightness)
{
this.fillQuadBounds(blockIn, bakedquad.getVertexData(), bakedquad.getFace(), (float[])null, boundsFlags);
brightnessIn = boundsFlags.get(0) ? blockIn.getLightmapValue(blockAccessIn, blockPosIn.offset(bakedquad.getFace())) : blockIn.getLightmapValue(blockAccessIn, blockPosIn);
brightnessIn = boundsFlags.get(0) ? getLightmapValue(blockAccessIn, blockPosIn.offset(bakedquad.getFace())) : getLightmapValue(blockAccessIn, blockPosIn);
}
worldRendererIn.addVertexData(bakedquad.getVertexData());
@ -3713,7 +3735,7 @@ public class Renderer {
f20 = textureatlassprite.getInterpolatedV((double)(8.0F + (-f22 - f21) * 16.0F));
}
int k2 = blockliquid.getLightmapValue(blockAccess, blockPosIn);
int k2 = getLightmapValueLiquid(blockAccess, blockPosIn);
int l2 = k2 >> 16 & 65535;
int i3 = k2 & 65535;
float f24 = f4;
@ -3739,7 +3761,7 @@ public class Renderer {
float f36 = atextureatlassprite[0].getMaxU();
float f37 = atextureatlassprite[0].getMinV();
float f38 = atextureatlassprite[0].getMaxV();
int l1 = blockliquid.getLightmapValue(blockAccess, blockPosIn.down());
int l1 = getLightmapValueLiquid(blockAccess, blockPosIn.down());
int i2 = l1 >> 16 & 65535;
int j2 = l1 & 65535;
worldRendererIn.pos(d0, d1, d2 + 1.0D).color(f3, f3, f3, 1.0F).tex((double)f35, (double)f38).lightmap(i2, j2).endVertex();
@ -3829,7 +3851,7 @@ public class Renderer {
float f28 = textureatlassprite1.getInterpolatedV((double)((1.0F - f39) * 16.0F * 0.5F));
float f29 = textureatlassprite1.getInterpolatedV((double)((1.0F - f40) * 16.0F * 0.5F));
float f30 = textureatlassprite1.getInterpolatedV(8.0D);
int j = blockliquid.getLightmapValue(blockAccess, blockpos);
int j = getLightmapValueLiquid(blockAccess, blockpos);
int k = j >> 16 & 65535;
int l = j & 65535;
float f31 = i1 < 2 ? f5 : f6;

View file

@ -2,6 +2,7 @@ package client.renderer.entity;
import client.renderer.Frustum;
import common.entity.Entity;
import common.util.BlockPos;
import common.util.BoundingBox;
public abstract class Render<T extends Entity>
@ -53,4 +54,9 @@ public abstract class Render<T extends Entity>
{
return this.manager;
}
protected static float getBrightness(Entity entity) {
BlockPos pos = new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ);
return entity.worldObj.isBlockLoaded(pos) ? entity.worldObj.getLightBrightness(pos) : 0.0F;
}
}

View file

@ -43,7 +43,7 @@ public class RenderBlockEntity extends Render<Entity>
// float f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F;
this.bindEntityTexture(entity);
GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
Client.CLIENT.renderer.renderBlockEntity(this.state, entity.getBrightness(partialTicks));
Client.CLIENT.renderer.renderBlockEntity(this.state, getBrightness(entity));
GL11.glTranslatef(0.0F, 0.0F, 1.0F);
// if (entity.fuse / 5 % 2 == 0)

View file

@ -44,7 +44,7 @@ public abstract class RenderLiving<T extends EntityLiving> extends RendererLivin
}
public void setLightmap(T entity, float partial) {
int l = entity.getBrightnessForRender(partial);
int l = RenderManager.getBrightnessForRender(entity);
int a = l % 65536;
int b = l / 65536;
GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)a / 1.0F, (float)b / 1.0F);

View file

@ -20,6 +20,7 @@ import common.collect.Maps;
import common.entity.Entity;
import common.entity.types.EntityLiving;
import common.init.SpeciesRegistry.ModelType;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.Vec3;
import common.world.World;
@ -119,6 +120,11 @@ public class RenderManager {
return render != null && render.shouldRender(entityIn, camX, camY, camZ);
}
public static int getBrightnessForRender(Entity entity) {
BlockPos pos = new BlockPos(entity.posX, entity.posY + (double)entity.getEyeHeight(), entity.posZ);
return entity.worldObj.isBlockLoaded(pos) ? entity.worldObj.getCombinedLight(pos, 0) : 0;
}
public boolean renderEntity(Entity entity, float partialTicks) {
if(entity.ticksExisted == 0) {
entity.lastTickPosX = entity.posX;
@ -129,7 +135,7 @@ public class RenderManager {
double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)partialTicks;
double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)partialTicks;
double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)partialTicks;
int i = entity.getBrightnessForRender(partialTicks);
int i = getBrightnessForRender(entity);
if(entity.isBurning()) {
i = 15728880;

View file

@ -124,7 +124,7 @@ public class RenderMinecart<T extends EntityCart> extends Render<T>
protected void func_180560_a(T minecart, float partialTicks, State state)
{
GL11.glPushMatrix();
Client.CLIENT.renderer.renderBlockEntity(state, minecart.getBrightness(partialTicks));
Client.CLIENT.renderer.renderBlockEntity(state, getBrightness(minecart));
GL11.glPopMatrix();
}
}

View file

@ -39,7 +39,7 @@ public class RenderTntPrimed extends Render<EntityTnt>
this.bindEntityTexture(entity);
GL11.glTranslatef(-0.5F, -0.5F, 0.5F);
Block tnt = BlockRegistry.byName("tnt" + (entity.explosionSize <= 0 || entity.explosionSize >= 8 ? "" : "_" + entity.explosionSize));
renderer.renderBlockEntity(tnt.getState(), entity.getBrightness(partialTicks));
renderer.renderBlockEntity(tnt.getState(), getBrightness(entity));
GL11.glTranslatef(0.0F, 0.0F, 1.0F);
if (entity.fuse / 5 % 2 == 0)

View file

@ -1,6 +1,5 @@
package client.renderer.entity;
import client.renderer.GlState;
import client.renderer.layers.LayerWolfCollar;
import client.renderer.model.ModelBase;
import common.entity.animal.EntityWolf;
@ -26,20 +25,6 @@ public class RenderWolf extends RenderLiving<EntityWolf>
return livingBase.getTailRotation();
}
/**
* Renders the desired {@code T} type Entity.
*/
public void doRender(EntityWolf entity, double x, double y, double z, float partialTicks)
{
if (entity.isWolfWet())
{
float f = entity.getBrightness(partialTicks) * entity.getShadingWhileWet(partialTicks);
GlState.color(f, f, f, 1.0F);
}
super.doRender(entity, x, y, z, partialTicks);
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/

View file

@ -29,7 +29,7 @@ public class RenderXp extends Render<EntityXp> {
float bx = 1.0F;
float dx = 0.5F;
float dy = 0.25F;
int light = entity.getBrightnessForRender(partial);
int light = RenderManager.getBrightnessForRender(entity);
int block = light % 65536;
int sky = light / 65536;
GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)block / 1.0F, (float)sky / 1.0F);

View file

@ -157,10 +157,7 @@ public class ModelWolf extends ModelBase
this.wolfLeg4.rotateAngleX = ExtMath.cos(p_78086_2_ * 0.6662F) * 1.4F * p_78086_3_;
}
this.wolfHeadMain.rotateAngleZ = wolf.getInterestedAngle(partialTickTime) + wolf.getShakeAngle(partialTickTime, 0.0F);
this.wolfMane.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.08F);
this.wolfBody.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.16F);
this.wolfTail.rotateAngleZ = wolf.getShakeAngle(partialTickTime, -0.2F);
this.wolfHeadMain.rotateAngleZ = wolf.getInterestedAngle(partialTickTime);
}
/**

View file

@ -13,7 +13,6 @@ import java.util.Set;
import java.util.Map.Entry;
import java.util.function.Function;
import common.block.artificial.BlockSlab;
import common.block.natural.BlockSnow;
import common.collect.ImmutableList;
import common.collect.ImmutableMap;
@ -1057,18 +1056,6 @@ public class Block {
(double)pos.getX() + this.maxX, (double)pos.getY() + this.maxY, (double)pos.getZ() + this.maxZ);
}
@Clientside
public int getLightmapValue(IWorldAccess world, BlockPos pos) {
Block block = world.getState(pos).getBlock();
int light = world.getCombinedLight(pos, block.getLight());
if(light == 0 && block instanceof BlockSlab) {
pos = pos.down();
block = world.getState(pos).getBlock();
return world.getCombinedLight(pos, block.getLight());
}
return light;
}
@Clientside
public boolean hasTransparency() {
return false;

View file

@ -212,17 +212,6 @@ public abstract class BlockLiquid extends Block
return this.flowRate >= 0 ? this.flowRate : (worldIn.isLavaFaster(pos) ? (-this.flowRate / 3) : (-this.flowRate));
}
public int getLightmapValue(IWorldAccess worldIn, BlockPos pos)
{
int i = worldIn.getCombinedLight(pos, 0);
int j = worldIn.getCombinedLight(pos.up(), 0);
int k = i & 255;
int l = j & 255;
int i1 = i >> 16 & 255;
int j1 = j >> 16 & 255;
return (k > l ? k : l) | (i1 > j1 ? i1 : j1) << 16;
}
@Clientside
public boolean hasTransparency() {
return !this.opaque;

View file

@ -1104,21 +1104,6 @@ public abstract class Entity
}
}
public int getBrightnessForRender(float partialTicks)
{
BlockPos blockpos = new BlockPos(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ);
return this.worldObj.isBlockLoaded(blockpos) ? this.worldObj.getCombinedLight(blockpos, 0) : 0;
}
/**
* Gets how bright this entity is.
*/
public float getBrightness(float partialTicks)
{
BlockPos blockpos = new BlockPos(this.posX, this.posY + (double)this.getEyeHeight(), this.posZ);
return this.worldObj.isBlockLoaded(blockpos) ? this.worldObj.getLightBrightness(blockpos) : 0.0F;
}
/**
* Sets the reference to the World object.
*/

View file

@ -111,7 +111,7 @@ public class EntityMouse extends EntityAnimal {
public float getBlockPathWeight(BlockPos pos)
{
return 0.5F - this.worldObj.getLightBrightness(pos);
return 0.5F;
}
public void setCustomNameTag(String name) {

View file

@ -30,31 +30,15 @@ import common.item.consumable.ItemFood;
import common.item.material.ItemDye;
import common.pathfinding.PathNavigateGround;
import common.tags.TagObject;
import common.util.Clientside;
import common.util.ExtMath;
import common.util.ParticleType;
import common.util.Color;
import common.vars.Vars;
import common.world.World;
public class EntityWolf extends EntityTameable
{
/** Float used to smooth the rotation of the wolf head */
private float headRotationCourse;
private float headRotationCourseOld;
/** true is the wolf is wet else false */
private boolean isWet;
/** True if the wolf is shaking else False */
private boolean isShaking;
/**
* This time increases while wolf is shaking and emitting water particles.
*/
private float timeWolfIsShaking;
private float prevTimeWolfIsShaking;
public EntityWolf(World worldIn)
{
super(worldIn);
@ -185,14 +169,6 @@ public class EntityWolf extends EntityTameable
{
super.onLivingUpdate();
if (!this.worldObj.client && this.isWet && !this.isShaking && !this.hasPath() && this.onGround)
{
this.isShaking = true;
this.timeWolfIsShaking = 0.0F;
this.prevTimeWolfIsShaking = 0.0F;
this.worldObj.setEntityState(this, (byte)8);
}
if (!this.worldObj.client && this.getAttackTarget() == null && this.isAngry())
{
this.setAngry(false);
@ -215,77 +191,6 @@ public class EntityWolf extends EntityTameable
{
this.headRotationCourse += (0.0F - this.headRotationCourse) * 0.4F;
}
if (this.isWet())
{
this.isWet = true;
this.isShaking = false;
this.timeWolfIsShaking = 0.0F;
this.prevTimeWolfIsShaking = 0.0F;
}
else if ((this.isWet || this.isShaking) && this.isShaking)
{
if (this.timeWolfIsShaking == 0.0F)
{
this.playSound(SoundEvent.WOLF_SHAKE, this.getSoundVolume());
}
this.prevTimeWolfIsShaking = this.timeWolfIsShaking;
this.timeWolfIsShaking += 0.05F;
if (this.prevTimeWolfIsShaking >= 2.0F)
{
this.isWet = false;
this.isShaking = false;
this.prevTimeWolfIsShaking = 0.0F;
this.timeWolfIsShaking = 0.0F;
}
if (this.timeWolfIsShaking > 0.4F)
{
float f = (float)this.getEntityBoundingBox().minY;
int i = (int)(ExtMath.sin((this.timeWolfIsShaking - 0.4F) * (float)Math.PI) * 7.0F);
for (int j = 0; j < i; ++j)
{
float f1 = (this.rand.floatv() * 2.0F - 1.0F) * this.width * 0.5F;
float f2 = (this.rand.floatv() * 2.0F - 1.0F) * this.width * 0.5F;
this.worldObj.clientParticle(ParticleType.SPLASH, this.posX + (double)f1, (double)(f + 0.8F), this.posZ + (double)f2);
}
}
}
}
/**
* True if the wolf is wet
*/
public boolean isWolfWet()
{
return this.isWet;
}
/**
* Used when calculating the amount of shading to apply while the wolf is wet.
*/
public float getShadingWhileWet(float p_70915_1_)
{
return 0.75F + (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70915_1_) / 2.0F * 0.25F;
}
public float getShakeAngle(float p_70923_1_, float p_70923_2_)
{
float f = (this.prevTimeWolfIsShaking + (this.timeWolfIsShaking - this.prevTimeWolfIsShaking) * p_70923_1_ + p_70923_2_) / 1.8F;
if (f < 0.0F)
{
f = 0.0F;
}
else if (f > 1.0F)
{
f = 1.0F;
}
return ExtMath.sin(f * (float)Math.PI) * ExtMath.sin(f * (float)Math.PI * 11.0F) * 0.15F * (float)Math.PI;
}
public float getInterestedAngle(float p_70917_1_)
@ -430,21 +335,6 @@ public class EntityWolf extends EntityTameable
return super.interact(player);
}
@Clientside
public void handleStatusUpdate(byte id)
{
if (id == 8)
{
this.isShaking = true;
this.timeWolfIsShaking = 0.0F;
this.prevTimeWolfIsShaking = 0.0F;
}
else
{
super.handleStatusUpdate(id);
}
}
public float getTailRotation()
{
return this.isAngry() ? 1.5393804F : (this.isTamed() ? (0.55F - (20.0F - (float)this.dataWatcher.getWatchableObjectInt(18)) * 0.02F) * (float)Math.PI : ((float)Math.PI / 5F));

View file

@ -85,23 +85,6 @@ public class EntityXp extends Entity implements IObjectData
return this.dataWatcher.getWatchableObjectInt(1);
}
public int getBrightnessForRender(float partialTicks)
{
float f = 0.5F;
f = ExtMath.clampf(f, 0.0F, 1.0F);
int i = super.getBrightnessForRender(partialTicks);
int j = i & 255;
int k = i >> 16 & 255;
j = j + (int)(f * 15.0F * 16.0F);
if (j > 240)
{
j = 240;
}
return j | k << 16;
}
/**
* Called to update the entity's position/logic.
*/

View file

@ -20,9 +20,7 @@ public class EntityArachnoid extends EntityNPC {
}
public boolean continueExecuting() {
float f = this.attacker.getBrightness(1.0F);
if(f >= 0.5F && this.attacker.getRNG().chance(100)) {
if(this.attacker.getRNG().chance(100)) {
this.attacker.setAttackTarget((EntityLiving)null);
return false;
}

View file

@ -350,19 +350,6 @@ public abstract class EntityProjectile extends Entity
// }
}
/**
* Gets how bright this entity is.
*/
public float getBrightness(float partialTicks)
{
return 1.0F;
}
public int getBrightnessForRender(float partialTicks)
{
return 15728880;
}
public int getTrackingRange() {
return 64;
}

View file

@ -93,7 +93,7 @@ public abstract class EntityAnimal extends EntityLiving
public float getBlockPathWeight(BlockPos pos)
{
return this.worldObj.getState(pos.down()).getBlock() == Blocks.grass ? 10.0F : this.worldObj.getLightBrightness(pos) - 0.5F;
return this.worldObj.getState(pos.down()).getBlock() == Blocks.grass ? 10.0F : 0.5F;
}
public void writeEntity(TagObject tagCompound)

View file

@ -100,7 +100,6 @@ public enum SoundEvent {
WOLF_GROWL("wolf_growl1", "wolf_growl2", "wolf_growl3"),
WOLF_HURT("wolf_hurt1", "wolf_hurt2", "wolf_hurt3"),
WOLF_PANTING("wolf_panting"),
WOLF_SHAKE("wolf_shake"),
WOLF_WHINE("wolf_whine"),
FOX_DEATH("fox_death"),

View file

@ -2,9 +2,11 @@ package common.world;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.Clientside;
public interface IWorldAccess extends IBlockAccess
{
TileEntity getTileEntity(BlockPos pos);
@Clientside
int getCombinedLight(BlockPos pos, int lightValue);
}

View file

@ -32,6 +32,7 @@ import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.BoundingBox;
import common.util.ChunkPos;
import common.util.Clientside;
import common.util.ExtMath;
import common.util.Facing;
import common.util.HitPosition;
@ -405,6 +406,7 @@ public abstract class World implements IWorldAccess {
}
}
@Clientside
public int getCombinedLight(BlockPos pos, int lightValue) {
int i = this.getLightFromNeighborsFor(LightType.SKY, pos);
int j = this.getLightFromNeighborsFor(LightType.BLOCK, pos);