mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Prevent various interactions from causing chunk loads
Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
This commit is contained in:
parent
ca42ec8f4e
commit
54b44d1f1c
4 changed files with 81 additions and 10 deletions
|
@ -23,3 +23,33 @@
|
|||
world.removeBlock(blockposition1, false);
|
||||
if (!world.isClientSide) {
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
@@ -118,7 +127,9 @@
|
||||
|
||||
@Nullable
|
||||
private BlockPos getPosWithBlock(BlockPos pos, BlockGetter world) {
|
||||
- if (world.getBlockState(pos).is(this.blockToRemove)) {
|
||||
+ net.minecraft.world.level.block.state.BlockState block = world.getBlockStateIfLoaded(pos); // Paper - Prevent AI rules from loading chunks
|
||||
+ if (block == null) return null; // Paper - Prevent AI rules from loading chunks
|
||||
+ if (block.is(this.blockToRemove)) { // Paper - Prevent AI rules from loading chunks
|
||||
return pos;
|
||||
} else {
|
||||
BlockPos[] ablockposition = new BlockPos[]{pos.below(), pos.west(), pos.east(), pos.north(), pos.south(), pos.below().below()};
|
||||
@@ -128,7 +139,8 @@
|
||||
for (int j = 0; j < i; ++j) {
|
||||
BlockPos blockposition1 = ablockposition1[j];
|
||||
|
||||
- if (world.getBlockState(blockposition1).is(this.blockToRemove)) {
|
||||
+ net.minecraft.world.level.block.state.BlockState block2 = world.getBlockStateIfLoaded(blockposition1); // Paper - Prevent AI rules from loading chunks
|
||||
+ if (block2 != null && block2.is(this.blockToRemove)) { // Paper - Prevent AI rules from loading chunks
|
||||
return blockposition1;
|
||||
}
|
||||
}
|
||||
@@ -139,7 +151,7 @@
|
||||
|
||||
@Override
|
||||
protected boolean isValidTarget(LevelReader world, BlockPos pos) {
|
||||
- ChunkAccess ichunkaccess = world.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()), ChunkStatus.FULL, false);
|
||||
+ ChunkAccess ichunkaccess = world.getChunkIfLoadedImmediately(pos.getX() >> 4, pos.getZ() >> 4); // Paper - Prevent AI rules from loading chunks
|
||||
|
||||
return ichunkaccess == null ? false : ichunkaccess.getBlockState(pos).is(this.blockToRemove) && ichunkaccess.getBlockState(pos.above()).isAir() && ichunkaccess.getBlockState(pos.above(2)).isAir();
|
||||
}
|
||||
|
|
|
@ -86,7 +86,17 @@
|
|||
|
||||
return flag1;
|
||||
}
|
||||
@@ -465,9 +496,11 @@
|
||||
@@ -457,7 +488,8 @@
|
||||
int j = Mth.floor(this.enderman.getY() + randomsource.nextDouble() * 2.0D);
|
||||
int k = Mth.floor(this.enderman.getZ() - 1.0D + randomsource.nextDouble() * 2.0D);
|
||||
BlockPos blockposition = new BlockPos(i, j, k);
|
||||
- BlockState iblockdata = world.getBlockState(blockposition);
|
||||
+ BlockState iblockdata = world.getBlockStateIfLoaded(blockposition); // Paper - Prevent endermen from loading chunks
|
||||
+ if (iblockdata == null) return; // Paper - Prevent endermen from loading chunks
|
||||
BlockPos blockposition1 = blockposition.below();
|
||||
BlockState iblockdata1 = world.getBlockState(blockposition1);
|
||||
BlockState iblockdata2 = this.enderman.getCarriedBlock();
|
||||
@@ -465,9 +497,11 @@
|
||||
if (iblockdata2 != null) {
|
||||
iblockdata2 = Block.updateFromNeighbourShapes(iblockdata2, this.enderman.level(), blockposition);
|
||||
if (this.canPlaceBlock(world, blockposition, iblockdata2, iblockdata, iblockdata1, blockposition1)) {
|
||||
|
@ -98,7 +108,16 @@
|
|||
}
|
||||
|
||||
}
|
||||
@@ -506,9 +539,11 @@
|
||||
@@ -499,16 +533,19 @@
|
||||
int j = Mth.floor(this.enderman.getY() + randomsource.nextDouble() * 3.0D);
|
||||
int k = Mth.floor(this.enderman.getZ() - 2.0D + randomsource.nextDouble() * 4.0D);
|
||||
BlockPos blockposition = new BlockPos(i, j, k);
|
||||
- BlockState iblockdata = world.getBlockState(blockposition);
|
||||
+ BlockState iblockdata = world.getBlockStateIfLoaded(blockposition); // Paper - Prevent endermen from loading chunks
|
||||
+ if (iblockdata == null) return; // Paper - Prevent endermen from loading chunks
|
||||
Vec3 vec3d = new Vec3((double) this.enderman.getBlockX() + 0.5D, (double) j + 0.5D, (double) this.enderman.getBlockZ() + 0.5D);
|
||||
Vec3 vec3d1 = new Vec3((double) i + 0.5D, (double) j + 0.5D, (double) k + 0.5D);
|
||||
BlockHitResult movingobjectpositionblock = world.clip(new ClipContext(vec3d, vec3d1, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, this.enderman));
|
||||
boolean flag = movingobjectpositionblock.getBlockPos().equals(blockposition);
|
||||
|
||||
if (iblockdata.is(BlockTags.ENDERMAN_HOLDABLE) && flag) {
|
||||
|
@ -110,7 +129,7 @@
|
|||
}
|
||||
|
||||
}
|
||||
@@ -592,7 +627,7 @@
|
||||
@@ -592,7 +629,7 @@
|
||||
} else {
|
||||
if (this.target != null && !this.enderman.isPassenger()) {
|
||||
if (this.enderman.isBeingStaredBy((Player) this.target)) {
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
--- a/net/minecraft/world/item/component/LodestoneTracker.java
|
||||
+++ b/net/minecraft/world/item/component/LodestoneTracker.java
|
||||
@@ -29,7 +29,7 @@
|
||||
return this;
|
||||
} else {
|
||||
BlockPos blockPos = this.target.get().pos();
|
||||
- return world.isInWorldBounds(blockPos) && world.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)
|
||||
+ return world.isInWorldBounds(blockPos) && (!world.hasChunkAt(blockPos) || world.getPoiManager().existsAtPosition(PoiTypes.LODESTONE, blockPos)) // Paper - Prevent compass from loading chunks
|
||||
? this
|
||||
: new LodestoneTracker(Optional.empty(), true);
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
@@ -31,10 +32,19 @@
|
||||
@@ -31,11 +32,20 @@
|
||||
default <T extends BlockEntity> Optional<T> getBlockEntity(BlockPos pos, BlockEntityType<T> type) {
|
||||
BlockEntity tileentity = this.getBlockEntity(pos);
|
||||
|
||||
|
@ -19,28 +19,39 @@
|
|||
BlockState getBlockState(BlockPos pos);
|
||||
+ // Paper start - if loaded util
|
||||
+ @Nullable BlockState getBlockStateIfLoaded(BlockPos blockposition);
|
||||
+
|
||||
|
||||
+ default @Nullable Block getBlockIfLoaded(BlockPos blockposition) {
|
||||
+ BlockState type = this.getBlockStateIfLoaded(blockposition);
|
||||
+ return type == null ? null : type.getBlock();
|
||||
+ }
|
||||
+ @Nullable FluidState getFluidIfLoaded(BlockPos blockposition);
|
||||
+ // Paper end
|
||||
|
||||
+
|
||||
FluidState getFluidState(BlockPos pos);
|
||||
|
||||
@@ -59,8 +69,8 @@
|
||||
default int getLightEmission(BlockPos pos) {
|
||||
@@ -59,9 +69,17 @@
|
||||
});
|
||||
}
|
||||
|
||||
- default BlockHitResult clip(ClipContext context) {
|
||||
- return (BlockHitResult) BlockGetter.traverseBlocks(context.getFrom(), context.getTo(), context, (raytrace1, blockposition) -> {
|
||||
- BlockState iblockdata = this.getBlockState(blockposition);
|
||||
+ // CraftBukkit start - moved block handling into separate method for use by Block#rayTrace
|
||||
+ default BlockHitResult clip(ClipContext raytrace1, BlockPos blockposition) {
|
||||
BlockState iblockdata = this.getBlockState(blockposition);
|
||||
+ // Paper start - Prevent raytrace from loading chunks
|
||||
+ BlockState iblockdata = this.getBlockStateIfLoaded(blockposition);
|
||||
+ if (iblockdata == null) {
|
||||
+ // copied the last function parameter (listed below)
|
||||
+ Vec3 vec3d = raytrace1.getFrom().subtract(raytrace1.getTo());
|
||||
+
|
||||
+ return BlockHitResult.miss(raytrace1.getTo(), Direction.getApproximateNearest(vec3d.x, vec3d.y, vec3d.z), BlockPos.containing(raytrace1.getTo()));
|
||||
+ }
|
||||
+ // Paper end - Prevent raytrace from loading chunks
|
||||
FluidState fluid = this.getFluidState(blockposition);
|
||||
Vec3 vec3d = raytrace1.getFrom();
|
||||
@@ -73,6 +83,12 @@
|
||||
Vec3 vec3d1 = raytrace1.getTo();
|
||||
@@ -73,6 +91,12 @@
|
||||
double d1 = movingobjectpositionblock1 == null ? Double.MAX_VALUE : raytrace1.getFrom().distanceToSqr(movingobjectpositionblock1.getLocation());
|
||||
|
||||
return d0 <= d1 ? movingobjectpositionblock : movingobjectpositionblock1;
|
||||
|
@ -53,7 +64,7 @@
|
|||
}, (raytrace1) -> {
|
||||
Vec3 vec3d = raytrace1.getFrom().subtract(raytrace1.getTo());
|
||||
|
||||
@@ -145,7 +161,7 @@
|
||||
@@ -145,7 +169,7 @@
|
||||
double d13 = d10 * (i1 > 0 ? 1.0D - Mth.frac(d4) : Mth.frac(d4));
|
||||
double d14 = d11 * (j1 > 0 ? 1.0D - Mth.frac(d5) : Mth.frac(d5));
|
||||
|
||||
|
|
Loading…
Reference in a new issue