From 2ae28c72d3f222487407a12acaf65096382dba10 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 26 Mar 2024 22:00:43 +0000 Subject: [PATCH] Fix edge sneaking when upside down --- .../mixin/gravity/MixinPlayerEntity.java | 43 +++++++++++++++++++ src/main/resources/unicopia.mixin.json | 1 + 2 files changed, 44 insertions(+) create mode 100644 src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java new file mode 100644 index 00000000..e6b8b24b --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java @@ -0,0 +1,43 @@ +package com.minelittlepony.unicopia.mixin.gravity; + +import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.minelittlepony.unicopia.entity.Equine; + +import net.minecraft.entity.MovementType; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.Vec3d; + +@Mixin(PlayerEntity.class) +abstract class MixinPlayerEntity { + @ModifyVariable(method = "adjustMovementForSneaking", at = @At("HEAD"), argsOnly = true) + private Vec3d flipMovementForSneaking(Vec3d movement) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + return movement.multiply(1, -1, 1); + } + return movement; + } + + @Inject(method = "adjustMovementForSneaking", at = @At("RETURN"), cancellable = true) + private void unflipMovementForSneaking(Vec3d movement, MovementType type, CallbackInfoReturnable info) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + info.setReturnValue(info.getReturnValue().multiply(1, -1, 1)); + } + } + + @ModifyArg(method = { "adjustMovementForSneaking", "method_30263" }, at = @At( + value = "INVOKE", + target = "net/minecraft/util/math/Box.offset(DDD)Lnet/minecraft/util/math/Box;"), + index = 1) + private double invertStepHeight(double stepHeight) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + return -stepHeight; + } + return stepHeight; + } +} diff --git a/src/main/resources/unicopia.mixin.json b/src/main/resources/unicopia.mixin.json index 530d0226..0a82eae8 100644 --- a/src/main/resources/unicopia.mixin.json +++ b/src/main/resources/unicopia.mixin.json @@ -58,6 +58,7 @@ "gravity.MixinLivingEntity", "gravity.MixinMobEntity", "gravity.MixinWorld", + "gravity.MixinPlayerEntity", "gravity.MixinPistonBlockEntity", "gravity.MixinServerWorld", "gravity.MixinServerPlayerEntity",