2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-09-03 23:59:54 +00:00
From: BillyGalbreath <Blake.Galbreath@GMail.com>
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/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
2020-08-25 02:22:08 +00:00
index adc2ba97b0f258ae9fdbde0bcee02f63fc9fbac7..5ebd2d25cc52de3f1a091f0620d6b46be4fca784 100644
2018-09-03 23:59:54 +00:00
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2020-08-25 02:22:08 +00:00
@@ -3462,6 +3462,23 @@ public abstract class EntityLiving extends Entity {
2020-01-22 02:02:07 +00:00
this.broadcastItemBreak(enumhand == EnumHand.MAIN_HAND ? EnumItemSlot.MAINHAND : EnumItemSlot.OFFHAND);
2018-09-03 23:59:54 +00:00
}
// Paper start
+ public MovingObjectPosition getRayTrace(int maxDistance) {
2019-05-05 23:24:37 +00:00
+ return getRayTrace(maxDistance, RayTrace.FluidCollisionOption.NONE);
2018-09-03 23:59:54 +00:00
+ }
+
2019-05-05 23:24:37 +00:00
+ public MovingObjectPosition getRayTrace(int maxDistance, RayTrace.FluidCollisionOption fluidCollisionOption) {
2018-09-03 23:59:54 +00:00
+ if (maxDistance < 1 || maxDistance > 120) {
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
+ }
+
2019-12-12 18:45:00 +00:00
+ Vec3D start = new Vec3D(locX(), locY() + getHeadHeight(), locZ());
2018-09-03 23:59:54 +00:00
+ org.bukkit.util.Vector dir = getBukkitEntity().getLocation().getDirection().multiply(maxDistance);
+ Vec3D end = new Vec3D(start.x + dir.getX(), start.y + dir.getY(), start.z + dir.getZ());
2019-05-13 00:23:21 +00:00
+ RayTrace raytrace = new RayTrace(start, end, RayTrace.BlockCollisionOption.OUTLINE, fluidCollisionOption, this);
2018-09-03 23:59:54 +00:00
+
2019-05-05 23:24:37 +00:00
+ return world.rayTrace(raytrace);
2018-09-03 23:59:54 +00:00
+ }
+
public int shieldBlockingDelay = world.paperConfig.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
2020-06-25 14:09:55 +00:00
index bbe6188f50dd3c456dec5c3239bdcffbfceb3589..2e7bacff55f57fda8b5644fb9d7934a615e5f550 100644
2018-09-03 23:59:54 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2020-06-25 14:09:55 +00:00
@@ -199,6 +199,28 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
2018-09-03 23:59:54 +00:00
return blocks.get(0);
}
+ // Paper start
2019-05-06 02:58:04 +00:00
+ @Override
2018-09-03 23:59:54 +00:00
+ public Block getTargetBlock(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
+ net.minecraft.server.MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, net.minecraft.server.MCUtil.getNMSFluidCollisionOption(fluidMode));
2019-05-06 00:57:14 +00:00
+ return !(rayTrace instanceof net.minecraft.server.MovingObjectPositionBlock) ? null : org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().world, ((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getBlockPosition());
2018-09-03 23:59:54 +00:00
+ }
+
2019-05-06 02:58:04 +00:00
+ @Override
2018-09-03 23:59:54 +00:00
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
+ net.minecraft.server.MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, net.minecraft.server.MCUtil.getNMSFluidCollisionOption(fluidMode));
2019-05-06 00:57:14 +00:00
+ return !(rayTrace instanceof net.minecraft.server.MovingObjectPositionBlock) ? null : net.minecraft.server.MCUtil.toBukkitBlockFace(((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getDirection());
2018-09-03 23:59:54 +00:00
+ }
+
2019-05-06 02:58:04 +00:00
+ @Override
2018-09-03 23:59:54 +00:00
+ public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
+ net.minecraft.server.MovingObjectPosition rayTrace = getHandle().getRayTrace(maxDistance, net.minecraft.server.MCUtil.getNMSFluidCollisionOption(fluidMode));
2019-05-06 00:57:14 +00:00
+ return !(rayTrace instanceof net.minecraft.server.MovingObjectPositionBlock) ? null :
+ new com.destroystokyo.paper.block.TargetBlockInfo(org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().world, ((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getBlockPosition()),
+ net.minecraft.server.MCUtil.toBukkitBlockFace(((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getDirection()));
2018-09-03 23:59:54 +00:00
+ }
+ // Paper end
+
2019-05-06 02:58:04 +00:00
@Override
2018-09-03 23:59:54 +00:00
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
return getLineOfSight(transparent, maxDistance, 2);