Files
AkarinMC/patches/server/0018-Remove-stream-and-simplify-operation-in-pathfinder.patch
Sotr 69537b0219 Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly

Paper Changes:
cfed00cf Fix Light Command
a6ff84ad Revert Nibble patch, causing issues still
f1a8eb7f Use a finalizer for light packet instead of onPacketDone
03c9bb05 Optimize NibbleArray to use pooled buffers
d0a528b1 Move delayed init down later in tick, improve accuracy of startup time
cc477e6a Force Plugins that use delayed tasks for init back in their place
597263fd Don't skip full player connection tick when dead
e2c23475 Revert loaded entity list (#3304)
fa87db6b Move another NetworkManager util into the inner class (#3303)
841c7d18 Make loaded entity list logic more consistent (#3301)
36f34f01 Updated Upstream (Bukkit/CraftBukkit)
5ca5f131 Rebuild all patches using the new rebuild pattern
1ccff6fa Add villager reputation API
5c0bfffa Speed up rebuilding patches and reduce diff
f37381ea Optimize Network Manager to not need synchronization
8f9df2ed Anti Xray cleanup
878c66f1 No-Tick view distance implementation - Closes #3196
b87743c1 Stop copy-on-write operations for updating light data
97a9c972 Optimize isOutsideRange to use distance maps
b4e629a2 Use distance map to optimise entity tracker / Misc Utils
d80d1517 Optimize Entity Ticking to Loaded Chunks only
31d7686d Add item slot helper methods for various inventories (#3221)
75e1e3b3 Mob Goal API
c7bc393a Revert "Don't flush packet queue off main thread"
1abd2bd2 Don't flush packet queue off main thread
a4ed58a9 Clean up Direct Memory Region Files Fix for different Java versions
55e35019 Set cap on JDK per-thread native byte buffer cache
b5101f4f Cleanup Region Files Direct Memory on close
81e655d7 Optimize Voxel Shape Merging
ed9fc11f Sync position on teleportation
9c326fce Nanothing to see here
3e9fc24b Attempt to fix FastLogin maybe
932e97f3 Rename to AsyncPlayerSendSuggestionsEvent to be consistent in naming
0dd19075 AsyncSendPlayerSuggestionsEvent Brigadier Event
a9e20e5f Fix being kicked in survival for block picking - Fixes #3277
4d20537e Expose game version (#3274)
85fb0015 Validate PickItem Packet and kick for invalid - Fixes #3256
5729bc71 Special case Keep Alive packets from Anti Xray
a76b7740 Improved oversized chunk data packet handling
a6f78170 Use Vanilla Bed Search for non players (Villagers)
68fb98b5 Fix 2 plugin specific issues with loot drop and pathfinders
6e41f7b7 Update Activation Range 2.0 with more villager controls
57dd3971 Updated Upstream (Bukkit/CraftBukkit)
a6a197b1 Bump API ASM version to follow server
5ab48ad9 Fix commodore (#3264)
87e7ee7e Improve Async Login to avoid firing in middle of Entity Ticking
8ce3dd5f [CI-SKIP] Fix Mojang API Brigadier dep - THIS IS NOT A NEW BUILD
00d760a5 Fix build due to spigot changing the build timestamp process
842e040c Updated Upstream (Bukkit/CraftBukkit/Spigot)
c03260a2 Add getter and setter for villager's numberOfRestocksToday (#3231)
fe366fbe null check tracker for entity metadata update - Fixes #3070
fdf41b74 Implement Brigadier Mojang API
e0ea2e0e Entity Activation Range 2.0! Major improvements to restoring behavior
10396d28 Fix Tracking Range mismatch on Vehicle/Passenger checks
68994c64 Add a config to turn off Optimized TickList #3145
d847d336 Improve blocking players from opening inventories while sleeping
ac4f6b50 Clean up Timings and Async Chunk Configs
fcf89e85 Improve mid tick chunk loading, Fix Oversleep, other improvements
ab36835c Improve random ticking behaviour - Fixes #3181
a6ac47e5 Fix numerous item duplication issues and teleport issues
b7402f11 Add phantom creative and insomniac controls (#3222)
75819fac Fix Potion#toItemStack swapping the extended and upgraded constructor values (#3216)
cb15cfa4 Improve Async Login so pending connections dont get exposed
f275e9cb Optimize Hoppers - Major Boost - Got2GoFast!
0106485c Improvements to watchdog changes
65934b1f Fix build for last commit. 5am commits are great
3f436029 Don't process watchdog until server has fully started and ticked.
938bd972 Don't fire BlockFade on worldgen threads - Fixes #3208
509a828e Fix loading spawn chunks when async chunks is off
8a91bfd2 Improvements to async login
bf698865 Revert "Re-track players that dismount from other players"
82b98418 Fix some issues with async login as well another source of sync loads
aa241d2b Allow multiple callbacks to schedule for Callback Executor
a2064a41 Add PlayerAttackEntityCooldownResetEvent This event is called when processing a player's attack on an entity right before their attack strength cd is reset, there are no existing events that fire within this period of time so it was impossible to capture the players attack strength via API prior to this commit.
f48d4299 Allow sleeping players to float
eeb2f67d Fix Bed respawn deviating too far from vanilla (#3195)
68a7b9fe Move player to spawn point if spawn in unloaded world
f29c7ebd Improve async login (#3189)
9fd36824 Fix Citizens Player NPC tracking issue - Fixes #3186
2020-05-08 17:57:09 +08:00

152 lines
6.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Wed, 15 Apr 2020 17:49:07 +0700
Subject: [PATCH] Remove stream and simplify operation in pathfinder
diff --git a/src/main/java/net/minecraft/server/PathDestination.java b/src/main/java/net/minecraft/server/PathDestination.java
index 9071d43d8b85a64a11566b2b535c3f6db65028f8..2f33aafe34d9cfd664abf006f8dbdf5cb981b692 100644
--- a/src/main/java/net/minecraft/server/PathDestination.java
+++ b/src/main/java/net/minecraft/server/PathDestination.java
@@ -5,6 +5,7 @@ public class PathDestination extends PathPoint {
private float m = Float.MAX_VALUE;
private PathPoint n;
private boolean o;
+ protected BlockPosition position; // Akarin - add BlockPosition
public PathDestination(PathPoint pathpoint) {
super(pathpoint.a, pathpoint.b, pathpoint.c);
diff --git a/src/main/java/net/minecraft/server/Pathfinder.java b/src/main/java/net/minecraft/server/Pathfinder.java
index 848e2fe8b84bfec5be332fd051512eda3838c108..379ee96b0801faaffc83c9f1b7473bc4b493bb6f 100644
--- a/src/main/java/net/minecraft/server/Pathfinder.java
+++ b/src/main/java/net/minecraft/server/Pathfinder.java
@@ -2,7 +2,9 @@ package net.minecraft.server;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -31,9 +33,20 @@ public class Pathfinder {
this.a.a();
this.e.a(chunkcache, entityinsentient);
PathPoint pathpoint = this.e.b();
+ // Akarin start - remove stream, add BlockPosition
+ /*
Map<PathDestination, BlockPosition> map = (Map) set.stream().collect(Collectors.toMap((blockposition) -> {
- return this.e.a((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
+ return this.e.a((double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ());
}, Function.identity()));
+ */
+ List<PathDestination> map = new java.util.ArrayList<PathDestination>(set.size());
+ for (BlockPosition position : set) {
+ PathDestination dest = this.e.a((double) position.getX(), position.getY(), position.getZ());
+ dest.position = position;
+
+ map.add(dest);
+ }
+ // Akarin end
PathEntity pathentity = this.a(pathpoint, map, f, i, f1);
this.e.a();
@@ -41,8 +54,8 @@ public class Pathfinder {
}
@Nullable
- private PathEntity a(PathPoint pathpoint, Map<PathDestination, BlockPosition> map, float f, int i, float f1) {
- Set<PathDestination> set = map.keySet();
+ private PathEntity a(PathPoint pathpoint, List<PathDestination> map, float f, int i, float f1) { // Akarin - Map -> List
+ List<PathDestination> set = map; // Akarin - Map -> List
pathpoint.e = 0.0F;
pathpoint.f = this.a(pathpoint, set);
@@ -53,6 +66,7 @@ public class Pathfinder {
int j = 0;
int k = (int) ((float) this.d * f1);
+ List<PathEntity> destinations = new java.util.ArrayList<PathEntity>(); // Akarin - remove stream
while (!this.a.e()) {
++j;
if (j >= k) {
@@ -62,12 +76,26 @@ public class Pathfinder {
PathPoint pathpoint1 = this.a.c();
pathpoint1.i = true;
+ // Akarin start - remove stream
+ /*
set.stream().filter((pathdestination) -> {
return pathpoint1.c((PathPoint) pathdestination) <= (float) i;
}).forEach(PathDestination::e);
if (set.stream().anyMatch(PathDestination::f)) {
break;
}
+ */
+ for (PathDestination dest : set) {
+ if (pathpoint1.c((PathPoint) dest) <= (float) i)
+ dest.e();
+
+ if (dest.f())
+ destinations.add(createPathEntityBy(dest.d(), dest.position, true)); // copied from below
+ }
+
+ if (!destinations.isEmpty())
+ break;
+ // Akarin end
if (pathpoint1.a(pathpoint) < f) {
int l = this.e.a(this.c, pathpoint1);
@@ -94,15 +122,17 @@ public class Pathfinder {
}
}
+ // Akarin start - remove stream
+ /*
Stream stream;
if (set.stream().anyMatch(PathDestination::f)) {
stream = set.stream().filter(PathDestination::f).map((pathdestination) -> {
- return this.a(pathdestination.d(), (BlockPosition) map.get(pathdestination), true);
+ return this.a(pathdestination.d(), (BlockPosition) pathdestination.position, true);
}).sorted(Comparator.comparingInt(PathEntity::e));
} else {
stream = set.stream().map((pathdestination) -> {
- return this.a(pathdestination.d(), (BlockPosition) map.get(pathdestination), false);
+ return this.a(pathdestination.d(), (BlockPosition) pathdestination.position, false);
}).sorted(Comparator.comparingDouble(PathEntity::l).thenComparingInt(PathEntity::e));
}
@@ -115,9 +145,21 @@ public class Pathfinder {
return pathentity;
}
+ */
+ if (!destinations.isEmpty()) {
+ Collections.sort(destinations, Comparator.comparingInt(PathEntity::e));
+ } else {
+ for (PathDestination dest : set)
+ destinations.add(createPathEntityBy(dest.d(), dest.position, false));
+
+ Collections.sort(destinations, Comparator.comparingDouble(PathEntity::l).thenComparingInt(PathEntity::e));
+ }
+
+ return destinations.get(0);
+ // Akarin end
}
- private float a(PathPoint pathpoint, Set<PathDestination> set) {
+ private float a(PathPoint pathpoint, List<PathDestination> set) { // Akarin - Set -> List
float f = Float.MAX_VALUE;
float f1;
@@ -132,6 +174,7 @@ public class Pathfinder {
return f;
}
+ private PathEntity createPathEntityBy(PathPoint pathpoint, BlockPosition blockposition, boolean flag) { return this.a(pathpoint, blockposition, flag); } // Akarin - OBFHELPER
private PathEntity a(PathPoint pathpoint, BlockPosition blockposition, boolean flag) {
List<PathPoint> list = Lists.newArrayList();
PathPoint pathpoint1 = pathpoint;