From f88dfe3d5d70161a0030a5e33442ac0a4227a819 Mon Sep 17 00:00:00 2001 From: MC_XiaoHei Date: Wed, 28 Aug 2024 17:28:07 +0800 Subject: [PATCH] fix: fix maxDistanceSqr calc, remove debug --- ...058-Rewrite-nether-portal-find-logic.patch | 89 +++++-------------- ...d-debug-output-to-nether-portal-find.patch | 26 ------ 2 files changed, 24 insertions(+), 91 deletions(-) delete mode 100644 patches/server/0059-debug-add-debug-output-to-nether-portal-find.patch diff --git a/patches/server/0058-Rewrite-nether-portal-find-logic.patch b/patches/server/0058-Rewrite-nether-portal-find-logic.patch index 0a3cbb7..6a6f251 100644 --- a/patches/server/0058-Rewrite-nether-portal-find-logic.patch +++ b/patches/server/0058-Rewrite-nether-portal-find-logic.patch @@ -172,10 +172,10 @@ index 4739bdb828be18d9bec7ae2d6c6b332de879acee..8cb99bc8719165824e434023fbff8be1 } diff --git a/src/main/java/org/leavesmc/lumina/utils/LevelNetherPortalPoiManager.java b/src/main/java/org/leavesmc/lumina/utils/LevelNetherPortalPoiManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..ca0660d245d52eb6bc5f5e8f72a21f2e076b4082 +index 0000000000000000000000000000000000000000..8f495d1e149f3c49d88759c58df20213e99fc9d8 --- /dev/null +++ b/src/main/java/org/leavesmc/lumina/utils/LevelNetherPortalPoiManager.java -@@ -0,0 +1,264 @@ +@@ -0,0 +1,223 @@ +package org.leavesmc.lumina.utils; + +import io.papermc.paper.threadedregions.RegionizedServer; @@ -374,69 +374,28 @@ index 0000000000000000000000000000000000000000..ca0660d245d52eb6bc5f5e8f72a21f2e + } + + private int getMaxDistanceSqr(int n) { -+ return isNether ? netherMaxDistanceSqr[n - 1] : overworldMaxDistanceSqr[n - 1]; ++ if (n < 4) { ++ return n - 1; ++ } ++ if (isNether) { ++ return netherMaxDistanceSqrCache.computeIfAbsent(n, (i) -> 1 + pow(16 * (i - 3) + 1)); ++ } else { ++ return overworldMaxDistanceSqrCache.computeIfAbsent(n, (i) -> { ++ int k = i / 3; ++ return switch (i - 3 * k) { ++ case 0 -> 3 * pow(16 * (k - 1) + 1) - 1; ++ case 1 -> pow(16 * k + 1) + 2 * pow(16 * (k - 1) + 1) - 1; ++ case 2 -> 2 * pow(16 * k + 1) + 2 * pow(16 * (k - 1) + 1) - 1; ++ default -> throw new RuntimeException("WTF"); ++ }; ++ }); ++ } ++ } ++ ++ private int pow(int a) { ++ return a * a; + } + -+ private final int[] overworldMaxDistanceSqr = { -+ 0, -+ 1, -+ 2, -+ 290, -+ 578, -+ 866, -+ 1666, -+ 2466, -+ 3266, -+ 4578, -+ 5890, -+ 7202, -+ 9026, -+ 10850, -+ 12674, -+ 15010, -+ 17346, -+ 19682, -+ 22530, -+ 25378, -+ 28226, -+ 31586, -+ 34946, -+ 38306, -+ 42178, -+ 46050, -+ 49922, -+ 54306, -+ 58690, -+ 63074, -+ 67970, -+ 72866, -+ 77762, -+ 83170, -+ 88578, -+ 93986, -+ 99906, -+ 105826, -+ 111746, -+ 118178 -+ }; -+ private final int[] netherMaxDistanceSqr = { -+ 0, -+ 1, -+ 2, -+ 290, -+ 1090, -+ 2402, -+ 4226, -+ 6562, -+ 9410, -+ 12770, -+ 16642, -+ 21026, -+ 25922, -+ 31330, -+ 37250, -+ 43682, -+ 50626, -+ 58082 -+ }; ++ private final ConcurrentMap overworldMaxDistanceSqrCache = new ConcurrentHashMap<>(); ++ private final ConcurrentMap netherMaxDistanceSqrCache = new ConcurrentHashMap<>(); +} diff --git a/patches/server/0059-debug-add-debug-output-to-nether-portal-find.patch b/patches/server/0059-debug-add-debug-output-to-nether-portal-find.patch deleted file mode 100644 index b23a82a..0000000 --- a/patches/server/0059-debug-add-debug-output-to-nether-portal-find.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: MC_XiaoHei -Date: Wed, 28 Aug 2024 11:30:23 +0800 -Subject: [PATCH] debug: add debug output to nether portal find - - -diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 45eb414e4771ddff644d0231d819cb35b1130ca9..3b5a75a94971531f94ce76cfba85148aaa725a3b 100644 ---- a/src/main/java/net/minecraft/world/entity/Entity.java -+++ b/src/main/java/net/minecraft/world/entity/Entity.java -@@ -4392,12 +4392,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess - // Lumina start - rewrite nether portal find logic - BlockUtil.FoundRectangle portal = destination.netherPortalPoiManager.findClosestPortal(targetPos, destinationBorder); - if (portal == null) { -+ System.out.println("No exist data in ConcurrentData."); - portal = destination.getPortalForcer().findPortalAround(targetPos, destinationBorder, portalSearchRadius).orElse(null); - } - if (portal != null) { -+ System.out.println("End foundRectangle: { minCorner: " + portal.minCorner + ", axis1Size: " + portal.axis1Size + ", axis2Size: " + portal.axis2Size + " }"); - portalFound.complete(portal); - return; - } -+ System.out.println("Fallback to folia logic"); - // Lumina end - rewrite nether portal find logic - - // add tickets so that we can re-search for a portal once the chunks are loaded