Paper/Spigot-Server-Patches/0453-Optimize-Collision-Chunk-lookup-and-avoid-loading-fa.patch
Aikar 36f34f01c0
Updated Upstream (Bukkit/CraftBukkit)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
da9ef3c5 #496: Add methods to get/set ItemStacks in EquipmentSlots
3abebc9f #492: Let Tameable extend Animals rather than Entity
941111a0 #495: Expose ItemStack and hand used in PlayerShearEntityEvent
4fe19cae #494: InventoryView - Add missing Brewing FUEL_TIME

CraftBukkit Changes:
933e9094 #664: Add methods to get/set ItemStacks in EquipmentSlots
18722312 #662: Expose ItemStack and hand used in PlayerShearEntityEvent
2020-05-06 06:05:22 -04:00

40 lines
2.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
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
index f851ed11df14fd9aa8017f44d82fb6cfc3bde345..d154487294b89d5a316929ed665c75d4dd3cfc6b 100644
--- 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);
+ // Paper start - ensure we don't load chunks
+ 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);