2021-06-13 06:03:02 +02:00
|
|
|
From 0000000000000000000000000000000000000000 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/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-08-31 20:29:50 +02:00
|
|
|
index ada79af49d1cafe25ca6c1fb456e1c4c3a42cb73..39dff0a38b53624c935f27cc86ff036c831f407f 100644
|
2021-06-13 06:03:02 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-07-06 21:19:14 +02:00
|
|
|
@@ -3977,6 +3977,19 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2021-06-13 06:03:02 +02:00
|
|
|
}
|
|
|
|
|
2024-01-21 19:37:09 +01:00
|
|
|
// Paper start - Make shield blocking delay configurable
|
2021-06-13 06:03:02 +02:00
|
|
|
+ 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);
|
|
|
|
+
|
2023-06-07 23:35:19 +02:00
|
|
|
+ return this.level().clip(raytrace);
|
2021-06-13 06:03:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
2023-06-07 23:35:19 +02:00
|
|
|
public int shieldBlockingDelay = this.level().paperConfig().misc.shieldBlockingDelay;
|
2021-06-13 06:03:02 +02:00
|
|
|
|
|
|
|
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
|
2024-06-14 14:11:52 +02:00
|
|
|
index e77380686b9f0c5695be36b3e16e11b2646ac00a..f58c9edd68b02bbca10897320fae63cee1562fe3 100644
|
2021-06-13 06:03:02 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
2024-06-13 21:04:27 +02:00
|
|
|
@@ -201,6 +201,33 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2021-06-13 06:03:02 +02:00
|
|
|
return blocks.get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public Block getTargetBlock(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
2022-12-15 18:10:03 +01:00
|
|
|
+ return this.getTargetBlockExact(maxDistance, fluidMode.bukkit);
|
2021-06-13 06:03:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
2022-12-15 18:10:03 +01:00
|
|
|
+ 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;
|
2021-06-13 06:03:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
2022-12-15 18:10:03 +01:00
|
|
|
+ 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;
|
2021-06-13 06:03:02 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
@Override
|
|
|
|
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
|
|
|
|
return this.getLineOfSight(transparent, maxDistance, 2);
|