mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Rainbows now consider the sun's brightness and are less visible during the night
This commit is contained in:
parent
0614d73072
commit
c01a01a417
2 changed files with 103 additions and 8 deletions
|
@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.render;
|
|||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.EntityRainbow;
|
||||
import com.minelittlepony.util.WorldHelper;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
|
@ -22,6 +23,21 @@ public class RenderRainbow extends Render<EntityRainbow> {
|
|||
private static final ResourceLocation TEXTURE = new ResourceLocation("unicopia", "textures/environment/rainbow.png");
|
||||
|
||||
public void doRender(EntityRainbow entity, double x, double y, double z, float entityYaw, float partialTicks) {
|
||||
|
||||
|
||||
float distance = Minecraft.getMinecraft().getRenderViewEntity().getDistance(entity);
|
||||
float maxDistance = 16 * Minecraft.getMinecraft().gameSettings.renderDistanceChunks;
|
||||
double r = entity.getRadius();
|
||||
float light = WorldHelper.getDaylightBrightness(entity.getEntityWorld(), partialTicks);
|
||||
|
||||
float opacity = ((maxDistance - distance) / maxDistance);
|
||||
|
||||
opacity *= light;
|
||||
|
||||
if (opacity <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
bindEntityTexture(entity);
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
@ -33,18 +49,11 @@ public class RenderRainbow extends Render<EntityRainbow> {
|
|||
GlStateManager.translate(x, y, z);
|
||||
GlStateManager.rotate(entityYaw, 0, 1, 0);
|
||||
|
||||
float distance = Minecraft.getMinecraft().getRenderViewEntity().getDistance(entity);
|
||||
|
||||
|
||||
float maxDistance = 16 * Minecraft.getMinecraft().gameSettings.renderDistanceChunks;
|
||||
|
||||
GlStateManager.color(1, 1, 1, ((maxDistance - distance) / maxDistance) * 0.9f);
|
||||
GlStateManager.color(1, 1, 1, opacity);
|
||||
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder bufferbuilder = tessellator.getBuffer();
|
||||
|
||||
double r = entity.getRadius();
|
||||
|
||||
bufferbuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX);
|
||||
bufferbuilder.pos(-r, r, 0).tex(1, 0).endVertex();
|
||||
bufferbuilder.pos( r, r, 0).tex(0, 0).endVertex();
|
||||
|
|
86
src/main/java/com/minelittlepony/util/WorldHelper.java
Normal file
86
src/main/java/com/minelittlepony/util/WorldHelper.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package com.minelittlepony.util;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public final class WorldHelper {
|
||||
|
||||
|
||||
/**
|
||||
* Gets the daylight brightness value on a scale of 0-1.
|
||||
* Midday = 1
|
||||
* Sunrise/Sunset = 0
|
||||
* Nighttime = 0
|
||||
*/
|
||||
public static float getDaylightBrightness(World w, float partialTicks) {
|
||||
float celst = w.getCelestialAngle(partialTicks);
|
||||
|
||||
// ----------------------------
|
||||
// 0 | 0.5 | 1
|
||||
// | | | midday
|
||||
// | midnight |
|
||||
// sunset |
|
||||
// sunrise
|
||||
//---| |-------
|
||||
//---// |-------|
|
||||
// / \
|
||||
// / \
|
||||
// \
|
||||
// \
|
||||
// midnight = 0.5
|
||||
// sunrise = 0.7
|
||||
// midday = 1
|
||||
// sunset = 0.3
|
||||
|
||||
if (celst >= 0.7F || celst <= 0.3F) {
|
||||
if (celst >= 0.7) {
|
||||
celst -= 0.7;
|
||||
} else {
|
||||
celst = -celst + 0.3F;
|
||||
}
|
||||
|
||||
return celst * (3 + 1/3);
|
||||
} else {
|
||||
celst = 0;
|
||||
}
|
||||
|
||||
|
||||
System.out.println(celst);
|
||||
|
||||
return celst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the brightness of the moon. Works as the inverse of getDaylightBrightness but for the moon.
|
||||
* Midnight = 1
|
||||
* Sunrise/Sunset = 0
|
||||
* Daytime = 0
|
||||
*/
|
||||
public static float getLunarBrightness(World w, float partialTicks) {
|
||||
float celst = w.getCelestialAngle(partialTicks);
|
||||
|
||||
// ----------------------------
|
||||
// 0 | 0.5 | 1
|
||||
// | | | midday
|
||||
// | midnight |
|
||||
// sunset |
|
||||
// sunrise
|
||||
// |-------------------|
|
||||
// \ | /
|
||||
// \ | /
|
||||
// \ | /
|
||||
// \ | /
|
||||
// |
|
||||
// midnight = 0.5
|
||||
// sunrise = 0.7
|
||||
// midday = 1
|
||||
// sunset = 0.3
|
||||
|
||||
if (celst < 0.7F && celst > 0.3F) {
|
||||
return Math.abs(celst - 0.5F) / 0.2F;
|
||||
}
|
||||
|
||||
System.out.println(celst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue