From 9648edfa6136394153d524fa89c347d86f455641 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Wed, 17 Dec 2014 18:44:34 -0600 Subject: [PATCH] Add alternatives for deprecated methods --- .../craftbukkit/entity/CraftLivingEntity.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 1c1aab10c2..c4f799de6b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -5,6 +5,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import net.minecraft.server.DamageSource; import net.minecraft.server.EntityArmorStand; @@ -151,19 +152,58 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return blocks; } + private List getLineOfSight(Set 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); + } + Material material = block.getType(); + if (transparent == null) { + if (!material.equals(Material.AIR)) { + break; + } + } else { + if (!transparent.contains(material)) { + break; + } + } + } + return blocks; + } + public List getLineOfSight(HashSet transparent, int maxDistance) { return getLineOfSight(transparent, maxDistance, 0); } + public List getLineOfSight(Set 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 Block getTargetBlock(Set 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 List getLastTwoTargetBlocks(Set transparent, int maxDistance) { + return getLineOfSight(transparent, maxDistance, 2); + } + @Deprecated public Arrow shootArrow() { return launchProjectile(Arrow.class);