Fix edge sneaking when upside down

This commit is contained in:
Sollace 2024-03-26 22:00:43 +00:00
parent dd8bf650d5
commit 2ae28c72d3
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 44 additions and 0 deletions

View file

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

View file

@ -58,6 +58,7 @@
"gravity.MixinLivingEntity", "gravity.MixinLivingEntity",
"gravity.MixinMobEntity", "gravity.MixinMobEntity",
"gravity.MixinWorld", "gravity.MixinWorld",
"gravity.MixinPlayerEntity",
"gravity.MixinPistonBlockEntity", "gravity.MixinPistonBlockEntity",
"gravity.MixinServerWorld", "gravity.MixinServerWorld",
"gravity.MixinServerPlayerEntity", "gravity.MixinServerPlayerEntity",