diff --git a/build.gradle b/build.gradle index 843dd3f6..b1d46da6 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,10 @@ group = project.maven_group configurations { implementation.extendsFrom libs api.extendsFrom libs + + implementation.extendsFrom bundleMod + include.extendsFrom bundleMod + annotationProcessor.extendsFrom bundleMod } allprojects { @@ -89,6 +93,8 @@ dependencies { } libs "net.lenni0451:Reflect:${project.reflect_version}" + bundleMod "com.github.LlamaLad7:MixinExtras:${project.mixin_extras_version}" + modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}" } diff --git a/gradle.properties b/gradle.properties index 5fea652e..a41c9dd0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -36,3 +36,4 @@ reflect_version=1.1.0 # other libs mod_menu_version=6.1.0-rc.4 netty_codec_http_version=4.1.90.Final +mixin_extras_version=0.2.0-beta.7 diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 7086d4be..2b3588e6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -19,6 +19,7 @@ package de.florianmichael.viafabricplus; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.llamalad7.mixinextras.MixinExtrasBootstrap; import de.florianmichael.viafabricplus.definition.ChatLengthCalculation; import de.florianmichael.viafabricplus.definition.v1_12_2.FontCacheFix; import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings; @@ -57,6 +58,7 @@ public class ViaFabricPlus { private final InformationSystem informationSystem = new InformationSystem(); public void init() { + MixinExtrasBootstrap.init(); PreLoadCallback.EVENT.invoker().onLoad(); // Classic Stuff diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java index cebb162e..0620837b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinClientPlayNetworkHandler.java @@ -17,6 +17,7 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.mojang.authlib.GameProfile; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.ViaFabricPlus; @@ -109,11 +110,9 @@ public abstract class MixinClientPlayNetworkHandler { } } - @Redirect(method = "onPlayerSpawnPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/DownloadingTerrainScreen;setReady()V")) - public void moveDownloadingTerrainClosing(DownloadingTerrainScreen instance) { - if (ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19)) { - instance.setReady(); - } + @WrapWithCondition(method = "onPlayerSpawnPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/DownloadingTerrainScreen;setReady()V")) + public boolean moveDownloadingTerrainClosing(DownloadingTerrainScreen instance) { + return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19); } @Inject(method = "onPlayerPositionLook", at = @At("RETURN")) @@ -132,11 +131,9 @@ public abstract class MixinClientPlayNetworkHandler { return constant; } - @Redirect(method = "onPlayerList", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false)) - public void removeNewWarning(Logger instance, String s, Object o) { - if (ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19_3)) { - instance.warn(s, o); - } + @WrapWithCondition(method = "onPlayerList", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;)V", remap = false)) + public boolean removeWarning(Logger instance, String s, Object o) { + return ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(ProtocolVersion.v1_19_3); } @Redirect(method = "onKeepAlive", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;Ljava/util/function/BooleanSupplier;Ljava/time/Duration;)V")) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinInGameHud.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinInGameHud.java index 8765a516..a9c9c449 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinInGameHud.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinInGameHud.java @@ -17,6 +17,7 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import de.florianmichael.viafabricplus.base.settings.groups.VisualSettings; import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.util.math.MatrixStack; @@ -63,10 +64,10 @@ public abstract class MixinInGameHud { // Moving down all remaining elements - @Redirect(method = "renderStatusBars", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/hud/InGameHud;scaledHeight:I", opcode = Opcodes.GETFIELD)) - private int moveHealthDown(InGameHud instance) { - if (VisualSettings.INSTANCE.removeNewerHudElements.getValue()) return scaledHeight + 6; - return scaledHeight; + @ModifyExpressionValue(method = "renderStatusBars", at = @At(value = "FIELD", target = "Lnet/minecraft/client/gui/hud/InGameHud;scaledHeight:I", opcode = Opcodes.GETFIELD)) + private int moveHealthDown(int originalValue) { + if (VisualSettings.INSTANCE.removeNewerHudElements.getValue()) return originalValue + 6; + return originalValue; } @ModifyArg(method = "renderStatusBars", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"), slice = @Slice( diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMinecraftClient.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMinecraftClient.java index 90d7a6b9..fce63549 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMinecraftClient.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinMinecraftClient.java @@ -17,6 +17,7 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; @@ -56,13 +57,11 @@ public abstract class MixinMinecraftClient implements IMinecraftClient { @Shadow @Nullable public abstract ClientPlayNetworkHandler getNetworkHandler(); - @Redirect(method = "doItemUse", + @WrapWithCondition(method = "doItemUse", slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;interactItem(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;")), at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;resetEquipProgress(Lnet/minecraft/util/Hand;)V", ordinal = 0)) - private void redirectDoItemUse(HeldItemRenderer heldItemRenderer, Hand hand) { - if (ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_8) || !(player.getStackInHand(hand).getItem() instanceof SwordItem)) { - heldItemRenderer.resetEquipProgress(hand); - } + public boolean removeEquipProgressReset(HeldItemRenderer instance, Hand hand) { + return ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_8) || !(player.getStackInHand(hand).getItem() instanceof SwordItem); } @Redirect(method = "doItemUse", diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinServerResourcePackProvider.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinServerResourcePackProvider.java index 2043b3c2..1667a1df 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinServerResourcePackProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/MixinServerResourcePackProvider.java @@ -89,7 +89,6 @@ public class MixinServerResourcePackProvider { if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) { return instance; } - return instance.toLowerCase(locale); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java index f879e985..7136330b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/entity/MixinLivingEntity.java @@ -17,6 +17,7 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity; +import com.llamalad7.mixinextras.injector.WrapWithCondition; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; import de.florianmichael.viafabricplus.base.settings.groups.ExperimentalSettings; @@ -88,13 +89,11 @@ public abstract class MixinLivingEntity extends Entity { return movingDown; } - @Redirect(method = "travel", + @WrapWithCondition(method = "travel", slice = @Slice(from = @At(value = "FIELD", target = "Lnet/minecraft/entity/effect/StatusEffects;LEVITATION:Lnet/minecraft/entity/effect/StatusEffect;", ordinal = 0)), at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;onLanding()V", ordinal = 0)) - private void dontResetLevitationFallDistance(LivingEntity instance) { - if (ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_12_2)) { - instance.onLanding(); - } + private boolean dontResetLevitationFallDistance(LivingEntity instance) { + return ProtocolHack.getTargetVersion().isNewerThan(ProtocolVersion.v1_12_2); } @Redirect(method = "travel", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;isSprinting()Z", ordinal = 0))