|
6 | 6 | import io.netty.channel.ChannelHandler; |
7 | 7 | import net.fabricmc.loader.api.FabricLoader; |
8 | 8 | import net.fabricmc.loader.api.ModContainer; |
9 | | -import net.fabricmc.loader.api.Version; |
10 | | -import net.fabricmc.loader.api.VersionParsingException; |
11 | 9 | import net.minecraft.SharedConstants; |
12 | 10 | import net.minecraft.client.MinecraftClient; |
13 | 11 | import net.minecraft.client.network.ClientPlayNetworkHandler; |
14 | 12 | import net.minecraft.item.Item; |
15 | 13 | import net.minecraft.network.ClientConnection; |
16 | 14 | import net.minecraft.util.Util; |
17 | | -import org.jetbrains.annotations.Nullable; |
18 | 15 | import org.slf4j.Logger; |
19 | 16 |
|
20 | 17 | import java.lang.reflect.Field; |
@@ -48,7 +45,7 @@ public boolean doesItemExist(Item item) { |
48 | 45 | if ((modContainer = loader.getModContainer("viafabric").orElse(null)) != null) { |
49 | 46 | return new ViaFabric(); |
50 | 47 | } else if ((modContainer = loader.getModContainer("viafabricplus").orElse(null)) != null) { |
51 | | - return new ViaFabricPlus(modContainer); |
| 48 | + return new ViaFabricPlus(); |
52 | 49 | } else { |
53 | 50 | return new None(); |
54 | 51 | } |
@@ -180,42 +177,32 @@ private int doGetProtocolVersion() throws ReflectiveOperationException { |
180 | 177 | private static final class ViaFabricPlus extends AbstractViaVersion { |
181 | 178 | private final Field itemReleaseVersionMappingsInstance; |
182 | 179 | private final Method getTargetVersion; |
183 | | - @Nullable |
184 | 180 | private final Method versionEnumGetProtocol; |
185 | 181 | private final Method itemReleaseVersionMappingsContains; |
186 | 182 |
|
187 | | - private static final Version V2_7_3 = Util.make(() -> { |
188 | | - try { |
189 | | - return Version.parse("2.7.3"); |
190 | | - } catch (VersionParsingException e) { |
191 | | - throw new AssertionError(e); |
192 | | - } |
193 | | - }); |
194 | | - |
195 | | - private ViaFabricPlus(ModContainer modContainer) throws ReflectiveOperationException { |
| 183 | + private ViaFabricPlus() throws ReflectiveOperationException { |
196 | 184 | Class<?> protocolHack = Class.forName("de.florianmichael.viafabricplus.protocolhack.ProtocolHack"); |
197 | 185 | Class<?> itemReleaseVersionMappings = Class.forName("de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings"); |
198 | 186 | itemReleaseVersionMappingsInstance = itemReleaseVersionMappings.getField("INSTANCE"); |
199 | 187 | getTargetVersion = protocolHack.getMethod("getTargetVersion"); |
200 | | - versionEnumGetProtocol = modContainer.getMetadata().getVersion().compareTo(V2_7_3) <= 0 ? null |
201 | | - : getTargetVersion.getReturnType().getMethod("getProtocol"); |
| 188 | + versionEnumGetProtocol = getTargetVersion.getReturnType().getMethod("getProtocol"); |
202 | 189 | itemReleaseVersionMappingsContains = itemReleaseVersionMappings.getMethod("contains", Item.class, getTargetVersion.getReturnType()); |
203 | 190 | } |
204 | 191 |
|
205 | 192 | @Override |
206 | 193 | protected Object getCurrentVersion() throws ReflectiveOperationException { |
207 | | - Object targetVersion = getTargetVersion.invoke(null); |
208 | | - if (versionEnumGetProtocol != null) { |
209 | | - targetVersion = versionEnumGetProtocol.invoke(targetVersion); |
210 | | - } |
211 | | - return targetVersion; |
| 194 | + return versionEnumGetProtocol.invoke(getVersionEnum()); |
| 195 | + } |
| 196 | + |
| 197 | + private Object getVersionEnum() throws ReflectiveOperationException { |
| 198 | + return getTargetVersion.invoke(null); |
212 | 199 | } |
213 | 200 |
|
214 | 201 | @Override |
215 | 202 | public boolean doesItemExist(Item item) { |
216 | 203 | try { |
217 | 204 | Object instance = itemReleaseVersionMappingsInstance.get(null); |
218 | | - return (Boolean) itemReleaseVersionMappingsContains.invoke(instance, item, getCurrentVersion()); |
| 205 | + return (Boolean) itemReleaseVersionMappingsContains.invoke(instance, item, getVersionEnum()); |
219 | 206 | } catch (ReflectiveOperationException e) { |
220 | 207 | throw new RuntimeException(e); |
221 | 208 | } |
|
0 commit comments