3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00

Add BlockData setter for FallingBlock (#9829)

Dieser Commit ist enthalten in:
Md5Lukas 2023-10-14 22:46:31 +02:00 committet von GitHub
Ursprung e4d184f39d
Commit 3e1c5e3eb0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 158 neuen und 55 gelöschten Zeilen

Datei anzeigen

@ -282,7 +282,7 @@ index e455eb21abf121dc6ff10ff8a13dd06f67096a8f..bbc01e7c192ae6689c301670047ff114
return origin;
}
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index be5baaf499cc76dd737d6203570e3d431c18afcf..c748679337989a7b4e2a39e542268b7fd851ed91 100644
index be5baaf499cc76dd737d6203570e3d431c18afcf..399fe079035e4d38030d8ad930fbc89c69f251b0 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -415,9 +415,8 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@ -296,18 +296,7 @@ index be5baaf499cc76dd737d6203570e3d431c18afcf..c748679337989a7b4e2a39e542268b7f
public boolean refreshChunk(int x, int z);
/**
@@ -2130,8 +2129,10 @@ 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;
/**
@@ -3707,6 +3708,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3707,6 +3706,10 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
// Paper end - view distance api
// Spigot start
@ -318,7 +307,7 @@ index be5baaf499cc76dd737d6203570e3d431c18afcf..c748679337989a7b4e2a39e542268b7f
public class Spigot {
/**
@@ -3715,8 +3720,12 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3715,8 +3718,12 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @param loc The location to strike lightning
* @param isSilent Whether this strike makes no sound
* @return The lightning entity.
@ -331,7 +320,7 @@ index be5baaf499cc76dd737d6203570e3d431c18afcf..c748679337989a7b4e2a39e542268b7f
public LightningStrike strikeLightning(@NotNull Location loc, boolean isSilent) {
throw new UnsupportedOperationException("Not supported yet.");
}
@@ -3727,14 +3736,22 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3727,14 +3734,22 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
* @param loc The location to strike lightning
* @param isSilent Whether this strike makes no sound
* @return The lightning entity.

Datei anzeigen

@ -5,10 +5,10 @@ Subject: [PATCH] More World API
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index e9423c88ccc35a7c32e1dca970faf0ec452fcbba..b7a2ef57ed089ca750693a413c57bc80048b5608 100644
index ec94aa4967cb2dfc92d6b41d91b31125a1509cb9..768be78bd617c21b360cf1b650dcb2e8c481c084 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -3716,6 +3716,114 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@@ -3714,6 +3714,114 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@Nullable
StructureSearchResult locateNearestStructure(@NotNull Location origin, @NotNull Structure structure, int radius, boolean findUnexplored);

Datei anzeigen

@ -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 109acbccfa0e5bcd32889e1911798176d600a5fc..8d861f5522a33669f67b3e41dfbc5234637114b4 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -2241,8 +2241,10 @@ 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;
/**
@@ -2255,8 +2257,10 @@ 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;
/**
@@ -2273,7 +2277,7 @@ 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 ae1ce2ee2deb82f3f4144ec54b3ba119b437c5e9..a945e76dd61ef132ae3f3ee69635c927b1180523 100644
--- 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();
}
+ // 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
}

Datei anzeigen

@ -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 ae1ce2ee2deb82f3f4144ec54b3ba119b437c5e9..95e75f5a4ccdedd3b26f8639f37de9450ed63d6b 100644
--- a/src/main/java/org/bukkit/entity/FallingBlock.java
+++ b/src/main/java/org/bukkit/entity/FallingBlock.java
@@ -137,4 +137,23 @@ 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
}

Datei anzeigen

@ -1,11 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
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
index c64dcceabc41c11542b535d104b7f43172032842..9105418b29c89f092378da11b14e3d324332a2ba 100644
index 5164c2bfb32275beff01b6e76dfbd9d031231bc6..e6f75a9cac46c8e3ddba664a9d5b27b665a94cb4 100644
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -66,6 +66,7 @@ public class FallingBlockEntity extends Entity {
@ -46,10 +54,42 @@ index c64dcceabc41c11542b535d104b7f43172032842..9105418b29c89f092378da11b14e3d32
public void setHurtsEntities(float fallHurtAmount, int fallHurtMax) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
index e85a5dcae1a752c48dc457d05191355d72ca4443..a39694a27e362312eb42a29fd7c833f9c7437d46 100644
index e85a5dcae1a752c48dc457d05191355d72ca4443..a8bed9c1d129ac31486af8b65e26aa245920d6b5 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftFallingBlock.java
@@ -101,4 +101,15 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
@@ -33,6 +33,31 @@ 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() {
@@ -101,4 +126,15 @@ public class CraftFallingBlock extends CraftEntity implements FallingBlock {
this.setHurtEntities(true);
}
}