aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-10-09 13:27:07 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-10-09 13:27:07 +0300
commite3ddc19843e7a70a391782e835091bb0bda9e2a6 (patch)
treec1c5348e6b2d50af8356550c1000b4ef4faebd3d /src/main/java/shcm/shsupercm/fabric
parentd7f842a6dd474d69709a6c47296e4873ead74a50 (diff)
downloadCITResewn-e3ddc19843e7a70a391782e835091bb0bda9e2a6.tar.gz
CITResewn-e3ddc19843e7a70a391782e835091bb0bda9e2a6.tar.bz2
CITResewn-e3ddc19843e7a70a391782e835091bb0bda9e2a6.zip
Register render layers for CITEnchantments
#15
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java6
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java15
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java44
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java105
4 files changed, 167 insertions, 3 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
index db5bc04..f4d2b5b 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java
@@ -46,7 +46,11 @@ public class ActiveCITs {
citEnchantmentLayers.computeIfAbsent(enchantment.layer, l -> new ArrayList<>()).add(enchantment);
}
- citEnchantments.addAll(citEnchantmentLayers.values());
+ for (List<CITEnchantment> layer : citEnchantmentLayers.values()) {
+ for (CITEnchantment enchantment : layer)
+ enchantment.activate();
+ citEnchantments.add(layer);
+ }
}
public void dispose() {
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java
new file mode 100644
index 0000000..619a82d
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java
@@ -0,0 +1,15 @@
+package shcm.shsupercm.fabric.citresewn.mixin.citenchantment;
+
+import net.minecraft.client.render.BufferBuilder;
+import net.minecraft.client.render.BufferBuilderStorage;
+import net.minecraft.client.render.RenderLayer;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import java.util.SortedMap;
+
+@Mixin(BufferBuilderStorage.class)
+public interface BufferBuilderStorageAccessor {
+ @Accessor("entityBuilders")
+ SortedMap<RenderLayer, BufferBuilder> entityBuilders();
+}
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java
new file mode 100644
index 0000000..b7e995e
--- /dev/null
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java
@@ -0,0 +1,44 @@
+package shcm.shsupercm.fabric.citresewn.mixin.citenchantment;
+
+import net.minecraft.client.render.RenderPhase;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(RenderPhase.class)
+public interface RenderPhaseAccessor {
+ @Accessor("GLINT_TRANSPARENCY") static RenderPhase.Transparency GLINT_TRANSPARENCY() { throw new RuntimeException(); }
+ @Accessor("ARMOR_GLINT_SHADER") static RenderPhase.Shader ARMOR_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("ARMOR_ENTITY_GLINT_SHADER") static RenderPhase.Shader ARMOR_ENTITY_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("TRANSLUCENT_GLINT_SHADER") static RenderPhase.Shader TRANSLUCENT_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("GLINT_SHADER") static RenderPhase.Shader GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("DIRECT_GLINT_SHADER") static RenderPhase.Shader DIRECT_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("ENTITY_GLINT_SHADER") static RenderPhase.Shader ENTITY_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("DIRECT_ENTITY_GLINT_SHADER") static RenderPhase.Shader DIRECT_ENTITY_GLINT_SHADER() { throw new RuntimeException(); }
+ @Accessor("MIPMAP_BLOCK_ATLAS_TEXTURE") static RenderPhase.Texture MIPMAP_BLOCK_ATLAS_TEXTURE() { throw new RuntimeException(); }
+ @Accessor("BLOCK_ATLAS_TEXTURE") static RenderPhase.Texture BLOCK_ATLAS_TEXTURE() { throw new RuntimeException(); }
+ @Accessor("DEFAULT_TEXTURING") static RenderPhase.Texturing DEFAULT_TEXTURING() { throw new RuntimeException(); }
+ @Accessor("GLINT_TEXTURING") static RenderPhase.Texturing GLINT_TEXTURING() { throw new RuntimeException(); }
+ @Accessor("ENTITY_GLINT_TEXTURING") static RenderPhase.Texturing ENTITY_GLINT_TEXTURING() { throw new RuntimeException(); }
+ @Accessor("ENABLE_LIGHTMAP") static RenderPhase.Lightmap ENABLE_LIGHTMAP() { throw new RuntimeException(); }
+ @Accessor("DISABLE_LIGHTMAP") static RenderPhase.Lightmap DISABLE_LIGHTMAP() { throw new RuntimeException(); }
+ @Accessor("ENABLE_OVERLAY_COLOR") static RenderPhase.Overlay ENABLE_OVERLAY_COLOR() { throw new RuntimeException(); }
+ @Accessor("DISABLE_OVERLAY_COLOR") static RenderPhase.Overlay DISABLE_OVERLAY_COLOR() { throw new RuntimeException(); }
+ @Accessor("ENABLE_CULLING") static RenderPhase.Cull ENABLE_CULLING() { throw new RuntimeException(); }
+ @Accessor("DISABLE_CULLING") static RenderPhase.Cull DISABLE_CULLING() { throw new RuntimeException(); }
+ @Accessor("ALWAYS_DEPTH_TEST") static RenderPhase.DepthTest ALWAYS_DEPTH_TEST() { throw new RuntimeException(); }
+ @Accessor("EQUAL_DEPTH_TEST") static RenderPhase.DepthTest EQUAL_DEPTH_TEST() { throw new RuntimeException(); }
+ @Accessor("LEQUAL_DEPTH_TEST") static RenderPhase.DepthTest LEQUAL_DEPTH_TEST() { throw new RuntimeException(); }
+ @Accessor("ALL_MASK") static RenderPhase.WriteMaskState ALL_MASK() { throw new RuntimeException(); }
+ @Accessor("COLOR_MASK") static RenderPhase.WriteMaskState COLOR_MASK() { throw new RuntimeException(); }
+ @Accessor("DEPTH_MASK") static RenderPhase.WriteMaskState DEPTH_MASK() { throw new RuntimeException(); }
+ @Accessor("NO_LAYERING") static RenderPhase.Layering NO_LAYERING() { throw new RuntimeException(); }
+ @Accessor("POLYGON_OFFSET_LAYERING") static RenderPhase.Layering POLYGON_OFFSET_LAYERING() { throw new RuntimeException(); }
+ @Accessor("VIEW_OFFSET_Z_LAYERING") static RenderPhase.Layering VIEW_OFFSET_Z_LAYERING() { throw new RuntimeException(); }
+ @Accessor("MAIN_TARGET") static RenderPhase.Target MAIN_TARGET() { throw new RuntimeException(); }
+ @Accessor("OUTLINE_TARGET") static RenderPhase.Target OUTLINE_TARGET() { throw new RuntimeException(); }
+ @Accessor("TRANSLUCENT_TARGET") static RenderPhase.Target TRANSLUCENT_TARGET() { throw new RuntimeException(); }
+ @Accessor("PARTICLES_TARGET") static RenderPhase.Target PARTICLES_TARGET() { throw new RuntimeException(); }
+ @Accessor("WEATHER_TARGET") static RenderPhase.Target WEATHER_TARGET() { throw new RuntimeException(); }
+ @Accessor("CLOUDS_TARGET") static RenderPhase.Target CLOUDS_TARGET() { throw new RuntimeException(); }
+ @Accessor("ITEM_TARGET") static RenderPhase.Target ITEM_TARGET() { throw new RuntimeException(); }
+}
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 16222a7..b1c37db 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
@@ -1,12 +1,16 @@
package shcm.shsupercm.fabric.citresewn.pack.cits;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.render.*;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
+import shcm.shsupercm.fabric.citresewn.mixin.citenchantment.BufferBuilderStorageAccessor;
+import shcm.shsupercm.fabric.citresewn.mixin.citenchantment.RenderPhaseAccessor;
import shcm.shsupercm.fabric.citresewn.pack.CITPack;
-import java.util.Locale;
-import java.util.Properties;
+import java.util.*;
+import java.util.function.Consumer;
public class CITEnchantment extends CIT {
public final Identifier textureIdentifier;
@@ -14,6 +18,8 @@ public class CITEnchantment extends CIT {
public final int layer;
public final Blend blend;
+ public final Map<GlintRenderLayer, RenderLayer> renderLayers = new EnumMap<>(GlintRenderLayer.class);
+
public CITEnchantment(CITPack pack, Identifier identifier, Properties properties) throws CITParseException {
super(pack, identifier, properties);
try {
@@ -30,11 +36,28 @@ public class CITEnchantment extends CIT {
rotation = Float.parseFloat(properties.getProperty("rotation", "0"));
duration = Float.max(0f, Float.parseFloat(properties.getProperty("duration", "0")));
+
+
} catch (Exception e) {
throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage());
}
}
+ public void activate() {
+ for (GlintRenderLayer glintLayer : GlintRenderLayer.values()) {
+ RenderLayer renderLayer = glintLayer.build(this);
+
+ renderLayers.put(glintLayer, renderLayer);
+ ((BufferBuilderStorageAccessor) MinecraftClient.getInstance().getBufferBuilders()).entityBuilders().put(renderLayer, new BufferBuilder(renderLayer.getExpectedBufferSize()));
+ }
+ }
+
+ @Override
+ public void dispose() {
+ for (RenderLayer renderLayer : renderLayers.values())
+ ((BufferBuilderStorageAccessor) MinecraftClient.getInstance().getBufferBuilders()).entityBuilders().remove(renderLayer);
+ }
+
public enum Blend {
ADD,
SUBTRACT,
@@ -46,4 +69,82 @@ public class CITEnchantment extends CIT {
OVERLAY,
ALPHA;
}
+
+ public enum GlintRenderLayer {
+ ARMOR_GLINT("armor_glint", layer -> layer
+ .shader(RenderPhaseAccessor.ARMOR_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .texturing(RenderPhaseAccessor.GLINT_TEXTURING())
+ .layering(RenderPhaseAccessor.VIEW_OFFSET_Z_LAYERING())),
+ ARMOR_ENTITY_GLINT("armor_entity_glint", layer -> layer
+ .shader(RenderPhaseAccessor.ARMOR_ENTITY_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .texturing(RenderPhaseAccessor.ENTITY_GLINT_TEXTURING())
+ .layering(RenderPhaseAccessor.VIEW_OFFSET_Z_LAYERING())),
+ GLINT_TRANSLUCENT("glint_translucent", layer -> layer
+ .shader(RenderPhaseAccessor.TRANSLUCENT_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .target(RenderPhaseAccessor.ITEM_TARGET())
+ .texturing(RenderPhaseAccessor.GLINT_TEXTURING())),
+ GLINT("glint", layer -> layer
+ .shader(RenderPhaseAccessor.GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .texturing(RenderPhaseAccessor.GLINT_TEXTURING())),
+ DIRECT_GLINT("glint_direct", layer -> layer
+ .shader(RenderPhaseAccessor.DIRECT_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .texturing(RenderPhaseAccessor.GLINT_TEXTURING())),
+ ENTITY_GLINT("entity_glint", layer -> layer
+ .shader(RenderPhaseAccessor.ENTITY_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .target(RenderPhaseAccessor.ITEM_TARGET())
+ .texturing(RenderPhaseAccessor.ENTITY_GLINT_TEXTURING())),
+ DIRECT_ENTITY_GLINT("entity_glint_direct", layer -> layer
+ .shader(RenderPhaseAccessor.DIRECT_ENTITY_GLINT_SHADER())
+ .writeMaskState(RenderPhaseAccessor.COLOR_MASK())
+ .cull(RenderPhaseAccessor.DISABLE_CULLING())
+ .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())
+ .transparency(RenderPhaseAccessor.GLINT_TRANSPARENCY())
+ .texturing(RenderPhaseAccessor.ENTITY_GLINT_TEXTURING()));
+
+ public final String name;
+ protected final Consumer<RenderLayer.MultiPhaseParameters.Builder> setup;
+
+ GlintRenderLayer(String name, Consumer<RenderLayer.MultiPhaseParameters.Builder> setup) {
+ this.name = name;
+ this.setup = setup;
+ }
+
+ public RenderLayer build(CITEnchantment enchantment) {
+ //noinspection ConstantConditions
+ RenderLayer.MultiPhaseParameters.Builder layer = RenderLayer.MultiPhaseParameters.builder()
+ .texture(new RenderPhase.Texture(enchantment.textureIdentifier, true, false));
+
+ this.setup.accept(layer);
+
+ return RenderLayer.of("citresewn:enchantment_" + this.name + ":" + enchantment.propertiesIdentifier.toString(),
+ VertexFormats.POSITION_TEXTURE,
+ VertexFormat.DrawMode.QUADS,
+ 256,
+ layer.build(false));
+ }
+ }
} \ No newline at end of file