Skip to content

Commit 5470edc

Browse files
authored
Repair the fluid registry for addons (#2216)
1 parent 2186489 commit 5470edc

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/main/java/gregtech/api/fluids/GTFluidRegistration.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.lang.reflect.Field;
2323
import java.util.Collection;
24+
import java.util.Objects;
2425

2526
public class GTFluidRegistration {
2627

@@ -30,6 +31,8 @@ public class GTFluidRegistration {
3031

3132
private static @Nullable BiMap<String, Fluid> MASTER_FLUID_REFERENCE;
3233

34+
private static @Nullable BiMap<String, String> DEFAULT_FLUID_NAME;
35+
3336
/**
3437
* Fixes all registered fluids being under the gregtech modid
3538
*
@@ -49,7 +52,29 @@ private static void fixFluidRegistryName(@NotNull Fluid fluid, @NotNull String m
4952
throw new IllegalStateException("Could not reflect the Forge Master Fluid Registry", e);
5053
}
5154
}
52-
MASTER_FLUID_REFERENCE.inverse().put(fluid, modid + ':' + fluid.getName());
55+
Objects.requireNonNull(MASTER_FLUID_REFERENCE);
56+
57+
if (DEFAULT_FLUID_NAME == null) {
58+
try {
59+
Field field = FluidRegistry.class.getDeclaredField("defaultFluidName");
60+
field.setAccessible(true);
61+
// noinspection unchecked
62+
DEFAULT_FLUID_NAME = (BiMap<String, String>) field.get(null);
63+
} catch (NoSuchFieldException | IllegalAccessException e) {
64+
throw new IllegalStateException("Could not reflect the Forge Default Fluid Name map", e);
65+
}
66+
}
67+
Objects.requireNonNull(DEFAULT_FLUID_NAME);
68+
69+
String masterKey = MASTER_FLUID_REFERENCE.inverse().get(fluid);
70+
if (masterKey != null && masterKey.startsWith(GTValues.MODID + ":")) {
71+
MASTER_FLUID_REFERENCE.inverse().put(fluid, modid + ':' + fluid.getName());
72+
}
73+
74+
String defaultName = DEFAULT_FLUID_NAME.get(fluid.getName());
75+
if (defaultName.startsWith(GTValues.MODID + ":")) {
76+
DEFAULT_FLUID_NAME.put(fluid.getName(), modid + ':' + fluid.getName());
77+
}
5378
}
5479

5580
@ApiStatus.Internal

0 commit comments

Comments
 (0)