Paper/patches/server/0227-SkeletonHorse-Additions.patch

88 lines
4.3 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 27 Jul 2018 22:36:31 -0500
Subject: [PATCH] SkeletonHorse Additions
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
2022-06-07 23:45:11 +02:00
index 114352b9e8aeea7c728b6b58047e38e2530401a9..68887c1a475c119d061c8325136c5245011cdcbb 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
2021-11-23 16:04:41 +01:00
@@ -17,6 +17,7 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
2021-06-11 14:02:28 +02:00
public class SkeletonTrapGoal extends Goal {
private final SkeletonHorse horse;
2021-06-13 01:45:00 +02:00
+ private java.util.List<org.bukkit.entity.HumanEntity> eligiblePlayers; // Paper
2021-06-11 14:02:28 +02:00
public SkeletonTrapGoal(SkeletonHorse skeletonHorse) {
this.horse = skeletonHorse;
2021-11-23 16:04:41 +01:00
@@ -24,12 +25,13 @@ public class SkeletonTrapGoal extends Goal {
2021-06-11 14:02:28 +02:00
@Override
public boolean canUse() {
- return this.horse.level.hasNearbyAlivePlayer(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D);
+ return !(eligiblePlayers = this.horse.level.findNearbyBukkitPlayers(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D, false)).isEmpty(); // Paper
}
@Override
public void tick() {
ServerLevel worldserver = (ServerLevel) this.horse.level;
+ if (!new com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent((org.bukkit.entity.SkeletonHorse) this.horse.getBukkitEntity(), eligiblePlayers).callEvent()) return; // Paper
DifficultyInstance difficultydamagescaler = worldserver.getCurrentDifficultyAt(this.horse.blockPosition());
this.horse.setTrap(false);
diff --git a/src/main/java/net/minecraft/world/level/EntityGetter.java b/src/main/java/net/minecraft/world/level/EntityGetter.java
2022-05-29 21:54:25 +02:00
index cfb286020b8ee87bad7edbda4cd0b999fb607a06..1a3be6f0570c7c746eafa36544debe90d7629432 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
2022-05-29 21:54:25 +02:00
@@ -88,6 +88,28 @@ public interface EntityGetter {
2021-06-13 01:45:00 +02:00
return player;
2021-06-11 14:02:28 +02:00
}
+ // Paper start
2021-06-13 01:45:00 +02:00
+ default List<org.bukkit.entity.HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, boolean notSpectator) {
+ return findNearbyBukkitPlayers(x, y, z, radius, notSpectator ? EntitySelector.NO_SPECTATORS : net.minecraft.world.entity.EntitySelector.NO_CREATIVE_OR_SPECTATOR);
2021-06-11 14:02:28 +02:00
+ }
+
2021-06-13 01:45:00 +02:00
+ default List<org.bukkit.entity.HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, @Nullable Predicate<Entity> predicate) {
+ com.google.common.collect.ImmutableList.Builder<org.bukkit.entity.HumanEntity> builder = com.google.common.collect.ImmutableList.builder();
2021-06-11 14:02:28 +02:00
+
+ for (Player human : this.players()) {
+ if (predicate == null || predicate.test(human)) {
2021-06-17 23:39:36 +02:00
+ double distanceSquared = human.distanceToSqr(x, y, z);
2021-06-11 14:02:28 +02:00
+
+ if (radius < 0.0D || distanceSquared < radius * radius) {
+ builder.add(human.getBukkitEntity());
+ }
+ }
+ }
+
+ return builder.build();
+ }
+ // Paper end
+
@Nullable
default Player getNearestPlayer(Entity entity, double maxDistance) {
return this.getNearestPlayer(entity.getX(), entity.getY(), entity.getZ(), maxDistance, false);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
index e42dfd154f05130ff26f4d47d6817a1a561bfd54..78bc77d9cc5797fa8edd189167bb60b75b7f920e 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
@@ -50,4 +50,16 @@ public class CraftSkeletonHorse extends CraftAbstractHorse implements SkeletonHo
public void setTrapTime(int trapTime) {
this.getHandle().trapTime = trapTime;
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start - replaced by above methods
2021-06-11 14:02:28 +02:00
+ @Override
+ public boolean isTrap() {
+ return getHandle().isTrap();
+ }
+
+ @Override
+ public void setTrap(boolean trap) {
+ getHandle().setTrap(trap);
+ }
+ // Paper end
}