From 4a7b8c3f26b515b7fa089d340fffcf3c8d0bc9d7 Mon Sep 17 00:00:00 2001 From: Tamion <70228790+notTamion@users.noreply.github.com> Date: Mon, 4 Dec 2023 19:05:53 +0100 Subject: [PATCH] Add EntityCollideWithEntityEvent --- patches/api/0371-Collision-API.patch | 61 +++++++++++++++++++ patches/server/0830-Collision-API.patch | 13 ++++ ...tEvent-cancellation-cant-fully-preve.patch | 4 +- .../server/0891-Improve-PortalEvents.patch | 4 +- ...Folia-scheduler-and-owned-region-API.patch | 6 +- ...estore-vanilla-entity-drops-behavior.patch | 6 +- 6 files changed, 84 insertions(+), 10 deletions(-) diff --git a/patches/api/0371-Collision-API.patch b/patches/api/0371-Collision-API.patch index 394d0d8feec28..90f3e3adc654d 100644 --- a/patches/api/0371-Collision-API.patch +++ b/patches/api/0371-Collision-API.patch @@ -3,7 +3,68 @@ From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:10:36 -0400 Subject: [PATCH] Collision API +Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> +diff --git a/src/main/java/io/papermc/paper/event/entity/EntityCollideWithEntityEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityCollideWithEntityEvent.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0505e5479526bcfb757e6078d6bbec423498c303 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/event/entity/EntityCollideWithEntityEvent.java +@@ -0,0 +1,54 @@ ++package io.papermc.paper.event.entity; ++ ++import org.bukkit.entity.Entity; ++import org.bukkit.event.Cancellable; ++import org.bukkit.event.Event; ++import org.bukkit.event.HandlerList; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.NotNull; ++import java.util.Set; ++ ++/** ++ * Fired when two entities collide with each other. ++ * If cancelled, the entities won't get pushed away from each other. ++ */ ++public class EntityCollideWithEntityEvent extends Event implements Cancellable { ++ ++ private static final HandlerList HANDLER_LIST = new HandlerList(); ++ private boolean cancelled; ++ private final Set entities; ++ ++ @ApiStatus.Internal ++ public EntityCollideWithEntityEvent(@NotNull Entity entity1, @NotNull Entity entity2) { ++ entities = Set.of(entity1, entity2); ++ } ++ ++ /** ++ * Returns the Entities involved in this event ++ * ++ * @return Entities that are involved in this event ++ */ ++ public @NotNull Set getEntities() { ++ return entities; ++ } ++ ++ @Override ++ public @NotNull HandlerList getHandlers() { ++ return HANDLER_LIST; ++ } ++ ++ @NotNull ++ public static HandlerList getHandlerList() { ++ return HANDLER_LIST; ++ } ++ ++ @Override ++ public boolean isCancelled() { ++ return cancelled; ++ } ++ ++ @Override ++ public void setCancelled(final boolean cancel) { ++ this.cancelled = cancel; ++ } ++} diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java index 44ee56a5956cc17194c767a0c1071a2abffe818a..43dd6c59cceba12f27e6b265acc3ad97eea37abd 100644 --- a/src/main/java/org/bukkit/RegionAccessor.java diff --git a/patches/server/0830-Collision-API.patch b/patches/server/0830-Collision-API.patch index 1a8631fdd266a..d176a3f26fd93 100644 --- a/patches/server/0830-Collision-API.patch +++ b/patches/server/0830-Collision-API.patch @@ -3,7 +3,20 @@ From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:10:44 -0400 Subject: [PATCH] Collision API +Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 52504f71a34fe8700c68533ff82d98fe23f8edc9..3a9cee33fc7ce310b5d04af3d018495149d59e6e 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -2098,6 +2098,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S + if (!this.isPassengerOfSameVehicle(entity)) { + if (!entity.noPhysics && !this.noPhysics) { + if (this.level.paperConfig().collisions.onlyPlayersCollide && !(entity instanceof ServerPlayer || this instanceof ServerPlayer)) return; // Paper ++ if (!new io.papermc.paper.event.entity.EntityCollideWithEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity()).callEvent()) return; // Paper + double d0 = entity.getX() - this.getX(); + double d1 = entity.getZ() - this.getZ(); + double d2 = Mth.absMax(d0, d1); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index 9c31a042d2ff82689a4bcc9d90fe08e5f8329985..76d529ad7d1ce543b8f262b3a36f17405cc9da92 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java diff --git a/patches/server/0866-Fix-EntityCombustEvent-cancellation-cant-fully-preve.patch b/patches/server/0866-Fix-EntityCombustEvent-cancellation-cant-fully-preve.patch index b222f94c0ec3d..069477e14cce9 100644 --- a/patches/server/0866-Fix-EntityCombustEvent-cancellation-cant-fully-preve.patch +++ b/patches/server/0866-Fix-EntityCombustEvent-cancellation-cant-fully-preve.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Fix EntityCombustEvent cancellation cant fully prevent diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 52504f71a34fe8700c68533ff82d98fe23f8edc9..e758f3dce618c7b021ea1828c1b2fc3807455f4a 100644 +index 3a9cee33fc7ce310b5d04af3d018495149d59e6e..1da4d1a59246010be84faee2f8b0d16b75a8686f 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -3382,6 +3382,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3383,6 +3383,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S pluginManager.callEvent(entityCombustEvent); if (!entityCombustEvent.isCancelled()) { this.setSecondsOnFire(entityCombustEvent.getDuration(), false); diff --git a/patches/server/0891-Improve-PortalEvents.patch b/patches/server/0891-Improve-PortalEvents.patch index e4cfe4be44e67..c83cbb7500a6a 100644 --- a/patches/server/0891-Improve-PortalEvents.patch +++ b/patches/server/0891-Improve-PortalEvents.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Improve PortalEvents diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index e758f3dce618c7b021ea1828c1b2fc3807455f4a..bfbb99e82c00eef9772c605e172645252af6e8ad 100644 +index 1da4d1a59246010be84faee2f8b0d16b75a8686f..737b1427597f01953256201afd387fed7eceeea8 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -3769,7 +3769,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -3770,7 +3770,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S Location enter = bukkitEntity.getLocation(); Location exit = CraftLocation.toBukkit(exitPosition, exitWorldServer.getWorld()); diff --git a/patches/server/0967-Folia-scheduler-and-owned-region-API.patch b/patches/server/0967-Folia-scheduler-and-owned-region-API.patch index 3efe7051b132d..c919703dbf293 100644 --- a/patches/server/0967-Folia-scheduler-and-owned-region-API.patch +++ b/patches/server/0967-Folia-scheduler-and-owned-region-API.patch @@ -1158,7 +1158,7 @@ index 3927558c62cf24af915d37eb8e983339bc0f2aa3..895c4accbcf43baaa8a4d560e8b5c0d4 this.players.remove(entityplayer); this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 8af2d49fdb46deab17fd801e5ba56eec289b4dd0..23488823fe48f502c1f64ace79030bf0f7e85626 100644 +index a704314aacf5b4e71560b6a4f3a16b6209ebcff4..b46562e65b6ba66f83cd551f0c58f3c0f4b09cce 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -247,11 +247,23 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @@ -1186,7 +1186,7 @@ index 8af2d49fdb46deab17fd801e5ba56eec289b4dd0..23488823fe48f502c1f64ace79030bf0 @Override public CommandSender getBukkitSender(CommandSourceStack wrapper) { return this.getBukkitEntity(); -@@ -4739,6 +4751,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4740,6 +4752,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S return; } // Paper end - rewrite chunk system @@ -1194,7 +1194,7 @@ index 8af2d49fdb46deab17fd801e5ba56eec289b4dd0..23488823fe48f502c1f64ace79030bf0 if (this.removalReason == null) { this.removalReason = reason; } -@@ -4749,12 +4762,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -4750,12 +4763,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S if (reason != RemovalReason.UNLOADED_TO_CHUNK) this.getPassengers().forEach(Entity::stopRiding); // Paper - chunk system - don't adjust passenger state when unloading, it's just not safe (and messes with our logic in entity chunk unload) this.levelCallback.onRemove(reason); diff --git a/patches/server/1047-Restore-vanilla-entity-drops-behavior.patch b/patches/server/1047-Restore-vanilla-entity-drops-behavior.patch index 648946920d551..c1e5e8c20b6ca 100644 --- a/patches/server/1047-Restore-vanilla-entity-drops-behavior.patch +++ b/patches/server/1047-Restore-vanilla-entity-drops-behavior.patch @@ -39,10 +39,10 @@ index 5fe743567f2e9cf0f9442ddd87453c51af8060e6..8efbbd379244e3ed54d4aba199037cc2 } // Paper diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 62bdce9516804942862b33667bc571e3bcac1a70..9abe817ae202edaa2d88cd59ae5c7db0b1c634be 100644 +index 430a3652a551f3a8a8fc1d6cc1ca4330b1240c10..6f6b54edf78b08216f1258e3e7ed3291eb00a28f 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -2702,6 +2702,25 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -2703,6 +2703,25 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S @Nullable public ItemEntity spawnAtLocation(ItemStack stack, float yOffset) { @@ -68,7 +68,7 @@ index 62bdce9516804942862b33667bc571e3bcac1a70..9abe817ae202edaa2d88cd59ae5c7db0 if (stack.isEmpty()) { return null; } else if (this.level().isClientSide) { -@@ -2709,14 +2728,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S +@@ -2710,14 +2729,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S } else { // CraftBukkit start - Capture drops for death event if (this instanceof net.minecraft.world.entity.LivingEntity && !((net.minecraft.world.entity.LivingEntity) this).forceDrops) {