aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/pack
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-10-29 09:39:16 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-10-29 09:39:16 +0300
commitf0b1531914871523f912b0e65b60979d7c22eb78 (patch)
treed3595efc4c5a3be780a8ecccb0c20405983fec03 /src/main/java/shcm/shsupercm/fabric/citresewn/pack
parent1d9d6a3de56202deb6e18a9538f82aa24ea2bca9 (diff)
downloadCITResewn-f0b1531914871523f912b0e65b60979d7c22eb78.tar.gz
CITResewn-f0b1531914871523f912b0e65b60979d7c22eb78.tar.bz2
CITResewn-f0b1531914871523f912b0e65b60979d7c22eb78.zip
Rewrote custom blend parsing
Now accepts either 2 or 4 separate blend func params and each parameter accepts either a decimal constant, a 0x prefixed hexadecimal constant or named GL constants in GL11.
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
index 70ad618..d738570 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java
@@ -8,6 +8,7 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.util.math.Matrix4f;
import net.minecraft.util.math.Vec3f;
+import org.lwjgl.opengl.GL11;
import shcm.shsupercm.fabric.citresewn.CITResewn;
import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
@@ -186,19 +187,24 @@ public class CITEnchantment extends CIT {
}
public static class Blend extends RenderPhase.Transparency {
- private final int src;
- private final int dst;
+ private final int src, dst, srcAlpha, dstAlpha;
- private Blend(String name, int src, int dst) {
+ private Blend(String name, int src, int dst, int srcAlpha, int dstAlpha) {
super(name + "_glint_transparency", null, null);
this.src = src;
this.dst = dst;
+ this.srcAlpha = srcAlpha;
+ this.dstAlpha = dstAlpha;
+ }
+
+ private Blend(String name, int src, int dst) {
+ this(name, src, dst, GL_ZERO, GL_ONE);
}
@Override
public void startDrawing() {
enableBlend();
- blendFuncSeparate(src, dst, GL_ZERO, GL_ONE);
+ blendFuncSeparate(src, dst, srcAlpha, dstAlpha);
}
@Override
@@ -212,12 +218,22 @@ public class CITEnchantment extends CIT {
return Named.valueOf(blendString.toUpperCase(Locale.ENGLISH)).blend;
} catch (IllegalArgumentException ignored) { // create custom blending function
try {
- String[] split = blendString.split("[ ,_]+");
- if (split.length != 2)
+ String[] split = blendString.split(" ");
+ int src, dst, srcAlpha, dstAlpha;
+ if (split.length == 2) {
+ src = parseGLConstant(split[0]);
+ dst = parseGLConstant(split[1]);
+ srcAlpha = GL_ZERO;
+ dstAlpha = GL_ONE;
+ } else if (split.length == 4) {
+ src = parseGLConstant(split[0]);
+ dst = parseGLConstant(split[1]);
+ srcAlpha = parseGLConstant(split[2]);
+ dstAlpha = parseGLConstant(split[3]);
+ } else
throw new Exception();
- int src = Integer.parseInt(split[0]), dst = Integer.parseInt(split[1]);
- return new Blend("custom_" + src + "_" + dst, src, dst);
+ return new Blend("custom_" + src + "_" + dst + "_" + srcAlpha + "_" + dstAlpha, src, dst, srcAlpha, dstAlpha);
} catch (Exception e) {
throw new BlendFormatException();
}
@@ -248,6 +264,14 @@ public class CITEnchantment extends CIT {
}
}
+ private static int parseGLConstant(String s) throws Exception {
+ try {
+ return GL11.class.getDeclaredField(s).getInt(null);
+ } catch (NoSuchFieldException ignored) { }
+
+ return s.startsWith("0x") ? Integer.parseInt(s.substring(2), 16) : Integer.parseInt(s);
+ }
+
public static class BlendFormatException extends Exception {
public BlendFormatException() {
super("Not a valid blending method");