aboutsummaryrefslogtreecommitdiff
path: root/defaults/src/main/java/shcm/shsupercm/fabric
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-02-22 19:54:53 +0200
committerSHsuperCM <shsupercm@gmail.com>2022-02-22 19:54:53 +0200
commit87baf18026aa53bba953888ac73ed656ceaf737c (patch)
tree70dd39cc354101daa153f0cfe44a5b49da0231b2 /defaults/src/main/java/shcm/shsupercm/fabric
parent2d99c1b5773eb4067bb873e21c409a9a2399ab3d (diff)
downloadCITResewn-87baf18026aa53bba953888ac73ed656ceaf737c.tar.gz
CITResewn-87baf18026aa53bba953888ac73ed656ceaf737c.tar.bz2
CITResewn-87baf18026aa53bba953888ac73ed656ceaf737c.zip
Started porting enchantment type
Diffstat (limited to 'defaults/src/main/java/shcm/shsupercm/fabric')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java152
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java16
2 files changed, 163 insertions, 5 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java
index 566273a..760cc83 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeEnchantment.java
@@ -1,17 +1,21 @@
package shcm.shsupercm.fabric.citresewn.defaults.cit.types;
import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint;
+import net.minecraft.client.render.RenderPhase;
import net.minecraft.resource.ResourceManager;
+import net.minecraft.util.Identifier;
+import org.lwjgl.opengl.GL11;
import shcm.shsupercm.fabric.citresewn.api.CITTypeContainer;
-import shcm.shsupercm.fabric.citresewn.cit.CIT;
-import shcm.shsupercm.fabric.citresewn.cit.CITCondition;
-import shcm.shsupercm.fabric.citresewn.cit.CITType;
+import shcm.shsupercm.fabric.citresewn.cit.*;
import shcm.shsupercm.fabric.citresewn.ex.CITParsingException;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyGroup;
import shcm.shsupercm.fabric.citresewn.pack.format.PropertyKey;
-import java.util.List;
-import java.util.Set;
+import java.lang.ref.WeakReference;
+import java.util.*;
+
+import static com.mojang.blaze3d.systems.RenderSystem.*;
+import static org.lwjgl.opengl.GL11.*;
public class TypeEnchantment extends CITType {
@Entrypoint(CITTypeContainer.ENTRYPOINT)
@@ -34,6 +38,12 @@ public class TypeEnchantment extends CITType {
PropertyKey.of("a"));
}
+ public Identifier texture;
+ public float speed, rotation, duration, r, g, b, a;
+ public int layer;
+ public boolean useGlint, blur;
+ public Blend blend;
+
@Override
public void load(List<CITCondition> conditions, PropertyGroup properties, ResourceManager resourceManager) throws CITParsingException {
@@ -44,14 +54,146 @@ public class TypeEnchantment extends CITType {
super(TypeEnchantment.class, TypeEnchantment::new, "enchantment");
}
+ public List<CIT<TypeEnchantment>> loaded = new ArrayList<>();
+ public List<List<CIT<TypeEnchantment>>> loadedLayered = new ArrayList<>();
+
@Override
public void load(List<CIT<TypeEnchantment>> parsedCITs) {
+ loaded.addAll(parsedCITs);
+ Map<Integer, List<CIT<TypeEnchantment>>> layers = new HashMap<>();
+ for (CIT<TypeEnchantment> cit : loaded)
+ layers.computeIfAbsent(cit.type.layer, i -> new ArrayList<>()).add(cit);
+ loadedLayered.clear();
+ layers.entrySet().stream()
+ .sorted(Map.Entry.comparingByKey())
+ .forEachOrdered(layer -> loadedLayered.add(layer.getValue()));
}
@Override
public void dispose() {
+ loaded.clear();
+ loadedLayered.clear();
+ }
+
+ public void apply(CITContext context) {
+ if (context == null) {
+ //todo clear
+ return;
+ }
+
+ List<WeakReference<CIT<TypeEnchantment>>> cits = ((CITCacheEnchantment) (Object) context.stack).citresewn$getCacheTypeEnchantment().get(context);
+
+ //todo apply
+ }
+
+ public List<CIT<TypeEnchantment>> getRealTimeCIT(CITContext context) {
+ List<CIT<TypeEnchantment>> cits = new ArrayList<>();
+ for (List<CIT<TypeEnchantment>> layer : loadedLayered)
+ for (CIT<TypeEnchantment> cit : layer)
+ if (cit.test(context)) {
+ cits.add(cit);
+ break;
+ }
+ return cits;
+ }
+ }
+
+ public static class Blend extends RenderPhase.Transparency {
+ private final int src, dst, srcAlpha, dstAlpha;
+
+ 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, srcAlpha, dstAlpha);
}
+
+ @Override
+ public void endDrawing() {
+ defaultBlendFunc();
+ disableBlend();
+ }
+
+ public static Blend getBlend(String blendString) throws BlendFormatException {
+ try { //check named blending function
+ return Named.valueOf(blendString.toUpperCase(Locale.ENGLISH)).blend;
+ } catch (IllegalArgumentException ignored) { // create custom blending function
+ try {
+ 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();
+
+ return new Blend("custom_" + src + "_" + dst + "_" + srcAlpha + "_" + dstAlpha, src, dst, srcAlpha, dstAlpha);
+ } catch (Exception e) {
+ throw new BlendFormatException();
+ }
+ }
+ }
+
+ private enum Named {
+ REPLACE(new Blend("replace", 0, 0) {
+ @Override
+ public void startDrawing() {
+ disableBlend();
+ }
+ }),
+ GLINT(new Blend("glint", GL_SRC_COLOR, GL_ONE)),
+ ALPHA(new Blend("alpha", GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)),
+ ADD(new Blend("add", GL_SRC_ALPHA, GL_ONE)),
+ SUBTRACT(new Blend("subtract", GL_ONE_MINUS_DST_COLOR, GL_ZERO)),
+ MULTIPLY(new Blend("multiply", GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA)),
+ DODGE(new Blend("dodge", GL_ONE, GL_ONE)),
+ BURN(new Blend("burn", GL_ZERO, GL_ONE_MINUS_SRC_COLOR)),
+ SCREEN(new Blend("screen", GL_ONE, GL_ONE_MINUS_SRC_COLOR)),
+ OVERLAY(new Blend("overlay", GL_DST_COLOR, GL_SRC_COLOR));
+
+ public final Blend blend;
+
+ Named(Blend blend) {
+ this.blend = blend;
+ }
+ }
+
+ 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");
+ }
+ }
+ }
+
+ public interface CITCacheEnchantment {
+ CITCache.MultiList<TypeEnchantment> citresewn$getCacheTypeEnchantment();
}
}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java
new file mode 100644
index 0000000..bbd61d9
--- /dev/null
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/enchantment/ItemStackMixin.java
@@ -0,0 +1,16 @@
+package shcm.shsupercm.fabric.citresewn.defaults.mixin.types.enchantment;
+
+import net.minecraft.item.ItemStack;
+import org.spongepowered.asm.mixin.Mixin;
+import shcm.shsupercm.fabric.citresewn.cit.CITCache;
+import shcm.shsupercm.fabric.citresewn.defaults.cit.types.TypeEnchantment;
+
+@Mixin(ItemStack.class)
+public class ItemStackMixin implements TypeEnchantment.CITCacheEnchantment {
+ private final CITCache.MultiList<TypeEnchantment> citresewn$cacheTypeEnchantment = new CITCache.MultiList<>(TypeEnchantment.CONTAINER::getRealTimeCIT);
+
+ @Override
+ public CITCache.MultiList<TypeEnchantment> citresewn$getCacheTypeEnchantment() {
+ return this.citresewn$cacheTypeEnchantment;
+ }
+}