Create 0044-Rewrite-Pathfinder-to-not-use-Streams.patch

This commit is contained in:
tr7zw 2020-03-22 19:13:15 +01:00
parent 108b6efbec
commit 8ae1a4c13e

View File

@ -0,0 +1,92 @@
From 811ff3fa87f91169e19575a7c5327feaf77f838d Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
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<PathEntity> optional = Optional.ofNullable(lowest);
+ /*
Stream stream;
if (set.stream().anyMatch(PathDestination::f)) {
@@ -107,7 +147,9 @@ public class Pathfinder {
}
Optional<PathEntity> optional = stream.findFirst();
-
+ */
+ // YAPFA end
+
if (!optional.isPresent()) {
return null;
} else {
--
2.25.1.windows.1