Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Feb 13, 2024
2 parents d637e43 + b85f617 commit b159ce3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -52,6 +53,7 @@ public void onLoad(String mixinPackage) {
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();
Expand All @@ -76,6 +78,9 @@ public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <[email protected]> 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);
}
}

}
3 changes: 2 additions & 1 deletion src/main/resources/viafabricplus.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@
"viaversion.MixinAbstractFenceConnectionHandler",
"viaversion.MixinConfig",
"viaversion.MixinGlassConnectionHandler",
"viaversion.MixinProtocolVersion"
"viaversion.MixinProtocolVersion",
"compat.lithium.MixinEntity"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit b159ce3

Please sign in to comment.