mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-07 07:32:03 -07:00
Add BlockData setter for FallingBlock (#9829)
This commit is contained in:
108
patches/api/Expand-FallingBlock-API.patch
Normal file
108
patches/api/Expand-FallingBlock-API.patch
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
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
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/World.java
|
||||||
|
+++ b/src/main/java/org/bukkit/World.java
|
||||||
|
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||||
|
* @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
|
||||||
|
+ @Deprecated // Paper
|
||||||
|
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull MaterialData data) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||||
|
* @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
|
||||||
|
+ @org.jetbrains.annotations.ApiStatus.Obsolete // Paper
|
||||||
|
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull BlockData data) throws IllegalArgumentException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||||
|
* @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
|
||||||
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
|
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
|
||||||
|
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
|
||||||
|
@@ -0,0 +0,0 @@ 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.
|
||||||
|
@@ -0,0 +0,0 @@ public interface FallingBlock extends Entity {
|
||||||
|
default org.bukkit.Location getSourceLoc() {
|
||||||
|
return this.getOrigin();
|
||||||
|
}
|
||||||
|
+ // Paper Start - Auto expire setting
|
||||||
|
+ /**
|
||||||
|
+ * 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);
|
||||||
|
+ // Paper End - Auto expire setting
|
||||||
|
}
|
@@ -1,34 +0,0 @@
|
|||||||
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] FallingBlock auto expire setting
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/entity/FallingBlock.java b/src/main/java/org/bukkit/entity/FallingBlock.java
|
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
||||||
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
|
|
||||||
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
|
|
||||||
@@ -0,0 +0,0 @@ public interface FallingBlock extends Entity {
|
|
||||||
default org.bukkit.Location getSourceLoc() {
|
|
||||||
return this.getOrigin();
|
|
||||||
}
|
|
||||||
+ // Paper Start - Auto expire setting
|
|
||||||
+ /**
|
|
||||||
+ * 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);
|
|
||||||
+ // Paper End - Auto expire setting
|
|
||||||
}
|
|
@@ -295,17 +295,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||||||
+ //@Deprecated // Paper
|
+ //@Deprecated // Paper
|
||||||
public boolean refreshChunk(int x, int z);
|
public boolean refreshChunk(int x, int z);
|
||||||
|
|
||||||
/**
|
|
||||||
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
|
||||||
* @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 #spawnFallingBlock(Location, BlockData)}
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
+ @Deprecated // Paper
|
|
||||||
public FallingBlock spawnFallingBlock(@NotNull Location location, @NotNull MaterialData data) throws IllegalArgumentException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
@@ -0,0 +0,0 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
|
||||||
// Paper end - view distance api
|
// Paper end - view distance api
|
||||||
|
@@ -1,8 +1,16 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
||||||
Date: Sun, 5 Dec 2021 14:58:17 -0500
|
Date: Sun, 5 Dec 2021 14:58:17 -0500
|
||||||
Subject: [PATCH] FallingBlock auto expire setting
|
Subject: [PATCH] Expand FallingBlock API
|
||||||
|
|
||||||
|
- add auto expire setting
|
||||||
|
- add setter for block data
|
||||||
|
- add accessors for block state
|
||||||
|
|
||||||
|
== AT ==
|
||||||
|
public net.minecraft.world.entity.item.FallingBlockEntity blockState
|
||||||
|
|
||||||
|
Co-authored-by: Lukas Planz <lukas.planz@web.de>
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
@@ -49,6 +57,38 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
|
|||||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
|
||||||
|
@@ -0,0 +0,0 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
|
||||||
|
public BlockData getBlockData() {
|
||||||
|
return CraftBlockData.fromData(this.getHandle().getBlockState());
|
||||||
|
}
|
||||||
|
+ // Paper start
|
||||||
|
+ @Override
|
||||||
|
+ public void setBlockData(final BlockData blockData) {
|
||||||
|
+ Preconditions.checkArgument(blockData != null, "blockData");
|
||||||
|
+ final net.minecraft.world.level.block.state.BlockState oldState = this.getHandle().blockState, newState = ((CraftBlockData) blockData).getState();
|
||||||
|
+ this.getHandle().blockState = newState;
|
||||||
|
+ this.getHandle().blockData = null;
|
||||||
|
+
|
||||||
|
+ if (oldState != newState) this.update();
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public org.bukkit.block.BlockState getBlockState() {
|
||||||
|
+ return org.bukkit.craftbukkit.block.CraftBlockStates.getBlockState(this.getHandle().blockState, this.getHandle().blockData);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setBlockState(final org.bukkit.block.BlockState blockState) {
|
||||||
|
+ Preconditions.checkArgument(blockState != null, "blockState");
|
||||||
|
+ // Calls #update if needed, the block data compound tag is not synced with the client and hence can be mutated after the sync with clients.
|
||||||
|
+ // The call also clears any potential old block data.
|
||||||
|
+ this.setBlockData(blockState.getBlockData());
|
||||||
|
+ if (blockState instanceof final org.bukkit.craftbukkit.block.CraftBlockEntityState<?> tileEntity) this.getHandle().blockData = tileEntity.getSnapshotNBT();
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getDropItem() {
|
||||||
@@ -0,0 +0,0 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
|
@@ -0,0 +0,0 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
|
||||||
this.setHurtEntities(true);
|
this.setHurtEntities(true);
|
||||||
}
|
}
|
Reference in New Issue
Block a user