Skip to content

Commit 07a7daa

Browse files
Fix fog coloring in low-atmosphere scenarios and add proper stars to low-light worlds
1 parent 66a074b commit 07a7daa

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

src/main/java/zmaster587/advancedRocketry/client/render/planet/RenderPlanetarySky.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,19 @@ public RenderPlanetarySky() {
9797

9898
Minecraft mc = Minecraft.getMinecraft();
9999

100-
private void renderStars()
101-
{
100+
private void renderStars() {
102101
Random random = new Random(10842L);
103102
BufferBuilder buffer = Tessellator.getInstance().getBuffer();
104103
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
105104

106-
for (int i = 0; i < 2000; ++i)
107-
{
105+
for (int i = 0; i < 2000; ++i) {
108106
double d0 = random.nextFloat() * 2.0F - 1.0F;
109107
double d1 = random.nextFloat() * 2.0F - 1.0F;
110108
double d2 = random.nextFloat() * 2.0F - 1.0F;
111109
double d3 = 0.15F + random.nextFloat() * 0.1F;
112110
double d4 = d0 * d0 + d1 * d1 + d2 * d2;
113111

114-
if (d4 < 1.0D && d4 > 0.01D)
115-
{
112+
if (d4 < 1.0D && d4 > 0.01D) {
116113
d4 = 1.0D / Math.sqrt(d4);
117114
d0 *= d4;
118115
d1 *= d4;
@@ -130,8 +127,7 @@ private void renderStars()
130127
double d15 = Math.sin(d14);
131128
double d16 = Math.cos(d14);
132129

133-
for (int j = 0; j < 4; ++j)
134-
{
130+
for (int j = 0; j < 4; ++j) {
135131
double d17 = 0.0D;
136132
double d18 = (double)((j & 2) - 1) * d3;
137133
double d19 = (double)((j + 1 & 2) - 1) * d3;
@@ -217,8 +213,7 @@ public void render(float partialTicks, WorldClient world, Minecraft mc) {
217213
primaryStar = properties.getStar();
218214
if (primaryStar != null) {
219215
sunSize = properties.getStar().getSize();
220-
}
221-
else
216+
} else
222217
primaryStar = DimensionManager.getInstance().getStar(0);
223218
if(world.provider.getDimension() == ARConfiguration.getCurrentConfig().spaceDimId) {
224219
isWarp = properties.getParentPlanet() == SpaceObjectManager.WARPDIMID;
@@ -227,8 +222,7 @@ public void render(float partialTicks, WorldClient world, Minecraft mc) {
227222
travelDirection = station.getForwardDirection();
228223
}
229224
}
230-
}
231-
else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getDimension())) {
225+
} else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getDimension())) {
232226

233227
properties = DimensionManager.getInstance().getDimensionProperties(mc.world.provider.getDimension());
234228

@@ -265,8 +259,7 @@ else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getD
265259
primaryStar = properties.getStar();
266260
if (primaryStar != null) {
267261
sunSize = properties.getStar().getSize();
268-
}
269-
else
262+
} else
270263
primaryStar = DimensionManager.getInstance().getStar(0);
271264
if(world.provider.getDimension() == ARConfiguration.getCurrentConfig().spaceDimId) {
272265
isWarp = properties.getParentPlanet() == SpaceObjectManager.WARPDIMID;
@@ -275,8 +268,7 @@ else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getD
275268
travelDirection = station.getForwardDirection();
276269
}
277270
}
278-
}
279-
else {
271+
} else {
280272
children = new LinkedList<>();
281273
isMoon = false;
282274
atmosphere = DimensionManager.overworldProperties.getAtmosphereDensityAtHeight(mc.getRenderViewEntity().posY);
@@ -293,8 +285,7 @@ else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getD
293285
float f3 = (float)vec3.z;
294286
float f6;
295287

296-
if (this.mc.gameSettings.anaglyph)
297-
{
288+
if (this.mc.gameSettings.anaglyph) {
298289
float f4 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F;
299290
float f5 = (f1 * 30.0F + f2 * 70.0F) / 100.0F;
300291
f6 = (f1 * 30.0F + f3 * 70.0F) / 100.0F;
@@ -303,10 +294,12 @@ else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getD
303294
f3 = f6;
304295
}
305296

306-
//Simulate atmospheric thickness
307-
f1 = (float)Math.pow(f1, Math.sqrt(atmosphere));
308-
f2 = (float)Math.pow(f2, Math.sqrt(atmosphere));
309-
f3 = (float)Math.pow(f3, Math.sqrt(atmosphere));
297+
//Simulate atmospheric thickness, vaugely
298+
//This is done like this to prevent problems with superbright atmospheres on low-atmosphere planets
299+
//Plus you couldn't see stars during the day anyway
300+
f1 = properties.getAtmosphereDensity() < 1 ? 0 : (float) Math.pow(f1, Math.sqrt(Math.max(atmosphere, 0.81)));
301+
f2 = properties.getAtmosphereDensity() < 1 ? 0 : (float) Math.pow(f2, Math.sqrt(Math.max(atmosphere, 0.81)));
302+
f3 = properties.getAtmosphereDensity() < 1 ? 0 : (float) Math.pow(f3, Math.sqrt(Math.max(atmosphere, 0.81)));
310303

311304

312305
GlStateManager.color(f1, f2, f3);
@@ -440,13 +433,12 @@ else if(DimensionManager.getInstance().isDimensionCreated(mc.world.provider.getD
440433

441434

442435
GlStateManager.disableTexture2D();
443-
float f18 = mc.world.getStarBrightness(partialTicks) * f6 * (atmosphere) + (1-atmosphere);
436+
float f18 = mc.world.getStarBrightness(partialTicks) * f6 + ((atmosphere == 0 || (f1 < 0.09 && f2 < 0.09 && f3 < 0.09)) ? 1 : 0) - (atmosphere > 1 ? atmosphere - 1 : 0);
444437

445438
if(mc.world.isRainingAt(mc.player.getPosition().add(0, 199, 0)))
446439
f18 *= 1-mc.world.getRainStrength(partialTicks);
447440

448-
if (f18 > 0.0F)
449-
{
441+
if (f18 > 0.0F) {
450442
GlStateManager.color(f18, f18, f18, f18);
451443
GL11.glPushMatrix();
452444
if(isWarp) {
@@ -629,8 +621,7 @@ else if (afloat != null && (planetPositionTheta < 105 || planetPositionTheta > 2
629621

630622
double d0 = this.mc.player.getPositionEyes(partialTicks).y - mc.world.getHorizon();
631623

632-
if (d0 < 0.0D)
633-
{
624+
if (d0 < 0.0D) {
634625
GL11.glPushMatrix();
635626
GL11.glTranslatef(0.0F, 12.0F, 0.0F);
636627
GL11.glCallList(this.glSkyList2);

src/main/java/zmaster587/advancedRocketry/event/PlanetEventHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,17 @@ public void fogColor(FogColors event) {
437437
DimensionProperties properties = DimensionManager.getInstance().getDimensionProperties(event.getEntity().dimension);
438438
if(properties != null) {
439439
if(event.getEntity().world.provider instanceof IPlanetaryProvider) {
440-
Vec3d color = event.getEntity().world.provider.getFogColor((float)event.getEntity().posY, 0f);
440+
Vec3d color = event.getEntity().world.provider.getFogColor(event.getEntity().world.getCelestialAngle((float)event.getRenderPartialTicks()), (float)event.getRenderPartialTicks());
441441
event.setRed((float) Math.min(color.x,1f));
442442
event.setGreen((float) Math.min(color.y, 1f));
443443
event.setBlue((float) Math.min(color.z, 1f));
444+
445+
//Make sure fog doesn't happen on zero atmospheres
446+
if (properties.getAtmosphereDensity() == 0) {
447+
event.setRed(0);
448+
event.setGreen(0);
449+
event.setBlue(0);
450+
}
444451
}
445452

446453
if(endTime > 0) {

src/main/java/zmaster587/advancedRocketry/world/provider/WorldProviderPlanet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import zmaster587.advancedRocketry.dimension.DimensionManager;
3737
import zmaster587.advancedRocketry.dimension.DimensionProperties;
3838
import zmaster587.advancedRocketry.integration.CompatibilityMgr;
39-
import zmaster587.advancedRocketry.item.components.ItemUpgrade;
4039
import zmaster587.advancedRocketry.util.AstronomicalBodyHelper;
4140
import zmaster587.advancedRocketry.world.ChunkManagerPlanet;
4241
import zmaster587.advancedRocketry.world.ChunkProviderCavePlanet;
@@ -335,7 +334,7 @@ public Vec3d getFogColor(float p_76562_1_, float p_76562_2_) {
335334
float[] vec = getDimensionProperties(new BlockPos((int) cameraEntity.posX, 0, (int) cameraEntity.posZ)).fogColor;
336335
if (cameraEntity.world.provider instanceof WorldProviderPlanet) {
337336
WorldProviderPlanet world = ((WorldProviderPlanet)cameraEntity.world.provider);
338-
vec = operateFloatOnTriFloatArray(vec, world.getSunBrightness(p_76562_2_));
337+
vec = operateFloatOnTriFloatArray(vec, world.getSunBrightness(Minecraft.getMinecraft().getRenderPartialTicks()));
339338
}
340339

341340
return new Vec3d(vec[0] * superVec.x, vec[1] * superVec.y, vec[2] * superVec.z);

0 commit comments

Comments
 (0)