From 8ea84d096280a4b9be60273ecce9f8baf4606de9 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 10 Sep 2018 23:36:16 -0400 Subject: [PATCH] Prevent chunk loading from Fluid Flowing --- .../level/material/FlowingFluid.java.patch | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/level/material/FlowingFluid.java.patch b/paper-server/patches/sources/net/minecraft/world/level/material/FlowingFluid.java.patch index 69b2babecc..7170e45a34 100644 --- a/paper-server/patches/sources/net/minecraft/world/level/material/FlowingFluid.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/level/material/FlowingFluid.java.patch @@ -31,24 +31,58 @@ this.spreadTo(world, blockposition1, iblockdata1, Direction.DOWN, fluid2); if (this.sourceNeighborCount(world, fluidPos) >= 3) { this.spreadToSides(world, fluidPos, fluidState, blockState); -@@ -167,7 +184,16 @@ +@@ -167,8 +184,19 @@ Direction enumdirection = (Direction) entry.getKey(); FluidState fluid1 = (FluidState) entry.getValue(); BlockPos blockposition1 = pos.relative(enumdirection); -+ ++ final BlockState blockStateIfLoaded = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing ++ if (blockStateIfLoaded == null) continue; // Paper - Prevent chunk loading from fluid flowing + +- this.spreadTo(world, blockposition1, world.getBlockState(blockposition1), enumdirection, fluid1); + // CraftBukkit start + org.bukkit.block.Block source = CraftBlock.at(world, pos); + BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection)); + world.getCraftServer().getPluginManager().callEvent(event); - ++ + if (event.isCancelled()) { + continue; + } + // CraftBukkit end - this.spreadTo(world, blockposition1, world.getBlockState(blockposition1), enumdirection, fluid1); ++ this.spreadTo(world, blockposition1, blockStateIfLoaded, enumdirection, fluid1); // Paper - Prevent chunk loading from fluid flowing } -@@ -444,10 +470,24 @@ + } +@@ -183,7 +211,8 @@ + while (iterator.hasNext()) { + Direction enumdirection = (Direction) iterator.next(); + BlockPos.MutableBlockPos blockposition_mutableblockposition1 = blockposition_mutableblockposition.setWithOffset(pos, enumdirection); +- BlockState iblockdata1 = world.getBlockState(blockposition_mutableblockposition1); ++ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition_mutableblockposition1); // Paper - Prevent chunk loading from fluid flowing ++ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing + FluidState fluid = iblockdata1.getFluidState(); + + if (fluid.getType().isSame(this) && FlowingFluid.canPassThroughWall(enumdirection, world, pos, state, blockposition_mutableblockposition1, iblockdata1)) { +@@ -306,7 +335,8 @@ + + if (enumdirection1 != direction) { + BlockPos blockposition1 = pos.relative(enumdirection1); +- BlockState iblockdata1 = spreadCache.getBlockState(blockposition1); ++ BlockState iblockdata1 = spreadCache.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing ++ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing + FluidState fluid = iblockdata1.getFluidState(); + + if (this.canPassThrough(world, this.getFlowing(), pos, state, enumdirection1, blockposition1, iblockdata1, fluid)) { +@@ -372,7 +402,8 @@ + while (iterator.hasNext()) { + Direction enumdirection = (Direction) iterator.next(); + BlockPos blockposition1 = pos.relative(enumdirection); +- BlockState iblockdata1 = world.getBlockState(blockposition1); ++ BlockState iblockdata1 = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent chunk loading from fluid flowing ++ if (iblockdata1 == null) continue; // Paper - Prevent chunk loading from fluid flowing + FluidState fluid = iblockdata1.getFluidState(); + + if (this.canMaybePassThrough(world, pos, state, enumdirection, blockposition1, iblockdata1, fluid)) { +@@ -444,10 +475,24 @@ if (fluid1.isEmpty()) { fluidState = fluid1; blockState = Blocks.AIR.defaultBlockState(); @@ -73,3 +107,34 @@ world.setBlock(pos, blockState, 3); world.scheduleTick(pos, fluid1.getType(), i); } +@@ -524,12 +569,27 @@ + public BlockState getBlockState(BlockPos pos) { + return this.getBlockState(pos, this.getCacheKey(pos)); + } ++ // Paper start - Prevent chunk loading from fluid flowing ++ public @javax.annotation.Nullable BlockState getBlockStateIfLoaded(BlockPos pos) { ++ return this.getBlockState(pos, this.getCacheKey(pos), false); ++ } ++ // Paper end - Prevent chunk loading from fluid flowing + + private BlockState getBlockState(BlockPos pos, short packed) { +- return (BlockState) this.stateCache.computeIfAbsent(packed, (short1) -> { +- return this.level.getBlockState(pos); +- }); ++ // Paper start - Prevent chunk loading from fluid flowing ++ return getBlockState(pos, packed, true); + } ++ private @javax.annotation.Nullable BlockState getBlockState(BlockPos pos, short packed, boolean load) { ++ BlockState blockState = this.stateCache.get(packed); ++ if (blockState == null) { ++ blockState = load ? level.getBlockState(pos) : level.getBlockStateIfLoaded(pos); ++ if (blockState != null) { ++ this.stateCache.put(packed, blockState); ++ } ++ } ++ return blockState; ++ // Paper end - Prevent chunk loading from fluid flowing ++ } + + public boolean isHole(BlockPos pos) { + return this.holeCache.computeIfAbsent(this.getCacheKey(pos), (short0) -> {