13
0
geforkt von Mirrors/Paper

Prevent chunk loading from Fluid Flowing

Dieser Commit ist enthalten in:
Aikar 2018-09-10 23:36:16 -04:00
Ursprung fed1922643
Commit 8ea84d0962

Datei anzeigen

@ -31,24 +31,58 @@
this.spreadTo(world, blockposition1, iblockdata1, Direction.DOWN, fluid2); this.spreadTo(world, blockposition1, iblockdata1, Direction.DOWN, fluid2);
if (this.sourceNeighborCount(world, fluidPos) >= 3) { if (this.sourceNeighborCount(world, fluidPos) >= 3) {
this.spreadToSides(world, fluidPos, fluidState, blockState); this.spreadToSides(world, fluidPos, fluidState, blockState);
@@ -167,7 +184,16 @@ @@ -167,8 +184,19 @@
Direction enumdirection = (Direction) entry.getKey(); Direction enumdirection = (Direction) entry.getKey();
FluidState fluid1 = (FluidState) entry.getValue(); FluidState fluid1 = (FluidState) entry.getValue();
BlockPos blockposition1 = pos.relative(enumdirection); 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 + // CraftBukkit start
+ org.bukkit.block.Block source = CraftBlock.at(world, pos); + org.bukkit.block.Block source = CraftBlock.at(world, pos);
+ BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection)); + BlockFromToEvent event = new BlockFromToEvent(source, org.bukkit.craftbukkit.block.CraftBlock.notchToBlockFace(enumdirection));
+ world.getCraftServer().getPluginManager().callEvent(event); + world.getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ continue; + continue;
+ } + }
+ // CraftBukkit end + // 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()) { if (fluid1.isEmpty()) {
fluidState = fluid1; fluidState = fluid1;
blockState = Blocks.AIR.defaultBlockState(); blockState = Blocks.AIR.defaultBlockState();
@ -73,3 +107,34 @@
world.setBlock(pos, blockState, 3); world.setBlock(pos, blockState, 3);
world.scheduleTick(pos, fluid1.getType(), i); 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) -> {