mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-22 08:57:35 +01:00
Add API for ticking fluids (#10435)
* Add API for ticking fluids * update javadocs
This commit is contained in:
parent
9e886c4310
commit
3b078f822a
@ -5,10 +5,10 @@ Subject: [PATCH] Block Ticking API
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
|
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
|
||||||
index cf9600c743e977312c0a15c455d602391797ef34..38cf77e32b76bc7d9db7523f7f21427ebb72f913 100644
|
index cf9600c743e977312c0a15c455d602391797ef34..8a842840e1a2652a6356d4a56e4749a5ba36e902 100644
|
||||||
--- a/src/main/java/org/bukkit/block/Block.java
|
--- a/src/main/java/org/bukkit/block/Block.java
|
||||||
+++ b/src/main/java/org/bukkit/block/Block.java
|
+++ b/src/main/java/org/bukkit/block/Block.java
|
||||||
@@ -589,6 +589,21 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr
|
@@ -589,6 +589,41 @@ public interface Block extends Metadatable, Translatable, net.kyori.adventure.tr
|
||||||
* @return true if the block was destroyed
|
* @return true if the block was destroyed
|
||||||
*/
|
*/
|
||||||
boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect, boolean dropExperience);
|
boolean breakNaturally(@NotNull ItemStack tool, boolean triggerEffect, boolean dropExperience);
|
||||||
@ -17,14 +17,34 @@ index cf9600c743e977312c0a15c455d602391797ef34..38cf77e32b76bc7d9db7523f7f21427e
|
|||||||
+ * Causes the block to be ticked, this is different from {@link Block#randomTick()},
|
+ * Causes the block to be ticked, this is different from {@link Block#randomTick()},
|
||||||
+ * in that it is usually scheduled to occur, for example
|
+ * in that it is usually scheduled to occur, for example
|
||||||
+ * redstone components being activated, sand falling, etc.
|
+ * redstone components being activated, sand falling, etc.
|
||||||
|
+ * <p>
|
||||||
|
+ * This method may directly fire events relating to block ticking.
|
||||||
|
+ *
|
||||||
|
+ * @see #fluidTick()
|
||||||
+ */
|
+ */
|
||||||
+ void tick();
|
+ void tick();
|
||||||
+
|
+
|
||||||
+ /**
|
+ /**
|
||||||
|
+ * Causes the fluid to be ticked, this is different from {@link Block#randomTick()},
|
||||||
|
+ * in that it is usually scheduled to occur, for example
|
||||||
|
+ * causing waterlogged blocks to spread.
|
||||||
|
+ * <p>
|
||||||
|
+ * This method may directly fire events relating to fluid ticking.
|
||||||
|
+ *
|
||||||
|
+ * @see #tick()
|
||||||
|
+ */
|
||||||
|
+ void fluidTick();
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
+ * Causes the block to be ticked randomly.
|
+ * Causes the block to be ticked randomly.
|
||||||
+ * This has a chance to execute naturally if {@link BlockData#isRandomlyTicked()} is true.
|
+ * This has a chance to execute naturally if {@link BlockData#isRandomlyTicked()} is true.
|
||||||
+ * <p>
|
+ * <p>
|
||||||
+ * For certain blocks, this behavior may be the same as {@link Block#tick()}.
|
+ * For certain blocks, this behavior may be the same as {@link Block#tick()}.
|
||||||
|
+ * <p>
|
||||||
|
+ * This method may directly fire events relating to block random ticking.
|
||||||
|
+ *
|
||||||
|
+ * @see #tick()
|
||||||
|
+ * @see #fluidTick()
|
||||||
+ */
|
+ */
|
||||||
+ void randomTick();
|
+ void randomTick();
|
||||||
// Paper end
|
// Paper end
|
||||||
|
@ -5,28 +5,43 @@ Subject: [PATCH] Block Ticking API
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
index 6d10396347b69d9243ab902ecc68ede93fa17b7d..0a96b00a98227714ef99005e0a223765feae8fe9 100644
|
index 6d10396347b69d9243ab902ecc68ede93fa17b7d..af219df5267589300f0ad1d30fa5c81a1f50234f 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
@@ -709,5 +709,21 @@ public class CraftBlock implements Block {
|
@@ -78,6 +78,12 @@ public class CraftBlock implements Block {
|
||||||
|
return this.world.getBlockState(this.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ // Paper start
|
||||||
|
+ public net.minecraft.world.level.material.FluidState getNMSFluid() {
|
||||||
|
+ return this.world.getFluidState(this.position);
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
|
public BlockPos getPosition() {
|
||||||
|
return this.position;
|
||||||
|
}
|
||||||
|
@@ -709,5 +715,23 @@ public class CraftBlock implements Block {
|
||||||
public boolean isValidTool(ItemStack itemStack) {
|
public boolean isValidTool(ItemStack itemStack) {
|
||||||
return getDrops(itemStack).size() != 0;
|
return getDrops(itemStack).size() != 0;
|
||||||
}
|
}
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void tick() {
|
+ public void tick() {
|
||||||
+ net.minecraft.world.level.block.state.BlockState blockData = this.getNMS();
|
+ final ServerLevel level = this.world.getMinecraftWorld();
|
||||||
+ net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld();
|
+ this.getNMS().tick(level, this.position, level.random);
|
||||||
|
+ }
|
||||||
+
|
+
|
||||||
+ blockData.getBlock().tick(blockData, level, this.position, level.random);
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void fluidTick() {
|
||||||
|
+ this.getNMSFluid().tick(this.world.getMinecraftWorld(), this.position);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void randomTick() {
|
+ public void randomTick() {
|
||||||
+ net.minecraft.world.level.block.state.BlockState blockData = this.getNMS();
|
+ final ServerLevel level = this.world.getMinecraftWorld();
|
||||||
+ net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld();
|
+ this.getNMS().randomTick(level, this.position, level.random);
|
||||||
+
|
|
||||||
+ blockData.getBlock().randomTick(blockData, level, this.position, level.random);
|
|
||||||
+ }
|
+ }
|
||||||
// Paper end
|
// Paper end
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,10 @@ index 83e6e3286d04c39d6d7ba496251aec962621f72e..3ff0d08e4964aae82d8e51d3b8bf9aa0
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
index 0a96b00a98227714ef99005e0a223765feae8fe9..e5506a7d074a9f89d41f4d5d7549a458779bef20 100644
|
index af219df5267589300f0ad1d30fa5c81a1f50234f..461a66c323a74db5a70981fafc5fa20f54f0f40d 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
@@ -566,6 +566,7 @@ public class CraftBlock implements Block {
|
@@ -572,6 +572,7 @@ public class CraftBlock implements Block {
|
||||||
if (!event.isCancelled()) {
|
if (!event.isCancelled()) {
|
||||||
for (BlockState blockstate : blocks) {
|
for (BlockState blockstate : blocks) {
|
||||||
blockstate.update(true);
|
blockstate.update(true);
|
||||||
|
@ -80,10 +80,10 @@ index e57e3a26b0fb856e1ab693df5783fe8b9bee9719..64300077fce6eb28b6bddd42b3467eaa
|
|||||||
|
|
||||||
public List<ItemStack> getDrops(LootParams.Builder builder) {
|
public List<ItemStack> getDrops(LootParams.Builder builder) {
|
||||||
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
index e5506a7d074a9f89d41f4d5d7549a458779bef20..4b42ef2a876ea210d948238e63fd7a2b7035bb5b 100644
|
index 461a66c323a74db5a70981fafc5fa20f54f0f40d..ac11f18690434922179b61ffcc3036dea025b0cb 100644
|
||||||
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
||||||
@@ -503,7 +503,7 @@ public class CraftBlock implements Block {
|
@@ -509,7 +509,7 @@ public class CraftBlock implements Block {
|
||||||
|
|
||||||
// Modelled off EntityHuman#hasBlock
|
// Modelled off EntityHuman#hasBlock
|
||||||
if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) {
|
if (block != Blocks.AIR && (item == null || !iblockdata.requiresCorrectToolForDrops() || nmsItem.isCorrectToolForDrops(iblockdata))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user