From 1c52237568518f25b31ca4bd6843f55a4d5d6fde Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 16 Sep 2024 19:16:05 +0100 Subject: [PATCH] Fixed changling clinging and bat pony hanging abilities. Closes #404 --- .../unicopia/ability/BatPonyHangAbility.java | 2 +- .../unicopia/entity/EntityPhysics.java | 13 ++++++------ .../unicopia/entity/player/Acrobatics.java | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java index 723cc0f5..95566b44 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java @@ -37,7 +37,7 @@ public class BatPonyHangAbility implements Ability { } return TraceHelper.findBlock(player.asEntity(), 5, 1) - .map(BlockPos::down) + .map(pos -> pos.down(player.getPhysics().getGravitySignum())) .filter(player.getAcrobatics()::canHangAt) .map(pos -> new Multi(pos, 1)); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java index c50d740f..bd51d7ba 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityPhysics.java @@ -10,12 +10,12 @@ import com.minelittlepony.unicopia.util.Tickable; import net.minecraft.block.BlockState; import net.minecraft.block.FenceGateBlock; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityPose; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.tag.BlockTags; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; public class EntityPhysics implements Physics, Copyable>, Tickable { @@ -75,18 +75,17 @@ public class EntityPhysics implements Physics, Copyable 1.5) { @@ -156,8 +159,9 @@ public class Acrobatics implements Tickable, NbtSerialisable { } public void startHanging(BlockPos pos) { + boolean inverted = pony.getPhysics().isGravityNegative(); hangingPos.set(Optional.of(pos)); - entity.teleport(pos.getX() + 0.5, pos.getY() - 1, pos.getZ() + 0.5); + entity.teleport(pos.getX() + 0.5, pos.getY() - (inverted ? 0 : 1), pos.getZ() + 0.5); entity.setVelocity(Vec3d.ZERO); entity.setSneaking(false); entity.stopFallFlying(); @@ -165,14 +169,17 @@ public class Acrobatics implements Tickable, NbtSerialisable { } public boolean canHangAt(BlockPos pos) { - if (!pony.asWorld().isAir(pos) || !pony.asWorld().isAir(pos.down())) { + int gravity = pony.getPhysics().getGravitySignum() * (isHanging() && pony.getObservedSpecies() == Race.BAT ? -1 : 1); + BlockState state = pony.asWorld().getBlockState(pos); + + if (!pony.asWorld().isAir(pos) || !pony.asWorld().isAir(pos.down(gravity))) { return false; } - pos = pos.up(); - BlockState state = pony.asWorld().getBlockState(pos); + pos = pos.up(gravity); + state = pony.asWorld().getBlockState(pos); - return state.isSolidSurface(pony.asWorld(), pos, entity, Direction.DOWN) && entity.getWorld().isAir(entity.getBlockPos().down()); + return state.isSolidSurface(pony.asWorld(), pos, entity, gravity > 0 ? Direction.UP : Direction.DOWN); } private boolean canKeepHanging() { @@ -184,7 +191,7 @@ public class Acrobatics implements Tickable, NbtSerialisable { return true; } return getHangingPosition().filter(hangingPos -> { - return (race != Race.BAT || hangingPos.equals(pony.getOrigin().down())) && canHangAt(hangingPos); + return (race != Race.BAT || hangingPos.equals(pony.asEntity().getBlockPos().up(pony.getPhysics().isGravityNegative() ? 1 : 0))) && canHangAt(hangingPos); }).isPresent(); }