diff --git a/src/main/java/com/minelittlepony/unicopia/render/RenderRainbow.java b/src/main/java/com/minelittlepony/unicopia/render/RenderRainbow.java index 82624b13..5aea9b58 100644 --- a/src/main/java/com/minelittlepony/unicopia/render/RenderRainbow.java +++ b/src/main/java/com/minelittlepony/unicopia/render/RenderRainbow.java @@ -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 { 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 { 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(); diff --git a/src/main/java/com/minelittlepony/util/WorldHelper.java b/src/main/java/com/minelittlepony/util/WorldHelper.java new file mode 100644 index 00000000..a01bd0ed --- /dev/null +++ b/src/main/java/com/minelittlepony/util/WorldHelper.java @@ -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; + } +}