From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: BillyGalbreath 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 cad754d6b75c3c16db4fd847fdf6cb8c0ec82dde..5c70fdefeb940837950e8a9692b1ac3a72e7c623 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 @@ -17,6 +17,7 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper; public class SkeletonTrapGoal extends Goal { private final SkeletonHorse horse; + private java.util.List eligiblePlayers; // Paper public SkeletonTrapGoal(SkeletonHorse skeletonHorse) { this.horse = skeletonHorse; @@ -24,12 +25,13 @@ public class SkeletonTrapGoal extends Goal { @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 index 0dc46471f7247e5d36c3896a0c87473072362fe6..bc3bfe8d3c2f87e2e9f167b9ff34d9ca8a696391 100644 --- a/src/main/java/net/minecraft/world/level/EntityGetter.java +++ b/src/main/java/net/minecraft/world/level/EntityGetter.java @@ -89,6 +89,28 @@ public interface EntityGetter { return player; } + // Paper start + default List 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 findNearbyBukkitPlayers(double x, double y, double z, double radius, @Nullable Predicate predicate) { + com.google.common.collect.ImmutableList.Builder 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 b52ca4a612e30542ef4029cb1340f616bc4c36e6..90a61d1472afea12637814256f91dbd2f5acb42e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java @@ -25,4 +25,26 @@ public class CraftSkeletonHorse extends CraftAbstractHorse implements SkeletonHo public Variant getVariant() { return Variant.SKELETON_HORSE; } + + // Paper start + @Override + public net.minecraft.world.entity.animal.horse.SkeletonHorse getHandle() { + return (net.minecraft.world.entity.animal.horse.SkeletonHorse) super.getHandle(); + } + + @Override + public int getTrapTime() { + return getHandle().trapTime; + } + + @Override + public boolean isTrap() { + return getHandle().isTrap(); + } + + @Override + public void setTrap(boolean trap) { + getHandle().setTrap(trap); + } + // Paper end }