mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Fixed changling clinging and bat pony hanging abilities. Closes #404
This commit is contained in:
parent
6a36249d68
commit
82aa1bc5af
3 changed files with 21 additions and 15 deletions
|
@ -37,7 +37,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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<T extends Entity> implements Physics, Copyable<EntityPhysics<T>>, Tickable {
|
||||
|
@ -75,18 +75,17 @@ public class EntityPhysics<T extends Entity> implements Physics, Copyable<Entity
|
|||
|
||||
@Override
|
||||
public BlockPos getHeadPosition() {
|
||||
|
||||
BlockPos pos = new BlockPos(
|
||||
MathHelper.floor(entity.getX()),
|
||||
MathHelper.floor(entity.getY() + entity.getHeight() + 0.20000000298023224D),
|
||||
MathHelper.floor(entity.getZ())
|
||||
BlockPos pos = BlockPos.ofFloored(
|
||||
entity.getX(),
|
||||
entity.getY() + entity.getEyeHeight(EntityPose.STANDING),
|
||||
entity.getZ()
|
||||
);
|
||||
|
||||
if (entity.getWorld().getBlockState(pos).isAir()) {
|
||||
BlockPos below = pos.down();
|
||||
BlockState block = entity.getWorld().getBlockState(below);
|
||||
if (block.isIn(BlockTags.FENCES) || block.isIn(BlockTags.WALLS) || block.getBlock() instanceof FenceGateBlock) {
|
||||
return below;
|
||||
// return below;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ public class Acrobatics implements Tickable, NbtSerialisable {
|
|||
public void tick() {
|
||||
BlockPos climbingPos = entity.getClimbingPos().orElse(null);
|
||||
|
||||
BlockPos hangingPos = pony.getPhysics().getHeadPosition();
|
||||
|
||||
if (!pony.getPhysics().isFlying() && !entity.getAbilities().flying
|
||||
&& climbingPos != null
|
||||
&& pony.getObservedSpecies() == Race.CHANGELING
|
||||
|
@ -68,7 +70,8 @@ public class Acrobatics implements Tickable, NbtSerialisable {
|
|||
}
|
||||
|
||||
distanceClimbed += Math.abs(pony.getMotion().getClientVelocity().y);
|
||||
BlockPos hangingPos = entity.getBlockPos().up();
|
||||
|
||||
|
||||
boolean canhangHere = canHangAt(hangingPos);
|
||||
|
||||
if (distanceClimbed > 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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue