aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0283-Prevent-rayTrace-from-loading-chunks.patch
blob: 695829c82bf1a9d76e562af0b6286b8de75ca846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 26 Nov 2018 19:21:58 -0500
Subject: [PATCH] Prevent rayTrace from loading chunks

ray tracing into an unloaded chunk should be treated as a miss
this saves a ton of lag for when AI tries to raytrace near unloaded chunks.

diff --git a/src/main/java/net/minecraft/world/level/BlockGetter.java b/src/main/java/net/minecraft/world/level/BlockGetter.java
index d6d8bbc98fc71997cb52521d59ebb59d727d3c22..89aadd30c1973cf45c5c05fd12462e04b0b05c97 100644
--- a/src/main/java/net/minecraft/world/level/BlockGetter.java
+++ b/src/main/java/net/minecraft/world/level/BlockGetter.java
@@ -70,7 +70,15 @@ public interface BlockGetter extends LevelHeightAccessor {
 
     // 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.getNearest(vec3d.x, vec3d.y, vec3d.z), BlockPos.containing(raytrace1.getTo()));
+            }
+            // Paper end
             FluidState fluid = this.getFluidState(blockposition);
             Vec3 vec3d = raytrace1.getFrom();
             Vec3 vec3d1 = raytrace1.getTo();