2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2018-08-05 03:12:41 +02:00
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 27 Jul 2018 22:36:31 -0500
Subject: [PATCH] SkeletonHorse Additions
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/IEntitySelector.java b/src/main/java/net/minecraft/world/entity/IEntitySelector.java
index dfcfdb31ca9531913d705aaaf85fb67399cfdc8c..4776a47566aac487dc77fd6b4b9b42b95974e31a 100644
--- a/src/main/java/net/minecraft/world/entity/IEntitySelector.java
+++ b/src/main/java/net/minecraft/world/entity/IEntitySelector.java
@@ -25,6 +25,7 @@ public final class IEntitySelector {
public static final Predicate<Entity> f = (entity) -> {
return !(entity instanceof EntityHuman) || !entity.isSpectator() && !((EntityHuman) entity).isCreative() && entity.world.getDifficulty() != EnumDifficulty.PEACEFUL;
};
+ public static Predicate<Entity> notSpectator() { return g; } // Paper - OBFHELPER
public static final Predicate<Entity> g = (entity) -> {
return !entity.isSpectator();
};
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java
index 0ddb676a2d1c38c97cd7750c1594fd6468156d0a..da5365372e89b847d626e52c5541544467f14702 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/EntityHorseSkeleton.java
@@ -26,7 +26,7 @@ public class EntityHorseSkeleton extends EntityHorseAbstract {
2019-01-01 04:15:55 +01:00
2020-08-25 04:22:08 +02:00
private final PathfinderGoalHorseTrap bw = new PathfinderGoalHorseTrap(this);
private boolean bx;
- private int by;
+ private int by; public int getTrapTime() { return this.by; } // Paper - OBFHELPER
2018-08-05 03:12:41 +02:00
2019-05-01 00:51:03 +02:00
public EntityHorseSkeleton(EntityTypes<? extends EntityHorseSkeleton> entitytypes, World world) {
super(entitytypes, world);
2021-03-16 08:19:45 +01:00
@@ -145,10 +145,12 @@ public class EntityHorseSkeleton extends EntityHorseAbstract {
2018-08-05 03:12:41 +02:00
return 0.96F;
}
2020-08-25 04:22:08 +02:00
+ public boolean isTrap() { return this.eM(); } // Paper - OBFHELPER
public boolean eM() {
return this.bx;
2018-08-05 03:12:41 +02:00
}
2020-06-25 16:09:55 +02:00
+ public void setTrap(boolean trap) { this.t(trap); } // Paper - OBFHELPER
public void t(boolean flag) {
2020-08-25 04:22:08 +02:00
if (flag != this.bx) {
this.bx = flag;
2021-03-16 08:19:45 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java b/src/main/java/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java
index 9b6a4f93dca6eeddad43d5f5675c551fb3fd2fdb..cf250cc6b7a77a7af742eab0b89cff2bc17fc5e4 100644
--- a/src/main/java/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java
+++ b/src/main/java/net/minecraft/world/entity/animal/horse/PathfinderGoalHorseTrap.java
@@ -15,9 +15,14 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.EnchantmentManager;
import net.minecraft.world.level.World;
+import org.bukkit.entity.HumanEntity;
+
+import java.util.List;
+
public class PathfinderGoalHorseTrap extends PathfinderGoal {
private final EntityHorseSkeleton a;
+ private List<HumanEntity> eligiblePlayers; // Paper
public PathfinderGoalHorseTrap(EntityHorseSkeleton entityhorseskeleton) {
this.a = entityhorseskeleton;
@@ -25,12 +30,13 @@ public class PathfinderGoalHorseTrap extends PathfinderGoal {
@Override
public boolean a() {
- return this.a.world.isPlayerNearby(this.a.locX(), this.a.locY(), this.a.locZ(), 10.0D);
+ return !(eligiblePlayers = this.a.world.findNearbyBukkitPlayers(this.a.locX(), this.a.locY(), this.a.locZ(), 10.0D, false)).isEmpty(); // Paper
}
@Override
public void e() {
WorldServer worldserver = (WorldServer) this.a.world;
+ if (!new com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent((org.bukkit.entity.SkeletonHorse) this.a.getBukkitEntity(), eligiblePlayers).callEvent()) return; // Paper
DifficultyDamageScaler difficultydamagescaler = worldserver.getDamageScaler(this.a.getChunkCoordinates());
this.a.t(false);
diff --git a/src/main/java/net/minecraft/world/level/IEntityAccess.java b/src/main/java/net/minecraft/world/level/IEntityAccess.java
index 6d5d4c3df65995b9a13b66d070ba08d553cc98a2..8fdc4b22e8c99d653bd213fe64339c133b46b4e9 100644
--- a/src/main/java/net/minecraft/world/level/IEntityAccess.java
+++ b/src/main/java/net/minecraft/world/level/IEntityAccess.java
2020-08-23 21:57:55 +02:00
@@ -1,6 +1,9 @@
2021-03-16 08:19:45 +01:00
package net.minecraft.world.level;
2020-08-23 21:57:55 +02:00
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import org.bukkit.entity.HumanEntity;
+
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
2021-03-16 08:19:45 +01:00
@@ -115,6 +118,28 @@ public interface IEntityAccess {
2020-08-23 21:57:55 +02:00
return entityhuman;
}
+ // Paper start
+ default List<HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, boolean notSpectator) {
+ return findNearbyBukkitPlayers(x, y, z, radius, notSpectator ? IEntitySelector.notSpectator() : IEntitySelector.canAITarget());
+ }
+
+ default List<HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, @Nullable Predicate<Entity> predicate) {
+ ImmutableList.Builder<HumanEntity> builder = ImmutableList.builder();
+
+ for (EntityHuman human : this.getPlayers()) {
+ if (predicate == null || predicate.test(human)) {
+ double distanceSquared = human.getDistanceSquared(x, y, z);
+
+ if (radius < 0.0D || distanceSquared < radius * radius) {
+ builder.add(human.getBukkitEntity());
+ }
+ }
+ }
+
+ return builder.build();
+ }
+ // Paper end
+
@Nullable
default EntityHuman findNearbyPlayer(Entity entity, double d0) {
return this.a(entity.locX(), entity.locY(), entity.locZ(), d0, false);
2018-08-05 03:12:41 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
2021-03-16 08:19:45 +01:00
index 4aec5fdb6b0379b0797969ff3c8f8a9629a18bfb..7366d56cefad45883f353ea5fb16b41f87006ec1 100644
2018-08-05 03:12:41 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSkeletonHorse.java
2019-05-01 00:51:03 +02:00
@@ -26,4 +26,26 @@ public class CraftSkeletonHorse extends CraftAbstractHorse implements SkeletonHo
2018-08-05 03:12:41 +02:00
public Variant getVariant() {
return Variant.SKELETON_HORSE;
}
+
+ // Paper start
+ @Override
+ public EntityHorseSkeleton getHandle() {
+ return (EntityHorseSkeleton) super.getHandle();
+ }
+
2019-05-01 00:51:03 +02:00
+ @Override
2018-08-05 03:12:41 +02:00
+ public int getTrapTime() {
+ return getHandle().getTrapTime();
+ }
+
2019-05-01 00:51:03 +02:00
+ @Override
2018-08-05 03:12:41 +02:00
+ public boolean isTrap() {
+ return getHandle().isTrap();
+ }
+
2019-05-01 00:51:03 +02:00
+ @Override
2018-08-05 03:12:41 +02:00
+ public void setTrap(boolean trap) {
+ getHandle().setTrap(trap);
+ }
+ // Paper end
}