5
5
import io .netty .channel .Channel ;
6
6
import io .netty .channel .ChannelHandler ;
7
7
import net .fabricmc .loader .api .FabricLoader ;
8
+ import net .fabricmc .loader .api .ModContainer ;
9
+ import net .fabricmc .loader .api .Version ;
10
+ import net .fabricmc .loader .api .VersionParsingException ;
8
11
import net .minecraft .SharedConstants ;
9
12
import net .minecraft .Util ;
10
13
import net .minecraft .client .Minecraft ;
@@ -37,13 +40,26 @@ public boolean doesItemExist(Item item) {
37
40
return true ;
38
41
}
39
42
43
+ private static final Version V3_0_6 = Util .make (() -> {
44
+ try {
45
+ return Version .parse ("3.0.6" );
46
+ } catch (VersionParsingException e ) {
47
+ throw new AssertionError (e );
48
+ }
49
+ });
50
+
40
51
public static final MultiVersionCompat INSTANCE = Util .make (() -> {
41
52
try {
42
53
FabricLoader loader = FabricLoader .getInstance ();
54
+ ModContainer modContainer ;
43
55
if (loader .isModLoaded ("viafabric" )) {
44
56
return new ViaFabric ();
45
- } else if (loader .isModLoaded ("viafabricplus" )) {
46
- return new ViaFabricPlus ();
57
+ } else if ((modContainer = loader .getModContainer ("viafabricplus" ).orElse (null )) != null ) {
58
+ if (modContainer .getMetadata ().getVersion ().compareTo (V3_0_6 ) > 0 ) {
59
+ return new ViaFabricPlus (); // VFP 3.1.0 and newer
60
+ } else {
61
+ return new ViaFabricPlus3_0_6AndOlder (); // Once 1.20.5 is released, this can be removed
62
+ }
47
63
} else {
48
64
return new None ();
49
65
}
@@ -172,12 +188,12 @@ private int doGetProtocolVersion() throws ReflectiveOperationException {
172
188
}
173
189
}
174
190
175
- private static final class ViaFabricPlus extends AbstractViaVersion {
191
+ private static final class ViaFabricPlus3_0_6AndOlder extends AbstractViaVersion {
176
192
private final Method getTargetVersion ;
177
193
private final Method versionEnumGetProtocol ;
178
194
private final Method itemRegistryDiffKeepItem ;
179
195
180
- private ViaFabricPlus () throws ReflectiveOperationException {
196
+ private ViaFabricPlus3_0_6AndOlder () throws ReflectiveOperationException {
181
197
Class <?> protocolHack = Class .forName ("de.florianmichael.viafabricplus.protocolhack.ProtocolHack" );
182
198
Class <?> itemRegistryDiff = Class .forName ("de.florianmichael.viafabricplus.fixes.data.ItemRegistryDiff" );
183
199
getTargetVersion = protocolHack .getMethod ("getTargetVersion" );
@@ -199,4 +215,30 @@ public boolean doesItemExist(Item item) {
199
215
}
200
216
}
201
217
}
218
+
219
+ private static final class ViaFabricPlus extends AbstractViaVersion {
220
+ private final Method getTargetVersion ;
221
+ private final Method itemRegistryDiffKeepItem ;
222
+
223
+ private ViaFabricPlus () throws ReflectiveOperationException {
224
+ Class <?> protocolTranslator = Class .forName ("de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator" );
225
+ Class <?> itemRegistryDiff = Class .forName ("de.florianmichael.viafabricplus.fixes.data.ItemRegistryDiff" );
226
+ getTargetVersion = protocolTranslator .getMethod ("getTargetVersion" );
227
+ itemRegistryDiffKeepItem = itemRegistryDiff .getMethod ("keepItem" , Item .class );
228
+ }
229
+
230
+ @ Override
231
+ protected Object getCurrentVersion () throws ReflectiveOperationException {
232
+ return getTargetVersion .invoke (null );
233
+ }
234
+
235
+ @ Override
236
+ public boolean doesItemExist (Item item ) {
237
+ try {
238
+ return (Boolean ) itemRegistryDiffKeepItem .invoke (null , item );
239
+ } catch (ReflectiveOperationException e ) {
240
+ throw new RuntimeException (e );
241
+ }
242
+ }
243
+ }
202
244
}
0 commit comments