mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
3e90a19183
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: 304e83eb PR-1002: Improve documentation and implementation of getMaxStackSize e8215ea2 SPIGOT-7638: Library loader does not seem to resolve every dependency 79c595c0 SPIGOT-7637: Bad logic in checking nullability of AttributeModifier slots CraftBukkit Changes: 91b1fc3f1 SPIGOT-7644: Fix ItemMeta#getAsString 4e77a81e1 SPIGOT-7615: PlayerLeashEntityEvent cancelled eats lead 996f660f3 Do not remove leash knot if leasing to an existing leash knot gets cancelled f70367d42 SPIGOT-7643: Fix inverted leash event cancelled usage and remove leash knot if no entity gets leashed 7ddb48294 SPIGOT-7640: Abnormal jumping height of wind charge 080c8711e SPIGOT-7639: Incoming plugin channels not working ad549847e Open a direct connection instead of pinging mojang server to check if it is reachable 38e2926c5 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime
109 lines
5.4 KiB
Diff
109 lines
5.4 KiB
Diff
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
|
|
index 21d2c43a97122025edd91662e39d44cc867593a3..bac78415e34d41e3a5de482b86185f2202ecf068 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -121,6 +121,7 @@ import net.minecraft.world.level.storage.loot.LootTable;
|
|
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;
|
|
@@ -4002,6 +4003,38 @@ public abstract class LivingEntity extends Entity implements Attackable {
|
|
return this.level().clip(raytrace);
|
|
}
|
|
|
|
+ public @Nullable EntityHitResult getTargetEntity(int maxDistance) {
|
|
+ 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);
|
|
+
|
|
+ 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));
|
|
+
|
|
+ double distance = 0.0D;
|
|
+ EntityHitResult result = null;
|
|
+
|
|
+ for (Entity entity : entityList) {
|
|
+ final double inflationAmount = (double) entity.getPickRadius();
|
|
+ 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;
|
|
+ }
|
|
+
|
|
public int shieldBlockingDelay = this.level().paperConfig().misc.shieldBlockingDelay;
|
|
|
|
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
|
|
index fa2cb4820698d4f0f317d7abd14216bdd54143a7..b2172a8c70ab77ba7c98b6b2b27595765d7eba11 100644
|
|
--- 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;
|
|
@@ -225,6 +226,39 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
|
|
}
|
|
return null;
|
|
}
|
|
+
|
|
+ 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));
|
|
+ }
|
|
+
|
|
+ @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) {
|
|
+ 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
|