21
21
22
22
import java .lang .reflect .Field ;
23
23
import java .util .Collection ;
24
+ import java .util .Objects ;
24
25
25
26
public class GTFluidRegistration {
26
27
@@ -30,6 +31,8 @@ public class GTFluidRegistration {
30
31
31
32
private static @ Nullable BiMap <String , Fluid > MASTER_FLUID_REFERENCE ;
32
33
34
+ private static @ Nullable BiMap <String , String > DEFAULT_FLUID_NAME ;
35
+
33
36
/**
34
37
* Fixes all registered fluids being under the gregtech modid
35
38
*
@@ -49,7 +52,29 @@ private static void fixFluidRegistryName(@NotNull Fluid fluid, @NotNull String m
49
52
throw new IllegalStateException ("Could not reflect the Forge Master Fluid Registry" , e );
50
53
}
51
54
}
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
+ }
53
78
}
54
79
55
80
@ ApiStatus .Internal
0 commit comments