Skip to content

Commit

Permalink
Make NotFine's sky toggle more granular (#222)
Browse files Browse the repository at this point in the history
Separated "Sky" toggle into "Sky", "Sun & Moon", and "Stars", like in OptiFine.
This also fixes NF's sky toggle turning off MCPF's skybox
  • Loading branch information
makamys authored Jan 21, 2024
1 parent 9210cd3 commit 0d79f5e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,79 @@

import jss.notfine.core.Settings;
import jss.notfine.render.RenderStars;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.Tessellator;
import net.minecraftforge.client.IRenderHandler;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
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;

import com.llamalad7.mixinextras.injector.WrapWithCondition;

@Mixin(value = RenderGlobal.class)
public abstract class MixinRenderGlobal {

@Inject(method = "renderSky", at = @At("HEAD"), cancellable = true)
void notFine$toggleSky(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SKY.option.getStore()) ci.cancel();

@Shadow private int glSkyList;
@Shadow private int starGLCallList;
@Shadow private int glSkyList2;

@WrapWithCondition(
method = "renderSky(F)V",
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallList(I)V", remap = false))
private boolean conditionalCallList(int i) {
if(i == starGLCallList) {
return (boolean)Settings.MODE_STARS.option.getStore();
} else {
return (boolean)Settings.MODE_SKY.option.getStore();
}
}

@WrapWithCondition(
method = "renderSky(F)V",
at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/IRenderHandler;render(FLnet/minecraft/client/multiplayer/WorldClient;Lnet/minecraft/client/Minecraft;)V", remap = false))
private boolean conditionalRenderHandlerRender(IRenderHandler irh, float f, WorldClient wc, Minecraft mc) {
return (boolean)Settings.MODE_SKY.option.getStore();
}

@Inject(method="renderSky(F)V", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 0))
private void conditionalTessellatorDrawEndSkybox(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SKY.option.getStore()) {
Tessellator.instance.vertexCount = 0;
}
}

@Inject(method="renderSky(F)V", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 1))
private void conditionalTessellatorDrawSunsetSunrise(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SKY.option.getStore()) {
Tessellator.instance.vertexCount = 0;
}
}

@Inject(method="renderSky(F)V", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 2))
private void conditionalTessellatorDrawSun(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SUN_MOON.option.getStore()) {
Tessellator.instance.vertexCount = 0;
}
}

@Inject(method="renderSky(F)V", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 3))
private void conditionalTessellatorDrawMoon(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SUN_MOON.option.getStore()) {
Tessellator.instance.vertexCount = 0;
}
}

@Inject(method="renderSky(F)V", at=@At(value="INVOKE", target="Lnet/minecraft/client/renderer/Tessellator;draw()I", ordinal = 4))
private void conditionalTessellatorDrawHorizon(CallbackInfo ci) {
if(!(boolean)Settings.MODE_SKY.option.getStore()) {
Tessellator.instance.vertexCount = 0;
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/jss/notfine/core/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public void applyChanges() {
SettingsManager.shadowsUpdated();
}
},
MODE_SKY(new NotFineOptionTickBox(true, OptionImpact.MEDIUM)),
MODE_SKY(new NotFineOptionTickBox(true, OptionImpact.LOW)),
MODE_STARS(new NotFineOptionTickBox(true, OptionImpact.LOW)),
MODE_SUN_MOON(new NotFineOptionTickBox(true, OptionImpact.LOW)),
MODE_WATER(new NotFineOptionCycling<>(GraphicsQuality.DEFAULT, OptionImpact.LOW)) {
@Override
public void applyChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public static OptionPage general() {
.setBinding((opts, value) -> opts.gammaSetting = value * 0.01F, (opts) -> (int) (opts.gammaSetting / 0.01F))
.build());
firstGroupBuilder.add(Settings.MODE_SKY.option);
firstGroupBuilder.add(Settings.MODE_SUN_MOON.option);
firstGroupBuilder.add(Settings.MODE_STARS.option);
firstGroupBuilder.add(OptionImpl.createBuilder(boolean.class, vanillaOpts)
.setName(I18n.format("sodium.options.clouds.name"))
.setTooltip(I18n.format("sodium.options.clouds.tooltip"))
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/notfine/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ options.mode_gui_background=Menu Backgrounds
options.mode_leaves=Foliage
options.mode_shadows=Entity Shadows
options.mode_sky=Sky
options.mode_sun_moon=Sun & Moon
options.mode_stars=Stars
options.mode_water=Water
options.mode_vignette=Vignette
options.particles_enc_table=Enchantment Particles
Expand Down

0 comments on commit 0d79f5e

Please sign in to comment.