SkeletonHorse Additions

This commit is contained in:
BillyGalbreath 2018-07-27 22:36:31 -05:00
parent c0a3a0d12c
commit da011362dc
3 changed files with 60 additions and 5 deletions

View file

@ -1,15 +1,29 @@
--- a/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
+++ b/net/minecraft/world/entity/animal/horse/SkeletonTrapGoal.java
@@ -27,7 +27,7 @@
@@ -20,6 +20,7 @@
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;
@@ -27,12 +28,13 @@
@Override
public boolean canUse() {
- return this.horse.level().hasNearbyAlivePlayer(this.horse.getX(), this.horse.getY(), this.horse.getZ(), 10.0D);
+ 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
@@ -43,12 +43,12 @@
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);
@@ -43,12 +45,12 @@
if (entitylightning != null) {
entitylightning.moveTo(this.horse.getX(), this.horse.getY(), this.horse.getZ());
entitylightning.setVisualOnly(true);
@ -24,7 +38,7 @@
for (int i = 0; i < 3; ++i) {
AbstractHorse entityhorseabstract = this.createHorse(difficultydamagescaler);
@@ -59,7 +59,7 @@
@@ -59,7 +61,7 @@
if (entityskeleton1 != null) {
entityskeleton1.startRiding(entityhorseabstract);
entityhorseabstract.push(this.horse.getRandom().triangle(0.0D, 1.1485D), 0.0D, this.horse.getRandom().triangle(0.0D, 1.1485D));

View file

@ -12,7 +12,36 @@
@Nullable
default Player getNearestPlayer(double x, double y, double z, double maxDistance, @Nullable Predicate<Entity> targetPredicate) {
double d = -1.0;
@@ -100,6 +105,20 @@
@@ -89,6 +94,28 @@
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);
@@ -100,6 +127,20 @@
return this.getNearestPlayer(x, y, z, maxDistance, predicate);
}

View file

@ -44,4 +44,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
}