2021-06-13 08:48:25 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
|
|
|
Date: Sat, 22 Sep 2018 00:33:08 -0500
|
|
|
|
Subject: [PATCH] Add LivingEntity#getTargetEntity
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
index 39ff6dd7ee8e821f5693f6a6e01b713b25d30393..5a1dc8f196b274a822db4aa1fa48cd066f12da94 100644
|
2021-06-13 08:48:25 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -115,6 +115,7 @@ import net.minecraft.world.level.storage.loot.LootTable;
|
2021-06-13 08:48:25 +02:00
|
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
|
|
|
|
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
|
|
|
import net.minecraft.world.phys.AABB;
|
|
|
|
+import net.minecraft.world.phys.EntityHitResult;
|
|
|
|
import net.minecraft.world.phys.HitResult;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
|
|
|
import net.minecraft.world.scores.PlayerTeam;
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
@@ -3911,6 +3912,38 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
2023-06-07 23:35:19 +02:00
|
|
|
return this.level().clip(raytrace);
|
2021-06-13 08:48:25 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 18:10:03 +01:00
|
|
|
+ public @Nullable EntityHitResult getTargetEntity(int maxDistance) {
|
2021-06-13 08:48:25 +02:00
|
|
|
+ if (maxDistance < 1 || maxDistance > 120) {
|
|
|
|
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Vec3 start = this.getEyePosition(1.0F);
|
|
|
|
+ Vec3 direction = this.getLookAngle();
|
|
|
|
+ Vec3 end = start.add(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance);
|
|
|
|
+
|
2023-06-07 23:35:19 +02:00
|
|
|
+ List<Entity> entityList = this.level().getEntities(this, getBoundingBox().expandTowards(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance).inflate(1.0D, 1.0D, 1.0D), EntitySelector.NO_SPECTATORS.and(Entity::isPickable));
|
2021-06-13 08:48:25 +02:00
|
|
|
+
|
|
|
|
+ double distance = 0.0D;
|
|
|
|
+ EntityHitResult result = null;
|
|
|
|
+
|
|
|
|
+ for (Entity entity : entityList) {
|
2021-06-17 23:39:36 +02:00
|
|
|
+ final double inflationAmount = (double) entity.getPickRadius();
|
2021-06-13 08:48:25 +02:00
|
|
|
+ AABB aabb = entity.getBoundingBox().inflate(inflationAmount, inflationAmount, inflationAmount);
|
|
|
|
+ Optional<Vec3> rayTraceResult = aabb.clip(start, end);
|
|
|
|
+
|
|
|
|
+ if (rayTraceResult.isPresent()) {
|
|
|
|
+ Vec3 rayTrace = rayTraceResult.get();
|
|
|
|
+ double distanceTo = start.distanceToSqr(rayTrace);
|
|
|
|
+ if (distanceTo < distance || distance == 0.0D) {
|
|
|
|
+ result = new EntityHitResult(entity, rayTrace);
|
|
|
|
+ distance = distanceTo;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
2023-06-07 23:35:19 +02:00
|
|
|
public int shieldBlockingDelay = this.level().paperConfig().misc.shieldBlockingDelay;
|
2021-06-13 08:48:25 +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
|
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#10277)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent
258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor
ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD
CraftBukkit Changes:
98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire
a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent
5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class
76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor
Spigot Changes:
e9ec5485 Rebuild patches
f1b62e0c Rebuild patches
2024-02-23 14:37:33 +01:00
|
|
|
index eb74778c0bb6fe6b7c09209eb58195e7fedc54ac..c9a487c1b85d46c1ce25147bd8a610a5631cdb5d 100644
|
2021-06-13 08:48:25 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
|
|
|
|
@@ -1,5 +1,6 @@
|
|
|
|
package org.bukkit.craftbukkit.entity;
|
|
|
|
|
|
|
|
+import com.destroystokyo.paper.entity.TargetEntityInfo;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import java.util.ArrayList;
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
@@ -226,6 +227,39 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
2022-12-15 18:10:03 +01:00
|
|
|
}
|
|
|
|
return null;
|
2021-06-13 08:48:25 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks) {
|
|
|
|
+ net.minecraft.world.phys.EntityHitResult rayTrace = rayTraceEntity(maxDistance, ignoreBlocks);
|
|
|
|
+ return rayTrace == null ? null : rayTrace.getEntity().getBukkitEntity();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public TargetEntityInfo getTargetEntityInfo(int maxDistance, boolean ignoreBlocks) {
|
|
|
|
+ net.minecraft.world.phys.EntityHitResult rayTrace = rayTraceEntity(maxDistance, ignoreBlocks);
|
|
|
|
+ return rayTrace == null ? null : new TargetEntityInfo(rayTrace.getEntity().getBukkitEntity(), new org.bukkit.util.Vector(rayTrace.getLocation().x, rayTrace.getLocation().y, rayTrace.getLocation().z));
|
|
|
|
+ }
|
|
|
|
+
|
2022-12-15 18:10:03 +01:00
|
|
|
+ @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());
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-13 08:48:25 +02:00
|
|
|
+ public net.minecraft.world.phys.EntityHitResult rayTraceEntity(int maxDistance, boolean ignoreBlocks) {
|
|
|
|
+ net.minecraft.world.phys.EntityHitResult rayTrace = getHandle().getTargetEntity(maxDistance);
|
|
|
|
+ if (rayTrace == null) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ if (!ignoreBlocks) {
|
|
|
|
+ net.minecraft.world.phys.HitResult rayTraceBlocks = getHandle().getRayTrace(maxDistance, net.minecraft.world.level.ClipContext.Fluid.NONE);
|
|
|
|
+ if (rayTraceBlocks != null) {
|
|
|
|
+ net.minecraft.world.phys.Vec3 eye = getHandle().getEyePosition(1.0F);
|
|
|
|
+ if (eye.distanceToSqr(rayTraceBlocks.getLocation()) <= eye.distanceToSqr(rayTrace.getLocation())) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return rayTrace;
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
@Override
|