Fixed changling clinging and bat pony hanging abilities. Closes #404

This commit is contained in:
Sollace 2024-09-16 19:16:05 +01:00
parent d6286c7a00
commit 1c52237568
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 21 additions and 15 deletions

View file

@ -37,7 +37,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
} }
return TraceHelper.findBlock(player.asEntity(), 5, 1) return TraceHelper.findBlock(player.asEntity(), 5, 1)
.map(BlockPos::down) .map(pos -> pos.down(player.getPhysics().getGravitySignum()))
.filter(player.getAcrobatics()::canHangAt) .filter(player.getAcrobatics()::canHangAt)
.map(pos -> new Multi(pos, 1)); .map(pos -> new Multi(pos, 1));
} }

View file

@ -10,12 +10,12 @@ import com.minelittlepony.unicopia.util.Tickable;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FenceGateBlock; import net.minecraft.block.FenceGateBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity; import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public class EntityPhysics<T extends Entity> implements Physics, Copyable<EntityPhysics<T>>, Tickable { public class EntityPhysics<T extends Entity> implements Physics, Copyable<EntityPhysics<T>>, Tickable {
@ -75,18 +75,17 @@ public class EntityPhysics<T extends Entity> implements Physics, Copyable<Entity
@Override @Override
public BlockPos getHeadPosition() { public BlockPos getHeadPosition() {
BlockPos pos = BlockPos.ofFloored(
BlockPos pos = new BlockPos( entity.getX(),
MathHelper.floor(entity.getX()), entity.getY() + entity.getEyeHeight(EntityPose.STANDING),
MathHelper.floor(entity.getY() + entity.getHeight() + 0.20000000298023224D), entity.getZ()
MathHelper.floor(entity.getZ())
); );
if (entity.getWorld().getBlockState(pos).isAir()) { if (entity.getWorld().getBlockState(pos).isAir()) {
BlockPos below = pos.down(); BlockPos below = pos.down();
BlockState block = entity.getWorld().getBlockState(below); BlockState block = entity.getWorld().getBlockState(below);
if (block.isIn(BlockTags.FENCES) || block.isIn(BlockTags.WALLS) || block.getBlock() instanceof FenceGateBlock) { if (block.isIn(BlockTags.FENCES) || block.isIn(BlockTags.WALLS) || block.getBlock() instanceof FenceGateBlock) {
return below; // return below;
} }
} }

View file

@ -58,6 +58,8 @@ public class Acrobatics implements Tickable, NbtSerialisable {
public void tick() { public void tick() {
BlockPos climbingPos = entity.getClimbingPos().orElse(null); BlockPos climbingPos = entity.getClimbingPos().orElse(null);
BlockPos hangingPos = pony.getPhysics().getHeadPosition();
if (!pony.getPhysics().isFlying() && !entity.getAbilities().flying if (!pony.getPhysics().isFlying() && !entity.getAbilities().flying
&& climbingPos != null && climbingPos != null
&& pony.getObservedSpecies() == Race.CHANGELING && pony.getObservedSpecies() == Race.CHANGELING
@ -68,7 +70,8 @@ public class Acrobatics implements Tickable, NbtSerialisable {
} }
distanceClimbed += Math.abs(pony.getMotion().getClientVelocity().y); distanceClimbed += Math.abs(pony.getMotion().getClientVelocity().y);
BlockPos hangingPos = entity.getBlockPos().up();
boolean canhangHere = canHangAt(hangingPos); boolean canhangHere = canHangAt(hangingPos);
if (distanceClimbed > 1.5) { if (distanceClimbed > 1.5) {
@ -156,8 +159,9 @@ public class Acrobatics implements Tickable, NbtSerialisable {
} }
public void startHanging(BlockPos pos) { public void startHanging(BlockPos pos) {
boolean inverted = pony.getPhysics().isGravityNegative();
hangingPos.set(Optional.of(pos)); 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.setVelocity(Vec3d.ZERO);
entity.setSneaking(false); entity.setSneaking(false);
entity.stopFallFlying(); entity.stopFallFlying();
@ -165,14 +169,17 @@ public class Acrobatics implements Tickable, NbtSerialisable {
} }
public boolean canHangAt(BlockPos pos) { 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; return false;
} }
pos = pos.up(); pos = pos.up(gravity);
BlockState state = pony.asWorld().getBlockState(pos); 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() { private boolean canKeepHanging() {
@ -184,7 +191,7 @@ public class Acrobatics implements Tickable, NbtSerialisable {
return true; return true;
} }
return getHangingPosition().filter(hangingPos -> { 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(); }).isPresent();
} }