mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Deprecate TargetBlock/EntityInfo and assocated methods (#7381)
This commit is contained in:
parent
9eb6b1db93
commit
b5ab281c29
@ -18,7 +18,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+/**
|
||||
+ * Represents information about a targeted entity
|
||||
+ * @deprecated use {@link org.bukkit.util.RayTraceResult}
|
||||
+ */
|
||||
+@Deprecated(forRemoval = true)
|
||||
+public class TargetEntityInfo {
|
||||
+ private final Entity entity;
|
||||
+ private final Vector hitVec;
|
||||
@ -53,7 +55,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
|
||||
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
|
||||
@@ -0,0 +0,0 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
@Nullable
|
||||
public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
|
||||
+
|
||||
@ -84,7 +86,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @param maxDistance this is the maximum distance to scan
|
||||
+ * @return TargetEntityInfo about the entity being targeted,
|
||||
+ * or null if no entity is targeted
|
||||
+ * @deprecated use {@link #rayTraceEntities(int)}
|
||||
+ */
|
||||
+ @Deprecated(forRemoval = true)
|
||||
+ @Nullable
|
||||
+ public default com.destroystokyo.paper.entity.TargetEntityInfo getTargetEntityInfo(int maxDistance) {
|
||||
+ return getTargetEntityInfo(maxDistance, false);
|
||||
@ -94,12 +98,37 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * Gets information about the entity being targeted
|
||||
+ *
|
||||
+ * @param maxDistance this is the maximum distance to scan
|
||||
+ * @param ignoreBlocks true to scan through blocks
|
||||
+ * @return TargetEntityInfo about the entity being targeted,
|
||||
+ * @return RayTraceResult about the entity being targeted,
|
||||
+ * or null if no entity is targeted
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ default RayTraceResult rayTraceEntities(int maxDistance) {
|
||||
+ return this.rayTraceEntities(maxDistance, false);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets information about the entity being targeted
|
||||
+ *
|
||||
+ * @param maxDistance this is the maximum distance to scan
|
||||
+ * @param ignoreBlocks true to scan through blocks
|
||||
+ * @return TargetEntityInfo about the entity being targeted,
|
||||
+ * or null if no entity is targeted
|
||||
+ * @deprecated use {@link #rayTraceEntities(int, boolean)}
|
||||
+ */
|
||||
+ @Deprecated(forRemoval = true)
|
||||
+ @Nullable
|
||||
+ public com.destroystokyo.paper.entity.TargetEntityInfo getTargetEntityInfo(int maxDistance, boolean ignoreBlocks);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets information about the entity being targeted
|
||||
+ *
|
||||
+ * @param maxDistance this is the maximum distance to scan
|
||||
+ * @param ignoreBlocks true to scan through blocks
|
||||
+ * @return RayTraceResult about the entity being targeted,
|
||||
+ * or null if no entity is targeted
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks);
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
|
@ -12,13 +12,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+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;
|
||||
@ -58,10 +61,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ return block.getRelative(blockFace);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated use {@link org.bukkit.FluidCollisionMode}
|
||||
+ */
|
||||
+ @Deprecated(forRemoval = true)
|
||||
+ public enum FluidMode {
|
||||
+ NEVER,
|
||||
+ SOURCE_ONLY,
|
||||
+ ALWAYS
|
||||
+ 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
|
||||
@ -79,7 +92,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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);
|
||||
@ -92,7 +107,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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);
|
||||
+
|
||||
@ -105,7 +122,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public default org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance) {
|
||||
+ return getTargetBlockFace(maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode.NEVER);
|
||||
+ return getTargetBlockFace(maxDistance, org.bukkit.FluidCollisionMode.NEVER);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
@ -115,9 +132,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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 com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
|
||||
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, @NotNull FluidCollisionMode fluidMode);
|
||||
+
|
||||
+ /**
|
||||
+ * Gets information about the block the living entity has targeted, ignoring fluids
|
||||
@ -125,7 +155,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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);
|
||||
@ -138,7 +170,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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
|
||||
|
@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
return level.clip(raytrace);
|
||||
}
|
||||
|
||||
+ public EntityHitResult getTargetEntity(int maxDistance) {
|
||||
+ public @Nullable EntityHitResult getTargetEntity(int maxDistance) {
|
||||
+ if (maxDistance < 1 || maxDistance > 120) {
|
||||
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
|
||||
+ }
|
||||
@ -67,8 +67,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.ArrayList;
|
||||
@@ -0,0 +0,0 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
||||
new com.destroystokyo.paper.block.TargetBlockInfo(org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().level, ((net.minecraft.world.phys.BlockHitResult)rayTrace).getBlockPos()),
|
||||
io.papermc.paper.util.MCUtil.toBukkitBlockFace(((net.minecraft.world.phys.BlockHitResult)rayTrace).getDirection()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+
|
||||
+ public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks) {
|
||||
@ -81,6 +81,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ return rayTrace == null ? null : new TargetEntityInfo(rayTrace.getEntity().getBukkitEntity(), new org.bukkit.util.Vector(rayTrace.getLocation().x, rayTrace.getLocation().y, rayTrace.getLocation().z));
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public RayTraceResult rayTraceEntities(int maxDistance, boolean ignoreBlocks) {
|
||||
+ net.minecraft.world.phys.EntityHitResult rayTrace = this.rayTraceEntity(maxDistance, ignoreBlocks);
|
||||
+ return rayTrace == null ? null : new org.bukkit.util.RayTraceResult(org.bukkit.craftbukkit.util.CraftVector.toBukkit(rayTrace.getLocation()), rayTrace.getEntity().getBukkitEntity());
|
||||
+ }
|
||||
+
|
||||
+ public net.minecraft.world.phys.EntityHitResult rayTraceEntity(int maxDistance, boolean ignoreBlocks) {
|
||||
+ net.minecraft.world.phys.EntityHitResult rayTrace = getHandle().getTargetEntity(maxDistance);
|
||||
+ if (rayTrace == null) {
|
||||
|
@ -4,29 +4,6 @@ Date: Mon, 3 Sep 2018 18:20:03 -0500
|
||||
Subject: [PATCH] Add ray tracing methods to LivingEntity
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/util/MCUtil.java b/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
+++ b/src/main/java/io/papermc/paper/util/MCUtil.java
|
||||
@@ -0,0 +0,0 @@ public final class MCUtil {
|
||||
return getNMSWorld(entity.getWorld());
|
||||
}
|
||||
|
||||
+ public static ClipContext.Fluid getNMSFluidCollisionOption(com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
||||
+ switch (fluidMode) {
|
||||
+ case NEVER:
|
||||
+ return ClipContext.Fluid.NONE;
|
||||
+ case SOURCE_ONLY:
|
||||
+ return ClipContext.Fluid.SOURCE_ONLY;
|
||||
+ case ALWAYS:
|
||||
+ return ClipContext.Fluid.ANY;
|
||||
+ }
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
public static BlockFace toBukkitBlockFace(Direction enumDirection) {
|
||||
switch (enumDirection) {
|
||||
case DOWN:
|
||||
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
||||
@ -35,9 +12,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
}
|
||||
|
||||
// Paper start
|
||||
+ public HitResult getRayTrace(int maxDistance) {
|
||||
+ return getRayTrace(maxDistance, ClipContext.Fluid.NONE);
|
||||
+ }
|
||||
+
|
||||
+ public HitResult getRayTrace(int maxDistance, ClipContext.Fluid fluidCollisionOption) {
|
||||
+ if (maxDistance < 1 || maxDistance > 120) {
|
||||
@ -66,22 +40,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public Block getTargetBlock(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
||||
+ net.minecraft.world.phys.HitResult rayTrace = getHandle().getRayTrace(maxDistance, io.papermc.paper.util.MCUtil.getNMSFluidCollisionOption(fluidMode));
|
||||
+ return !(rayTrace instanceof net.minecraft.world.phys.BlockHitResult) ? null : org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().level, ((net.minecraft.world.phys.BlockHitResult)rayTrace).getBlockPos());
|
||||
+ return this.getTargetBlockExact(maxDistance, fluidMode.bukkit);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public org.bukkit.block.BlockFace getTargetBlockFace(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
||||
+ net.minecraft.world.phys.HitResult rayTrace = getHandle().getRayTrace(maxDistance, io.papermc.paper.util.MCUtil.getNMSFluidCollisionOption(fluidMode));
|
||||
+ return !(rayTrace instanceof net.minecraft.world.phys.BlockHitResult) ? null : io.papermc.paper.util.MCUtil.toBukkitBlockFace(((net.minecraft.world.phys.BlockHitResult)rayTrace).getDirection());
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode) {
|
||||
+ net.minecraft.world.phys.HitResult rayTrace = getHandle().getRayTrace(maxDistance, io.papermc.paper.util.MCUtil.getNMSFluidCollisionOption(fluidMode));
|
||||
+ return !(rayTrace instanceof net.minecraft.world.phys.BlockHitResult) ? null :
|
||||
+ new com.destroystokyo.paper.block.TargetBlockInfo(org.bukkit.craftbukkit.block.CraftBlock.at(getHandle().level, ((net.minecraft.world.phys.BlockHitResult)rayTrace).getBlockPos()),
|
||||
+ io.papermc.paper.util.MCUtil.toBukkitBlockFace(((net.minecraft.world.phys.BlockHitResult)rayTrace).getDirection()));
|
||||
+ 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;
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
|
Loading…
Reference in New Issue
Block a user