From b5ab281c2963efb80182df52c912c9f4e86dee09 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Thu, 15 Dec 2022 09:10:03 -0800 Subject: [PATCH] Deprecate TargetBlock/EntityInfo and assocated methods (#7381) --- .../Add-LivingEntity-getTargetEntity.patch | 35 ++++++++++++-- ...-ray-tracing-methods-to-LivingEntity.patch | 44 +++++++++++++++-- .../Add-LivingEntity-getTargetEntity.patch | 12 +++-- ...-ray-tracing-methods-to-LivingEntity.patch | 47 +++++-------------- 4 files changed, 93 insertions(+), 45 deletions(-) diff --git a/patches/api/Add-LivingEntity-getTargetEntity.patch b/patches/api/Add-LivingEntity-getTargetEntity.patch index 77f496ecc9..437892a4a6 100644 --- a/patches/api/Add-LivingEntity-getTargetEntity.patch +++ b/patches/api/Add-LivingEntity-getTargetEntity.patch @@ -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 /** diff --git a/patches/api/Add-ray-tracing-methods-to-LivingEntity.patch b/patches/api/Add-ray-tracing-methods-to-LivingEntity.patch index 75aca09a8d..e468a44fdf 100644 --- a/patches/api/Add-ray-tracing-methods-to-LivingEntity.patch +++ b/patches/api/Add-ray-tracing-methods-to-LivingEntity.patch @@ -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 diff --git a/patches/server/Add-LivingEntity-getTargetEntity.patch b/patches/server/Add-LivingEntity-getTargetEntity.patch index f4f2b86695..f4fc306669 100644 --- a/patches/server/Add-LivingEntity-getTargetEntity.patch +++ b/patches/server/Add-LivingEntity-getTargetEntity.patch @@ -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) { diff --git a/patches/server/Add-ray-tracing-methods-to-LivingEntity.patch b/patches/server/Add-ray-tracing-methods-to-LivingEntity.patch index d6df104431..6334cb29fb 100644 --- a/patches/server/Add-ray-tracing-methods-to-LivingEntity.patch +++ b/patches/server/Add-ray-tracing-methods-to-LivingEntity.patch @@ -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 +