From b85f61708d7e0bada2785f5ce7f296481c9687ab Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sat, 10 Feb 2024 20:07:26 +0100 Subject: [PATCH] Fixed incompatibility with lithium --- .../injection/ViaFabricPlusMixinPlugin.java | 5 +++ .../mixin/compat/lithium/MixinEntity.java | 43 +++++++++++++++++++ src/main/resources/viafabricplus.mixins.json | 3 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/lithium/MixinEntity.java diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java b/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java index 5129e8f6..e91abbe4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/ViaFabricPlusMixinPlugin.java @@ -41,6 +41,7 @@ public class ViaFabricPlusMixinPlugin implements IMixinConfigPlugin { public static boolean ARMOR_SKIN_PRESENT; public static boolean IPNEXT_PRESENT; public static boolean MORE_CULLING_PRESENT; + public static boolean LITHIUM_PRESENT; @Override public void onLoad(String mixinPackage) { @@ -52,6 +53,7 @@ public class ViaFabricPlusMixinPlugin implements IMixinConfigPlugin { ARMOR_SKIN_PRESENT = loader.isModLoaded("armorskin"); IPNEXT_PRESENT = loader.isModLoaded("inventoryprofilesnext"); MORE_CULLING_PRESENT = loader.isModLoaded("moreculling"); + LITHIUM_PRESENT = loader.isModLoaded("lithium"); // Force unload some FabricAPI mixins because FabricAPI overwrites some of the elytra code final Set loadedMixins = RStream.of("org.spongepowered.asm.mixin.transformer.MixinConfig").fields().by("globalMixinList").get(); @@ -76,6 +78,9 @@ public class ViaFabricPlusMixinPlugin implements IMixinConfigPlugin { if (mixinClassName.equals(INJECTOR_PACKAGE + COMPAT_PACKAGE + "ipnext.MixinAutoRefillHandler_ItemSlotMonitor")) { return IPNEXT_PRESENT; } + if (mixinClassName.equals(INJECTOR_PACKAGE + COMPAT_PACKAGE + "lithium.MixinEntity")) { + return LITHIUM_PRESENT; + } return true; } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/lithium/MixinEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/lithium/MixinEntity.java new file mode 100644 index 00000000..fec4d686 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/compat/lithium/MixinEntity.java @@ -0,0 +1,43 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2024 FlorianMichael/EnZaXD and RK_01/RaphiMC + * Copyright (C) 2023-2024 contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.florianmichael.viafabricplus.injection.mixin.compat.lithium; + +import de.florianmichael.viafabricplus.protocolhack.ProtocolHack; +import net.minecraft.entity.Entity; +import net.raphimc.vialoader.util.VersionEnum; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +// Lithium is overriding the sorting with an optimized implementation +// https://github.com/CaffeineMC/lithium-fabric/blob/develop/src/main/java/me/jellysquid/mods/lithium/mixin/entity/collisions/movement/EntityMixin.java#L54 +@Mixin(value = Entity.class, priority = 1001 /* Lithium has to be applied first */) +public abstract class MixinEntity { + + @Redirect(method = "lithiumCollideMultiAxisMovement", at = @At(value = "INVOKE", target = "Ljava/lang/Math;abs(D)D", ordinal = 0)) + private static double alwaysSortYXZ(double a) { + if (ProtocolHack.getTargetVersion().isOlderThanOrEqualTo(VersionEnum.r1_13_2)) { + return Double.MAX_VALUE; + } else { + return Math.abs(a); + } + } + +} diff --git a/src/main/resources/viafabricplus.mixins.json b/src/main/resources/viafabricplus.mixins.json index 240c7402..eb496e5e 100644 --- a/src/main/resources/viafabricplus.mixins.json +++ b/src/main/resources/viafabricplus.mixins.json @@ -199,7 +199,8 @@ "viaversion.MixinAbstractFenceConnectionHandler", "viaversion.MixinConfig", "viaversion.MixinGlassConnectionHandler", - "viaversion.MixinProtocolVersion" + "viaversion.MixinProtocolVersion", + "compat.lithium.MixinEntity" ], "injectors": { "defaultRequire": 1