From 214acef12c678626b8e516ea83133db9f246b159 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 3 Oct 2024 19:16:11 +0100 Subject: [PATCH] Fix more mixins --- .../unicopia/mixin/MixinPlayerEntity.java | 13 +++++------ .../mixin/gravity/MixinPlayerEntity.java | 22 ++++++++++++++----- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java index bc43568c..4edd57a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPlayerEntity.java @@ -41,9 +41,10 @@ abstract class MixinPlayerEntity extends LivingEntity implements Equine.Containe return new Pony((PlayerEntity)(Object)this); } - @Inject(method = "createPlayerAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN")) - private static void onCreateAttributes(CallbackInfoReturnable info) { - Pony.registerAttributes(info.getReturnValue()); + @ModifyReturnValue(method = "createPlayerAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", at = @At("RETURN")) + private static DefaultAttributeContainer.Builder onCreateAttributes(DefaultAttributeContainer.Builder builder) { + Pony.registerAttributes(builder); + return builder; } @ModifyVariable(method = "applyDamage(Lnet/minecraft/entity/damage/DamageSource;F)V", at = @At("HEAD"), ordinal = 0, argsOnly = true) @@ -52,13 +53,11 @@ abstract class MixinPlayerEntity extends LivingEntity implements Equine.Containe } @ModifyVariable(method = "eatFood(Lnet/minecraft/world/World;Lnet/minecraft/item/ItemStack;Lnet/minecraft/component/type/FoodComponent;)Lnet/minecraft/item/ItemStack;", at = @At("HEAD"), argsOnly = true) - private FoodComponent onEatFood(FoodComponent initial, World world, ItemStack stack, FoodComponent food, CallbackInfoReturnable info) { + private FoodComponent onEatFood(FoodComponent initial, World world, ItemStack stack, FoodComponent food) { return get().onEat(stack, food); } - @Inject(method = "trySleep(Lnet/minecraft/util/math/BlockPos;)Lcom/mojang/datafixers/util/Either;", - at = @At("HEAD"), - cancellable = true) + @Inject(method = "trySleep(Lnet/minecraft/util/math/BlockPos;)Lcom/mojang/datafixers/util/Either;", at = @At("HEAD"), cancellable = true) private void onTrySleep(BlockPos pos, CallbackInfoReturnable> info) { if (!getWorld().isClient) { get().trySleep(pos).ifPresent(reason -> { diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java index 6a8e0110..250a0cd3 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/gravity/MixinPlayerEntity.java @@ -7,6 +7,7 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.llamalad7.mixinextras.sugar.Local; import com.minelittlepony.unicopia.entity.Equine; import net.minecraft.entity.Entity; @@ -32,15 +33,24 @@ abstract class MixinPlayerEntity { } } - @ModifyArg(method = { "adjustMovementForSneaking", "method_30263" }, at = @At( - value = "INVOKE", - target = "net/minecraft/util/math/Box.offset(DDD)Lnet/minecraft/util/math/Box;"), + @ModifyArg(method = "isSpaceAroundPlayerEmpty", + at = @At(value = "INVOKE", target = "net/minecraft/util/math/Box.(DDDDDD)V"), index = 1) - private double invertStepHeight(double stepHeight) { + private double invertStepHeightCheckBoxBottom(double bottom) { if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { - return -stepHeight; + return eq.get().asEntity().getBoundingBox().maxY; } - return stepHeight; + return bottom; + } + + @ModifyArg(method = "isSpaceAroundPlayerEmpty", + at = @At(value = "INVOKE", target = "net/minecraft/util/math/Box.(DDDDDD)V"), + index = 4) + private double invertStepHeightCheckBoxTop(double top, @Local(argsOnly = true) float stepHeight) { + if (this instanceof Equine.Container eq && eq.get().getPhysics().isGravityNegative()) { + return eq.get().asEntity().getBoundingBox().maxY + stepHeight + 1.0E-5F; + } + return top; } @ModifyArg(method = "canChangeIntoPose",