diff --git a/gradle.properties b/gradle.properties index 2adf2fd..8927d97 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs=-Xmx1G # check these on https://fabricmc.net/use minecraft_version=1.17.1 yarn_mappings=1.17.1+build.10 -loader_version=0.11.6 +loader_version=0.12.1 # Mod Properties mod_version=0.3.9-alpha.114514 maven_group=com.plusls diff --git a/src/main/java/com/plusls/ommc/OmmcCompatMixinPlugin.java b/src/main/java/com/plusls/ommc/OmmcCompatMixinPlugin.java index 1aaebc1..8689b53 100644 --- a/src/main/java/com/plusls/ommc/OmmcCompatMixinPlugin.java +++ b/src/main/java/com/plusls/ommc/OmmcCompatMixinPlugin.java @@ -6,8 +6,9 @@ import com.plusls.ommc.util.YarnUtil; import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; +import net.fabricmc.loader.api.Version; import net.fabricmc.loader.api.VersionParsingException; -import net.fabricmc.loader.util.version.VersionPredicateParser; +import net.fabricmc.loader.impl.util.version.VersionPredicateParser; import org.apache.commons.io.FileUtils; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Type; @@ -33,6 +34,8 @@ public class OmmcCompatMixinPlugin extends OmmcMixinPlugin { private final List obfuscatedMixinList = new ArrayList<>(); static private Path tempDirectory; + static private Method oldMatchesMethod; + static { if (!FabricLoader.getInstance().isDevelopmentEnvironment()) { try { @@ -42,6 +45,11 @@ public class OmmcCompatMixinPlugin extends OmmcMixinPlugin { throw new IllegalStateException("Cannot create temp directory."); } } + try { + oldMatchesMethod = Class.forName("net.fabricmc.loader.util.version.VersionPredicateParser").getMethod("matches", Version.class, String.class); + } catch (ClassNotFoundException | NoSuchMethodException ignored) { + } + } // private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); @@ -139,7 +147,12 @@ public void onLoad(String mixinPackage) { Object urlLoader = Thread.currentThread().getContextClassLoader(); Class knotClassLoader; try { - knotClassLoader = Class.forName("net.fabricmc.loader.launch.knot.KnotClassLoader"); + if (oldMatchesMethod == null) { + knotClassLoader = Class.forName("net.fabricmc.loader.impl.launch.knot.KnotClassLoader"); + } else { + knotClassLoader = Class.forName("net.fabricmc.loader.launch.knot.KnotClassLoader"); + } + } catch (ClassNotFoundException e) { e.printStackTrace(); throw new IllegalStateException("Cannot load class: net.fabricmc.loader.launch.knot.KnotClassLoader"); @@ -169,22 +182,29 @@ private void obfuscateClass(String classFullName) { } } + + private boolean myMatches(Version version, String s) { + try { + if (oldMatchesMethod != null) { + return (boolean) oldMatchesMethod.invoke(null, version, s); + } + return VersionPredicateParser.parse(s).test(version); + } catch (VersionParsingException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + return false; + } + } + private boolean checkDependency(String targerClassName, AnnotationNode dependency) { String modId = Annotations.getValue(dependency, "modId"); Optional modContainerOptional = FabricLoader.getInstance().getModContainer(modId); if (modContainerOptional.isPresent()) { ModContainer modContainer = modContainerOptional.get(); List versionList = Annotations.getValue(dependency, "version"); - try { - for (String version : versionList) { - // not work in fabric-loader 0.12 - if (!VersionPredicateParser.matches(modContainer.getMetadata().getVersion(), version)) { - return false; - } + for (String version : versionList) { + if (!myMatches(modContainer.getMetadata().getVersion(), version)) { + return false; } - } catch (VersionParsingException e) { - e.printStackTrace(); - throw new IllegalStateException(String.format("VersionParsingException, modid=%s, version=%s", modId, versionList)); } ClassNode targetClassNode; try { diff --git a/src/main/java/com/plusls/ommc/mixin/feature/betterSneaking/MixinPlayerEntity.java b/src/main/java/com/plusls/ommc/mixin/feature/betterSneaking/MixinPlayerEntity.java index a3dd763..e0a0a31 100644 --- a/src/main/java/com/plusls/ommc/mixin/feature/betterSneaking/MixinPlayerEntity.java +++ b/src/main/java/com/plusls/ommc/mixin/feature/betterSneaking/MixinPlayerEntity.java @@ -1,7 +1,6 @@ package com.plusls.ommc.mixin.feature.betterSneaking; import com.plusls.ommc.config.Configs; -import net.minecraft.client.MinecraftClient; import net.minecraft.entity.MovementType; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.Vec3d; @@ -12,13 +11,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerEntity.class) -public class MixinPlayerEntity { +public class MixinPlayerEntity { final private static float MAX_STEP_HEIGHT = 1.25f; final private static float DEFAULT_STEP_HEIGHT = 114514; private float prevStepHeight = DEFAULT_STEP_HEIGHT; - @Inject(method = "adjustMovementForSneaking", at=@At(value = "FIELD", target = "Lnet/minecraft/util/math/Vec3d;x:D", opcode = Opcodes.GETFIELD, ordinal = 0)) + @Inject(method = "adjustMovementForSneaking", at = @At(value = "FIELD", target = "Lnet/minecraft/util/math/Vec3d;x:D", opcode = Opcodes.GETFIELD, ordinal = 0)) private void setStepHeight(Vec3d movement, MovementType type, CallbackInfoReturnable cir) { if (!Configs.FeatureToggle.BETTER_SNEAKING.getBooleanValue()) { return; @@ -28,7 +27,7 @@ private void setStepHeight(Vec3d movement, MovementType type, CallbackInfoReturn playerEntity.stepHeight = MAX_STEP_HEIGHT; } - @Inject(method = "adjustMovementForSneaking", at=@At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;(DDD)V", ordinal = 0)) + @Inject(method = "adjustMovementForSneaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/Vec3d;(DDD)V", ordinal = 0)) private void restoreStepHeight(Vec3d movement, MovementType type, CallbackInfoReturnable cir) { if (!Configs.FeatureToggle.BETTER_SNEAKING.getBooleanValue() || Math.abs(prevStepHeight - DEFAULT_STEP_HEIGHT) <= 0.001) { return;