diff --git a/paper-api/src/main/java/org/bukkit/entity/Entity.java b/paper-api/src/main/java/org/bukkit/entity/Entity.java index 2c68aae864a7..66d8d1349c6a 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Entity.java +++ b/paper-api/src/main/java/org/bukkit/entity/Entity.java @@ -5,6 +5,8 @@ import java.util.UUID; import io.papermc.paper.datacomponent.DataComponentView; import io.papermc.paper.entity.LookAnchor; +import java.util.function.Predicate; +import net.kyori.adventure.key.Key; import net.kyori.adventure.util.TriState; import org.bukkit.Chunk; // Paper import org.bukkit.EntityEffect; @@ -1322,4 +1324,39 @@ default boolean spawnAt(@NotNull Location location) { */ void broadcastHurtAnimation(@NotNull java.util.Collection players); // Paper end - broadcast hurt animation + + /** + * Gets if the entity is allied to the given entity. + * + * @param other the other entity + * @return true if the entity is allied to the given entity + */ + boolean isAlliedTo(@NotNull Entity other); + + /** + * Gets the current additional rule of alliance with any entity. + *
+ * This is an additional rule from the vanilla behaviour for any entity, like share a team. + *
+ * This rule is not (currently) persistent. + * + * @return additional rule of alliance + * @see #addAdditionalAlliedRule(Key, Predicate) + */ + @Nullable Predicate getAdditionalAlliedRule(@NotNull Key key); + + /** + * Sets the current additional rule of alliance with any entity. + * + * @param key the key of the additional rule + * @param predicate the additional rule of alliance with any entity + */ + void addAdditionalAlliedRule(@NotNull Key key, @NotNull Predicate predicate); + + /** + * Remove the additional rule of alliance with any entity. + * + * @param key the key of the additional rule + */ + void removeAdditionalAlliedRule(@NotNull Key key); } diff --git a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch index 2f5fc143544b..3da8abd7020d 100644 --- a/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch +++ b/paper-server/patches/features/0001-Moonrise-optimisation-patches.patch @@ -28453,7 +28453,7 @@ index c974b6cafb1f6aa2a57cfdc8a39c887f02f42b1d..ec40f02032f965f548b0c0a29aa9d9bb // Paper start - PlayerChunkLoadEvent if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) { diff --git a/net/minecraft/server/network/config/PrepareSpawnTask.java b/net/minecraft/server/network/config/PrepareSpawnTask.java -index 83af9ee3ba150da85b9b694cd76a5fabb5b2d8ef..1fb40837bd02672850ec9adc2797190df22b33fc 100644 +index b5d993095aa77bb132c513f73dbf6d2afb2e3943..8b318dd8aa918284c5fa89e990b13bec425102cb 100644 --- a/net/minecraft/server/network/config/PrepareSpawnTask.java +++ b/net/minecraft/server/network/config/PrepareSpawnTask.java @@ -171,7 +171,7 @@ public class PrepareSpawnTask implements ConfigurationTask { @@ -28885,7 +28885,7 @@ index 1ceb7e4a3abd4d9de5133d182d3267d2164918f6..eb2fa32cff6824c14f865c8731df7d08 + // Paper end - block counting } diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index 29896cb17fcf8ab967a937e9b0e102a8354b6889..e087d5596979044fe7fbcf7f2cccdae4e81a3d3a 100644 +index 67a0481c2dbfe1c6692a0ced2179d272100b1979..2d7616e6d5a425677c1057b3e16325150cc87ae6 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -167,7 +167,7 @@ public abstract class Entity diff --git a/paper-server/patches/features/0005-Entity-Activation-Range-2.0.patch b/paper-server/patches/features/0005-Entity-Activation-Range-2.0.patch index bf988f7f15f9..270fba53b128 100644 --- a/paper-server/patches/features/0005-Entity-Activation-Range-2.0.patch +++ b/paper-server/patches/features/0005-Entity-Activation-Range-2.0.patch @@ -462,7 +462,7 @@ index 0df8332933203a904bd9ef9efb3c9bce21e65441..1a502cbd8acea9420fa6dd8d716018b5 public void tick() { super.tick(); diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java -index e087d5596979044fe7fbcf7f2cccdae4e81a3d3a..fea6c3b48c4eb162fbdc099fa775bc3161a4dd4e 100644 +index 2d7616e6d5a425677c1057b3e16325150cc87ae6..7ab3cf2fb50804c314df576743d19b0aba1ee8bb 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -382,6 +382,15 @@ public abstract class Entity @@ -817,7 +817,7 @@ index 3a590d4dc980a2912e9cc043d8c8db4cf9d60803..06ab7c48b18c03af494ab10fc2b584ce + } diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java -index b8d56c7a14521cb77ba2cf619be826fb06be81da..2b3ec0a012918815ed0eda8b40647c2274a5b418 100644 +index c0f901c4ac61a0aa2b480f102feb3669b111f4c0..07c301ba02c7f2c032a29a0ae3bdf95fc522c03b 100644 --- a/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java @@ -155,6 +155,12 @@ public abstract class Level implements LevelAccessor, AutoCloseable, ca.spottedl diff --git a/paper-server/patches/features/0025-Optimise-EntityScheduler-ticking.patch b/paper-server/patches/features/0025-Optimise-EntityScheduler-ticking.patch index c929667c8ef8..b78ca6ef9f6c 100644 --- a/paper-server/patches/features/0025-Optimise-EntityScheduler-ticking.patch +++ b/paper-server/patches/features/0025-Optimise-EntityScheduler-ticking.patch @@ -20,7 +20,7 @@ index 2bc436cdf5180a7943c45fabb9fbbedae6f7db56..f312a7f5b1b2a777ab36b94ce7cbf387 @Override diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java -index 8c4b40362f77cdea6e57315a6639006ac7ab27c7..a5217deb236ee922d020a7a6a03141a5f67acd77 100644 +index 72bc7f6efc8f23d6ff31d2dabb13490655c58074..9a438cbdb05c7a8c33804c3b66ff42f357a96bc3 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1794,32 +1794,22 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop> additionalAlliedRules = new HashMap<>(); private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftEntity.DATA_TYPE_REGISTRY); // Paper start - Folia shedulers public final io.papermc.paper.threadedregions.EntityScheduler taskScheduler = new io.papermc.paper.threadedregions.EntityScheduler(this); @@ -1331,4 +1336,29 @@ public boolean hasData(final @NotNull DataComponentType type) { return this.entity.get(io.papermc.paper.datacomponent.PaperDataComponentType.bukkitToMinecraft(type)) != null; } + public boolean considersEntityAsAlly0(org.bukkit.entity.Entity entity) { + return this.additionalAlliedRules.values().stream().anyMatch(entityPredicate -> entityPredicate.test(entity)); + } + + @Override + public boolean isAlliedTo(@NotNull org.bukkit.entity.Entity other) { + Preconditions.checkArgument(other != null, "other cannot be null"); + return this.getHandle().isAlliedTo(((CraftEntity)other).getHandle()); + } + + @Override + public Predicate getAdditionalAlliedRule(@NotNull Key key) { + return this.additionalAlliedRules.get(key); + } + + @Override + public void addAdditionalAlliedRule(@NotNull Key key, @NotNull Predicate predicate) { + this.additionalAlliedRules.put(key, predicate); + } + + @Override + public void removeAdditionalAlliedRule(@NotNull Key key) { + this.additionalAlliedRules.remove(key); + } + }