59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
package codes.som.hibiscus.mixins.xray;
|
|
|
|
import codes.som.hibiscus.subsystems.xray.XrayBlockRenderView;
|
|
import codes.som.hibiscus.subsystems.xray.XraySystem;
|
|
import me.jellysquid.mods.sodium.client.render.pipeline.FluidRenderer;
|
|
import net.minecraft.fluid.Fluid;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.BlockRenderView;
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
|
|
@Mixin(FluidRenderer.class)
|
|
public abstract class MixinFluidRenderer {
|
|
@Shadow
|
|
protected abstract boolean isFluidOccluded(BlockRenderView world, int x, int y, int z, Direction dir, Fluid fluid);
|
|
|
|
@Shadow
|
|
protected abstract boolean isSideExposed(BlockRenderView world, int x, int y, int z, Direction dir, float height);
|
|
|
|
private boolean ignoreFluidOccluded = false;
|
|
private boolean ignoreSideExposed = false;
|
|
|
|
@Inject(method = "isFluidOccluded", at = @At("HEAD"), cancellable = true)
|
|
private void onIsFluidOccluded(BlockRenderView world, int x, int y, int z, Direction dir, Fluid fluid, CallbackInfoReturnable<Boolean> cir) {
|
|
if (ignoreFluidOccluded)
|
|
return;
|
|
|
|
if (!XraySystem.shouldRenderXray())
|
|
return;
|
|
|
|
var xrayView = new XrayBlockRenderView(world);
|
|
ignoreFluidOccluded = true;
|
|
var xrayFluidOccluded = this.isFluidOccluded(xrayView, x, y, z, dir, fluid);
|
|
ignoreFluidOccluded = false;
|
|
|
|
cir.setReturnValue(xrayFluidOccluded);
|
|
}
|
|
|
|
|
|
@Inject(method = "isSideExposed", at = @At("HEAD"), cancellable = true)
|
|
private void onIsSideExposed(BlockRenderView world, int x, int y, int z, Direction dir, float height, CallbackInfoReturnable<Boolean> cir) {
|
|
if (ignoreSideExposed)
|
|
return;
|
|
|
|
if (!XraySystem.shouldRenderXray())
|
|
return;
|
|
|
|
var xrayView = new XrayBlockRenderView(world);
|
|
ignoreSideExposed = true;
|
|
var xraySideExposed = this.isSideExposed(xrayView, x, y, z, dir, height);
|
|
ignoreSideExposed = false;
|
|
|
|
cir.setReturnValue(xraySideExposed);
|
|
}
|
|
}
|