From bdfe4c21f633df7be2f6f9148f698272c78297f2 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 19 Apr 2024 13:03:32 -0700 Subject: [PATCH] Add API for ticking fluids (#10435) * Add API for ticking fluids * update javadocs --- patches/api/Block-Ticking-API.patch | 20 ++++++++++++++++++ patches/server/Block-Ticking-API.patch | 29 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/patches/api/Block-Ticking-API.patch b/patches/api/Block-Ticking-API.patch index ec40b4ec81..7b9db3daba 100644 --- a/patches/api/Block-Ticking-API.patch +++ b/patches/api/Block-Ticking-API.patch @@ -17,14 +17,34 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Causes the block to be ticked, this is different from {@link Block#randomTick()}, + * in that it is usually scheduled to occur, for example + * redstone components being activated, sand falling, etc. ++ *

++ * This method may directly fire events relating to block ticking. ++ * ++ * @see #fluidTick() + */ + 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. ++ *

++ * This method may directly fire events relating to fluid ticking. ++ * ++ * @see #tick() ++ */ ++ void fluidTick(); ++ ++ /** + * Causes the block to be ticked randomly. + * This has a chance to execute naturally if {@link BlockData#isRandomlyTicked()} is true. + *

+ * For certain blocks, this behavior may be the same as {@link Block#tick()}. ++ *

++ * This method may directly fire events relating to block random ticking. ++ * ++ * @see #tick() ++ * @see #fluidTick() + */ + void randomTick(); // Paper end diff --git a/patches/server/Block-Ticking-API.patch b/patches/server/Block-Ticking-API.patch index 2e064734ba..f070bfa210 100644 --- a/patches/server/Block-Ticking-API.patch +++ b/patches/server/Block-Ticking-API.patch @@ -8,6 +8,19 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/ma index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +@@ -0,0 +0,0 @@ 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; + } @@ -0,0 +0,0 @@ public class CraftBlock implements Block { public boolean isValidTool(ItemStack itemStack) { return getDrops(itemStack).size() != 0; @@ -15,18 +28,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public void tick() { -+ net.minecraft.world.level.block.state.BlockState blockData = this.getNMS(); -+ net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld(); ++ final 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 + public void randomTick() { -+ net.minecraft.world.level.block.state.BlockState blockData = this.getNMS(); -+ net.minecraft.server.level.ServerLevel level = this.world.getMinecraftWorld(); -+ -+ blockData.getBlock().randomTick(blockData, level, this.position, level.random); ++ final ServerLevel level = this.world.getMinecraftWorld(); ++ this.getNMS().randomTick(level, this.position, level.random); + } // Paper end }