-
-
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
11 changed files
with
100 additions
and
26 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 4b54b3e121508fb1590654123e86c6c5de54a755..f8125c2319013241b48b818977fb1dc5d9050905 100644 | ||
--- a/src/main/java/net/minecraft/world/entity/Entity.java | ||
+++ b/src/main/java/net/minecraft/world/entity/Entity.java | ||
@@ -1907,6 +1907,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess | ||
if (!this.isPassengerOfSameVehicle(entity)) { | ||
if (!entity.noPhysics && !this.noPhysics) { | ||
if (this.level.paperConfig().collisions.onlyPlayersCollide && !(entity instanceof ServerPlayer || this instanceof ServerPlayer)) return; // Paper - Collision option for requiring a player participant | ||
+ 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 d1c265733941874002f6dfc7543917af88600659..72c275d7da798ee10a224bbd3f4c92abd82601e1 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
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
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