diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java index 722d8c53..b0e56857 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java @@ -39,7 +39,7 @@ public class BatPonyHangAbility implements Ability { return new Multi(BlockPos.ZERO, 0); } - BlockPos poss = RayTraceHelper.doTrace(player.getOwner(), 5, 1, EntityPredicates.EXCEPT_SPECTATOR).getBlockPos().orElse(null); + BlockPos poss = RayTraceHelper.doTrace(player.getOwner(), 3, 1, EntityPredicates.EXCEPT_SPECTATOR).getBlockPos().orElse(null); if (poss != null) { boolean air = player.getWorld().isAir(poss.down()) && player.getWorld().isAir(poss.down(2)); @@ -72,7 +72,10 @@ public class BatPonyHangAbility implements Ability { if (data.hitType == 1 && player.canHangAt(data.pos())) { player.getOwner().teleport(data.x + 0.5, data.y - 2, data.z + 0.5); player.getOwner().setVelocity(Vec3d.ZERO); - attr.addPersistentModifier(PlayerAttributes.BAT_HANGING); + + if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) { + attr.addPersistentModifier(PlayerAttributes.BAT_HANGING); + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 2f76416e..62242269 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -13,6 +13,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityPose; +import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; @@ -83,7 +84,10 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti if (!creative) { entity.abilities.flying |= (canFly || entity.abilities.allowFlying) && isFlyingEither; - if ((entity.isOnGround() && entity.isSneaking()) || entity.isTouchingWater() || entity.horizontalCollision || entity.verticalCollision) { + if ((entity.isOnGround() && entity.isSneaking()) + || entity.isTouchingWater() + || entity.horizontalCollision + || (entity.verticalCollision && (pony.getSpecies() != Race.BAT || velocity.y < 0))) { if (entity.abilities.flying && entity.horizontalCollision) { handleWallCollission(entity, velocity); @@ -108,6 +112,17 @@ public class PlayerPhysics extends EntityPhysics implements Tickable, Moti if (canFly) { if (isFlying()) { + + if (pony.getSpecies() == Race.BAT && entity.verticalCollision && pony.canHangAt(pony.getOrigin().up(2))) { + EntityAttributeInstance attr = entity.getAttributeInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER); + + if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) { + attr.addPersistentModifier(PlayerAttributes.BAT_HANGING); + entity.setVelocity(Vec3d.ZERO); + return; + } + } + int level = pony.getLevel().get() + 1; if (ticksInAir++ > (level * 100)) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index eb4eae7f..915c85fb 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -34,6 +34,7 @@ import com.mojang.authlib.GameProfile; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.attribute.DefaultAttributeContainer; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; @@ -81,6 +82,8 @@ public class Pony implements Caster, Equine, Transmi private boolean prevSneaking; private boolean prevLanded; + private int ticksHanging; + @Nullable private Race clientPreferredRace; @@ -255,21 +258,25 @@ public class Pony implements Caster, Equine, Transmi private BlockPos getHangingPos() { BlockPos pos = getOrigin(); - return new BlockPos(pos.getX(), getOwner().getEyeY() + 1, pos.getZ()); + return new BlockPos(pos.getX(), pos.getY() + entity.getEyeHeight(entity.getPose()) + 2, pos.getZ()); } @Override public void tick() { if (isHanging()) { - gravity.isFlyingSurvival = false; - gravity.isFlyingEither = false; - entity.abilities.flying = false; + if (ticksHanging++ > 40) { + if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 + || entity.isSneaking() + || !canHangAt(getHangingPos())) { - if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 || entity.isSneaking() || !canHangAt(getHangingPos())) { - entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING); - entity.calculateDimensions(); + + entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING); + entity.calculateDimensions(); + } } + } else { + ticksHanging = 0; } gravity.tick(); @@ -303,6 +310,11 @@ public class Pony implements Caster, Equine, Transmi prevSneaking = entity.isSneaking(); prevLanded = entity.isOnGround(); + + + if (gravity.isGravityNegative() && entity.getY() > entity.world.getHeight() + 64) { + entity.damage(DamageSource.OUT_OF_WORLD, 4.0F); + } } public Optional onImpact(float distance, float damageMultiplier) {