3
3
import java .lang .invoke .MethodHandle ;
4
4
import java .lang .invoke .MethodHandles ;
5
5
import java .lang .invoke .MethodType ;
6
- import java .util .Optional ;
7
6
import java .util .function .Consumer ;
8
7
import java .util .function .Function ;
9
8
import java .util .function .Predicate ;
9
+ import java .util .function .Supplier ;
10
10
11
11
import com .simibubi .create .Create ;
12
12
import com .simibubi .create .compat .Mods ;
@@ -41,34 +41,39 @@ public class SodiumCompat {
41
41
public static final ResourceLocation SAW_TEXTURE = Create .asResource ("block/saw_reversed" );
42
42
43
43
public static void init () {
44
- if (!Mods .INDIUM .isLoaded ()) {
44
+ ModContainer container = FabricLoader .getInstance ().getModContainer (Mods .SODIUM .id ()).orElseThrow ();
45
+ Version sodiumVersion = container .getMetadata ().getVersion ();
46
+
47
+ boolean supportsFRAPI = false ;
48
+
49
+ try {
50
+ // Any 0.6.0 version or alpha/beta for it
51
+ supportsFRAPI = VersionPredicate .parse ("~0.6.0-" )
52
+ .test (sodiumVersion );
53
+ } catch (VersionParsingException ignored ) {}
54
+
55
+ // If the sodium version is 0.6.0* then it natively supports FRAPI
56
+ if (!Mods .INDIUM .isLoaded () && !supportsFRAPI ) {
45
57
ClientPlayConnectionEvents .JOIN .register (SodiumCompat ::sendNoIndiumWarning );
46
58
}
47
59
48
60
boolean compatInitialized = false ;
49
61
50
- Optional <ModContainer > containerOptional = FabricLoader .getInstance ()
51
- .getModContainer (Mods .SODIUM .id ());
52
-
53
- if (containerOptional .isPresent ()) {
54
- Version sodiumVersion = containerOptional .get ()
55
- .getMetadata ()
56
- .getVersion ();
57
-
58
- for (SpriteUtilCompat value : SpriteUtilCompat .values ()) {
59
- if (value .doesWork .test (sodiumVersion )) {
60
- Minecraft mc = Minecraft .getInstance ();
61
- WorldRenderEvents .START .register (ctx -> {
62
- Function <ResourceLocation , TextureAtlasSprite > atlas = mc .getTextureAtlas (InventoryMenu .BLOCK_ATLAS );
63
- TextureAtlasSprite sawSprite = atlas .apply (SAW_TEXTURE );
64
- value .markSpriteAsActive .accept (sawSprite );
65
- });
66
- compatInitialized = true ;
67
- break ;
68
- }
62
+
63
+ for (SpriteUtilCompat value : SpriteUtilCompat .values ()) {
64
+ if (value .doesWork .test (sodiumVersion )) {
65
+ Minecraft mc = Minecraft .getInstance ();
66
+ WorldRenderEvents .START .register (ctx -> {
67
+ Function <ResourceLocation , TextureAtlasSprite > atlas = mc .getTextureAtlas (InventoryMenu .BLOCK_ATLAS );
68
+ TextureAtlasSprite sawSprite = atlas .apply (SAW_TEXTURE );
69
+ value .markSpriteAsActive .get ().accept (sawSprite );
70
+ });
71
+ compatInitialized = true ;
72
+ break ;
69
73
}
70
74
}
71
75
76
+
72
77
if (!compatInitialized ) {
73
78
Create .LOGGER .error ("Create's Sodium compat errored and has been partially disabled. Report this!" );
74
79
}
@@ -102,29 +107,21 @@ private enum SpriteUtilCompat {
102
107
} catch (Throwable ignored ) {
103
108
return false ;
104
109
}
105
- }, (sawSprite ) -> {
106
- try {
107
- invokeOld (sawSprite );
108
- } catch (Throwable ignored ) {}
109
- }),
110
+ }, () -> SpriteUtilCompat ::invokeOld ),
110
111
V0_6_API ((version ) -> {
111
112
try {
112
113
return VersionPredicate .parse (">=0.6.0-beta.3" ).test (version );
113
114
} catch (VersionParsingException e ) {
114
115
return false ;
115
116
}
116
- }, (sawSprite ) -> {
117
- try {
118
- SpriteUtil .INSTANCE .markSpriteActive (sawSprite );
119
- } catch (Throwable ignored ) {}
120
- });
117
+ }, () -> SpriteUtil .INSTANCE ::markSpriteActive );
121
118
122
119
private static MethodHandle markSpriteActiveHandle ;
123
120
124
121
private final Predicate <Version > doesWork ;
125
- private final Consumer <TextureAtlasSprite > markSpriteAsActive ;
122
+ private final Supplier < Consumer <TextureAtlasSprite > > markSpriteAsActive ;
126
123
127
- SpriteUtilCompat (Predicate <Version > doesWork , Consumer <TextureAtlasSprite > markSpriteAsActive ) {
124
+ SpriteUtilCompat (Predicate <Version > doesWork , Supplier < Consumer <TextureAtlasSprite > > markSpriteAsActive ) {
128
125
this .doesWork = doesWork ;
129
126
this .markSpriteAsActive = markSpriteAsActive ;
130
127
}
@@ -138,8 +135,10 @@ private enum SpriteUtilCompat {
138
135
} catch (Throwable ignored ) {}
139
136
}
140
137
141
- public static void invokeOld (TextureAtlasSprite sawSprite ) throws Throwable {
142
- markSpriteActiveHandle .invoke (sawSprite );
138
+ public static void invokeOld (TextureAtlasSprite sawSprite ) {
139
+ try {
140
+ markSpriteActiveHandle .invoke (sawSprite );
141
+ } catch (Throwable ignored ) {}
143
142
}
144
143
}
145
144
}
0 commit comments