Fixed incompatibility with lithium

This commit is contained in:
FlorianMichael 2024-02-10 20:07:26 +01:00
parent e91e19473f
commit b85f61708d
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
3 changed files with 50 additions and 1 deletions

View File

@ -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<String> 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;
}

View File

@ -0,0 +1,43 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@ -199,7 +199,8 @@
"viaversion.MixinAbstractFenceConnectionHandler",
"viaversion.MixinConfig",
"viaversion.MixinGlassConnectionHandler",
"viaversion.MixinProtocolVersion"
"viaversion.MixinProtocolVersion",
"compat.lithium.MixinEntity"
],
"injectors": {
"defaultRequire": 1