Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
d1a72eac31
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: 1fc1020a PR-1049: Add MenuType API 8ae2e3be PR-1055: Expand riptiding API cac68bfb SPIGOT-7890: AttributeModifier#getUniqueId() doesn't match the UUID passed to its constructor 7004fcf2 SPIGOT-7886: Fix mistake in AttributeModifier UUID shim 1ac7f950 PR-1054: Add FireworkMeta#hasPower 4cfb565f SPIGOT-7873: Add powered state for skulls CraftBukkit Changes: bbb30e7a8 SPIGOT-7894: NPE when sending tile entity update ba21e9472 SPIGOT-7895: PlayerItemBreakEvent not firing 0fb24bbe0 SPIGOT-7875: Fix PlayerItemConsumeEvent cancellation causing client-side desync 815066449 SPIGOT-7891: Can't remove second ingredient of MerchantRecipe 45c206f2c PR-1458: Add MenuType API 19c8ef9ae SPIGOT-7867: Merchant instanceof AbstractVillager always returns false 4e006d28f PR-1468: Expand riptiding API bd8aded7d Ignore checks in CraftPlayerProfile for ResolvableProfile used in profile components 8679620b5 SPIGOT-7889: Fix tool component deserialisation without speed and/or correct-for-drops 8d5222691 SPIGOT-7882, PR-1467: Fix conversion of name in Profile Component to empty if it is missing 63f91669a SPIGOT-7887: Remove duplicate ProjectileHitEvent for fireballs 7070de8c8 SPIGOT-7878: Server#getLootTable does not return null on invalid loot table 060ee6cae SPIGOT-7876: Can't kick player or disconnect player in PlayerLoginEvent when checking for cookies 7ccb86cc0 PR-1465: Add FireworkMeta#hasPower 804ad6491 SPIGOT-7873: Add powered state for skulls f9610cdcb Improve minecart movement Spigot Changes: a759b629 Rebuild patches Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
109 Zeilen
5.4 KiB
Diff
109 Zeilen
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 64aa52c2d1fe50d304d75ebb197e8a834016c3cf..7bc0a66602d77902d83d6ca515da48e3453de900 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
|
|
@@ -127,6 +127,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;
|
|
@@ -4044,6 +4045,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 aa5b67c704a1ae95f4b6e01696c1489c07625d16..97e76c3701c5e58ff5c8cd0f243efd7998f1c93d 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;
|
|
@@ -226,6 +227,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
|