2023-10-14 22:46:31 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 5 Dec 2021 14:58:55 -0500
Subject: [PATCH] Expand FallingBlock API
- add auto expire setting
- add setter for block data
- add accessors for block state
Co-authored-by: Lukas Planz <lukas.planz@web.de>
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
2024-06-04 21:40:18 +02:00
index 2272c52c28f5f14e1ea8891feec47b18733319d9..6eeb919f478dbe33c9994f2141e77216c7d7e174 100644
2023-10-14 22:46:31 +02:00
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
2024-04-23 19:02:08 +02:00
@@ -2282,8 +2282,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
2023-10-14 22:46:31 +02:00
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* MaterialData} are null or {@link Material} of the {@link MaterialData} is not a block
+ * @deprecated Use {@link #spawn(Location, Class, Consumer)} (or a variation thereof) in combination with {@link FallingBlock#setBlockData(BlockData)}
*/
@NotNull
2024-06-04 21:40:18 +02:00
+ @Deprecated(since = "1.20.2") // Paper
2023-10-14 22:46:31 +02:00
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull MaterialData data) throws IllegalArgumentException;
/**
2024-04-23 19:02:08 +02:00
@@ -2296,8 +2298,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
2023-10-14 22:46:31 +02:00
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* BlockData} are null
+ * @deprecated Use {@link #spawn(Location, Class, Consumer)} (or a variation thereof) in combination with {@link FallingBlock#setBlockData(BlockData)}
*/
@NotNull
2024-06-04 21:40:18 +02:00
+ @org.jetbrains.annotations.ApiStatus.Obsolete(since = "1.20.2") // Paper
2023-10-14 22:46:31 +02:00
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull BlockData data) throws IllegalArgumentException;
/**
2024-04-23 19:02:08 +02:00
@@ -2314,7 +2318,7 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
2023-10-14 22:46:31 +02:00
* @return The spawned {@link FallingBlock} instance
* @throws IllegalArgumentException if {@link Location} or {@link
* Material} are null or {@link Material} is not a block
- * @deprecated Magic value
+ * @deprecated Magic value. Use {@link #spawn(Location, Class, Consumer)} (or a variation thereof) in combination with {@link FallingBlock#setBlockData(BlockData)}
*/
@Deprecated
@NotNull
diff --git a/src/main/java/org/bukkit/entity/FallingBlock.java b/src/main/java/org/bukkit/entity/FallingBlock.java
2024-01-19 22:13:42 +01:00
index ae1ce2ee2deb82f3f4144ec54b3ba119b437c5e9..7904c716a3b0869ebf2f9b416536c59121a539a8 100644
2023-10-14 22:46:31 +02:00
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
@@ -26,6 +26,33 @@ public interface FallingBlock extends Entity {
*/
@NotNull
BlockData getBlockData();
+ // Paper start
+ /**
+ * Sets the data for the falling block.
+ * <br>
+ * Any potential additional data currently stored in the falling blocks {@link #getBlockState()} will be
+ * purged by calling this setter.
+ *
+ * @param blockData the data to use as the block
+ */
+ void setBlockData(@NotNull BlockData blockData);
+
+ /**
+ * Get the data of the falling block represented as a {@link org.bukkit.block.BlockState BlockState}
+ * which includes potential NBT data that gets applied when the block gets placed on landing.
+ *
+ * @return the BlockState representing this block
+ */
+ @NotNull
+ org.bukkit.block.BlockState getBlockState();
+
+ /**
+ * Sets the {@link BlockData} and possibly present tile entity data for the falling block.
+ *
+ * @param blockState the BlockState to use
+ */
+ void setBlockState(@NotNull org.bukkit.block.BlockState blockState);
+ // Paper end
/**
* Get if the falling block will break into an item if it cannot be placed.
@@ -137,4 +164,23 @@ public interface FallingBlock extends Entity {
default org.bukkit.Location getSourceLoc() {
return this.getOrigin();
}
2024-01-19 22:13:42 +01:00
+ // Paper start - Auto expire setting
2023-10-14 22:46:31 +02:00
+ /**
+ * Sets if this falling block should expire after:
+ * - 30 seconds
+ * - 5 seconds and is outside of the world
+ *
+ * @return if this behavior occurs
+ */
+ boolean doesAutoExpire();
+
+ /**
+ * Sets if this falling block should expire after:
+ * - 30 seconds
+ * - 5 seconds and is outside of the world
+ *
+ * @param autoExpires if this behavior should occur
+ */
+ void shouldAutoExpire(boolean autoExpires);
2024-01-19 22:13:42 +01:00
+ // Paper end - Auto expire setting
2023-10-14 22:46:31 +02:00
}