From 8ae1a4c13e9677a99e841316813b6bb1c7573a5d Mon Sep 17 00:00:00 2001 From: tr7zw Date: Sun, 22 Mar 2020 19:13:15 +0100 Subject: [PATCH] Create 0044-Rewrite-Pathfinder-to-not-use-Streams.patch --- ...ewrite-Pathfinder-to-not-use-Streams.patch | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 patches/server/0044-Rewrite-Pathfinder-to-not-use-Streams.patch diff --git a/patches/server/0044-Rewrite-Pathfinder-to-not-use-Streams.patch b/patches/server/0044-Rewrite-Pathfinder-to-not-use-Streams.patch new file mode 100644 index 00000000..18f04fe3 --- /dev/null +++ b/patches/server/0044-Rewrite-Pathfinder-to-not-use-Streams.patch @@ -0,0 +1,92 @@ +From 811ff3fa87f91169e19575a7c5327feaf77f838d Mon Sep 17 00:00:00 2001 +From: tr7zw +Date: Sun, 22 Mar 2020 19:12:07 +0100 +Subject: [PATCH] Rewrite Pathfinder to not use Streams + +--- + .../java/net/minecraft/server/Pathfinder.java | 48 +++++++++++++++++-- + 1 file changed, 45 insertions(+), 3 deletions(-) + +diff --git a/src/main/java/net/minecraft/server/Pathfinder.java b/src/main/java/net/minecraft/server/Pathfinder.java +index 67c63cfe3..b0fa7dbf7 100644 +--- a/src/main/java/net/minecraft/server/Pathfinder.java ++++ b/src/main/java/net/minecraft/server/Pathfinder.java +@@ -2,7 +2,6 @@ package net.minecraft.server; + + import com.google.common.collect.Lists; + import com.google.common.collect.Sets; +-import java.util.Comparator; + import java.util.Iterator; + import java.util.List; + import java.util.Map; +@@ -10,7 +9,6 @@ import java.util.Optional; + import java.util.Set; + import java.util.function.Function; + import java.util.stream.Collectors; +-import java.util.stream.Stream; + import javax.annotation.Nullable; + + public class Pathfinder { +@@ -94,6 +92,48 @@ public class Pathfinder { + } + } + ++ // YAPFA start ++ ++ boolean anyMatch = false; ++ for(PathDestination path : set) { ++ if(path.f()) { ++ anyMatch = true; ++ break; ++ } ++ } ++ PathEntity lowest = null; ++ if(anyMatch) { ++ for(PathDestination path : set) { ++ if(path.f()) { ++ if(lowest == null) { ++ lowest = this.a(path.d(), (BlockPosition) map.get(path), true); ++ }else { ++ PathEntity dest = this.a(path.d(), (BlockPosition) map.get(path), true); ++ if(dest.e() < lowest.e()) { ++ lowest = dest; ++ } ++ } ++ } ++ } ++ } else { ++ for(PathDestination path : set) { ++ if(path.f()) { ++ if(lowest == null) { ++ lowest = this.a(path.d(), (BlockPosition) map.get(path), false); ++ }else { ++ PathEntity dest = this.a(path.d(), (BlockPosition) map.get(path), false); ++ if(dest.l() < lowest.l()) { ++ lowest = dest; ++ }else if(dest.l() == lowest.l() && dest.e() < lowest.e()) { ++ lowest = dest; ++ } ++ } ++ } ++ } ++ } ++ ++ Optional optional = Optional.ofNullable(lowest); ++ /* + Stream stream; + + if (set.stream().anyMatch(PathDestination::f)) { +@@ -107,7 +147,9 @@ public class Pathfinder { + } + + Optional optional = stream.findFirst(); +- ++ */ ++ // YAPFA end ++ + if (!optional.isPresent()) { + return null; + } else { +-- +2.25.1.windows.1 +