Reimplement gog sky with mixins

This commit is contained in:
Vincent Lee committed 2020-07-19 11:49:28 -05:00
1 parent 4d8174cf95
commit 822071984b
8 files changed
+136 -224

No files matched your search

@@ -48,7 +48,6 @@ import vazkii.botania.client.core.helper.ShaderHelper;
import vazkii.botania.client.fx.FXLightning;
import vazkii.botania.client.fx.ModParticles;
import vazkii.botania.client.render.entity.RenderMagicLandmine;
import vazkii.botania.client.render.world.SkyblockRenderEvents;
import vazkii.botania.common.Botania;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.block.ModFluffBlocks;
@@ -127,7 +126,6 @@ public class ClientProxy implements IProxy {
forgeBus.addListener(BossBarHandler::onBarRender);
forgeBus.addListener(RenderMagicLandmine::onWorldRenderLast);
forgeBus.addListener(AstrolabePreviewHandler::onWorldRenderLast);
forgeBus.addListener(SkyblockRenderEvents::onRender);
forgeBus.addListener(ItemDodgeRing::onKeyDown);
forgeBus.addListener(EventPriority.LOWEST, BergamuteEventHandler::onSoundEvent);
}
@@ -1,34 +0,0 @@
/*
* This class is distributed as part of the Botania Mod.
* Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*/
package vazkii.botania.client.render.world;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.world.SkyblockChunkGenerator;
public final class SkyblockRenderEvents {
public static void onRender(RenderWorldLastEvent event) {
World world = Minecraft.getInstance().world;
if (ConfigHandler.CLIENT.enableFancySkybox.get()
&& world.func_234923_W_() == World.field_234918_g_
&& (ConfigHandler.CLIENT.enableFancySkyboxInNormalWorlds.get()
|| SkyblockChunkGenerator.isWorldSkyblock(world))) {
/* todo 1.16
if (!(world.getDimension().getSkyRenderer() instanceof SkyblockSkyRenderer)) {
world.getDimension().setSkyRenderer(new SkyblockSkyRenderer());
}
*/
}
}
}
@@ -13,35 +13,26 @@ import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldVertexBufferUploader;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector3f;
import net.minecraftforge.client.SkyRenderHandler;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.mixin.AccessorWorldRenderer;
import java.util.Random;
public class SkyblockSkyRenderer implements SkyRenderHandler {
public class SkyblockSkyRenderer {
private static final ResourceLocation textureSkybox = new ResourceLocation(LibResources.MISC_SKYBOX);
private static final ResourceLocation textureRainbow = new ResourceLocation(LibResources.MISC_RAINBOW);
private static final ResourceLocation MOON_PHASES_TEXTURES = new ResourceLocation("textures/environment/moon_phases.png");
private static final ResourceLocation SUN_TEXTURES = new ResourceLocation("textures/environment/sun.png");
private static final ResourceLocation[] planetTextures = new ResourceLocation[] {
new ResourceLocation(LibResources.MISC_PLANET + "0.png"),
new ResourceLocation(LibResources.MISC_PLANET + "1.png"),
@@ -51,165 +42,7 @@ public class SkyblockSkyRenderer implements SkyRenderHandler {
new ResourceLocation(LibResources.MISC_PLANET + "5.png")
};
// [VanillaCopy] WorldRenderer.renderSky, overworld section, edits noted
@Override
public void render(int ticks, float partialTicks, MatrixStack matrixStackIn, ClientWorld world, Minecraft mc) {
// Environment setup
VertexBuffer skyVBO = ((AccessorWorldRenderer) mc.worldRenderer).getSkyVBO();
VertexFormat skyVertexFormat = ((AccessorWorldRenderer) mc.worldRenderer).getSkyVertexFormat();
RenderSystem.disableTexture();
Vector3d Vector3d = world.getSkyColor(mc.gameRenderer.getActiveRenderInfo().getBlockPos(), partialTicks);
float f = (float) Vector3d.x;
float f1 = (float) Vector3d.y;
float f2 = (float) Vector3d.z;
// Botania - darken in void
float insideVoid = 0;
if (mc.player.getPosY() <= -2) {
insideVoid = (float) Math.min(1F, -(mc.player.getPosY() + 2) / 30F);
}
f = Math.max(0F, f - insideVoid);
f1 = Math.max(0F, f1 - insideVoid);
f2 = Math.max(0F, f2 - insideVoid);
FogRenderer.applyFog();
BufferBuilder bufferbuilder = Tessellator.getInstance().getBuffer();
RenderSystem.depthMask(false);
RenderSystem.enableFog();
RenderSystem.color3f(f, f1, f2);
skyVBO.bindBuffer();
skyVertexFormat.setupBufferState(0L);
skyVBO.draw(matrixStackIn.getLast().getMatrix(), 7);
VertexBuffer.unbindBuffer();
skyVertexFormat.clearBufferState();
RenderSystem.disableFog();
RenderSystem.disableAlphaTest();
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
float[] afloat = world.func_239132_a_().func_230492_a_(world.getCelestialAngle(partialTicks), partialTicks);
if (afloat != null) {
RenderSystem.disableTexture();
RenderSystem.shadeModel(7425);
matrixStackIn.push();
matrixStackIn.rotate(Vector3f.XP.rotationDegrees(90.0F));
float f3 = MathHelper.sin(world.getCelestialAngleRadians(partialTicks)) < 0.0F ? 180.0F : 0.0F;
matrixStackIn.rotate(Vector3f.ZP.rotationDegrees(f3));
matrixStackIn.rotate(Vector3f.ZP.rotationDegrees(90.0F));
float f4 = afloat[0];
float f5 = afloat[1];
float f6 = afloat[2];
Matrix4f matrix4f = matrixStackIn.getLast().getMatrix();
bufferbuilder.begin(6, DefaultVertexFormats.POSITION_COLOR);
bufferbuilder.pos(matrix4f, 0.0F, 100.0F, 0.0F).color(f4, f5, f6, afloat[3]).endVertex();
int i = 16;
for (int j = 0; j <= 16; ++j) {
float f7 = (float) j * ((float) Math.PI * 2F) / 16.0F;
float f8 = MathHelper.sin(f7);
float f9 = MathHelper.cos(f7);
bufferbuilder.pos(matrix4f, f8 * 120.0F, f9 * 120.0F, -f9 * 40.0F * afloat[3]).color(afloat[0], afloat[1], afloat[2], 0.0F).endVertex();
}
bufferbuilder.finishDrawing();
WorldVertexBufferUploader.draw(bufferbuilder);
matrixStackIn.pop();
RenderSystem.shadeModel(7424);
}
RenderSystem.enableTexture();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
matrixStackIn.push();
float f11 = 1.0F - world.getRainStrength(partialTicks);
RenderSystem.color4f(1.0F, 1.0F, 1.0F, f11);
matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-90.0F));
// Botania: extras
renderExtra(matrixStackIn, world, partialTicks, insideVoid);
matrixStackIn.rotate(Vector3f.XP.rotationDegrees(world.getCelestialAngle(partialTicks) * 360.0F));
Matrix4f matrix4f1 = matrixStackIn.getLast().getMatrix();
float f12 = 60.0F; // Botania: 30 -> 60
mc.textureManager.bindTexture(SUN_TEXTURES);
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(matrix4f1, -f12, 100.0F, -f12).tex(0.0F, 0.0F).endVertex();
bufferbuilder.pos(matrix4f1, f12, 100.0F, -f12).tex(1.0F, 0.0F).endVertex();
bufferbuilder.pos(matrix4f1, f12, 100.0F, f12).tex(1.0F, 1.0F).endVertex();
bufferbuilder.pos(matrix4f1, -f12, 100.0F, f12).tex(0.0F, 1.0F).endVertex();
bufferbuilder.finishDrawing();
WorldVertexBufferUploader.draw(bufferbuilder);
f12 = 60.0F; // Botania: 20 -> 60
mc.textureManager.bindTexture(MOON_PHASES_TEXTURES);
int k = world.getMoonPhase();
int l = k % 4;
int i1 = k / 4 % 2;
float f13 = (float) (l + 0) / 4.0F;
float f14 = (float) (i1 + 0) / 2.0F;
float f15 = (float) (l + 1) / 4.0F;
float f16 = (float) (i1 + 1) / 2.0F;
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(matrix4f1, -f12, -100.0F, f12).tex(f15, f16).endVertex();
bufferbuilder.pos(matrix4f1, f12, -100.0F, f12).tex(f13, f16).endVertex();
bufferbuilder.pos(matrix4f1, f12, -100.0F, -f12).tex(f13, f14).endVertex();
bufferbuilder.pos(matrix4f1, -f12, -100.0F, -f12).tex(f15, f14).endVertex();
bufferbuilder.finishDrawing();
WorldVertexBufferUploader.draw(bufferbuilder);
RenderSystem.disableTexture();
// Botania: custom stars
{
float celAng = world.getCelestialAngle(partialTicks);
float effCelAng = celAng;
if (celAng > 0.5) {
effCelAng = 0.5F - (celAng - 0.5F);
}
float starAlpha = f11 * Math.max(0.1F, effCelAng * 2);
renderStars(skyVertexFormat, matrixStackIn, mc, starAlpha, partialTicks);
}
/*
float f10 = world.getStarBrightness(partialTicks) * f11;
if (f10 > 0.0F) {
RenderSystem.color4f(f10, f10, f10, f10);
this.starVBO.bindBuffer();
this.skyVertexFormat.setupBufferState(0L);
this.starVBO.draw(matrixStackIn.getLast().getMatrix(), 7);
VertexBuffer.unbindBuffer();
this.skyVertexFormat.clearBufferState();
}
*/
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.disableBlend();
RenderSystem.enableAlphaTest();
RenderSystem.enableFog();
matrixStackIn.pop();
// Botania: No horizon
/*
RenderSystem.disableTexture();
RenderSystem.color3f(0.0F, 0.0F, 0.0F);
double d0 = mc.player.getEyePosition(partialTicks).y - world.getHorizonHeight();
if (d0 < 0.0D) {
matrixStackIn.push();
matrixStackIn.translate(0.0D, 12.0D, 0.0D);
sky2VBO.bindBuffer();
skyVertexFormat.setupBufferState(0L);
sky2VBO.draw(matrixStackIn.getLast().getMatrix(), 7);
VertexBuffer.unbindBuffer();
skyVertexFormat.clearBufferState();
matrixStackIn.pop();
}
if (world.dimension.isSkyColored()) {
RenderSystem.color3f(f * 0.2F + 0.04F, f1 * 0.2F + 0.04F, f2 * 0.6F + 0.1F);
} else {
RenderSystem.color3f(f, f1, f2);
}
*/
RenderSystem.enableTexture();
RenderSystem.depthMask(true);
RenderSystem.disableFog();
}
private void renderExtra(MatrixStack ms, ClientWorld world, float partialTicks, float insideVoid) {
public static void renderExtra(MatrixStack ms, ClientWorld world, float partialTicks, float insideVoid) {
// Botania - Begin extra stuff
Tessellator tessellator = Tessellator.getInstance();
float rain = 1.0F - world.getRainStrength(partialTicks);
@@ -377,57 +210,62 @@ public class SkyblockSkyRenderer implements SkyRenderHandler {
GlStateManager.blendFuncSeparate(770, 1, 1, 0);
}
private void renderStars(VertexFormat format, MatrixStack ms, Minecraft mc, float alpha, float partialTicks) {
net.minecraft.client.renderer.vertex.VertexBuffer starVBO = ((AccessorWorldRenderer) mc.worldRenderer).getStarVBO();
public static void renderStars(VertexFormat format, VertexBuffer starVBO, MatrixStack ms, float partialTicks) {
Minecraft mc = Minecraft.getInstance();
float rain = 1.0F - mc.world.getRainStrength(partialTicks);
float celAng = mc.world.getCelestialAngle(partialTicks);
float effCelAng = celAng;
if (celAng > 0.5) {
effCelAng = 0.5F - (celAng - 0.5F);
}
float alpha = rain * Math.max(0.1F, effCelAng * 2);
float t = (ClientTickHandler.ticksInGame + partialTicks + 2000) * 0.005F;
ms.push();
starVBO.bindBuffer();
format.setupBufferState(0);
ms.push();
ms.rotate(Vector3f.YP.rotationDegrees(t * 3));
RenderSystem.color4f(1F, 1F, 1F, alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.push();
ms.rotate(Vector3f.YP.rotationDegrees(t));
RenderSystem.color4f(0.5F, 1F, 1F, alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.push();
ms.rotate(Vector3f.YP.rotationDegrees(t * 2));
RenderSystem.color4f(1F, 0.75F, 0.75F, alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.push();
ms.rotate(Vector3f.ZP.rotationDegrees(t * 3));
RenderSystem.color4f(1F, 1F, 1F, 0.25F * alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.push();
ms.rotate(Vector3f.ZP.rotationDegrees(t));
RenderSystem.color4f(0.5F, 1F, 1F, 0.25F * alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.push();
ms.rotate(Vector3f.ZP.rotationDegrees(t * 2));
RenderSystem.color4f(1F, 0.75F, 0.75F, 0.25F * alpha);
drawVbo(format, ms, starVBO);
starVBO.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
ms.pop();
ms.pop();
}
private void drawVbo(VertexFormat skyVertexFormat, MatrixStack ms, VertexBuffer vbo) {
vbo.bindBuffer();
skyVertexFormat.setupBufferState(0);
vbo.draw(ms.getLast().getMatrix(), GL11.GL_QUADS);
VertexBuffer.unbindBuffer();
skyVertexFormat.clearBufferState();
format.clearBufferState();
}
}
@@ -10,6 +10,9 @@ import vazkii.botania.common.core.handler.PixieHandler;
@Mixin(PlayerEntity.class)
public class MixinPlayerEntity {
/**
* Registers the pixie spawn chance attribute on players
*/
@Inject(at = @At("RETURN"), method = "func_234570_el_")
private static void addPixieAttribute(CallbackInfoReturnable<AttributeModifierMap.MutableAttribute> cir) {
cir.getReturnValue().func_233814_a_(PixieHandler.PIXIE_SPAWN_CHANCE);
@@ -26,12 +26,12 @@ import vazkii.botania.common.block.BlockGaiaHead;
import javax.annotation.Nullable;
/**
* This hook is necessary instead of just overriding render() in RenderTileGaiaHead as normal
* because vanilla ItemStackTileEntityRenderer checks for skull blocks and calls this static method directly.
*/
@Mixin(SkullTileEntityRenderer.class)
public abstract class MixinSkullTileEntityRenderer {
/**
* This hook is necessary instead of just overriding render() in RenderTileGaiaHead as normal
* because vanilla ItemStackTileEntityRenderer checks for skull blocks and calls this static method directly.
*/
@Inject(at = @At("HEAD"), method = "render(Lnet/minecraft/util/Direction;FLnet/minecraft/block/SkullBlock$ISkullType;Lcom/mojang/authlib/GameProfile;FLcom/mojang/blaze3d/matrix/MatrixStack;Lnet/minecraft/client/renderer/IRenderTypeBuffer;I)V", cancellable = true)
private static void onRender(@Nullable Direction direction, float angle, SkullBlock.ISkullType skullType, @Nullable GameProfile gameProfileIn, float animationProgress, MatrixStack ms, IRenderTypeBuffer buffers, int light, CallbackInfo ci) {
if (skullType == BlockGaiaHead.GAIA_TYPE) {
@@ -29,6 +29,9 @@ public class MixinSplashes {
@Final
private List<String> possibleSplashes;
/**
* Adds splash texts if enabled
*/
@Inject(at = @At("RETURN"), method = "apply")
public void addSplashes(List<String> splashes, IResourceManager resourceManager, IProfiler profiler, CallbackInfo ci) {
if (ConfigHandler.CLIENT.splashesEnabled.get()) {
@@ -0,0 +1,103 @@
package vazkii.botania.mixin;
import com.mojang.blaze3d.matrix.MatrixStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.vertex.VertexBuffer;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import vazkii.botania.client.render.world.SkyblockSkyRenderer;
import vazkii.botania.common.core.handler.ConfigHandler;
import vazkii.botania.common.world.SkyblockChunkGenerator;
import javax.annotation.Nullable;
/**
* This Mixin implements the Garden of Glass skybox
*/
@Mixin(WorldRenderer.class)
public class MixinWorldRenderer {
@Shadow @Final private VertexFormat skyVertexFormat;
@Shadow @Nullable private VertexBuffer starVBO;
// TODO 1.16 isWorldSkyblock doesnt work on client (needs to be communicated separately)
@Unique
private static boolean isGogSky() {
World world = Minecraft.getInstance().world;
return ConfigHandler.CLIENT.enableFancySkybox.get()
&& world.func_234923_W_() == World.field_234918_g_
&& (ConfigHandler.CLIENT.enableFancySkyboxInNormalWorlds.get()
|| SkyblockChunkGenerator.isWorldSkyblock(world));
}
/**
* Render planets and other extras, after the first invoke to ms.rotate(Y) after getRainStrength is called
*/
@Inject(method = "renderSky(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V",
slice = @Slice(from = @At(ordinal = 0, value = "INVOKE",
target = "Lnet/minecraft/client/world/ClientWorld;getRainStrength(F)F")),
at = @At(shift = At.Shift.AFTER,
ordinal = 0,
value = "INVOKE",
target = "Lcom/mojang/blaze3d/matrix/MatrixStack;rotate(Lnet/minecraft/util/math/vector/Quaternion;)V")
)
private void renderExtras(MatrixStack ms, float partialTicks, CallbackInfo ci) {
if (isGogSky()) {
SkyblockSkyRenderer.renderExtra(ms, Minecraft.getInstance().world, partialTicks, 0);
}
}
/**
* Make the sun bigger, replace any 30.0F seen before first call to bindTexture
*/
@ModifyConstant(
method = "renderSky(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V",
slice = @Slice(to = @At(ordinal = 0, value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V")),
constant = { @Constant(floatValue = 30.0F) })
private float makeSunBigger(float oldValue) {
if (isGogSky()) {
return 60.0F;
} else {
return oldValue;
}
}
/**
* Make the moon bigger, replace any 20.0F seen between first and second call to bindTexture
*/
@ModifyConstant(
method = "renderSky(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V",
slice = @Slice(
from = @At(ordinal = 0, value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V"),
to = @At(ordinal = 1, value = "INVOKE", target = "Lnet/minecraft/client/renderer/texture/TextureManager;bindTexture(Lnet/minecraft/util/ResourceLocation;)V")
),
constant = { @Constant(floatValue = 20.0F) }
)
private float makeMoonBigger(float oldValue) {
if (isGogSky()) {
return 60.0F;
} else {
return oldValue;
}
}
/**
* Render lots of extra stars
*/
@Inject(
method = "renderSky(Lcom/mojang/blaze3d/matrix/MatrixStack;F)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;getStarBrightness(F)F")
)
private void renderExtraStars(MatrixStack ms, float partialTicks, CallbackInfo ci) {
if (isGogSky()) {
SkyblockSkyRenderer.renderStars(skyVertexFormat, starVBO, ms, partialTicks);
}
}
}
@@ -35,7 +35,8 @@
"AccessorSkullTileEntityRenderer",
"AccessorWorldRenderer",
"MixinSkullTileEntityRenderer",
"MixinSplashes"
"MixinSplashes",
"MixinWorldRenderer"
],
"injectors": {
"defaultRequire": 1