Update dynamic lights

This commit is contained in:
PeytonPlayz595 2024-06-07 18:08:26 -04:00
parent 9e952ad73a
commit b125383b56
2 changed files with 43 additions and 51 deletions

View File

@ -51,6 +51,10 @@ public class DynamicLight {
double d4 = d1 - this.lastPosZ;
double d5 = 0.1D;
int i = MathHelper.floor_double(d6);
int i1 = MathHelper.floor_double(d0);
int i2 = MathHelper.floor_double(d1);
if (Math.abs(d2) > d5 || Math.abs(d3) > d5 || Math.abs(d4) > d5 || this.lastLightLevel != j) {
this.lastPosX = d6;
this.lastPosY = d0;
@ -60,7 +64,7 @@ public class DynamicLight {
World world = p_update_1_.getWorld();
if (world != null) {
this.blockPosMutable.func_181079_c(MathHelper.floor_double(d6), MathHelper.floor_double(d0), MathHelper.floor_double(d1));
this.blockPosMutable.func_181079_c(i, i1, i2);
IBlockState iblockstate = world.getBlockState(this.blockPosMutable);
Block block = iblockstate.getBlock();
this.underwater = block == Blocks.water;
@ -69,9 +73,9 @@ public class DynamicLight {
Set < BlockPos > set = new HashSet();
if (j > 0) {
EnumFacing enumfacing2 = (MathHelper.floor_double(d6) & 15) >= 8 ? EnumFacing.EAST : EnumFacing.WEST;
EnumFacing enumfacing = (MathHelper.floor_double(d0) & 15) >= 8 ? EnumFacing.UP : EnumFacing.DOWN;
EnumFacing enumfacing1 = (MathHelper.floor_double(d1) & 15) >= 8 ? EnumFacing.SOUTH : EnumFacing.NORTH;
EnumFacing enumfacing2 = (i & 15) >= 8 ? EnumFacing.EAST : EnumFacing.WEST;
EnumFacing enumfacing = (i1 & 15) >= 8 ? EnumFacing.UP : EnumFacing.DOWN;
EnumFacing enumfacing1 = (i2 & 15) >= 8 ? EnumFacing.SOUTH : EnumFacing.NORTH;
BlockPos blockpos = new BlockPos(d6, d0, d1);
RenderChunk renderchunk = p_update_1_.getRenderChunk(blockpos);
RenderChunk renderchunk1 = p_update_1_.getRenderChunk(renderchunk, enumfacing2);

View File

@ -41,12 +41,10 @@ public class DynamicLights {
public static void entityAdded(Entity p_entityAdded_0_, RenderGlobal p_entityAdded_1_) {}
public static void entityRemoved(Entity p_entityRemoved_0_, RenderGlobal p_entityRemoved_1_) {
synchronized(mapDynamicLights) {
DynamicLight dynamiclight = (DynamicLight) mapDynamicLights.remove(IntegerCache.func_181756_a(p_entityRemoved_0_.getEntityId()));
DynamicLight dynamiclight = (DynamicLight) mapDynamicLights.remove(IntegerCache.func_181756_a(p_entityRemoved_0_.getEntityId()));
if (dynamiclight != null) {
dynamiclight.updateLitChunks(p_entityRemoved_1_);
}
if (dynamiclight != null) {
dynamiclight.updateLitChunks(p_entityRemoved_1_);
}
}
@ -56,13 +54,11 @@ public class DynamicLights {
if (i >= timeUpdateMs + 50L) {
timeUpdateMs = i;
synchronized(mapDynamicLights) {
updateMapDynamicLights(p_update_0_);
updateMapDynamicLights(p_update_0_);
if (mapDynamicLights.size() > 0) {
for (DynamicLight dynamiclight: mapDynamicLights.values()) {
dynamiclight.update(p_update_0_);
}
if (mapDynamicLights.size() > 0) {
for (DynamicLight dynamiclight: mapDynamicLights.values()) {
dynamiclight.update(p_update_0_);
}
}
}
@ -124,32 +120,30 @@ public class DynamicLights {
public static double getLightLevel(BlockPos p_getLightLevel_0_) {
double d0 = 0.0D;
synchronized(mapDynamicLights) {
for (DynamicLight dynamiclight: mapDynamicLights.values()) {
int i = dynamiclight.getLastLightLevel();
for (DynamicLight dynamiclight: mapDynamicLights.values()) {
int i = dynamiclight.getLastLightLevel();
if (i > 0) {
double d1 = dynamiclight.getLastPosX();
double d2 = dynamiclight.getLastPosY();
double d3 = dynamiclight.getLastPosZ();
double d4 = (double) p_getLightLevel_0_.getX() - d1;
double d5 = (double) p_getLightLevel_0_.getY() - d2;
double d6 = (double) p_getLightLevel_0_.getZ() - d3;
double d7 = d4 * d4 + d5 * d5 + d6 * d6;
if (i > 0) {
double d1 = dynamiclight.getLastPosX();
double d2 = dynamiclight.getLastPosY();
double d3 = dynamiclight.getLastPosZ();
double d4 = (double) p_getLightLevel_0_.getX() - d1;
double d5 = (double) p_getLightLevel_0_.getY() - d2;
double d6 = (double) p_getLightLevel_0_.getZ() - d3;
double d7 = d4 * d4 + d5 * d5 + d6 * d6;
if (dynamiclight.isUnderwater() && !Config.isClearWater()) {
i = Config.limit(i - 2, 0, 15);
d7 *= 2.0D;
}
if (dynamiclight.isUnderwater() && !Config.isClearWater()) {
i = Config.limit(i - 2, 0, 15);
d7 *= 2.0D;
}
if (d7 <= 56.25D) {
double d8 = Math.sqrt(d7);
double d9 = 1.0D - d8 / 7.5D;
double d10 = d9 * (double) i;
if (d7 <= 56.25D) {
double d8 = Math.sqrt(d7);
double d9 = 1.0D - d8 / 7.5D;
double d10 = d9 * (double) i;
if (d10 > d0) {
d0 = d10;
}
if (d10 > d0) {
d0 = d10;
}
}
}
@ -230,28 +224,22 @@ public class DynamicLights {
}
public static void removeLights(RenderGlobal p_removeLights_0_) {
synchronized(mapDynamicLights) {
Collection < DynamicLight > collection = mapDynamicLights.values();
Iterator iterator = collection.iterator();
Collection < DynamicLight > collection = mapDynamicLights.values();
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
DynamicLight dynamiclight = (DynamicLight) iterator.next();
iterator.remove();
dynamiclight.updateLitChunks(p_removeLights_0_);
}
while (iterator.hasNext()) {
DynamicLight dynamiclight = (DynamicLight) iterator.next();
iterator.remove();
dynamiclight.updateLitChunks(p_removeLights_0_);
}
}
public static void clear() {
synchronized(mapDynamicLights) {
mapDynamicLights.clear();
}
mapDynamicLights.clear();
}
public static int getCount() {
synchronized(mapDynamicLights) {
return mapDynamicLights.size();
}
return mapDynamicLights.size();
}
public static ItemStack getItemStack(EntityItem p_getItemStack_0_) {