summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2011-10-01 16:18:17 -0400
committerEvilSeph <evilseph@gmail.com>2011-10-02 23:04:03 -0400
commitaaefd4ecb5d688827e5b0999abad0bc4abfb2cb6 (patch)
tree2530bb81caa90bffaa4710e477078faf2ecf3655
parent80c2bc266a7684b3a1851ba519ff694fcfc4aada (diff)
downloadcraftbukkit-aaefd4ecb5d688827e5b0999abad0bc4abfb2cb6.tar
craftbukkit-aaefd4ecb5d688827e5b0999abad0bc4abfb2cb6.tar.gz
craftbukkit-aaefd4ecb5d688827e5b0999abad0bc4abfb2cb6.tar.lz
craftbukkit-aaefd4ecb5d688827e5b0999abad0bc4abfb2cb6.tar.xz
craftbukkit-aaefd4ecb5d688827e5b0999abad0bc4abfb2cb6.zip
Added callback line of sight methods. Thanks xZise!
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java40
1 files changed, 40 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 63e1d1b9..6d5558d1 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -18,6 +18,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Snowball;
import org.bukkit.entity.Vehicle;
import org.bukkit.util.BlockIterator;
+import org.bukkit.util.Callback;
import java.util.List;
import java.util.HashSet;
@@ -86,6 +87,45 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return getEyeHeight();
}
+ private List<Block> getLineOfSight(Callback<Boolean, Block> callback, int maxDistance, int maxLength) {
+ if (maxDistance > 120) {
+ maxDistance = 120;
+ }
+ ArrayList<Block> blocks = new ArrayList<Block>(maxLength == 0 ? 10 : maxLength);
+ Iterator<Block> itr = new BlockIterator(this, maxDistance);
+ while (itr.hasNext()) {
+ Block block = itr.next();
+ if (maxLength != 0 && blocks.size() + 1 > maxLength) {
+ blocks.remove(0);
+ }
+ blocks.add(block);
+ if (callback == null) {
+ if (block.getTypeId() != 0) {
+ break;
+ }
+ } else {
+ Boolean result = callback.call(block);
+ if (result != null && !result) {
+ break;
+ }
+ }
+ }
+ return blocks;
+ }
+
+ public List<Block> getLineOfSight(Callback<Boolean, Block> callback, int maxDistance) {
+ return getLineOfSight(callback, maxDistance, 0);
+ }
+
+ public Block getTargetBlock(Callback<Boolean, Block> callback, int maxDistance) {
+ List<Block> blocks = getLineOfSight(callback, maxDistance, 1);
+ return blocks.get(0);
+ }
+
+ public List<Block> getLastTwoTargetBlocks(Callback<Boolean, Block> callback, int maxDistance) {
+ return getLineOfSight(callback, maxDistance, 2);
+ }
+
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
if (maxDistance > 120) {
maxDistance = 120;