Paper/Spigot-Server-Patches/0302-Add-ray-tracing-methods-to-LivingEntity.patch

71 lines
4.2 KiB
Diff
Raw Normal View History

From b6105261367e63baf2e1ce70a806a9bde3d2273e Mon Sep 17 00:00:00 2001
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
index 2c29c8943..b9fc57eae 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
2019-05-06 01:24:37 +02:00
@@ -3170,6 +3170,23 @@ public abstract class EntityLiving extends Entity {
2019-05-05 10:33:44 +02:00
this.c(enumhand == EnumHand.MAIN_HAND ? EnumItemSlot.MAINHAND : EnumItemSlot.OFFHAND);
}
// Paper start
+ public MovingObjectPosition getRayTrace(int maxDistance) {
2019-05-06 01:24:37 +02:00
+ return getRayTrace(maxDistance, RayTrace.FluidCollisionOption.NONE);
+ }
+
2019-05-06 01:24:37 +02:00
+ public MovingObjectPosition getRayTrace(int maxDistance, RayTrace.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());
+ RayTrace raytrace = new RayTrace(start, end, RayTrace.BlockCollisionOption.OUTLINE, fluidCollisionOption, this);
+
2019-05-06 01:24:37 +02:00
+ return world.rayTrace(raytrace);
+ }
+
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
index 8dea7d36b..d5c4115a8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
2019-05-22 06:14:56 +02:00
@@ -182,6 +182,28 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return blocks.get(0);
}
+ // Paper start
2019-05-06 04:58:04 +02:00
+ @Override
+ 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 02:57:14 +02:00
+ return !(rayTrace instanceof net.minecraft.server.MovingObjectPositionBlock) ? null : org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().world, ((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getBlockPosition());
+ }
+
2019-05-06 04:58:04 +02:00
+ @Override
+ 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 02:57:14 +02:00
+ return !(rayTrace instanceof net.minecraft.server.MovingObjectPositionBlock) ? null : net.minecraft.server.MCUtil.toBukkitBlockFace(((net.minecraft.server.MovingObjectPositionBlock)rayTrace).getDirection());
+ }
+
2019-05-06 04:58:04 +02:00
+ @Override
+ 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 02:57:14 +02: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()));
+ }
+ // Paper end
+
2019-05-06 04:58:04 +02:00
@Override
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
return getLineOfSight(transparent, maxDistance, 2);
--
2019-05-05 13:32:20 +02:00
2.21.0