aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0143-Add-ray-tracing-methods-to-LivingEntity.patch
blob: b2299ab7129e29067d525c5ddd04bbe04d1b1e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Mon, 3 Sep 2018 18:13:53 -0500
Subject: [PATCH] Add ray tracing methods to LivingEntity


diff --git a/src/main/java/com/destroystokyo/paper/block/TargetBlockInfo.java b/src/main/java/com/destroystokyo/paper/block/TargetBlockInfo.java
new file mode 100644
index 0000000000000000000000000000000000000000..c896d172519a8552a132031cb956378db272878f
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/block/TargetBlockInfo.java
@@ -0,0 +1,67 @@
+package com.destroystokyo.paper.block;
+
+import org.bukkit.FluidCollisionMode;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Represents information about a targeted block
+ * @deprecated use {@link org.bukkit.util.RayTraceResult}
+ */
+@Deprecated(forRemoval = true)
+public class TargetBlockInfo {
+    private final Block block;
+    private final BlockFace blockFace;
+
+    public TargetBlockInfo(@NotNull Block block, @NotNull BlockFace blockFace) {
+        this.block = block;
+        this.blockFace = blockFace;
+    }
+
+    /**
+     * Get the block that is targeted
+     *
+     * @return Targeted block
+     */
+    @NotNull
+    public Block getBlock() {
+        return block;
+    }
+
+    /**
+     * Get the targeted BlockFace
+     *
+     * @return Targeted blockface
+     */
+    @NotNull
+    public BlockFace getBlockFace() {
+        return blockFace;
+    }
+
+    /**
+     * Get the relative Block to the targeted block on the side it is targeted at
+     *
+     * @return Block relative to targeted block
+     */
+    @NotNull
+    public Block getRelativeBlock() {
+        return block.getRelative(blockFace);
+    }
+
+    /**
+     * @deprecated use {@link org.bukkit.FluidCollisionMode}
+     */
+    @Deprecated(forRemoval = true)
+    public enum FluidMode {
+        NEVER(FluidCollisionMode.NEVER),
+        SOURCE_ONLY(FluidCollisionMode.SOURCE_ONLY),
+        ALWAYS(FluidCollisionMode.ALWAYS);
+
+        public final FluidCollisionMode bukkit;
+
+        FluidMode(FluidCollisionMode bukkit) {
+            this.bukkit = bukkit;
+        }
+    }
+}
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 17e5d2e2acdae23d8ea3b3b1a89f62e8be7b81a8..8cccec99cdb028e86b71b3984f4f94201fd9a390 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -83,6 +83,98 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
     @NotNull
     public Block getTargetBlock(@Nullable Set<Material> transparent, int maxDistance);
 
+    // Paper start
+    /**
+     * Gets the block that the living entity has targeted, ignoring fluids
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @return block that the living entity has targeted,
+     *     or null if no block is within maxDistance
+     * @deprecated use {@link #getTargetBlockExact(int)}
+     */
+    @Deprecated(forRemoval = true)
+    @Nullable
+    public default Block getTargetBlock(int maxDistance) {
+        return getTargetBlock(maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.NEVER);
+    }
+
+    /**
+     * Gets the block that the living entity has targeted
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @param fluidMode whether to check fluids or not
+     * @return block that the living entity has targeted,
+     *     or null if no block is within maxDistance
+     * @deprecated use {@link #getTargetBlockExact(int, FluidCollisionMode)}
+     */
+    @Deprecated(forRemoval = true)
+    @Nullable
+    public Block getTargetBlock(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
+
+    /**
+     * Gets the blockface of that block that the living entity has targeted, ignoring fluids
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @return blockface of the block that the living entity has targeted,
+     *     or null if no block is targeted
+     */
+    @Nullable
+    public default org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance) {
+        return getTargetBlockFace(maxDistance, org.bukkit.FluidCollisionMode.NEVER);
+    }
+
+    /**
+     * Gets the blockface of that block that the living entity has targeted
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @param fluidMode whether to check fluids or not
+     * @return blockface of the block that the living entity has targeted,
+     *     or null if no block is targeted
+     * @deprecated use {@link #getTargetBlockFace(int, FluidCollisionMode)}
+     */
+    @Deprecated(forRemoval = true)
+    @Nullable
+    public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
+
+    /**
+     * Gets the blockface of that block that the living entity has targeted
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @param fluidMode whether to check fluids or not
+     * @return blockface of the block that the living entity has targeted,
+     *     or null if no block is targeted
+     */
+    @Nullable
+    public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode);
+
+    /**
+     * Gets information about the block the living entity has targeted, ignoring fluids
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @return TargetBlockInfo about the block the living entity has targeted,
+     *     or null if no block is targeted
+     * @deprecated use {@link #rayTraceBlocks(double)}
+     */
+    @Deprecated(forRemoval = true)
+    @Nullable
+    public default com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance) {
+        return getTargetBlockInfo(maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.NEVER);
+    }
+
+    /**
+     * Gets information about the block the living entity has targeted
+     *
+     * @param maxDistance this is the maximum distance to scan
+     * @param fluidMode whether to check fluids or not
+     * @return TargetBlockInfo about the block the living entity has targeted,
+     *     or null if no block is targeted
+     * @deprecated use {@link #rayTraceBlocks(double, FluidCollisionMode)}
+     */
+    @Deprecated(forRemoval = true)
+    @Nullable
+    public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
+    // Paper end
+
     /**
      * Gets the last two blocks along the living entity's line of sight.
      * <p>