Skip to content

Commit

Permalink
Move FluidRenderHandlerRegistry access to FluidHandlerCompatClient
Browse files Browse the repository at this point in the history
  • Loading branch information
unilock committed Nov 12, 2024
1 parent fc583c0 commit bcda4c1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.sinytra.connector.mod.compat;

import com.mojang.logging.LogUtils;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler;
import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant;
import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes;
import net.minecraft.core.registries.BuiltInRegistries;
Expand All @@ -12,12 +10,10 @@
import net.minecraft.world.level.material.Fluid;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModList;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.FluidType;
import net.neoforged.neoforge.registries.NeoForgeRegistries;
import net.neoforged.neoforge.registries.RegisterEvent;
import org.jetbrains.annotations.Nullable;
import org.sinytra.connector.ConnectorEarlyLoader;
import org.slf4j.Logger;

Expand Down Expand Up @@ -52,13 +48,7 @@ private static void initFabricFluidTypes() {
ResourceKey<Fluid> key = entry.getKey();
Fluid fluid = entry.getValue();
if (ModList.get().getModContainerById(key.location().getNamespace()).map(c -> ConnectorEarlyLoader.isConnectorMod(c.getModId())).orElse(false)) {
FluidType type;
if (FMLEnvironment.dist.isClient()) {
FluidRenderHandler renderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
type = new FabricFluidType(FluidType.Properties.create(), fluid, renderHandler);
} else {
type = new FabricFluidType(FluidType.Properties.create(), fluid, null);
}
FluidType type = new FabricFluidType(FluidType.Properties.create(), fluid);
FABRIC_FLUID_TYPES.put(fluid, type);
FABRIC_FLUID_TYPES_BY_NAME.put(key.location(), type);
}
Expand All @@ -70,20 +60,13 @@ private static void onRegisterFluids(RegisterEvent event) {
}

static class FabricFluidType extends FluidType {
@Nullable
private final FluidRenderHandler renderHandler;
private final Component name;

public FabricFluidType(Properties properties, Fluid fluid, @Nullable FluidRenderHandler renderHandler) {
public FabricFluidType(Properties properties, Fluid fluid) {
super(properties);
this.renderHandler = renderHandler;
this.name = FluidVariantAttributes.getName(FluidVariant.of(fluid));
}

public FluidRenderHandler getRenderHandler() {
return renderHandler;
}

@Override
public Component getDescription() {
return this.name.copy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sinytra.connector.mod.compat;

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.resources.ResourceLocation;
Expand All @@ -14,7 +15,7 @@ public final class FluidHandlerCompatClient {

public static void onRegisterClientExtensions(RegisterClientExtensionsEvent event) {
FluidHandlerCompat.getFabricFluidTypes().forEach((fluid, type) -> {
FluidRenderHandler renderHandler = ((FluidHandlerCompat.FabricFluidType) type).getRenderHandler();
FluidRenderHandler renderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
event.registerFluidType(new IClientFluidTypeExtensions() {
private TextureAtlasSprite[] getSprites() {
return renderHandler.getFluidSprites(null, null, fluid.defaultFluidState());
Expand Down

0 comments on commit bcda4c1

Please sign in to comment.