From c7444ccca338b44d7562c6ffa3ff0abd7623a218 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 12 Aug 2019 16:55:37 +0200 Subject: [PATCH] Backport: Fixed floating pegasi --- .../com/minelittlepony/pony/data/Pony.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minelittlepony/pony/data/Pony.java b/src/main/java/com/minelittlepony/pony/data/Pony.java index e70a15d9..4a081299 100644 --- a/src/main/java/com/minelittlepony/pony/data/Pony.java +++ b/src/main/java/com/minelittlepony/pony/data/Pony.java @@ -8,13 +8,18 @@ import com.voxelmodpack.hdskins.resources.texture.DynamicTextureImage; import com.voxelmodpack.hdskins.resources.texture.IBufferedTexture; import com.voxelmodpack.hdskins.util.ProfileTextureUtil; +import net.minecraft.block.BlockStairs; +import net.minecraft.block.BlockState; +import net.minecraft.block.StairsBlock; import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.ITextureObject; import net.minecraft.client.renderer.texture.TextureUtil; import net.minecraft.client.resources.IResource; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; @@ -130,13 +135,37 @@ public class Pony extends Touchable implements IPony { @Override public boolean isFlying(EntityLivingBase entity) { - return !(entity.onGround + return !(isOnGround(entity) || entity.isRiding() || (entity.isOnLadder() && !(entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.isFlying)) || entity.isInWater() || entity.isPlayerSleeping()); } + /** + * Checks if the entity is on the ground, or close enough to be "effectively" grounded. + * this is to keep Pegasus wings from flapping in odd situations (Hypixel). + */ + private boolean isOnGround(EntityLivingBase entity) { + if (entity.onGround) { + return true; + } + + IBlockState below = entity.getEntityWorld() + .getBlockState(entity.getPosition().down()); + + // Check for stairs so we can keep Pegasi from flailing their wings as they descend + double offsetAmount = below.getBlock() instanceof BlockStairs ? 1 : 0.05; + + Vec3d pos = entity.getPositionVector(); + BlockPos blockpos = new BlockPos( + Math.floor(pos.x), + Math.floor(pos.y - offsetAmount), + Math.floor(pos.z)); + + return !entity.getEntityWorld().isAirBlock(blockpos); + } + @Override public boolean isSwimming(EntityLivingBase entity) { return isFullySubmerged(entity) && !(entity.onGround || entity.isOnLadder());