diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 6606dc0b4b..0fc66e8850 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -9,11 +9,18 @@ import net.minecraft.server.EntitySnowball; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.block.Block; import org.bukkit.entity.Arrow; import org.bukkit.entity.Egg; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Snowball; import org.bukkit.entity.Vehicle; +import org.bukkit.util.BlockIterator; + +import java.util.List; +import java.util.HashSet; +import java.util.ArrayList; +import java.util.Iterator; public class CraftLivingEntity extends CraftEntity implements LivingEntity { private EntityLiving entity; @@ -64,6 +71,53 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return (Snowball) snowball.getBukkitEntity(); } + public double getEyeHeight() { + return 1.0D; + } + + public double getEyeHeight(boolean ignoreSneaking) { + return getEyeHeight(); + } + + private List getLineOfSight(HashSet transparent, int maxDistance, int maxLength) { + if (maxDistance > 120) { + maxDistance = 120; + } + ArrayList blocks = new ArrayList(); + Iterator itr = new BlockIterator(this, maxDistance); + while (itr.hasNext()) { + Block block = itr.next(); + blocks.add(block); + if (maxLength != 0 && blocks.size() > maxLength) { + blocks.remove(0); + } + int id = block.getTypeId(); + if (transparent == null) { + if (id != 0) { + break; + } + } else { + if (!transparent.contains((byte)id)) { + break; + } + } + } + return blocks; + } + + public List getLineOfSight(HashSet transparent, int maxDistance) { + return getLineOfSight(transparent, maxDistance, 0); + } + + public Block getTargetBlock(HashSet transparent, int maxDistance) { + List blocks = getLineOfSight(transparent, maxDistance, 1); + return blocks.get(0); + } + + public List getLastTwoTargetBlocks(HashSet transparent, int maxDistance) { + return getLineOfSight(transparent, maxDistance, 2); + } + public Arrow shootArrow() { net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); EntityArrow arrow = new EntityArrow(world, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 3faa3e32e9..69a95e1e83 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -58,6 +58,22 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return entity; } + public double getEyeHeight() { + return getEyeHeight(false); + } + + public double getEyeHeight(boolean ignoreSneaking) { + if(ignoreSneaking) { + return 1.62D; + } else { + if (isSneaking()) { + return 1.42D; + } else { + return 1.62D; + } + } + } + public void setHandle(final EntityPlayer entity) { super.setHandle((EntityHuman) entity); this.entity = entity;