2019-03-20 02:46:00 +01:00
|
|
|
From 7f59337d09a8d3aa24f52603aa0b5d05cfb4dd6a 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: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
|
2019-03-20 01:28:15 +01:00
|
|
|
index 000000000..18a96dbb0
|
2018-09-04 01:59:54 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/block/TargetBlockInfo.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -0,0 +1,54 @@
|
2018-09-04 01:59:54 +02:00
|
|
|
+package com.destroystokyo.paper.block;
|
|
|
|
+
|
|
|
|
+import org.bukkit.block.Block;
|
|
|
|
+import org.bukkit.block.BlockFace;
|
2019-03-20 01:28:15 +01:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
2018-09-04 01:59:54 +02:00
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Represents information about a targeted block
|
|
|
|
+ */
|
|
|
|
+public class TargetBlockInfo {
|
|
|
|
+ private final Block block;
|
|
|
|
+ private final BlockFace blockFace;
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public TargetBlockInfo(@NotNull Block block, @NotNull BlockFace blockFace) {
|
2018-09-04 01:59:54 +02:00
|
|
|
+ this.block = block;
|
|
|
|
+ this.blockFace = blockFace;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get the block that is targeted
|
|
|
|
+ *
|
|
|
|
+ * @return Targeted block
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-09-04 01:59:54 +02:00
|
|
|
+ public Block getBlock() {
|
|
|
|
+ return block;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Get the targeted BlockFace
|
|
|
|
+ *
|
|
|
|
+ * @return Targeted blockface
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-09-04 01:59:54 +02:00
|
|
|
+ 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
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-09-04 01:59:54 +02:00
|
|
|
+ public Block getRelativeBlock() {
|
|
|
|
+ return block.getRelative(blockFace);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public enum FluidMode {
|
|
|
|
+ NEVER,
|
|
|
|
+ SOURCE_ONLY,
|
|
|
|
+ ALWAYS
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
|
2019-03-20 01:28:15 +01:00
|
|
|
index 863d727d0..4dec50caf 100644
|
2018-09-04 01:59:54 +02:00
|
|
|
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -81,6 +81,77 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
|
|
|
|
@NotNull
|
|
|
|
public Block getTargetBlock(@Nullable Set<Material> transparent, int maxDistance);
|
2018-09-04 01:59:54 +02:00
|
|
|
|
|
|
|
+ // 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
|
|
|
|
+ */
|
|
|
|
+ @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
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public Block getTargetBlock(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
|
2018-09-04 01:59:54 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.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
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
|
2018-09-04 01:59:54 +02:00
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 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
|
|
|
|
+ */
|
|
|
|
+ @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
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
|
2018-09-04 01:59:54 +02:00
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Gets the last two blocks along the living entity's line of sight.
|
|
|
|
* <p>
|
|
|
|
--
|
2019-03-20 01:28:15 +01:00
|
|
|
2.21.0
|
2018-09-04 01:59:54 +02:00
|
|
|
|