From c3eaa827e323c4181089a8087e883f118c1c7fa4 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Sun, 31 Jul 2022 11:30:34 -0400 Subject: [PATCH] Collision API (#6736) --- patches/api/Collision-API.patch | 57 ++++++++++++++++++++++++++++++ patches/server/Collision-API.patch | 47 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 patches/api/Collision-API.patch create mode 100644 patches/server/Collision-API.patch diff --git a/patches/api/Collision-API.patch b/patches/api/Collision-API.patch new file mode 100644 index 0000000000..f4133df27f --- /dev/null +++ b/patches/api/Collision-API.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> +Date: Wed, 6 Oct 2021 20:10:36 -0400 +Subject: [PATCH] Collision API + + +diff --git a/src/main/java/org/bukkit/RegionAccessor.java b/src/main/java/org/bukkit/RegionAccessor.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/RegionAccessor.java ++++ b/src/main/java/org/bukkit/RegionAccessor.java +@@ -0,0 +0,0 @@ public interface RegionAccessor extends Keyed { // Paper + * @return whether a line of sight exists between {@code from} and {@code to} + */ + public boolean lineOfSightExists(@NotNull Location from, @NotNull Location to); ++ ++ /** ++ * Checks if the world collides with the given boundingbox. ++ * This will check for any colliding hard entities (boats, shulkers) / worldborder / blocks. ++ * Does not load chunks that are within the bounding box. ++ * ++ * @param boundingBox the box to check collisions in ++ * @return collides or not ++ */ ++ boolean hasCollisionsIn(@NotNull org.bukkit.util.BoundingBox boundingBox); + // Paper end + } +diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/entity/Entity.java ++++ b/src/main/java/org/bukkit/entity/Entity.java +@@ -0,0 +0,0 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent + */ + boolean isInPowderedSnow(); + // Paper end ++ ++ // Paper Start - Collision API ++ /** ++ * Checks for any collisions with the entity's bounding box at the provided location. ++ * This will check for any colliding entities (boats, shulkers) / worldborder / blocks. ++ * Does not load chunks that are within the bounding box at the specified location. ++ * ++ * @param location the location to check collisions in ++ * @return collides or not ++ */ ++ boolean collidesAt(@NotNull Location location); ++ ++ /** ++ * This checks using the given boundingbox as the entity's boundingbox if the entity would collide with anything. ++ * This will check for any colliding entities (boats, shulkers) / worldborder / blocks. ++ * Does not load chunks that are within the bounding box. ++ * ++ * @param boundingBox the box to check collisions in ++ * @return collides or not ++ */ ++ boolean wouldCollideUsing(@NotNull BoundingBox boundingBox); ++ // Paper End - Collision API + } diff --git a/patches/server/Collision-API.patch b/patches/server/Collision-API.patch new file mode 100644 index 0000000000..d1ed5db60e --- /dev/null +++ b/patches/server/Collision-API.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> +Date: Wed, 6 Oct 2021 20:10:44 -0400 +Subject: [PATCH] Collision API + + +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +@@ -0,0 +0,0 @@ public abstract class CraftRegionAccessor implements RegionAccessor { + + return this.getHandle().clip(new net.minecraft.world.level.ClipContext(vec3d, vec3d1, net.minecraft.world.level.ClipContext.Block.COLLIDER, net.minecraft.world.level.ClipContext.Fluid.NONE, null)).getType() == net.minecraft.world.phys.HitResult.Type.MISS; + } ++ ++ @Override ++ public boolean hasCollisionsIn(@org.jetbrains.annotations.NotNull org.bukkit.util.BoundingBox boundingBox) { ++ net.minecraft.world.phys.AABB aabb = new AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), false); ++ ++ return !this.getHandle().noCollision(aabb); ++ } + // 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +@@ -0,0 +0,0 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { + return getHandle().isInPowderSnow || getHandle().wasInPowderSnow; // depending on the location in the entity "tick" either could be needed. + } + // Paper end ++ // Paper Start - Collision API ++ @Override ++ public boolean collidesAt(@org.jetbrains.annotations.NotNull Location location) { ++ net.minecraft.world.phys.AABB aabb = this.getHandle().getBoundingBoxAt(location.getX(), location.getY(), location.getZ()); ++ ++ return !this.getHandle().level.noCollision(this.getHandle(), aabb); ++ } ++ ++ @Override ++ public boolean wouldCollideUsing(@org.jetbrains.annotations.NotNull BoundingBox boundingBox) { ++ net.minecraft.world.phys.AABB aabb = new AABB(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ(), false); ++ ++ return !this.getHandle().level.noCollision(this.getHandle(), aabb); ++ } ++ // Paper End - Collision API + }