-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
246 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...java/net/fabricmc/fabric/impl/client/rendering/fluid/FabricClientFluidTypeExtensions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.fabricmc.fabric.impl.client.rendering.fluid; | ||
|
||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public record FabricClientFluidTypeExtensions(Fluid fluid, FluidRenderHandler handler) implements IClientFluidTypeExtensions { | ||
private TextureAtlasSprite[] getSprites() { | ||
return handler.getFluidSprites(null, null, fluid.defaultFluidState()); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getStillTexture() { | ||
TextureAtlasSprite[] sprites = getSprites(); | ||
return sprites[0].contents().name(); | ||
} | ||
|
||
@Override | ||
public ResourceLocation getFlowingTexture() { | ||
TextureAtlasSprite[] sprites = getSprites(); | ||
return sprites[1].contents().name(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ResourceLocation getOverlayTexture() { | ||
TextureAtlasSprite[] sprites = getSprites(); | ||
return sprites.length > 2 ? sprites[2].contents().name() : null; | ||
} | ||
|
||
@Override | ||
public int getTintColor() { | ||
int baseColor = handler.getFluidColor(null, null, fluid.defaultFluidState()); | ||
return 0xFF000000 | baseColor; | ||
} | ||
|
||
@Override | ||
public int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos) { | ||
int baseColor = handler.getFluidColor(getter, pos, state); | ||
return 0xFF000000 | baseColor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
.../src/client/java/net/fabricmc/fabric/impl/client/rendering/fluid/FluidRendererCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package net.fabricmc.fabric.impl.client.rendering.fluid; | ||
|
||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler; | ||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; | ||
import net.minecraft.client.renderer.texture.TextureAtlasSprite; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; | ||
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; | ||
import net.neoforged.neoforge.client.textures.FluidSpriteCache; | ||
import net.neoforged.neoforge.common.NeoForgeMod; | ||
import net.neoforged.neoforge.fluids.FluidType; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class FluidRendererCompat { | ||
|
||
public static void onClientSetup(FMLClientSetupEvent event) { | ||
// Register forge handlers only to the "handlers" map and not "modHandlers" | ||
// This allows fabric mods to access render handlers for forge mods' fluids without them being | ||
// used for rendering fluids, as that should remain handled by forge | ||
Map<FluidType, FluidRenderHandler> forgeHandlers = new HashMap<>(); | ||
for (Map.Entry<ResourceKey<Fluid>, Fluid> entry : BuiltInRegistries.FLUID.entrySet()) { | ||
Fluid fluid = entry.getValue(); | ||
if (fluid != Fluids.EMPTY && fluid.getFluidType() != NeoForgeMod.EMPTY_TYPE.value() && FluidRenderHandlerRegistry.INSTANCE.get(fluid) == null) { | ||
FluidRenderHandler handler = forgeHandlers.computeIfAbsent(fluid.getFluidType(), ForgeFluidRenderHandler::new); | ||
((FluidRenderHandlerRegistryImpl) FluidRenderHandlerRegistry.INSTANCE).registerHandlerOnly(fluid, handler); | ||
} | ||
} | ||
} | ||
|
||
private record ForgeFluidRenderHandler(FluidType fluidType) implements FluidRenderHandler { | ||
@Override | ||
public TextureAtlasSprite[] getFluidSprites(@Nullable BlockAndTintGetter view, @Nullable BlockPos pos, FluidState state) { | ||
TextureAtlasSprite[] forgeSprites = FluidSpriteCache.getFluidSprites(view, pos, state); | ||
return forgeSprites[2] == null ? Arrays.copyOfRange(forgeSprites, 0, 2) : forgeSprites; | ||
} | ||
|
||
@Override | ||
public int getFluidColor(@Nullable BlockAndTintGetter view, @Nullable BlockPos pos, FluidState state) { | ||
int color = IClientFluidTypeExtensions.of(this.fluidType).getTintColor(state, view, pos); | ||
return 0x00FFFFFF & color; | ||
} | ||
} | ||
|
||
private FluidRendererCompat() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...ient/java/net/fabricmc/fabric/mixin/client/rendering/fluid/IBlockStateExtensionMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.fabricmc.fabric.mixin.client.rendering.fluid; | ||
|
||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.neoforged.neoforge.common.extensions.IBlockStateExtension; | ||
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(IBlockStateExtension.class) | ||
public interface IBlockStateExtensionMixin { | ||
|
||
@Inject(method = "shouldDisplayFluidOverlay", at = @At("HEAD"), cancellable = true) | ||
default void shouldDisplayFluidOverlay(BlockAndTintGetter level, BlockPos pos, FluidState fluidState, CallbackInfoReturnable<Boolean> cir) { | ||
cir.setReturnValue(FluidRenderHandlerRegistry.INSTANCE.isBlockTransparent((BlockState) this, level, pos, fluidState)); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ava/net/fabricmc/fabric/mixin/client/rendering/fluid/IClientFluidTypeExtensionsMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.fabricmc.fabric.mixin.client.rendering.fluid; | ||
|
||
import com.llamalad7.mixinextras.injector.ModifyReturnValue; | ||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler; | ||
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; | ||
import net.fabricmc.fabric.impl.client.rendering.fluid.FabricClientFluidTypeExtensions; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.neoforged.neoforge.client.extensions.common.IClientFluidTypeExtensions; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
@Mixin(IClientFluidTypeExtensions.class) | ||
public interface IClientFluidTypeExtensionsMixin { | ||
|
||
@ModifyReturnValue(method = "of(Lnet/minecraft/world/level/material/FluidState;)Lnet/neoforged/neoforge/client/extensions/common/IClientFluidTypeExtensions;", at = @At("RETURN")) | ||
private static IClientFluidTypeExtensions of(IClientFluidTypeExtensions ret, FluidState state) { | ||
if (ret == IClientFluidTypeExtensions.DEFAULT) { | ||
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.getOverride(state.getType()); | ||
if (handler != null) { | ||
return new FabricClientFluidTypeExtensions(state.getType(), handler); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
@ModifyReturnValue(method = "of(Lnet/minecraft/world/level/material/Fluid;)Lnet/neoforged/neoforge/client/extensions/common/IClientFluidTypeExtensions;", at = @At("RETURN")) | ||
private static IClientFluidTypeExtensions of(IClientFluidTypeExtensions ret, Fluid fluid) { | ||
if (ret == IClientFluidTypeExtensions.DEFAULT) { | ||
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.getOverride(fluid); | ||
if (handler != null) { | ||
return new FabricClientFluidTypeExtensions(fluid, handler); | ||
} | ||
} | ||
return ret; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...luids-v1/src/client/java/org/sinytra/fabric/rendering_fluids/FabricRenderingFabricV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.sinytra.fabric.rendering_fluids; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.impl.client.rendering.fluid.FluidRendererCompat; | ||
import net.neoforged.bus.api.IEventBus; | ||
import net.neoforged.fml.ModLoadingContext; | ||
|
||
public class FabricRenderingFabricV1 implements ClientModInitializer { | ||
|
||
@Override | ||
public void onInitializeClient() { | ||
IEventBus bus = ModLoadingContext.get().getActiveContainer().getEventBus(); | ||
bus.addListener(FluidRendererCompat::onClientSetup); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.