-
-
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
87 additions
and
13 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 87489972dff661c7c9ec4d128e25e2f7666b598e..14edb1b4caeda0c8aecf3528bd0005fafa6197ff 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,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 { | ||
|
@@ -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 { | ||
|
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