Skip to content

Commit

Permalink
Add EntityCollideWithEntityEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Dec 5, 2023
1 parent 931781c commit b6fa9ca
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 13 deletions.
61 changes: 61 additions & 0 deletions patches/api/0373-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 87489972dff661c7c9ec4d128e25e2f7666b598e..14edb1b4caeda0c8aecf3528bd0005fafa6197ff 100644
--- a/src/main/java/org/bukkit/RegionAccessor.java
Expand Down
17 changes: 15 additions & 2 deletions patches/server/0837-Collision-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ 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 ce765fbe067d56ce0e5ae0bfade01f3b50e004be..32e38163d42c069056269defd4c2e2905de93bd5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2093,6 +2093,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
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 57bb76050919d187adef4bfa8b21416a70867d23..254cdf5efe85583c5ef126d46af7c5246daa97c2 100644
index 5a94a06bb531fe7805b43b5033a1d6edeee3b883..8cc1d7f5c5f8e9b9d6f7ab26025acf7237262959 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
@@ -1021,5 +1021,12 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
Expand All @@ -22,7 +35,7 @@ index 57bb76050919d187adef4bfa8b21416a70867d23..254cdf5efe85583c5ef126d46af7c524
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 706eeebe3ebbecd431c42140e7f351d5f7faf032..53bda7a59a3abf6f99a044df5f2c44bedf1af501 100644
index e02c454ba75f440342d85b466426b9363992d923..4199bc76c1f304e19fa7c3b7763d31b56a57221b 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1435,4 +1435,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
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 45178d204a79eb47b36adf6e4dfa17d71c6b2c3a..f402f9c530b9c98ea6295ba88ed0179ff7670986 100644
index 32e38163d42c069056269defd4c2e2905de93bd5..293d4de2a71f5b8a438de3d65ec5a789a28de45a 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3353,6 +3353,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -3354,6 +3354,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
pluginManager.callEvent(entityCombustEvent);
if (!entityCombustEvent.isCancelled()) {
this.setSecondsOnFire(entityCombustEvent.getDuration(), false);
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0899-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 f402f9c530b9c98ea6295ba88ed0179ff7670986..83d9487f20f42b678682ccb53b5e20c5932a579f 100644
index 293d4de2a71f5b8a438de3d65ec5a789a28de45a..276384053ea9c18f9ca068d960861d53efa1c003 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3736,7 +3736,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -3737,7 +3737,14 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
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 12bb0c619762ca9fc080ae884ce29de477dbcdc2..80919d247a9204ebf8d0e55df7fc6a24
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 bf77b0dae2ca25437df7386d2196da24d681e2ed..4516991a4d1299d7e93019a4b9bc227b4844e9ef 100644
index 6ca846263778cba7acb35830c1259ef7cf07405a..7bb6e398e7ecc3e971ca8c13a5b31b774967c0d2 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -246,11 +246,23 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
Expand Down Expand Up @@ -1186,15 +1186,15 @@ index bf77b0dae2ca25437df7386d2196da24d681e2ed..4516991a4d1299d7e93019a4b9bc227b
@Override
public CommandSender getBukkitSender(CommandSourceStack wrapper) {
return this.getBukkitEntity();
@@ -4697,6 +4709,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -4698,6 +4710,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
return;
}
// Paper end - rewrite chunk system
+ final boolean alreadyRemoved = this.removalReason != null;
if (this.removalReason == null) {
this.removalReason = reason;
}
@@ -4707,12 +4720,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -4708,12 +4721,28 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {

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 Expand Up @@ -1224,7 +1224,7 @@ index bf77b0dae2ca25437df7386d2196da24d681e2ed..4516991a4d1299d7e93019a4b9bc227b
public void setLevelCallback(EntityInLevelCallback changeListener) {
this.levelCallback = changeListener;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 9d86b54a9945d4644f7920e06e5d04faaaa2e8c8..16906e8ba7d05275561d465a08b792137d284c4e 100644
index 4d2443f40dc2e1b38b7c80e7b5f9ca7a4f84c107..3363ac5f0b2c059e0794fe22194c7fc1006806f4 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -310,6 +310,76 @@ public final class CraftServer implements Server {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ index 08980763020a13ab49dc7d637625a4fba56da8c9..907c8f15f5247f9972c6677ff0f9e1aa
} // Paper

diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index c655c6fee393c62ba79301f76baa72f9b1154a9a..fece91254b10b59474056aa730fd420f90cd7bec 100644
index 899262f1b7bea923eb680bbb8f976ed39b8319e3..44772a4404cfbc7348db5015f68b2357ed969e34 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2673,6 +2673,25 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -2674,6 +2674,25 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {

@Nullable
public ItemEntity spawnAtLocation(ItemStack stack, float yOffset) {
Expand All @@ -68,7 +68,7 @@ index c655c6fee393c62ba79301f76baa72f9b1154a9a..fece91254b10b59474056aa730fd420f
if (stack.isEmpty()) {
return null;
} else if (this.level().isClientSide) {
@@ -2680,14 +2699,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
@@ -2681,14 +2700,21 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
} 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 b6fa9ca

Please sign in to comment.