Compare commits

...

1 commit

Author SHA1 Message Date
Shane Freeder
fbe33f4f2c
Add getTargetEntity predicate 2022-03-13 21:38:09 +00:00
15 changed files with 63 additions and 34 deletions

View file

@ -49,10 +49,10 @@ index 0000000000000000000000000000000000000000..f52644fab1522bdf83ff4f489e9805b2
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index ad885a0775b387e3e8ca6bfae80c18465038056c..93d20f67bf856d80226470ae2442d199d3e2f45b 100644
index ad885a0775b387e3e8ca6bfae80c18465038056c..454533528fc05f632b22ca81909b6eac3841e26e 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -151,6 +151,50 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -151,6 +151,61 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
*/
@Nullable
public com.destroystokyo.paper.block.TargetBlockInfo getTargetBlockInfo(int maxDistance, @NotNull com.destroystokyo.paper.block.TargetBlockInfo.FluidMode fluidMode);
@ -82,6 +82,17 @@ index ad885a0775b387e3e8ca6bfae80c18465038056c..93d20f67bf856d80226470ae2442d199
+ * Gets information about the entity being targeted
+ *
+ * @param maxDistance this is the maximum distance to scan
+ * @param ignoreBlocks true to scan through blocks
+ * @param entityPredicate predicate to determine if an entity can be targeted
+ * @return entity being targeted, or null if no entity is targeted
+ */
+ @Nullable
+ public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks, @Nullable java.util.function.Predicate<Entity> entityPredicate);
+
+ /**
+ * Gets information about the entity being targeted
+ *
+ * @param maxDistance this is the maximum distance to scan
+ * @return TargetEntityInfo about the entity being targeted,
+ * or null if no entity is targeted
+ */

View file

@ -57,10 +57,10 @@ index 0000000000000000000000000000000000000000..f0067c2e953d18e1a33536980071ba3f
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 93d20f67bf856d80226470ae2442d199d3e2f45b..5ab8db52160049e36464df4e20e374b8849ef29c 100644
index 454533528fc05f632b22ca81909b6eac3841e26e..19806ef742f08aa1561fc4081724177c6d9e6a90 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -802,5 +802,25 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -813,5 +813,25 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
*/
@NotNull
org.bukkit.inventory.EquipmentSlot getHandRaised();

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add playPickupItemAnimation to LivingEntity
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 5ab8db52160049e36464df4e20e374b8849ef29c..1b6c2b2cfb910e7651e7f18ea407e31db685af8a 100644
index 19806ef742f08aa1561fc4081724177c6d9e6a90..83303ef5376a59cff39f73142e35f816cf08e1c3 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -822,5 +822,28 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -833,5 +833,28 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* @param jumping entity jump state
*/
void setJumping(boolean jumping);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add LivingEntity#clearActiveItem
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 1b6c2b2cfb910e7651e7f18ea407e31db685af8a..751a7345b650e96bbfd3ca9d22c9623bd5444f67 100644
index 83303ef5376a59cff39f73142e35f816cf08e1c3..767c47ad1fdaa1c61b9dfc0d6d181ab8dd53bb46 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -773,6 +773,13 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -784,6 +784,13 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@Nullable
ItemStack getActiveItem();

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Expose LivingEntity hurt direction
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 751a7345b650e96bbfd3ca9d22c9623bd5444f67..330eab77547ae059f716418f71ad1d3391a57a9b 100644
index 767c47ad1fdaa1c61b9dfc0d6d181ab8dd53bb46..4f6f363385893f07959d85d7a5af05a195ad1db0 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -852,5 +852,19 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -863,5 +863,19 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
* @param quantity quantity of item
*/
void playPickupItemAnimation(@NotNull Item item, int quantity);

View file

@ -24,10 +24,10 @@ index def9f0f9803e71cbe57abcffeb9114a5ab462e54..d149dd1d3d2703a428006e0c3ab5f925
/**
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 330eab77547ae059f716418f71ad1d3391a57a9b..cda05df6784dd4d6a09710a416dcb71c016dabfc 100644
index 4f6f363385893f07959d85d7a5af05a195ad1db0..23d167fcac15f2169c19640fd7c01b198b6d4003 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -483,6 +483,19 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -494,6 +494,19 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
*/
public boolean hasLineOfSight(@NotNull Entity other);

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Stinger API
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index cda05df6784dd4d6a09710a416dcb71c016dabfc..31353bd20404a8c2acf6bf0df524dc3cae324272 100644
index 23d167fcac15f2169c19640fd7c01b198b6d4003..e98603eeebfeb4ca5071482db857ef08f1a9183f 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -336,6 +336,36 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
@@ -347,6 +347,36 @@ public interface LivingEntity extends Attributable, Damageable, ProjectileSource
*/
public void setArrowsInBody(int count);

View file

@ -16,11 +16,15 @@ index bd4230a4e5fc9c1264b390b59ddefbd0aa8e73c8..e5c5bdc83804f335d7163cfefba79b57
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.PlayerTeam;
@@ -3743,6 +3744,38 @@ public abstract class LivingEntity extends Entity {
@@ -3745,6 +3746,42 @@ public abstract class LivingEntity extends Entity {
return level.clip(raytrace);
}
+ public EntityHitResult getTargetEntity(int maxDistance) {
+ return this.getTargetEntity(maxDistance, EntitySelector.NO_CREATIVE_OR_SPECTATOR.and(Entity::isPickable));
+ }
+
+ public EntityHitResult getTargetEntity(int maxDistance, @Nullable Predicate<Entity> entityPredicate) {
+ if (maxDistance < 1 || maxDistance > 120) {
+ throw new IllegalArgumentException("maxDistance must be between 1-120");
+ }
@ -29,7 +33,7 @@ index bd4230a4e5fc9c1264b390b59ddefbd0aa8e73c8..e5c5bdc83804f335d7163cfefba79b57
+ Vec3 direction = this.getLookAngle();
+ Vec3 end = start.add(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance);
+
+ List<Entity> entityList = level.getEntities(this, getBoundingBox().expandTowards(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance).inflate(1.0D, 1.0D, 1.0D), EntitySelector.NO_CREATIVE_OR_SPECTATOR.and(Entity::isPickable));
+ List<Entity> entityList = level.getEntities(this, getBoundingBox().expandTowards(direction.x * maxDistance, direction.y * maxDistance, direction.z * maxDistance).inflate(1.0D, 1.0D, 1.0D), entityPredicate);
+
+ double distance = 0.0D;
+ EntityHitResult result = null;
@ -56,7 +60,7 @@ index bd4230a4e5fc9c1264b390b59ddefbd0aa8e73c8..e5c5bdc83804f335d7163cfefba79b57
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 9c024b46522e2984ed662538302fbac68a77fd86..fb0e0c629d16bc97efc3e91f7ba6fe9e87fc950b 100644
index 9c024b46522e2984ed662538302fbac68a77fd86..d55652c94a43464575f64c9f033bde62587b13a7 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 @@
@ -66,13 +70,17 @@ index 9c024b46522e2984ed662538302fbac68a77fd86..fb0e0c629d16bc97efc3e91f7ba6fe9e
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import java.util.ArrayList;
@@ -218,6 +219,33 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -218,6 +219,43 @@ 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()),
net.minecraft.server.MCUtil.toBukkitBlockFace(((net.minecraft.world.phys.BlockHitResult)rayTrace).getDirection()));
}
+
+ public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks) {
+ net.minecraft.world.phys.EntityHitResult rayTrace = rayTraceEntity(maxDistance, ignoreBlocks);
+ return this.getTargetEntity(maxDistance, ignoreBlocks, null);
+ }
+
+ public Entity getTargetEntity(int maxDistance, boolean ignoreBlocks, java.util.function.Predicate<Entity> entityPredicate) {
+ net.minecraft.world.phys.EntityHitResult rayTrace = rayTraceEntity(maxDistance, ignoreBlocks, entityPredicate);
+ return rayTrace == null ? null : rayTrace.getEntity().getBukkitEntity();
+ }
+
@ -82,7 +90,13 @@ index 9c024b46522e2984ed662538302fbac68a77fd86..fb0e0c629d16bc97efc3e91f7ba6fe9e
+ }
+
+ public net.minecraft.world.phys.EntityHitResult rayTraceEntity(int maxDistance, boolean ignoreBlocks) {
+ net.minecraft.world.phys.EntityHitResult rayTrace = getHandle().getTargetEntity(maxDistance);
+ return this.rayTraceEntity(maxDistance, ignoreBlocks, null);
+ }
+
+ public net.minecraft.world.phys.EntityHitResult rayTraceEntity(int maxDistance, boolean ignoreBlocks, @org.jetbrains.annotations.Nullable java.util.function.Predicate<Entity> entityPredicate) {
+ net.minecraft.world.phys.EntityHitResult rayTrace = getHandle().getTargetEntity(maxDistance, entityPredicate == null ? null : (entity) -> {
+ return entityPredicate.test(entity.getBukkitEntity());
+ });
+ if (rayTrace == null) {
+ return null;
+ }

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add playPickupItemAnimation to LivingEntity
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 639d376bf382409410e26385134d36fd6e3b5f0c..537d1a6dcf8add34e8dac8aee2fa50c50ce7e5d0 100644
index b26f97094cdec117342e0045cd931b0b4141b73f..6934a8b4b15d6b8b01d5c4c54bdf465ffeaa26e5 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -838,5 +838,10 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -848,5 +848,10 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
((Mob) getHandle()).getJumpControl().jump();
}
}

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Add LivingEntity#clearActiveItem
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 537d1a6dcf8add34e8dac8aee2fa50c50ce7e5d0..24ffc967391c9ba175f41396a90007ecdc32f55c 100644
index 6934a8b4b15d6b8b01d5c4c54bdf465ffeaa26e5..8b1c26e17dc98069648d354f709224636785c7e6 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -805,6 +805,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -815,6 +815,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return getHandle().getUseItem().asBukkitMirror();
}

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Expose LivingEntity hurt direction
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 24ffc967391c9ba175f41396a90007ecdc32f55c..0293d6fd1bb29f75fa1fa1cdfa36b3f679c1bc45 100644
index 8b1c26e17dc98069648d354f709224636785c7e6..c75dffe431a423dedff35cf9ea56768a4afa67eb 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -850,5 +850,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -860,5 +860,15 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public void playPickupItemAnimation(org.bukkit.entity.Item item, int quantity) {
getHandle().take(((CraftItem) item).getHandle(), quantity);
}

View file

@ -41,10 +41,10 @@ index 46c313d581b9af6aa0a48f97ae3cc800a88535f2..07d700382fc356837045c46d320b7b69
return net.minecraft.core.Registry.ATTRIBUTE.get(CraftNamespacedKey.toMinecraft(attribute.getKey()));
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 0293d6fd1bb29f75fa1fa1cdfa36b3f679c1bc45..6555db49ff57bba13a7eb3c0bf7ecb66d7828dce 100644
index c75dffe431a423dedff35cf9ea56768a4afa67eb..9e49dedac14b7033a862609d7c22d8c61d78fd0b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -686,6 +686,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -696,6 +696,13 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return this.getHandle().craftAttributes.getAttribute(attribute);
}

View file

@ -64,10 +64,10 @@ index c536eceef3365a7b726cd970df345ba1d055207d..11c1eb0e0bc326b28dc0cab16f67c413
public net.minecraft.world.item.enchantment.Enchantment getHandle() {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 6555db49ff57bba13a7eb3c0bf7ecb66d7828dce..8fe1f5deddfee329c020d93c990dc686fe2b458e 100644
index 9e49dedac14b7033a862609d7c22d8c61d78fd0b..be1a75bbe3038483ad34b6a0ae14eb9cfd18b6b8 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -867,5 +867,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -877,5 +877,21 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public void setHurtDirection(float hurtDirection) {
getHandle().hurtDir = hurtDirection;
}

View file

@ -5,7 +5,11 @@ Subject: [PATCH] Line Of Sight Changes
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
<<<<<<< HEAD:patches/server/0671-Line-Of-Sight-Changes.patch
index fd2d5e274a3bf889b954bed17d286d1157cd208e..709ca3f249a5c4d3a405e94ca353864df349ffcd 100644
=======
index 471b038564a2507bc1048cad2eb575bec733c009..794a533d61e415f1b7787044a26c94d6331014f4 100644
>>>>>>> d1059c199 (Add getTargetEntity predicate):patches/server/0677-Line-Of-Sight-Changes.patch
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3449,7 +3449,8 @@ public abstract class LivingEntity extends Entity {
@ -42,7 +46,7 @@ index 06b3377cbe2808187d9f4af1253be9e787ec7f2f..e2f88425ea748384af18b126c6478a58
private static final Random rand = new Random();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index 8fe1f5deddfee329c020d93c990dc686fe2b458e..ca176b9331345e343c19a02b6ba2ea886d20962d 100644
index be1a75bbe3038483ad34b6a0ae14eb9cfd18b6b8..90ec80270f8bc0180f60c2e4f3d1cc50958ee1de 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -29,6 +29,9 @@ import net.minecraft.world.entity.projectile.ThrownEgg;
@ -55,7 +59,7 @@ index 8fe1f5deddfee329c020d93c990dc686fe2b458e..ca176b9331345e343c19a02b6ba2ea88
import org.apache.commons.lang.Validate;
import org.bukkit.FluidCollisionMode;
import org.bukkit.Location;
@@ -557,6 +560,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -567,6 +570,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
return this.getHandle().hasLineOfSight(((CraftEntity) other).getHandle());
}

View file

@ -5,10 +5,10 @@ Subject: [PATCH] Stinger API
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
index ca176b9331345e343c19a02b6ba2ea886d20962d..c022751e3b45469cc0ad6732e2d6ff08918bafa4 100644
index 90ec80270f8bc0180f60c2e4f3d1cc50958ee1de..6a01ba2308f7befdb29323f572e9b19f780cd791 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java
@@ -321,7 +321,28 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
@@ -331,7 +331,28 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
Preconditions.checkArgument(count >= 0, "New arrow amount must be >= 0");
this.getHandle().getEntityData().set(net.minecraft.world.entity.LivingEntity.DATA_ARROW_COUNT_ID, count);
}