From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Mon, 3 Sep 2018 18:20:03 -0500 Subject: [PATCH] Add ray tracing methods to LivingEntity diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java index 677ba704c32e590f3298575b1cc060bb69414ca4..dc78b04128c5eb2375a049948133aa05fff2c022 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -3772,6 +3772,20 @@ public abstract class LivingEntity extends Entity { } // Paper start + + public HitResult getRayTrace(int maxDistance, ClipContext.Fluid fluidCollisionOption) { + if (maxDistance < 1 || maxDistance > 120) { + throw new IllegalArgumentException("maxDistance must be between 1-120"); + } + + Vec3 start = new Vec3(getX(), getY() + getEyeHeight(), getZ()); + org.bukkit.util.Vector dir = getBukkitEntity().getLocation().getDirection().multiply(maxDistance); + Vec3 end = new Vec3(start.x + dir.getX(), start.y + dir.getY(), start.z + dir.getZ()); + ClipContext raytrace = new ClipContext(start, end, ClipContext.Block.OUTLINE, fluidCollisionOption, this); + + return level.clip(raytrace); + } + public int shieldBlockingDelay = level.paperConfig().misc.shieldBlockingDelay; public int getShieldBlockingDelay() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java index 04829ced2048b07aa4b2dcf98a601d1fdd9431fb..76c66e3533779a966d164637bac0c66415605b2c 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -200,6 +200,33 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return blocks.get(0); } + // Paper start + @Override + public Block getTargetBlock(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) { + return this.getTargetBlockExact(maxDistance, fluidMode.bukkit); + } + + @Override + public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) { + return this.getTargetBlockFace(maxDistance, fluidMode.bukkit); + } + + @Override + public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, org.bukkit.FluidCollisionMode fluidMode) { + RayTraceResult result = this.rayTraceBlocks(maxDistance, fluidMode); + return result != null ? result.getHitBlockFace() : null; + } + + @Override + public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) { + RayTraceResult result = this.rayTraceBlocks(maxDistance, fluidMode.bukkit); + if (result != null && result.getHitBlock() != null && result.getHitBlockFace() != null) { + return new com.destroystokyo.paper.block.TargetBlockInfo(result.getHitBlock(), result.getHitBlockFace()); + } + return null; + } + // Paper end + @Override public List getLastTwoTargetBlocks(Set transparent, int maxDistance) { return this.getLineOfSight(transparent, maxDistance, 2);