aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1008-Optimise-general-POI-access.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/1008-Optimise-general-POI-access.patch')
-rw-r--r--patches/server/1008-Optimise-general-POI-access.patch113
1 files changed, 60 insertions, 53 deletions
diff --git a/patches/server/1008-Optimise-general-POI-access.patch b/patches/server/1008-Optimise-general-POI-access.patch
index 9be40e9753..715dea7d5c 100644
--- a/patches/server/1008-Optimise-general-POI-access.patch
+++ b/patches/server/1008-Optimise-general-POI-access.patch
@@ -841,33 +841,38 @@ index 0000000000000000000000000000000000000000..69be1761b3b5ba7b496c1c10a4db897e
+ }
+}
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
-index a0799baca3ae05ef1ff818abfe6a53d28fd99246..abcc3ef59475ac170fd10b4dd4a4f3371faf17e0 100644
+index e8aa27547e3fa1a42720889c7038d4fb0273e7b5..e1b6fe9ecda25f86431baf414f1bfd3a26a8b2bd 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/AcquirePoi.java
-@@ -63,7 +63,11 @@ public class AcquirePoi {
- return true;
- }
- };
-- Set<Pair<Holder<PoiType>, BlockPos>> set = poiManager.findAllClosestFirstWithType(poiPredicate, predicate2, entity.blockPosition(), 48, PoiManager.Occupancy.HAS_SPACE).limit(5L).collect(Collectors.toSet());
-+ // Paper start - optimise POI access
-+ java.util.List<Pair<Holder<PoiType>, BlockPos>> poiposes = new java.util.ArrayList<>();
-+ io.papermc.paper.util.PoiAccess.findNearestPoiPositions(poiManager, poiPredicate, predicate2, entity.blockPosition(), 48, 48*48, PoiManager.Occupancy.HAS_SPACE, false, 5, poiposes);
-+ Set<Pair<Holder<PoiType>, BlockPos>> set = new java.util.HashSet<>(poiposes);
-+ // Paper end - optimise POI access
- Path path = findPathToPois(entity, set);
- if (path != null && path.canReach()) {
- BlockPos blockPos = path.getTarget();
+@@ -71,11 +71,11 @@ public class AcquirePoi {
+ return true;
+ }
+ };
+- Set<Pair<Holder<PoiType>, BlockPos>> set = poiManager.findAllClosestFirstWithType(
+- poiPredicate, predicate2, entity.blockPosition(), 48, PoiManager.Occupancy.HAS_SPACE
+- )
+- .limit(5L)
+- .collect(Collectors.toSet());
++ // Paper start - optimise POI access
++ java.util.List<Pair<Holder<PoiType>, BlockPos>> poiposes = new java.util.ArrayList<>();
++ io.papermc.paper.util.PoiAccess.findNearestPoiPositions(poiManager, poiPredicate, predicate2, entity.blockPosition(), 48, 48*48, PoiManager.Occupancy.HAS_SPACE, false, 5, poiposes);
++ Set<Pair<Holder<PoiType>, BlockPos>> set = new java.util.HashSet<>(poiposes);
++ // Paper end - optimise POI access
+ Path path = findPathToPois(entity, set);
+ if (path != null && path.canReach()) {
+ BlockPos blockPos = path.getTarget();
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
-index 33fbf72b440e0d164ecd4fb0fdec72e2394d0a1e..8db20db72cd51046213625fac46c35854c59ec5d 100644
+index d5a549f08b98c80a5cf0eef02cb8a389c32dfecb..92731b6b593289e9f583c9b705b219e81fcd8e73 100644
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/NearestBedSensor.java
-@@ -53,10 +53,12 @@ public class NearestBedSensor extends Sensor<Mob> {
+@@ -53,11 +53,12 @@ public class NearestBedSensor extends Sensor<Mob> {
return true;
}
};
-- Set<Pair<Holder<PoiType>, BlockPos>> set = poiManager.findAllWithType((holder) -> {
-- return holder.is(PoiTypes.HOME);
-- }, predicate, entity.blockPosition(), 48, PoiManager.Occupancy.ANY).collect(Collectors.toSet());
+- Set<Pair<Holder<PoiType>, BlockPos>> set = poiManager.findAllWithType(
+- holder -> holder.is(PoiTypes.HOME), predicate, entity.blockPosition(), 48, PoiManager.Occupancy.ANY
+- )
+- .collect(Collectors.toSet());
- Path path = AcquirePoi.findPathToPois(entity, set);
+ // Paper start - optimise POI access
+ java.util.List<Pair<Holder<PoiType>, BlockPos>> poiposes = new java.util.ArrayList<>();
@@ -879,13 +884,13 @@ index 33fbf72b440e0d164ecd4fb0fdec72e2394d0a1e..8db20db72cd51046213625fac46c3585
BlockPos blockPos = path.getTarget();
Optional<Holder<PoiType>> optional = poiManager.getType(blockPos);
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
-index 6f2c7baea0d1ac7813c7b85e1f5558573745762c..12a7aaeaa8b4b788b620b1985591c3b93253ccd5 100644
+index c07cc1bf3b98525d72924edee4233364fd8174d0..61a06706f1468a8d4cceb9fb2aae61cf56bd991d 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiManager.java
-@@ -127,43 +127,62 @@ public class PoiManager extends SectionStorage<PoiSection> {
- }
-
- public Optional<BlockPos> find(Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> posPredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
+@@ -124,36 +124,45 @@ public class PoiManager extends SectionStorage<PoiSection> {
+ public Optional<BlockPos> find(
+ Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> posPredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus
+ ) {
- return this.findAll(typePredicate, posPredicate, pos, radius, occupationStatus).findFirst();
+ // Paper start - re-route to faster logic
+ BlockPos ret = io.papermc.paper.util.PoiAccess.findAnyPoiPosition(this, typePredicate, posPredicate, pos, radius, occupationStatus, false);
@@ -894,21 +899,21 @@ index 6f2c7baea0d1ac7813c7b85e1f5558573745762c..12a7aaeaa8b4b788b620b1985591c3b9
}
public Optional<BlockPos> findClosest(Predicate<Holder<PoiType>> typePredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
-- return this.getInRange(typePredicate, pos, radius, occupationStatus).map(PoiRecord::getPos).min(Comparator.comparingDouble((blockPos2) -> {
-- return blockPos2.distSqr(pos);
-- }));
+- return this.getInRange(typePredicate, pos, radius, occupationStatus)
+- .map(PoiRecord::getPos)
+- .min(Comparator.comparingDouble(blockPos2 -> blockPos2.distSqr(pos)));
+ // Paper start - re-route to faster logic
+ BlockPos ret = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, null, pos, radius, radius * radius, occupationStatus, false);
+ return Optional.ofNullable(ret);
+ // Paper end - re-route to faster logic
}
- public Optional<Pair<Holder<PoiType>, BlockPos>> findClosestWithType(Predicate<Holder<PoiType>> typePredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
-- return this.getInRange(typePredicate, pos, radius, occupationStatus).min(Comparator.comparingDouble((poi) -> {
-- return poi.getPos().distSqr(pos);
-- })).map((poi) -> {
-- return Pair.of(poi.getPoiType(), poi.getPos());
-- });
+ public Optional<Pair<Holder<PoiType>, BlockPos>> findClosestWithType(
+ Predicate<Holder<PoiType>> typePredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus
+ ) {
+- return this.getInRange(typePredicate, pos, radius, occupationStatus)
+- .min(Comparator.comparingDouble(poi -> poi.getPos().distSqr(pos)))
+- .map(poi -> Pair.of(poi.getPoiType(), poi.getPos()));
+ // Paper start - re-route to faster logic
+ return Optional.ofNullable(io.papermc.paper.util.PoiAccess.findClosestPoiDataTypeAndPosition(
+ this, typePredicate, null, pos, radius, radius * radius, occupationStatus, false
@@ -916,10 +921,13 @@ index 6f2c7baea0d1ac7813c7b85e1f5558573745762c..12a7aaeaa8b4b788b620b1985591c3b9
+ // Paper end - re-route to faster logic
}
- public Optional<BlockPos> findClosest(Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> posPredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus) {
-- return this.getInRange(typePredicate, pos, radius, occupationStatus).map(PoiRecord::getPos).filter(posPredicate).min(Comparator.comparingDouble((blockPos2) -> {
-- return blockPos2.distSqr(pos);
-- }));
+ public Optional<BlockPos> findClosest(
+ Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> posPredicate, BlockPos pos, int radius, PoiManager.Occupancy occupationStatus
+ ) {
+- return this.getInRange(typePredicate, pos, radius, occupationStatus)
+- .map(PoiRecord::getPos)
+- .filter(posPredicate)
+- .min(Comparator.comparingDouble(blockPos2 -> blockPos2.distSqr(pos)));
+ // Paper start - re-route to faster logic
+ BlockPos ret = io.papermc.paper.util.PoiAccess.findClosestPoiDataPosition(this, typePredicate, posPredicate, pos, radius, radius * radius, occupationStatus, false);
+ return Optional.ofNullable(ret);
@@ -927,25 +935,24 @@ index 6f2c7baea0d1ac7813c7b85e1f5558573745762c..12a7aaeaa8b4b788b620b1985591c3b9
}
public Optional<BlockPos> take(Predicate<Holder<PoiType>> typePredicate, BiPredicate<Holder<PoiType>, BlockPos> biPredicate, BlockPos pos, int radius) {
-- return this.getInRange(typePredicate, pos, radius, PoiManager.Occupancy.HAS_SPACE).filter((poi) -> {
-- return biPredicate.test(poi.getPoiType(), poi.getPos());
-- }).findFirst().map((poi) -> {
+- return this.getInRange(typePredicate, pos, radius, PoiManager.Occupancy.HAS_SPACE)
+- .filter(poi -> biPredicate.test(poi.getPoiType(), poi.getPos()))
+- .findFirst()
+ // Paper start - re-route to faster logic
+ final @javax.annotation.Nullable PoiRecord closest = io.papermc.paper.util.PoiAccess.findClosestPoiDataRecord(
+ this, typePredicate, biPredicate, pos, radius, radius * radius, Occupancy.HAS_SPACE, false
+ );
-+ return Optional.ofNullable(closest).map(poi -> {
++ return Optional.ofNullable(closest)
+ // Paper end - re-route to faster logic
- poi.acquireTicket();
- return poi.getPos();
- });
- }
-
- public Optional<BlockPos> getRandom(Predicate<Holder<PoiType>> typePredicate, Predicate<BlockPos> positionPredicate, PoiManager.Occupancy occupationStatus, BlockPos pos, int radius, RandomSource random) {
+ .map(poi -> {
+ poi.acquireTicket();
+ return poi.getPos();
+@@ -168,8 +177,21 @@ public class PoiManager extends SectionStorage<PoiSection> {
+ int radius,
+ RandomSource random
+ ) {
- List<PoiRecord> list = Util.toShuffledList(this.getInRange(typePredicate, pos, radius, occupationStatus), random);
-- return list.stream().filter((poi) -> {
-- return positionPredicate.test(poi.getPos());
-- }).findFirst().map(PoiRecord::getPos);
+- return list.stream().filter(poi -> positionPredicate.test(poi.getPos())).findFirst().map(PoiRecord::getPos);
+ // Paper start - re-route to faster logic
+ List<PoiRecord> list = new java.util.ArrayList<>();
+ io.papermc.paper.util.PoiAccess.findAnyPoiRecords(
@@ -965,7 +972,7 @@ index 6f2c7baea0d1ac7813c7b85e1f5558573745762c..12a7aaeaa8b4b788b620b1985591c3b9
public boolean release(BlockPos pos) {
diff --git a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
-index 3fc17817906876e83f040f908b8b1ba6cfa37b8b..9f138bc471b5c2a4fa813ff943dbe34018b8df74 100644
+index f7d69dd83aad8e0ec1497441c61188bcf230865f..94404922304cfe23ea5fe8524387bc9b675cbc78 100644
--- a/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
+++ b/src/main/java/net/minecraft/world/entity/ai/village/poi/PoiSection.java
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
@@ -978,10 +985,10 @@ index 3fc17817906876e83f040f908b8b1ba6cfa37b8b..9f138bc471b5c2a4fa813ff943dbe340
private boolean isValid;
public final Optional<PoiSection> noAllocateOptional = Optional.of(this); // Paper - rewrite chunk system
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
-index 54db563d80bbabd87a2be6f5ead92b482ac07b10..4aac1979cf57300825a999c876fcf24d3170e68e 100644
+index bc6043a21227ce8c9c3879bc9c93c3803f79857b..4ac5024936987c15f927e3148af4bfa57228ad1e 100644
--- a/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/SectionStorage.java
-@@ -71,11 +71,11 @@ public class SectionStorage<R> extends RegionFileStorage implements AutoCloseabl
+@@ -79,11 +79,11 @@ public class SectionStorage<R> extends RegionFileStorage implements AutoCloseabl
}
@Nullable