2018-12-08 11:09:55 +01:00
|
|
|
From 1d1819863a8c32551ce0cda7eb22264e3581eaab Mon Sep 17 00:00:00 2001
|
2018-09-04 01:59:54 +02: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
|
2018-12-08 11:09:55 +01:00
|
|
|
index 1dcb9a7e9..5ea5d4b78 100644
|
2018-09-04 01:59:54 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
2018-12-08 11:09:55 +01:00
|
|
|
@@ -2816,6 +2816,22 @@ public abstract class EntityLiving extends Entity {
|
2018-09-04 01:59:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paper start
|
|
|
|
+ public MovingObjectPosition getRayTrace(int maxDistance) {
|
|
|
|
+ return getRayTrace(maxDistance, FluidCollisionOption.NEVER);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public MovingObjectPosition getRayTrace(int maxDistance, FluidCollisionOption fluidCollisionOption) {
|
|
|
|
+ if (maxDistance < 1 || maxDistance > 120) {
|
|
|
|
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Vec3D start = new Vec3D(locX, locY + getHeadHeight(), locZ);
|
|
|
|
+ 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());
|
|
|
|
+
|
|
|
|
+ return world.rayTrace(start, end, fluidCollisionOption);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
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
|
2018-10-27 06:02:22 +02:00
|
|
|
index 52834b6da..eeab59379 100644
|
2018-09-04 01:59:54 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2018-10-27 06:02:22 +02:00
|
|
|
@@ -171,6 +171,23 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2018-09-04 01:59:54 +02:00
|
|
|
return blocks.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ 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));
|
|
|
|
+ return rayTrace == null ? null : org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().world, rayTrace.getBlockPosition());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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));
|
|
|
|
+ return rayTrace == null ? null : net.minecraft.server.MCUtil.toBukkitBlockFace(rayTrace.direction);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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));
|
|
|
|
+ return rayTrace == null ? null : new com.destroystokyo.paper.block.TargetBlockInfo(org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().world, rayTrace.getBlockPosition()), net.minecraft.server.MCUtil.toBukkitBlockFace(rayTrace.direction));
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
|
|
|
|
return getLineOfSight(transparent, maxDistance, 2);
|
|
|
|
}
|
|
|
|
--
|
2018-12-08 11:09:55 +01:00
|
|
|
2.19.2
|
2018-09-04 01:59:54 +02:00
|
|
|
|