Add two Akarin patches

This commit is contained in:
tr7zw 2020-04-21 14:25:04 +02:00
parent e332a17d5b
commit 026b294dac
3 changed files with 251 additions and 62 deletions

View File

@ -1,4 +1,4 @@
From c30286683a3515cf85f0f6c31d02053720b5b6ea Mon Sep 17 00:00:00 2001
From af238121798ee5b64ad6daa1c3d24d9bb7aa0a61 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Mon, 23 Mar 2020 18:20:58 +0100
Subject: [PATCH] Remove Stream usage
@ -6,14 +6,13 @@ Subject: [PATCH] Remove Stream usage
This removes streams from the entity collision code, Crafting Manager and some other useless places.
---
.../yapfa/collision/CollisionHelper.java | 123 +++++++++++++++
.../server/BehaviorInteractDoor.java | 27 +++-
src/main/java/net/minecraft/server/Block.java | 2 +-
.../net/minecraft/server/BlockPosition.java | 2 +-
.../net/minecraft/server/CraftingManager.java | 58 +++++--
.../java/net/minecraft/server/Entity.java | 145 ++++++++++++++++--
.../net/minecraft/server/EntityLiving.java | 1 +
.../net/minecraft/server/VoxelShapes.java | 103 +++++++++++++
8 files changed, 425 insertions(+), 36 deletions(-)
7 files changed, 400 insertions(+), 34 deletions(-)
create mode 100644 src/main/java/de/tr7zw/yapfa/collision/CollisionHelper.java
diff --git a/src/main/java/de/tr7zw/yapfa/collision/CollisionHelper.java b/src/main/java/de/tr7zw/yapfa/collision/CollisionHelper.java
@ -145,65 +144,6 @@ index 0000000000..d67753937f
+ }
+
+}
diff --git a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
index 01d9c2d92c..8c8be194e7 100644
--- a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
+++ b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
@@ -2,6 +2,9 @@ package net.minecraft.server;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
+
+import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -19,9 +22,16 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
BehaviorController<?> behaviorcontroller = entityliving.getBehaviorController();
PathEntity pathentity = (PathEntity) behaviorcontroller.getMemory(MemoryModuleType.PATH).get();
List<GlobalPos> list = (List) behaviorcontroller.getMemory(MemoryModuleType.INTERACTABLE_DOORS).get();
+ // YAPFA start
+ List<BlockPosition> list1 = new ArrayList<BlockPosition>();
+ for(PathPoint pathpoint : pathentity.d()) {
+ list1.add(new BlockPosition(pathpoint.a, pathpoint.b, pathpoint.c));
+ }
+ /*
List<BlockPosition> list1 = (List) pathentity.d().stream().map((pathpoint) -> {
return new BlockPosition(pathpoint.a, pathpoint.b, pathpoint.c);
}).collect(Collectors.toList());
+ */ // YAPFA end
Set<BlockPosition> set = this.a(worldserver, list, list1);
int j = pathentity.f() - 1;
@@ -29,12 +39,25 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
}
private Set<BlockPosition> a(WorldServer worldserver, List<GlobalPos> list, List<BlockPosition> list1) {
- Stream stream = list.stream().filter((globalpos) -> {
+ // YAPFA start
+ Set<BlockPosition> positions = new HashSet<BlockPosition>();
+ for(GlobalPos globalpos : list) {
+ if(globalpos.getDimensionManager() == worldserver.getWorldProvider().getDimensionManager()) {
+ BlockPosition pos = globalpos.getBlockPosition();
+ if(list1.contains(pos)) {
+ positions.add(pos);
+ }
+ }
+ }
+ return positions;
+ /*
+ Stream stream = list.stream().filter((globalpos) -> {
return globalpos.getDimensionManager() == worldserver.getWorldProvider().getDimensionManager();
}).map(GlobalPos::getBlockPosition);
-
+
list1.getClass();
return (Set) stream.filter(list1::contains).collect(Collectors.toSet());
+ */ // YAPFA end
}
private void a(WorldServer worldserver, List<BlockPosition> list, Set<BlockPosition> set, int i, EntityLiving entityliving, BehaviorController<?> behaviorcontroller) {
diff --git a/src/main/java/net/minecraft/server/Block.java b/src/main/java/net/minecraft/server/Block.java
index e40375b67a..2a5574be3a 100644
--- a/src/main/java/net/minecraft/server/Block.java

View File

@ -0,0 +1,79 @@
From 9394f4829c1f1787ffd500b09d49c359887e7485 Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Wed, 15 Apr 2020 04:28:25 +0700
Subject: [PATCH] Akarin Cache hashcode for BlockPosition
---
.../net/minecraft/server/BaseBlockPosition.java | 15 ++++++++++++++-
.../java/net/minecraft/server/BlockPosition.java | 4 ++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/src/main/java/net/minecraft/server/BaseBlockPosition.java b/src/main/java/net/minecraft/server/BaseBlockPosition.java
index c439a8d019..cc18560431 100644
--- a/src/main/java/net/minecraft/server/BaseBlockPosition.java
+++ b/src/main/java/net/minecraft/server/BaseBlockPosition.java
@@ -18,6 +18,7 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
return y < 0 || y >= 256;
}
// Paper end
+ protected int hash; // Akarin - cache hashcode
public BaseBlockPosition(int i, int j, int k) {
this.x = i;
@@ -42,8 +43,20 @@ public class BaseBlockPosition implements Comparable<BaseBlockPosition> {
}
public int hashCode() {
- return (this.getY() + this.getZ() * 31) * 31 + this.getX();
+ // Akarin start - cache hashcode
+ int result = hash; // Make the situation not too bad when it is modified by multiple threads
+ if (result == 0) {
+ result = (this.getY() + this.getZ() * 31) * 31 + this.getX();
+ hash = result;
+ }
+ return result;
+ // return (this.getY() + this.getZ() * 31) * 31 + this.getX();
+ }
+
+ public void recalcHashCode() {
+ hash = 0;
}
+ // Akarin end
public int compareTo(BaseBlockPosition baseblockposition) {
return this.getY() == baseblockposition.getY() ? (this.getZ() == baseblockposition.getZ() ? this.getX() - baseblockposition.getX() : this.getZ() - baseblockposition.getZ()) : this.getY() - baseblockposition.getY();
diff --git a/src/main/java/net/minecraft/server/BlockPosition.java b/src/main/java/net/minecraft/server/BlockPosition.java
index 51a5741846..3a2983f411 100644
--- a/src/main/java/net/minecraft/server/BlockPosition.java
+++ b/src/main/java/net/minecraft/server/BlockPosition.java
@@ -439,6 +439,7 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
this.y = j;
this.z = k;
// Paper end
+ this.recalcHashCode(); // Akarin - cache hashcode
return this;
}
@@ -479,16 +480,19 @@ public class BlockPosition extends BaseBlockPosition implements MinecraftSeriali
public final void setX(final int x) { this.o(x); } // Paper - OBFHELPER
public void o(int i) {
this.x = i; // Paper change to x
+ this.recalcHashCode(); // Akarin - cache hashcode
}
public final void setY(final int y) { this.p(y); } // Paper - OBFHELPER
public void p(int i) {
this.y = i; // Paper change to y
+ this.recalcHashCode(); // Akarin - cache hashcode
}
public final void setZ(final int z) { this.q(z); } // Paper - OBFHELPER
public void q(int i) {
this.z = i; // Paper change to z
+ this.recalcHashCode(); // Akarin - cache hashcode
}
@Override
--
2.25.1.windows.1

View File

@ -0,0 +1,170 @@
From a0b270da01695d6c3b1368d6c3ce7fdf884aba2a Mon Sep 17 00:00:00 2001
From: Sotr <i@omc.hk>
Date: Wed, 15 Apr 2020 03:51:50 +0700
Subject: [PATCH] Akarin Optimize door interact with pathfinding
---
.../akarin/server/IndexedBlockPosition.java | 35 +++++++++++++
.../server/BehaviorInteractDoor.java | 49 ++++++++++++++++---
.../net/minecraft/server/BehaviorSleep.java | 2 +-
3 files changed, 77 insertions(+), 9 deletions(-)
create mode 100644 src/main/java/io/akarin/server/IndexedBlockPosition.java
diff --git a/src/main/java/io/akarin/server/IndexedBlockPosition.java b/src/main/java/io/akarin/server/IndexedBlockPosition.java
new file mode 100644
index 0000000000..83bf1d4cab
--- /dev/null
+++ b/src/main/java/io/akarin/server/IndexedBlockPosition.java
@@ -0,0 +1,35 @@
+package io.akarin.server;
+
+import net.minecraft.server.BlockPosition;
+
+public class IndexedBlockPosition {
+ private final int index;
+ private final BlockPosition position;
+
+ public IndexedBlockPosition(int index, BlockPosition position) {
+ this.index = index;
+ this.position = position;
+ }
+
+ public static IndexedBlockPosition of(int index, BlockPosition position) {
+ return new IndexedBlockPosition(index, position);
+ }
+
+ public int index() {
+ return index;
+ }
+
+ public BlockPosition get() {
+ return position;
+ }
+
+ @Override
+ public int hashCode() {
+ return position.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return position.equals(obj);
+ }
+}
diff --git a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
index 01d9c2d92c..3db22c5f4d 100644
--- a/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
+++ b/src/main/java/net/minecraft/server/BehaviorInteractDoor.java
@@ -1,7 +1,9 @@
package net.minecraft.server;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import io.akarin.server.IndexedBlockPosition;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -19,32 +21,63 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
BehaviorController<?> behaviorcontroller = entityliving.getBehaviorController();
PathEntity pathentity = (PathEntity) behaviorcontroller.getMemory(MemoryModuleType.PATH).get();
List<GlobalPos> list = (List) behaviorcontroller.getMemory(MemoryModuleType.INTERACTABLE_DOORS).get();
+ // Akarin start - remove stream
+ /*
List<BlockPosition> list1 = (List) pathentity.d().stream().map((pathpoint) -> {
return new BlockPosition(pathpoint.a, pathpoint.b, pathpoint.c);
}).collect(Collectors.toList());
- Set<BlockPosition> set = this.a(worldserver, list, list1);
+ */
+
+ List<PathPoint> points = pathentity.getPoints();
+ java.util.Map<BlockPosition, Integer> list1 = new java.util.HashMap<BlockPosition, Integer>(points.size());
+ for (int index = 0; index < points.size(); index++) {
+ PathPoint point = points.get(index);
+ list1.put(new BlockPosition(point.a, point.b, point.c), index);
+ }
+
+ // Akarin end
+ Set<io.akarin.server.IndexedBlockPosition> set = this.a(worldserver, list, list1); // Akarin - IndexedBlockPosition
int j = pathentity.f() - 1;
this.a(worldserver, list1, set, j, entityliving, behaviorcontroller);
}
- private Set<BlockPosition> a(WorldServer worldserver, List<GlobalPos> list, List<BlockPosition> list1) {
+ private Set<io.akarin.server.IndexedBlockPosition> a(WorldServer worldserver, List<GlobalPos> list, java.util.Map<BlockPosition, Integer> list1) { // Akarin - List -> Map, IndexedBlockPosition
+ // Akarin start - remove stream
+ /*
Stream stream = list.stream().filter((globalpos) -> {
return globalpos.getDimensionManager() == worldserver.getWorldProvider().getDimensionManager();
}).map(GlobalPos::getBlockPosition);
list1.getClass();
return (Set) stream.filter(list1::contains).collect(Collectors.toSet());
+ */
+
+ Set<io.akarin.server.IndexedBlockPosition> set = Sets.newHashSet();
+ DimensionManager manager = worldserver.getWorldProvider().getDimensionManager();
+
+ for (GlobalPos globalPos : list) {
+ if (globalPos.getDimensionManager() == manager) {
+ BlockPosition position = globalPos.getBlockPosition();
+ Integer index = list1.get(position);
+ if (index != null) // contains
+ set.add(IndexedBlockPosition.of(index, position));
+ }
+ }
+
+ return set;
+ // Akarin end
}
- private void a(WorldServer worldserver, List<BlockPosition> list, Set<BlockPosition> set, int i, EntityLiving entityliving, BehaviorController<?> behaviorcontroller) {
- set.forEach((blockposition) -> {
- int j = list.indexOf(blockposition);
+ private void a(WorldServer worldserver, java.util.Map<BlockPosition, Integer> list, Set<io.akarin.server.IndexedBlockPosition> set, int i, EntityLiving entityliving, BehaviorController<?> behaviorcontroller) { // Akarin - List -> Map, IndexedBlockPosition
+ set.forEach((indexedblockposition) -> { // Akarin - IndexedBlockPosition
+ BlockPosition blockposition = indexedblockposition.get(); // Akarin - IndexedBlockPosition
+ // int j = list.indexOf(blockposition); // Akarin - IndexedBlockPosition
IBlockData iblockdata = worldserver.getType(blockposition);
Block block = iblockdata.getBlock();
if (TagsBlock.WOODEN_DOORS.isTagged(block) && block instanceof BlockDoor) {
- boolean flag = j >= i;
+ boolean flag = indexedblockposition.index() >= i; // Akarin - IndexedBlockPosition
// CraftBukkit start - entities opening doors
org.bukkit.event.entity.EntityInteractEvent event = new org.bukkit.event.entity.EntityInteractEvent(entityliving.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(entityliving.world, blockposition));
@@ -74,14 +107,14 @@ public class BehaviorInteractDoor extends Behavior<EntityLiving> {
a(worldserver, list, i, entityliving, behaviorcontroller);
}
- public static void a(WorldServer worldserver, List<BlockPosition> list, int i, EntityLiving entityliving, BehaviorController<?> behaviorcontroller) {
+ public static void a(WorldServer worldserver, java.util.Map<BlockPosition, Integer> list, int i, EntityLiving entityliving, BehaviorController<?> behaviorcontroller) { // Akarin - List -> Map
behaviorcontroller.getMemory(MemoryModuleType.OPENED_DOORS).ifPresent((set) -> {
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
GlobalPos globalpos = (GlobalPos) iterator.next();
BlockPosition blockposition = globalpos.getBlockPosition();
- int j = list.indexOf(blockposition);
+ int j = list.getOrDefault(blockposition, -1); // Akarin - List -> Map
if (worldserver.getWorldProvider().getDimensionManager() != globalpos.getDimensionManager()) {
iterator.remove();
diff --git a/src/main/java/net/minecraft/server/BehaviorSleep.java b/src/main/java/net/minecraft/server/BehaviorSleep.java
index dfe0f66500..46eb633084 100644
--- a/src/main/java/net/minecraft/server/BehaviorSleep.java
+++ b/src/main/java/net/minecraft/server/BehaviorSleep.java
@@ -57,7 +57,7 @@ public class BehaviorSleep extends Behavior<EntityLiving> {
protected void a(WorldServer worldserver, EntityLiving entityliving, long i) {
if (i > this.a) {
entityliving.getBehaviorController().getMemory(MemoryModuleType.OPENED_DOORS).ifPresent((set) -> {
- BehaviorInteractDoor.a(worldserver, (List) ImmutableList.of(), 0, entityliving, entityliving.getBehaviorController());
+ BehaviorInteractDoor.a(worldserver, com.google.common.collect.ImmutableMap.of(), 0, entityliving, entityliving.getBehaviorController()); // Akarin - List -> Map
});
entityliving.entitySleep(((GlobalPos) entityliving.getBehaviorController().getMemory(MemoryModuleType.HOME).get()).getBlockPosition());
}
--
2.25.1.windows.1