Player standing on position API

This commit is contained in:
Owen1212055 2023-06-09 22:50:14 -04:00
parent b3c81089ae
commit d000933c6f
No known key found for this signature in database
GPG Key ID: 2133292072886A30
2 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,55 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Fri, 9 Jun 2023 22:49:45 -0400
Subject: [PATCH] Player standing on position API
diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
index a2a423d4e4c2702ba5967223cab0432dd7d04732..6fa7d251f54be9d0ef6b0ec0283efa927bae1a0b 100644
--- a/src/main/java/org/bukkit/entity/Entity.java
+++ b/src/main/java/org/bukkit/entity/Entity.java
@@ -954,4 +954,44 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
*/
boolean wouldCollideUsing(@NotNull BoundingBox boundingBox);
// Paper End - Collision API
+ // Paper start - Player standing on position API
+ /**
+ * Gets the block that is currently being used to calculate movement affects (i.e friction) on the entity.
+ * <p>
+ * Examples:
+ * - When sanding on a slab under an ice block, this will return the position of the ice block.
+ * - When flying on top of a flower located under a grass block this will return the position of the grass block (although this technically will not affect your movement).
+ *
+ * @return block position used for movement affects
+ */
+ @NotNull
+ io.papermc.paper.math.BlockPosition getBlockPosBelowThatAffectsMyMovement();
+
+ /**
+ * Gets the block that is currently under the entity.
+ * This will return {@link Entity#getSupportingPos()} as long as it is not null,
+ * else it will instead return the bottom most block at the entity's hitbox.
+ * <p>
+ * Examples:
+ * - When sanding on a slab under an ice block, this will return the position of the slab.
+ * - When flying on top of a flower located under a grass block this will return the position of the corn flower.
+ *
+ * @return {@link Entity#getSupportingPos()} if not null or the entity's bottom most block
+ */
+ @NotNull
+ io.papermc.paper.math.BlockPosition getOnPos();
+
+ /**
+ * Gets the block that is currently supporting the entity.
+ * This takes into account the collisions of blocks under the entity.
+ * <p>
+ * Examples:
+ * - When sanding on a slab under an ice block, this will return the position of the slab.
+ * - When flying on top of a flower located under a grass block this will return null, because no block is holding your location.
+ *
+ * @return block position currently supporting the entity, or null if a block is currently not supporting the entity
+ */
+ @Nullable
+ io.papermc.paper.math.BlockPosition getSupportingPos();
+ // Paper end
}

View File

@ -0,0 +1,35 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Fri, 9 Jun 2023 22:49:38 -0400
Subject: [PATCH] Player standing on position API
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index ea056babe2f8123f20dc608d8a636da1de634b8c..146019c3021439d5738fe0b32cb05b28ad8ce78f 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -1442,4 +1442,24 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return !this.getHandle().level().noCollision(this.getHandle(), aabb);
}
// Paper End - Collision API
+ // Paper start - Player standing on position API
+ @Override
+ public io.papermc.paper.math.BlockPosition getBlockPosBelowThatAffectsMyMovement() {
+ net.minecraft.core.BlockPos blockPos = this.getHandle().getBlockPosBelowThatAffectsMyMovement();
+ return io.papermc.paper.math.Position.block(blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ }
+
+ @Override
+ public io.papermc.paper.math.BlockPosition getOnPos() {
+ net.minecraft.core.BlockPos blockPos = this.getHandle().getOnPos();
+ return io.papermc.paper.math.Position.block(blockPos.getX(), blockPos.getY(), blockPos.getZ());
+ }
+
+ @Override
+ public io.papermc.paper.math.BlockPosition getSupportingPos() {
+ return this.getHandle().mainSupportingBlockPos
+ .map((func) -> io.papermc.paper.math.Position.block(func.getX(), func.getY(), func.getZ()))
+ .orElse(null);
+ }
+ // Paper end - Player standing on position API
}