From 1ccd38765559e9aae57db002269103bc2d7fb878 Mon Sep 17 00:00:00 2001 From: ZhuRuoLing Date: Tue, 17 Dec 2024 23:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=92=8Cembeddium=E4=B8=8Eso?= =?UTF-8?q?dium=E7=9A=84=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../embeddium/ModEmbeddiumMaterials.java | 9 +++++ .../ModEmbeddiumTerrainRenderPasses.java | 9 +++++ .../sodium/ModSodiumMaterials.java | 8 +++++ .../sodium/ModSodiumTerrainRenderPasses.java | 9 +++++ .../EmbeddiumDefaultMaterialsMixin.java | 26 ++++++++++++++ ...eddiumDefaultTerrainRenderPassesMixin.java | 34 +++++++++++++++++++ .../compat/SodiumDefaultMaterialsMixin.java | 26 ++++++++++++++ ...SodiumDefaultTerrainRenderPassesMixin.java | 32 +++++++++++++++++ src/main/resources/anvilcraft.mixins.json | 6 +++- 9 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumMaterials.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumTerrainRenderPasses.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumMaterials.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumTerrainRenderPasses.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultMaterialsMixin.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultTerrainRenderPassesMixin.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultMaterialsMixin.java create mode 100644 src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultTerrainRenderPassesMixin.java diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumMaterials.java b/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumMaterials.java new file mode 100644 index 000000000..3da7d7519 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumMaterials.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.embeddium; + + +import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material; +import org.embeddedt.embeddium.impl.render.chunk.terrain.material.parameters.AlphaCutoffParameter; + +public class ModEmbeddiumMaterials { + public static final Material LASER = new Material(ModEmbeddiumTerrainRenderPasses.LASER, AlphaCutoffParameter.ZERO, true); +} diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumTerrainRenderPasses.java b/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumTerrainRenderPasses.java new file mode 100644 index 000000000..536b4c6f1 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/embeddium/ModEmbeddiumTerrainRenderPasses.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.embeddium; + + +import dev.dubhe.anvilcraft.client.init.ModRenderTypes; +import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass; + +public class ModEmbeddiumTerrainRenderPasses { + public static final TerrainRenderPass LASER = new TerrainRenderPass(ModRenderTypes.LASER, true, true); +} diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumMaterials.java b/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumMaterials.java new file mode 100644 index 000000000..aacef0308 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumMaterials.java @@ -0,0 +1,8 @@ +package dev.dubhe.anvilcraft.integration.sodium; + +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.Material; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.parameters.AlphaCutoffParameter; + +public class ModSodiumMaterials { + public static final Material LASER = new Material(ModSodiumTerrainRenderPasses.LASER, AlphaCutoffParameter.ZERO, true); +} diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumTerrainRenderPasses.java b/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumTerrainRenderPasses.java new file mode 100644 index 000000000..6515f8f5c --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/sodium/ModSodiumTerrainRenderPasses.java @@ -0,0 +1,9 @@ +package dev.dubhe.anvilcraft.integration.sodium; + + +import dev.dubhe.anvilcraft.client.init.ModRenderTypes; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; + +public class ModSodiumTerrainRenderPasses { + public static final TerrainRenderPass LASER = new TerrainRenderPass(ModRenderTypes.LASER, true, true); +} diff --git a/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultMaterialsMixin.java b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultMaterialsMixin.java new file mode 100644 index 000000000..4b146b668 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultMaterialsMixin.java @@ -0,0 +1,26 @@ +package dev.dubhe.anvilcraft.mixin.compat; + +import dev.dubhe.anvilcraft.client.init.ModRenderTypes; +import dev.dubhe.anvilcraft.integration.embeddium.ModEmbeddiumMaterials; +import net.minecraft.client.renderer.RenderType; +import org.embeddedt.embeddium.impl.render.chunk.terrain.material.DefaultMaterials; +import org.embeddedt.embeddium.impl.render.chunk.terrain.material.Material; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(DefaultMaterials.class) +public class EmbeddiumDefaultMaterialsMixin { + @Inject( + method = "forRenderLayer", + at = @At("HEAD"), + cancellable = true + ) + private static void anvilcraft$forRenderLayer(RenderType layer, CallbackInfoReturnable cir){ + if (layer == ModRenderTypes.LASER){ + cir.setReturnValue(ModEmbeddiumMaterials.LASER); + cir.cancel(); + } + } +} diff --git a/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultTerrainRenderPassesMixin.java b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultTerrainRenderPassesMixin.java new file mode 100644 index 000000000..46bf4c8b4 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/EmbeddiumDefaultTerrainRenderPassesMixin.java @@ -0,0 +1,34 @@ +package dev.dubhe.anvilcraft.mixin.compat; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.dubhe.anvilcraft.integration.embeddium.ModEmbeddiumTerrainRenderPasses; +import org.apache.commons.lang3.ArrayUtils; +import org.embeddedt.embeddium.impl.render.chunk.terrain.DefaultTerrainRenderPasses; +import org.embeddedt.embeddium.impl.render.chunk.terrain.TerrainRenderPass; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DefaultTerrainRenderPasses.class) +public class EmbeddiumDefaultTerrainRenderPassesMixin { + + @Shadow + @Final + @Mutable + public static TerrainRenderPass[] ALL; + + @WrapOperation( + method = "", + at = @At( + value = "FIELD", + target = "Lorg/embeddedt/embeddium/impl/render/chunk/terrain/DefaultTerrainRenderPasses;ALL:[Lorg/embeddedt/embeddium/impl/render/chunk/terrain/TerrainRenderPass;" + ) + ) + private static void wrapAllClinit(TerrainRenderPass[] value, Operation original) { + original.call((Object) ArrayUtils.add(value, ModEmbeddiumTerrainRenderPasses.LASER)); + } + +} diff --git a/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultMaterialsMixin.java b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultMaterialsMixin.java new file mode 100644 index 000000000..5369cb48b --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultMaterialsMixin.java @@ -0,0 +1,26 @@ +package dev.dubhe.anvilcraft.mixin.compat; + +import dev.dubhe.anvilcraft.client.init.ModRenderTypes; +import dev.dubhe.anvilcraft.integration.sodium.ModSodiumMaterials; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.DefaultMaterials; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.material.Material; +import net.minecraft.client.renderer.RenderType; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(DefaultMaterials.class) +public class SodiumDefaultMaterialsMixin { + @Inject( + method = "forRenderLayer", + at = @At("HEAD"), + cancellable = true + ) + private static void anvilcraft$forRenderLayer(RenderType layer, CallbackInfoReturnable cir){ + if (layer == ModRenderTypes.LASER){ + cir.setReturnValue(ModSodiumMaterials.LASER); + cir.cancel(); + } + } +} diff --git a/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultTerrainRenderPassesMixin.java b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultTerrainRenderPassesMixin.java new file mode 100644 index 000000000..f630f252d --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/mixin/compat/SodiumDefaultTerrainRenderPassesMixin.java @@ -0,0 +1,32 @@ +package dev.dubhe.anvilcraft.mixin.compat; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.dubhe.anvilcraft.integration.sodium.ModSodiumTerrainRenderPasses; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.DefaultTerrainRenderPasses; +import net.caffeinemc.mods.sodium.client.render.chunk.terrain.TerrainRenderPass; +import org.apache.commons.lang3.ArrayUtils; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DefaultTerrainRenderPasses.class) +public class SodiumDefaultTerrainRenderPassesMixin { + + @Shadow @Final @Mutable + public static TerrainRenderPass[] ALL; + + @WrapOperation( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/DefaultTerrainRenderPasses;ALL:[Lnet/caffeinemc/mods/sodium/client/render/chunk/terrain/TerrainRenderPass;" + ) + ) + private static void wrapAllClinit(TerrainRenderPass[] value, Operation original) { + original.call((Object) ArrayUtils.add(value, ModSodiumTerrainRenderPasses.LASER)); + } + +} diff --git a/src/main/resources/anvilcraft.mixins.json b/src/main/resources/anvilcraft.mixins.json index d720609bc..33eb92b73 100644 --- a/src/main/resources/anvilcraft.mixins.json +++ b/src/main/resources/anvilcraft.mixins.json @@ -41,7 +41,11 @@ "SectionCompilerMixin", "SoundEngineMixin", "compat.EmbChunkBuilderMeshingTaskMixin", - "compat.SodiumChunkBuilderMeshingTaskMixin" + "compat.SodiumChunkBuilderMeshingTaskMixin", + "compat.EmbeddiumDefaultMaterialsMixin", + "compat.EmbeddiumDefaultTerrainRenderPassesMixin", + "compat.SodiumDefaultMaterialsMixin", + "compat.SodiumDefaultTerrainRenderPassesMixin" ], "plugin": "dev.dubhe.anvilcraft.mixin.plugin.AnvilCraftMixinPlugin", "injectors": {