-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters