Skip to content

Commit

Permalink
Add EntityCollideWithEntityEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Dec 9, 2023
1 parent b42a1da commit 7c549cf
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 10 deletions.
61 changes: 61 additions & 0 deletions patches/api/0371-Collision-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,68 @@ From: Owen1212055 <[email protected]>
Date: Wed, 6 Oct 2021 20:10:36 -0400
Subject: [PATCH] Collision API

Co-authored-by: Tamion <[email protected]>

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<Entity> 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<Entity> 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
Expand Down
13 changes: 13 additions & 0 deletions patches/server/0831-Collision-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ From: Owen1212055 <[email protected]>
Date: Wed, 6 Oct 2021 20:10:44 -0400
Subject: [PATCH] Collision API

Co-authored-by: Tamion <[email protected]>

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0892-Improve-PortalEvents.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1186,15 +1186,15 @@ 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
+ final boolean alreadyRemoved = this.removalReason != null;
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 7c549cf

Please sign in to comment.