Skip to content

Commit

Permalink
Don't classload FluidRenderHandler on dedicated server (#1529)
Browse files Browse the repository at this point in the history
* Properly mark some mixins as client-side

Silences some warnings in dedicated server logs

* Move FluidRenderHandlerRegistry access to FluidHandlerCompatClient
  • Loading branch information
unilock authored Nov 12, 2024
1 parent ffe828a commit 20f42c7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 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 @@ -16,7 +14,6 @@
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 @@ -51,8 +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)) {
FluidRenderHandler renderHandler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
FluidType type = new FabricFluidType(FluidType.Properties.create(), fluid, renderHandler);
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 @@ -64,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
8 changes: 4 additions & 4 deletions src/mod/resources/connector.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
"item.IItemExtensionMixin",
"item.ItemStackMixin",
"network.StreamCodecMixin",
"recipebook.RecipeBookCategoriesAccessor",
"recipebook.RecipeBookCategoriesMixin",
"recipebook.RecipeBookManagerMixin",
"registries.DataPackRegistriesHooksAccessor",
"registries.MappedRegistryAccessor",
"registries.NeoForgeRegistriesSetupAccessor",
"registries.BuiltInRegistriesMixin",
"registries.EntityDataSerializersMixin",
"registries.ItemBlockRenderTypesMixin",
"registries.NeoForgeRegistriesSetupMixin",
"registries.NetworkRegistryMixin",
"registries.PoiTypesMixin",
Expand All @@ -34,7 +31,10 @@
"client.ItemColorsMixin",
"client.ItemOverridesMixin",
"client.KeyMappingMixin",
"client.ParticleEngineMixin"
"client.ParticleEngineMixin",
"recipebook.RecipeBookCategoriesAccessor",
"recipebook.RecipeBookCategoriesMixin",
"registries.ItemBlockRenderTypesMixin"
],
"server": [
"boot.ServerMainMixin"
Expand Down

0 comments on commit 20f42c7

Please sign in to comment.