Skip to content

Commit

Permalink
修复和embeddium与sodium的兼容性问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuRuoLing committed Dec 17, 2024
1 parent f6468b0 commit 1ccd387
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<Material> cir){
if (layer == ModRenderTypes.LASER){
cir.setReturnValue(ModEmbeddiumMaterials.LASER);
cir.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<clinit>",
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<Void> original) {
original.call((Object) ArrayUtils.add(value, ModEmbeddiumTerrainRenderPasses.LASER));
}

}
Original file line number Diff line number Diff line change
@@ -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<Material> cir){
if (layer == ModRenderTypes.LASER){
cir.setReturnValue(ModSodiumMaterials.LASER);
cir.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 = "<clinit>",
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<Void> original) {
original.call((Object) ArrayUtils.add(value, ModSodiumTerrainRenderPasses.LASER));
}

}
6 changes: 5 additions & 1 deletion src/main/resources/anvilcraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 1ccd387

Please sign in to comment.