13
0
geforkt von Mirrors/Paper

Add API for ticking fluids (#10435)

* Add API for ticking fluids

* update javadocs
Dieser Commit ist enthalten in:
Jake Potrebic 2024-04-19 13:03:32 -07:00
Ursprung 07e8f74355
Commit bdfe4c21f6
2 geänderte Dateien mit 42 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -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.
+ * <p>
+ * 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.
+ * <p>
+ * 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.
+ * <p>
+ * 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();
// Paper end

Datei anzeigen

@ -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
}