Skip to content

Commit

Permalink
Fix for Glitchfiend#2161, Blood & Liquid Null (Glitchfiend#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
njsharpe authored Jan 28, 2024
1 parent 1a66976 commit 58c4db5
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ public class ModClientFabric
{
public static void setup()
{
FluidRenderHandlerRegistry.INSTANCE.register(BOPFluids.BLOOD, BOPFluids.FLOWING_BLOOD, new SimpleFluidRenderHandler(new ResourceLocation("biomesoplenty:block/blood_still"), new ResourceLocation("biomesoplenty:block/blood_flow")));
FluidRenderHandlerRegistry.INSTANCE.register(BOPFluids.LIQUID_NULL, BOPFluids.FLOWING_LIQUID_NULL, new SimpleFluidRenderHandler(new ResourceLocation("biomesoplenty:block/liquid_null_still"), new ResourceLocation("biomesoplenty:block/liquid_null_flow")));
FluidRenderHandlerRegistry.INSTANCE.register(BOPFluids.BLOOD, BOPFluids.FLOWING_BLOOD, new SimpleFluidRenderHandler(
new ResourceLocation("biomesoplenty:block/blood_still"),
new ResourceLocation("biomesoplenty:block/blood_flow"),
new ResourceLocation("biomesoplenty:textures/block/blood_underwater.png")));
FluidRenderHandlerRegistry.INSTANCE.register(BOPFluids.LIQUID_NULL, BOPFluids.FLOWING_LIQUID_NULL, new SimpleFluidRenderHandler(
new ResourceLocation("biomesoplenty:block/liquid_null_still"),
new ResourceLocation("biomesoplenty:block/liquid_null_flow"),
new ResourceLocation("biomesoplenty:textures/block/liquid_null_underwater.png")));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright 2024, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package biomesoplenty.fabric.mixin;

import biomesoplenty.api.block.BOPFluids;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Environment(EnvType.CLIENT)
@Mixin(FogRenderer.class)
public abstract class MixinBloodFluid
{
@Shadow
private static float fogRed;

@Shadow
private static float fogGreen;

@Shadow
private static float fogBlue;

@ModifyArgs(method = "setupColor", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clearColor(FFFF)V", remap = false))
private static void modifyFlogColors(Args args, Camera camera, float partialTicks, ClientLevel level, int renderDistanceChunks, float bossColorModifier)
{
BlockPos blockPos = camera.getBlockPosition();
FluidState fluidState = level.getFluidState(blockPos);
if(camera.getPosition().y > blockPos.getY() + fluidState.getHeight(level, blockPos))
{
return;
}

Fluid fluid = fluidState.getType();

if(BOPFluids.BLOOD.isSame(fluid))
{
fogRed = 0.407F;
fogGreen = 0.121F;
fogBlue = 0.137F;
}
}

@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
private static void setupFog(Camera camera, FogRenderer.FogMode fogType, float viewDistance, boolean thickFog, float thickDelta, CallbackInfo ci)
{
Level level = Minecraft.getInstance().level;
BlockPos blockPos = camera.getBlockPosition();
FluidState fluidState = level.getFluidState(blockPos);
if(camera.getPosition().y >= blockPos.getY() + fluidState.getHeight(level, blockPos))
{
return;
}

Fluid fluid = fluidState.getType();

if(BOPFluids.BLOOD.isSame(fluid))
{
RenderSystem.setShaderFogStart(0.125F);
RenderSystem.setShaderFogEnd(5.0F);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************************************************************
* Copyright 2024, the Glitchfiend Team.
* All rights reserved.
******************************************************************************/
package biomesoplenty.fabric.mixin;

import biomesoplenty.api.block.BOPFluids;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Environment(EnvType.CLIENT)
@Mixin(FogRenderer.class)
public abstract class MixinLiquidNullFluid
{
@Shadow
private static float fogRed;

@Shadow
private static float fogGreen;

@Shadow
private static float fogBlue;

@ModifyArgs(method = "setupColor", at = @At(value = "INVOKE", target = "Lcom/mojang/blaze3d/systems/RenderSystem;clearColor(FFFF)V", remap = false))
private static void modifyFlogColors(Args args, Camera camera, float partialTicks, ClientLevel level, int renderDistanceChunks, float bossColorModifier)
{
BlockPos blockPos = camera.getBlockPosition();
FluidState fluidState = level.getFluidState(blockPos);
if(camera.getPosition().y > blockPos.getY() + fluidState.getHeight(level, blockPos))
{
return;
}

Fluid fluid = fluidState.getType();

if(BOPFluids.LIQUID_NULL.isSame(fluid))
{
fogRed = 0.0F;
fogGreen = 0.0F;
fogBlue = 0.0F;
}
}

@Inject(method = "setupFog", at = @At("HEAD"), cancellable = true)
private static void setupFog(Camera camera, FogRenderer.FogMode fogType, float viewDistance, boolean thickFog, float thickDelta, CallbackInfo ci)
{
Level level = Minecraft.getInstance().level;
BlockPos blockPos = camera.getBlockPosition();
FluidState fluidState = level.getFluidState(blockPos);
if(camera.getPosition().y >= blockPos.getY() + fluidState.getHeight(level, blockPos))
{
return;
}

Fluid fluid = fluidState.getType();

if(BOPFluids.LIQUID_NULL.isSame(fluid))
{
RenderSystem.setShaderFogStart(0.1F);
RenderSystem.setShaderFogEnd(2.5F);
}
}

}

2 changes: 2 additions & 0 deletions fabric/src/main/resources/biomesoplenty.fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"compatibilityLevel": "JAVA_17",
"refmap": "biomesoplenty.refmap.json",
"mixins": [
"MixinBloodFluid",
"MixinLiquidNullFluid"
],
"client": [
],
Expand Down

0 comments on commit 58c4db5

Please sign in to comment.