Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1322,4 +1324,39 @@ default boolean spawnAt(@NotNull Location location) {
*/
void broadcastHurtAnimation(@NotNull java.util.Collection<Player> 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.
* <br>
* This is an additional rule from the vanilla behaviour for any entity, like share a team.
* <br>
* This rule is not (currently) persistent.
*
* @return additional rule of alliance
* @see #addAdditionalAlliedRule(Key, Predicate)
*/
@Nullable Predicate<Entity> 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<Entity> predicate);

/**
* Remove the additional rule of alliance with any entity.
*
* @param key the key of the additional rule
*/
void removeAdditionalAlliedRule(@NotNull Key key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TickTa
Expand Down Expand Up @@ -66,7 +66,7 @@ index 8c4b40362f77cdea6e57315a6639006ac7ab27c7..a5217deb236ee922d020a7a6a03141a5
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.ADVENTURE_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index fea6c3b48c4eb162fbdc099fa775bc3161a4dd4e..82f6582a92f17bdeb3218c4c1fcac86981fd9c37 100644
index 7ab3cf2fb50804c314df576743d19b0aba1ee8bb..960ab20654b054e1518c48be3434465a1ca28803 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -5146,6 +5146,11 @@ public abstract class Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,15 @@
return this.level().getScoreboard().getPlayersTeam(this.getScoreboardName());
}

@@ -2699,7 +_,7 @@
}

protected boolean considersEntityAsAlly(final Entity other) {
- return this.isAlliedTo(other.getTeam());
+ return this.isAlliedTo(other.getTeam()) || this.getBukkitEntity().considersEntityAsAlly0(other.getBukkitEntity()); // Paper - Allies API
}

public boolean isAlliedTo(final @Nullable Team other) {
@@ -2707,7 +_,11 @@
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import io.papermc.paper.entity.LookAnchor;
import io.papermc.paper.entity.TeleportFlag;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.pointer.PointersSupplier;
import net.kyori.adventure.util.TriState;
import net.md_5.bungee.api.chat.BaseComponent;
Expand Down Expand Up @@ -97,6 +101,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
protected Entity entity;
private final EntityType entityType;
private EntityDamageEvent lastDamageEvent;
private final Map<Key, Predicate<org.bukkit.entity.Entity>> 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);
Expand Down Expand Up @@ -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<org.bukkit.entity.Entity> getAdditionalAlliedRule(@NotNull Key key) {
return this.additionalAlliedRules.get(key);
}

@Override
public void addAdditionalAlliedRule(@NotNull Key key, @NotNull Predicate<org.bukkit.entity.Entity> predicate) {
this.additionalAlliedRules.put(key, predicate);
}

@Override
public void removeAdditionalAlliedRule(@NotNull Key key) {
this.additionalAlliedRules.remove(key);
}

}
Loading