From dae847397d4aebf7f05ff33445070cdb4dd17a41 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 67c63cfe33..b0fa7dbf71 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