summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java54
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java16
2 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 6606dc0b..0fc66e88 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/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<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
+ if (maxDistance > 120) {
+ maxDistance = 120;
+ }
+ ArrayList<Block> blocks = new ArrayList();
+ Iterator<Block> 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<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance) {
+ return getLineOfSight(transparent, maxDistance, 0);
+ }
+
+ public Block getTargetBlock(HashSet<Byte> transparent, int maxDistance) {
+ List<Block> blocks = getLineOfSight(transparent, maxDistance, 1);
+ return blocks.get(0);
+ }
+
+ public List<Block> getLastTwoTargetBlocks(HashSet<Byte> 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/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 3faa3e32..69a95e1e 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/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;