Skip to content

Commit

Permalink
Extended fluids fully working with Sodium
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadiboo committed Jan 20, 2024
1 parent 27834c6 commit 0b0c1cc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/io/github/cadiboo/nocubes/hooks/MixinAsm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class MixinAsm {
private static boolean transformChunkRendererRanAlready = false;
private static boolean transformFluidRendererRanAlready = false;
private static boolean transformSodiumChunkRendererRanAlready = false;
private static boolean transformSodiumFluidRendererRanAlready = false;
private static boolean transformSodiumWorldRendererRanAlready = false;
private static boolean transformSodiumLevelRendererRanAlready = false;

Expand Down Expand Up @@ -262,6 +263,29 @@ public static void transformSodiumChunkRenderer(ClassNode classNode) {
redirectBlockStateGetFluidStateSoExtendedFluidsWork(methodNode, blockPosLocalVarIndex);
}

/**
* Same as {@link MixinAsm#transformFluidRenderer} but for Sodium.
*/
public static void transformSodiumFluidRenderer(ClassNode classNode) {
if (transformSodiumFluidRendererRanAlready)
return;
transformSodiumFluidRendererRanAlready = true;

var methodNode = findMethodNode(
classNode,
"fluidHeight",
"(Lnet/minecraft/world/level/BlockAndTintGetter;Lnet/minecraft/world/level/material/Fluid;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/Direction;)F"
);

redirectBlockStateGetFluidStateSoExtendedFluidsWork(
methodNode,
// blockPosLocalVarIndex
3
);

// Not implemented yet - see comments in transformSodiumWorldRenderer
}

/**
* Same as {@link io.github.cadiboo.nocubes.mixin.LevelRendererMixin#nocubes_setBlocksDirty} but for Sodium.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private static void transformClass(String mixinClassName, ClassNode classNode) {
case "io.github.cadiboo.nocubes.mixin.RenderChunkRebuildTaskMixin" -> MixinAsm.transformChunkRenderer(classNode);
case "io.github.cadiboo.nocubes.mixin.LiquidBlockRendererMixin" -> MixinAsm.transformFluidRenderer(classNode);
case "io.github.cadiboo.nocubes.mixin.SodiumChunkBuilderMeshingTaskMixin" -> MixinAsm.transformSodiumChunkRenderer(classNode);
case "io.github.cadiboo.nocubes.mixin.SodiumFluidRendererMixin" -> MixinAsm.transformSodiumFluidRenderer(classNode);
case "io.github.cadiboo.nocubes.mixin.SodiumWorldRendererMixin" -> MixinAsm.transformSodiumWorldRenderer(classNode);
case "io.github.cadiboo.nocubes.mixin.SodiumLevelRendererMixin" -> MixinAsm.transformSodiumLevelRenderer(classNode);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.github.cadiboo.nocubes.mixin;

import io.github.cadiboo.nocubes.hooks.Hooks;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.fluids.FluidStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

/**
* There is more to this mixin, see the documentation in {@link io.github.cadiboo.nocubes.hooks.MixinAsm}
* and {@link io.github.cadiboo.nocubes.hooks.MixinAsm#transformSodiumLevelRenderer}.
*/
@Pseudo // Sodium may not be installed
@Mixin(targets = "me.jellysquid.mods.sodium.client.render.chunk.compile.pipeline.FluidRenderer")
public class SodiumFluidRendererMixin {

@Redirect(
method = "isFluidOccluded",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/BlockAndTintGetter;getFluidState(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/world/level/material/FluidState;"
),
require = 2 // Redirect both calls to the function
)
private FluidState nocubes_getFluidState(BlockAndTintGetter world, BlockPos adjPos) {
return Hooks.getRenderFluidState(adjPos, world.getBlockState(adjPos));
}

}
1 change: 1 addition & 0 deletions src/main/resources/mixins.nocubes.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"RenderChunkRegionMixin",
"ScreenEffectRendererMixin",
"SodiumChunkBuilderMeshingTaskMixin",
"SodiumFluidRendererMixin",
"SodiumWorldRendererMixin",
"SodiumLevelRendererMixin"
],
Expand Down

0 comments on commit 0b0c1cc

Please sign in to comment.