2020-04-21 22:06:30 +00:00
|
|
|
From a56120c2a391adb9f33f16ba182c59660359e064 Mon Sep 17 00:00:00 2001
|
2020-04-02 06:42:24 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Thu, 2 Apr 2020 02:37:57 -0400
|
|
|
|
Subject: [PATCH] Optimize Collision Chunk lookup and avoid loading far chunks
|
|
|
|
|
|
|
|
Try to use a faster chunk lookup for collision detection, and only
|
|
|
|
fall back to the original for nearby chunks.
|
|
|
|
|
|
|
|
The collision code takes an AABB and generates a cuboid of checks rather
|
|
|
|
than a cylinder, so at high velocity this can generate a lot of chunk checks.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ICollisionAccess.java b/src/main/java/net/minecraft/server/ICollisionAccess.java
|
2020-04-21 22:06:30 +00:00
|
|
|
index f851ed11..d1544872 100644
|
2020-04-02 06:42:24 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ICollisionAccess.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ICollisionAccess.java
|
|
|
|
@@ -83,15 +83,19 @@ public interface ICollisionAccess extends IBlockAccess {
|
|
|
|
}
|
|
|
|
|
|
|
|
while (cursorposition.a()) {
|
|
|
|
- int k1 = cursorposition.b();
|
|
|
|
- int l1 = cursorposition.c();
|
|
|
|
- int i2 = cursorposition.d();
|
|
|
|
+ int k1 = cursorposition.b();int x = k1; // Paper
|
|
|
|
+ int l1 = cursorposition.c();int y = l1; // Paper
|
|
|
|
+ int i2 = cursorposition.d();int z = i2; // Paper
|
|
|
|
int j2 = cursorposition.e();
|
|
|
|
|
|
|
|
if (j2 != 3) {
|
|
|
|
int k2 = k1 >> 4;
|
|
|
|
int l2 = i2 >> 4;
|
|
|
|
- IBlockAccess iblockaccess = ICollisionAccess.this.c(k2, l2);
|
2020-04-02 21:07:06 +00:00
|
|
|
+ // Paper start - ensure we don't load chunks
|
2020-04-02 06:42:24 +00:00
|
|
|
+ boolean far = entity != null && MCUtil.distance(entity.locX(), entity.locY(), entity.locZ(), x, y, z) > 32;
|
|
|
|
+ IBlockAccess iblockaccess = ICollisionAccess.this instanceof WorldServer ? ((WorldServer) ICollisionAccess.this).getChunkProvider().getChunkAtIfLoadedMainThread(k2, l2) : null;
|
|
|
|
+ if (!far && iblockaccess == null) iblockaccess = ICollisionAccess.this.c(k2, l2);
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
if (iblockaccess != null) {
|
|
|
|
blockposition_mutableblockposition.d(k1, l1, i2);
|
|
|
|
--
|
2020-04-21 22:06:30 +00:00
|
|
|
2.25.1.windows.1
|
2020-04-02 06:42:24 +00:00
|
|
|
|