Paper/patches/server/0230-SkeletonHorse-Additions.patch
2022-12-07 19:52:24 +01:00

88 lines
4.5 KiB
Diff

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
index 17fda4857f74d2994525262472700e7788dec383..3b452b960a5e5e5d6582d7b64fe034402fb5fc2b 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
@@ -18,6 +18,7 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
public class SkeletonTrapGoal extends Goal {
private final SkeletonHorse horse;
+ private java.util.List<org.bukkit.entity.HumanEntity> eligiblePlayers; // Paper
public SkeletonTrapGoal(SkeletonHorse skeletonHorse) {
this.horse = skeletonHorse;
@@ -25,12 +26,13 @@ public class SkeletonTrapGoal extends Goal {
@Override
public boolean canUse() {
- return this.horse.level.hasNearbyAlivePlayerThatAffectsSpawning(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D); // Paper - Affects Spawning API
+ return !(eligiblePlayers = this.horse.level.findNearbyBukkitPlayers(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D, net.minecraft.world.entity.EntitySelector.PLAYER_AFFECTS_SPAWNING)).isEmpty(); // Paper - Affects Spawning API & SkeletonHorseTrapEvent
}
@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
index ea98625fe7c00743b8df74a24e6d4b75df4189a5..66a5783e2a83c75ca46d1fd6f97d9de733c01a09 100644
--- a/src/main/java/net/minecraft/world/level/EntityGetter.java
+++ b/src/main/java/net/minecraft/world/level/EntityGetter.java
@@ -105,6 +105,28 @@ public interface EntityGetter {
return player;
}
+ // Paper start
+ 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);
+ }
+
+ 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();
+
+ for (Player human : this.players()) {
+ if (predicate == null || predicate.test(human)) {
+ double distanceSquared = human.distanceToSqr(x, y, z);
+
+ 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
--- 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;
}
+
+ // Paper start - replaced by above methods
+ @Override
+ public boolean isTrap() {
+ return getHandle().isTrap();
+ }
+
+ @Override
+ public void setTrap(boolean trap) {
+ getHandle().setTrap(trap);
+ }
+ // Paper end
}