Skip to content

Commit

Permalink
Refactor a bit of the sky code
Browse files Browse the repository at this point in the history
  • Loading branch information
lowercasebtw committed Jan 15, 2025
1 parent 6bab2d1 commit b3817af
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ modmenu_version=13.0.0
yacl_version=3.6.2+1.21.4-fabric

# Mod Properties
mod_version=1.0.0-dev-32
mod_version=1.0.0-dev-33
maven_group=btw.mixces
archives_base_name=animatium
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import org.joml.Matrix4fStack;
import org.joml.Vector3f;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -53,7 +54,7 @@ public abstract class MixinLevelRenderer {
private void animatium$oldBlueVoidSky(FogParameters fog, DimensionSpecialEffects.SkyType skyType, float tickDelta, DimensionSpecialEffects dimensionSpecialEffects, CallbackInfo ci, @Local PoseStack poseStack) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldBlueVoidSky() && skyType != DimensionSpecialEffects.SkyType.END && this.level != null && this.minecraft.player != null) {
int skyColor = this.level.getSkyColor(this.minecraft.gameRenderer.getMainCamera().getPosition(), tickDelta);
this.animatium$renderSkyBlueVoid(poseStack, skyColor, this.minecraft.player.getEyePosition(tickDelta).y - RenderUtils.getLevelHorizonHeight(this.level));
this.animatium$renderSkyBlueVoid(skyColor, this.minecraft.player.getEyePosition(tickDelta).y - RenderUtils.getLevelHorizonHeight(this.level));
}
}

Expand All @@ -77,7 +78,7 @@ public abstract class MixinLevelRenderer {
}

@Unique
private void animatium$renderSkyBlueVoid(PoseStack poseStack, int skyColor, double depth) {
private void animatium$renderSkyBlueVoid(int skyColor, double depth) {
assert this.level != null;
Vector3f skyColorVec = ARGB.vector3fFromRGB24(skyColor);
if (this.level.effects().hasGround()) {
Expand All @@ -86,14 +87,14 @@ public abstract class MixinLevelRenderer {
RenderSystem.setShaderColor(skyColorVec.x, skyColorVec.y, skyColorVec.z, 1.0F);
}

poseStack.pushPose();
poseStack.mulPose(RenderSystem.getModelViewMatrix());
poseStack.translate(0.0F, -((float) (depth - 16.0)), 0.0F);
Matrix4fStack modelViewStack = RenderSystem.getModelViewStack();
modelViewStack.pushMatrix();
modelViewStack.translate(0.0F, -((float) (depth - 16.0)), 0.0F);
SkyRendererAccessor skyRendererAccessor = (SkyRendererAccessor) this.skyRenderer;
skyRendererAccessor.getBottomSkyBuffer().bind();
skyRendererAccessor.getBottomSkyBuffer().drawWithShader(poseStack.last().pose(), RenderSystem.getProjectionMatrix(), RenderSystem.setShader(CoreShaders.POSITION));
skyRendererAccessor.getBottomSkyBuffer().drawWithShader(modelViewStack, RenderSystem.getProjectionMatrix(), RenderSystem.setShader(CoreShaders.POSITION));
VertexBuffer.unbind();
poseStack.popPose();
modelViewStack.popMatrix();

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,32 @@
import btw.mixces.animatium.config.AnimatiumConfig;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexBuffer;
import net.minecraft.client.renderer.CoreShaders;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.SkyRenderer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(SkyRenderer.class)
public abstract class MixinSkyRenderer {
@Shadow
@Final
private VertexBuffer bottomSkyBuffer;
@WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V"))
private void animatium$pushMatrix(PoseStack instance, Operation<Void> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldVoidSkyFogHeight()) {
RenderSystem.getModelViewStack().pushMatrix();
}
}

@Inject(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;pushPose()V", shift = At.Shift.AFTER))
private void animatium$oldVoidSkyRendering$position(PoseStack poseStack, CallbackInfo ci) {
@WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;translate(FFF)V"))
private void animatium$translate(PoseStack instance, float x, float y, float z, Operation<Void> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldVoidSkyFogHeight()) {
poseStack.mulPose(RenderSystem.getModelViewMatrix());
RenderSystem.getModelViewStack().translate(x, y, z);
}
}

@WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/VertexBuffer;drawWithRenderType(Lnet/minecraft/client/renderer/RenderType;)V"))
private void animatium$oldVoidSkyRendering(VertexBuffer instance, RenderType renderType, Operation<Void> original, @Local(argsOnly = true) PoseStack poseStack) {
@WrapOperation(method = "renderDarkDisc", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/vertex/PoseStack;popPose()V"))
private void animatium$popMatrix(PoseStack instance, Operation<Void> original) {
if (AnimatiumClient.getEnabled() && AnimatiumConfig.instance().getOldVoidSkyFogHeight()) {
this.bottomSkyBuffer.bind();
this.bottomSkyBuffer.drawWithShader(poseStack.last().pose(), RenderSystem.getProjectionMatrix(), RenderSystem.setShader(CoreShaders.POSITION));
VertexBuffer.unbind();
} else {
original.call(instance, renderType);
RenderSystem.getModelViewStack().popMatrix();
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/btw/mixces/animatium/AnimatiumClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AnimatiumClient : ClientModInitializer {

// Info
const val VERSION = 1.0
val DEVELOPMENT_VERSION = Optional.ofNullable(32)
val DEVELOPMENT_VERSION = Optional.ofNullable(33)

@JvmStatic
fun getInfoPayload(): AnimatiumInfoPayloadPacket {
Expand Down

0 comments on commit b3817af

Please sign in to comment.