Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 54a8c4e

Browse files
committed
blend modes in Custom Skies
1 parent 8f2cb17 commit 54a8c4e

File tree

8 files changed

+119
-18
lines changed

8 files changed

+119
-18
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/io/github/axolotlclient/mixin/MinecraftClientMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void tickClient(CallbackInfo ci){
105105
}
106106

107107

108-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I"))
108+
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventDWheel()I"), remap = false)
109109
public int onScroll() {
110110
int amount = Mouse.getEventDWheel();
111111
if(amount != 0) {

src/main/java/io/github/axolotlclient/mixin/WorldRendererMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public void sky(float f, int ih, CallbackInfo ci){
5757

5858
Tessellator tessellator = Tessellator.getInstance();
5959
BufferBuilder bufferBuilder = tessellator.getBuffer();
60+
float n = 1.0F - this.world.getRainGradient(f);
6061

6162
this.client.profiler.push("Custom Skies");
62-
SkyboxManager.getInstance().renderSkyboxes();
63+
SkyboxManager.getInstance().renderSkyboxes(n);
6364

6465
this.client.profiler.pop();
6566

6667
GlStateManager.pushMatrix();
67-
float n = 1.0F - this.world.getRainGradient(f);
6868
GlStateManager.color4f(1.0F, 1.0F, 1.0F, n);
6969
GlStateManager.rotatef(-90.0F, 0.0F, 1.0F, 0.0F);
7070
GlStateManager.rotatef(this.world.getSkyAngle(f) * 360.0F, 1.0F, 0.0F, 0.0F);
@@ -188,7 +188,7 @@ public float getCloudHeight(Dimension instance){
188188
}
189189

190190

191-
@ModifyArg(method = "method_1380", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glLineWidth(F)V"))
191+
@ModifyArg(method = "method_1380", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glLineWidth(F)V"), remap = false)
192192
public float OutlineWidth(float width){
193193
if(AxolotlClient.CONFIG.enableCustomOutlines.get() && AxolotlClient.CONFIG.outlineWidth.get()>1){
194194
return 1.0F+ AxolotlClient.CONFIG.outlineWidth.get();

src/main/java/io/github/axolotlclient/modules/sky/FSBSkyboxInstance.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@ public FSBSkyboxInstance(JsonObject json){
3030
this.fade[1] = props.get("fade").getAsJsonObject().get("endFadeIn").getAsInt();
3131
this.fade[2] = props.get("fade").getAsJsonObject().get("startFadeOut").getAsInt();
3232
this.fade[3] = props.get("fade").getAsJsonObject().get("endFadeOut").getAsInt();
33+
34+
this.blendMode = parseBlend(props.get("blend").getAsJsonObject().get("type").getAsString());
3335
}
3436

3537
public void renderSkybox(){
3638
this.alpha = getAlpha();
3739
this.distance=MinecraftClient.getInstance().options.viewDistance;
3840

39-
GlStateManager.enableBlend();
40-
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
41-
4241
Tessellator tessellator = Tessellator.getInstance();
4342
BufferBuilder bufferBuilder = tessellator.getBuffer();
4443

@@ -73,6 +72,5 @@ public void renderSkybox(){
7372
tessellator.draw();
7473
GlStateManager.popMatrix();
7574
}
76-
GlStateManager.disableBlend();
7775
}
7876
}

src/main/java/io/github/axolotlclient/modules/sky/MCPSkyboxInstance.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ public MCPSkyboxInstance(JsonObject json){
1818
this.fade[1] = json.get("endFadeIn").getAsInt();
1919
this.fade[2] = json.get("startFadeOut").getAsInt();
2020
this.fade[3] = json.get("endFadeOut").getAsInt();
21+
this.blendMode=parseBlend(json.get("blend").getAsString());
2122
}
2223

2324
@Override
2425
public void renderSkybox() {
2526
this.alpha=getAlpha();
2627
this.distance=MinecraftClient.getInstance().options.viewDistance;
2728

28-
GlStateManager.enableBlend();
29-
GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
30-
3129
Tessellator tessellator = Tessellator.getInstance();
3230
BufferBuilder bufferBuilder = tessellator.getBuffer();
3331

@@ -85,6 +83,5 @@ public void renderSkybox() {
8583
GlStateManager.popMatrix();
8684
}
8785
}
88-
GlStateManager.disableBlend();
8986
}
9087
}

src/main/java/io/github/axolotlclient/modules/sky/SkyResourceManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public static void loadMCPSky(ResourcePack pack, String loader, SkyLoadingScreen
8686
int endFadeIn = 0;
8787
int startFadeOut= 0;
8888
int endFadeOut = 0;
89+
String blend="alpha";
8990
InputStream stream = pack.open(new Identifier("minecraft", loader + "/sky/world0/sky" + i + ".properties"));
9091

9192
loadingScreen.setDesc("sky"+i+".properties");
@@ -100,6 +101,7 @@ public static void loadMCPSky(ResourcePack pack, String loader, SkyLoadingScreen
100101
if(option[0].equals("endFadeIn"))endFadeIn= Integer.parseInt(option[1].split(":")[0]+option[1].split(":")[1]);
101102
if(option[0].equals("startFadeOut"))startFadeOut= Integer.parseInt(option[1].split(":")[0]+option[1].split(":")[1]);
102103
if(option[0].equals("endFadeOut"))endFadeOut= Integer.parseInt(option[1].split(":")[0]+option[1].split(":")[1]);
104+
if(option[0].equals("blend")) blend=option[1];
103105

104106

105107
} catch (Exception ignored){}
@@ -109,7 +111,8 @@ public static void loadMCPSky(ResourcePack pack, String loader, SkyLoadingScreen
109111
"\"startFadeIn\":"+startFadeIn/2+", " +
110112
"\"endFadeIn\":"+endFadeIn/2+", " +
111113
"\"startFadeOut\":"+startFadeOut/2+", " +
112-
"\"endFadeOut\":"+endFadeOut/2+
114+
"\"endFadeOut\":"+endFadeOut/2+", " +
115+
"\"blend\":\""+blend+ "\""+
113116
"}";
114117
JsonObject object = gson.fromJson(text, JsonObject.class);
115118
if(!source.contains("sunflare")) SkyboxManager.getInstance().addSkybox(new MCPSkyboxInstance(object));

src/main/java/io/github/axolotlclient/modules/sky/SkyboxInstance.java

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package io.github.axolotlclient.modules.sky;
22

33
import com.google.gson.JsonObject;
4+
import com.mojang.blaze3d.platform.GlStateManager;
5+
import io.github.axolotlclient.AxolotlClient;
46
import io.github.axolotlclient.util.Util;
57
import net.minecraft.client.MinecraftClient;
68
import net.minecraft.util.Identifier;
79

10+
import java.util.Locale;
811
import java.util.Objects;
912

1013
/**
1114
* This implementation of custom skies is based on the FabricSkyBoxes mod by AMereBagatelle
1215
* https://github.com/AMereBagatelle/FabricSkyBoxes
1316
**/
1417

15-
public class SkyboxInstance {
18+
public abstract class SkyboxInstance {
1619

1720
JsonObject object;
1821
float alpha = 1F;
1922
Identifier[] textures = new Identifier[6];
2023
int[] fade = new int[4];
2124

25+
protected int blendMode = 1;
26+
2227
// ! These are the options variables. Do not mess with these.
2328
protected float maxAlpha = 1f;
2429
int distance;
@@ -91,6 +96,104 @@ public float getAlpha(){
9196
return maxPossibleAlpha;
9297
}
9398

94-
public void renderSkybox(){
99+
protected int parseBlend(String str){
100+
if (str == null) {
101+
return 1;
102+
} else {
103+
104+
switch (str.toLowerCase(Locale.ENGLISH).trim()) {
105+
case "alpha":
106+
return 0;
107+
case "add":
108+
return 1;
109+
case "subtract":
110+
return 2;
111+
case "multiply":
112+
return 3;
113+
case "dodge":
114+
return 4;
115+
case "burn":
116+
return 5;
117+
case "screen":
118+
return 6;
119+
case "overlay":
120+
return 7;
121+
case "replace":
122+
return 8;
123+
default:
124+
AxolotlClient.LOGGER.warn("Unknown blend: " + str);
125+
return 1;
126+
}
127+
}
128+
}
129+
130+
protected void setupBlend(float brightness){
131+
GlStateManager.disableAlphaTest();
132+
133+
switch (blendMode)
134+
{
135+
case 0:
136+
137+
GlStateManager.enableBlend();
138+
GlStateManager.blendFunc(770, 771);
139+
break;
140+
141+
case 1:
142+
143+
GlStateManager.enableBlend();
144+
GlStateManager.blendFunc(770, 1);
145+
break;
146+
147+
case 2:
148+
GlStateManager.enableBlend();
149+
GlStateManager.blendFunc(775, 0);
150+
break;
151+
152+
case 3:
153+
GlStateManager.enableBlend();
154+
GlStateManager.blendFunc(774, 771);
155+
break;
156+
157+
case 4:
158+
GlStateManager.enableBlend();
159+
GlStateManager.blendFunc(1, 1);
160+
break;
161+
162+
case 5:
163+
GlStateManager.enableBlend();
164+
GlStateManager.blendFunc(0, 769);
165+
break;
166+
167+
case 6:
168+
GlStateManager.enableBlend();
169+
GlStateManager.blendFunc(1, 769);
170+
break;
171+
172+
case 7:
173+
GlStateManager.enableBlend();
174+
GlStateManager.blendFunc(774, 768);
175+
break;
176+
177+
case 8:
178+
GlStateManager.disableBlend();
179+
}
180+
GlStateManager.color4f(1.0F, 1.0F, 1.0F, brightness);
181+
182+
GlStateManager.enableTexture();
183+
}
184+
185+
protected void clearBlend(float brightness){
186+
GlStateManager.disableAlphaTest();
187+
GlStateManager.enableBlend();
188+
GlStateManager.blendFunc(770, 1);
189+
GlStateManager.color4f(1.0F, 1.0F, 1.0F, brightness);
95190
}
191+
192+
public void render(float brightness){
193+
setupBlend(brightness);
194+
renderSkybox();
195+
clearBlend(brightness);
196+
}
197+
198+
public abstract void renderSkybox();
96199
}

src/main/java/io/github/axolotlclient/modules/sky/SkyboxManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class SkyboxManager {
2121

2222
private static final SkyboxManager INSTANCE = new SkyboxManager();
2323

24-
public void renderSkyboxes(){
24+
public void renderSkyboxes(float brightness){
2525
this.skyboxes.stream().filter(this.renderPredicate).forEach(this.active_skies::add);
26-
this.active_skies.forEach(skyboxInstance -> {if(skyboxInstance!=null)skyboxInstance.renderSkybox();});
26+
this.active_skies.forEach(skyboxInstance -> {if(skyboxInstance!=null)skyboxInstance.render(brightness);});
2727
this.active_skies.removeIf((skybox) -> skybox.getAlpha() <= MINIMUM_ALPHA);
2828
}
2929

0 commit comments

Comments
 (0)