From c096fe19fa07bebcd78b25ee6b84f62f45d64e19 Mon Sep 17 00:00:00 2001 From: Callahan Date: Wed, 8 Apr 2020 18:02:26 -0500 Subject: [PATCH] Port 20w15a Villager AI optimizations --- ...-Villager-AI-optimizations-DROP-1.16.patch | 198 ++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 Spigot-Server-Patches/0471-Port-20w15a-Villager-AI-optimizations-DROP-1.16.patch diff --git a/Spigot-Server-Patches/0471-Port-20w15a-Villager-AI-optimizations-DROP-1.16.patch b/Spigot-Server-Patches/0471-Port-20w15a-Villager-AI-optimizations-DROP-1.16.patch new file mode 100644 index 0000000000..73b07e48b9 --- /dev/null +++ b/Spigot-Server-Patches/0471-Port-20w15a-Villager-AI-optimizations-DROP-1.16.patch @@ -0,0 +1,198 @@ +From 167e72427fbd9d69884047a7fd62c3f0ca69fdf1 Mon Sep 17 00:00:00 2001 +From: Callahan +Date: Wed, 8 Apr 2020 18:00:17 -0500 +Subject: [PATCH] Port 20w15a Villager AI optimizations - DROP 1.16 + + +diff --git a/src/main/java/net/minecraft/server/BehaviorController.java b/src/main/java/net/minecraft/server/BehaviorController.java +index a1883eba6..c75581dd5 100644 +--- a/src/main/java/net/minecraft/server/BehaviorController.java ++++ b/src/main/java/net/minecraft/server/BehaviorController.java +@@ -38,30 +38,22 @@ public class BehaviorController implements MinecraftSeri + this.g = Sets.newHashSet(); + this.h = Activity.IDLE; + this.i = -9999L; +- collection.forEach((memorymoduletype) -> { +- Optional optional = (Optional) this.memories.put(memorymoduletype, Optional.empty()); +- }); +- collection1.forEach((sensortype) -> { +- Sensor sensor = (Sensor) this.sensors.put(sensortype, sensortype.a()); +- }); +- this.sensors.values().forEach((sensor) -> { +- Iterator iterator = sensor.a().iterator(); +- +- while (iterator.hasNext()) { +- MemoryModuleType memorymoduletype = (MemoryModuleType) iterator.next(); +- +- this.memories.put(memorymoduletype, Optional.empty()); ++ // Paper start - Port 20w15a pathfinder optimizations ++ for (final MemoryModuleType memoryModuleType : collection) { ++ this.memories.put(memoryModuleType, Optional.empty()); ++ } ++ for (final SensorType> sensorType : collection1) { ++ this.sensors.put(sensorType, sensorType.a()); ++ } ++ for (final Sensor sensor : this.sensors.values()) { ++ for (final MemoryModuleType memoryModuleType : sensor.a()) { ++ this.memories.put(memoryModuleType, Optional.empty()); + } +- +- }); +- Iterator iterator = dynamic.get("memories").asMap(Function.identity(), Function.identity()).entrySet().iterator(); +- +- while (iterator.hasNext()) { +- Entry, Dynamic> entry = (Entry) iterator.next(); +- +- this.a((MemoryModuleType) IRegistry.MEMORY_MODULE_TYPE.get(new MinecraftKey(((Dynamic) entry.getKey()).asString(""))), (Dynamic) entry.getValue()); + } +- ++ for (final Map.Entry, Dynamic> entry : dynamic.get("memories").asMap(Function.identity(), Function.identity()).entrySet()) { ++ this.a((MemoryModuleType) IRegistry.MEMORY_MODULE_TYPE.get(new MinecraftKey((entry.getKey()).asString(""))), entry.getValue()); ++ } ++ // Paper end - Port 20w15a pathfinder optimizations + } + + public boolean hasMemory(MemoryModuleType memorymoduletype) { +@@ -69,7 +61,7 @@ public class BehaviorController implements MinecraftSeri + } + + private void a(MemoryModuleType memorymoduletype, Dynamic dynamic) { +- this.setMemory(memorymoduletype, ((Function) memorymoduletype.getSerializer().orElseThrow(RuntimeException::new)).apply(dynamic)); ++ this.setMemory(memorymoduletype, (memorymoduletype.getSerializer().orElseThrow(RuntimeException::new)).apply(dynamic)); // Paper - decompile fix + } + + public void removeMemory(MemoryModuleType memorymoduletype) { +@@ -113,13 +105,21 @@ public class BehaviorController implements MinecraftSeri + this.f = set; + } + ++ // Paper start - Port 20w15a pathfinder optimizations + @Deprecated +- public Stream> d() { +- return this.c.values().stream().flatMap((map) -> { +- return map.values().stream(); +- }).flatMap(Collection::stream).filter((behavior) -> { +- return behavior.a() == Behavior.Status.RUNNING; +- }); ++ public java.util.List> d() { ++ final java.util.List> behaviorList = (java.util.List>) new it.unimi.dsi.fastutil.objects.ObjectArrayList(); ++ for (final Map>> map : this.c.values()) { ++ for (final Set> set : map.values()) { ++ for (final Behavior behavior : set) { ++ if (behavior.a() == Behavior.Status.RUNNING) { ++ behaviorList.add(behavior); ++ } ++ } ++ } ++ } ++ return behaviorList; ++ // Paper end - Port 20w15a pathfinder optimizations + } + + public void a(Activity activity) { +@@ -167,12 +167,14 @@ public class BehaviorController implements MinecraftSeri + + public BehaviorController f() { + BehaviorController behaviorcontroller = new BehaviorController<>(this.memories.keySet(), this.sensors.keySet(), new Dynamic(DynamicOpsNBT.a, new NBTTagCompound())); +- +- this.memories.forEach((memorymoduletype, optional) -> { +- optional.ifPresent((object) -> { +- Optional optional1 = (Optional) behaviorcontroller.memories.put(memorymoduletype, Optional.of(object)); +- }); +- }); ++ // Paper start - Port 20w15a pathfinder optimizations ++ for (final Entry, Optional> entry : this.memories.entrySet()) { ++ final MemoryModuleType memoryModuleType = entry.getKey(); ++ if (entry.getValue().isPresent()) { ++ behaviorcontroller.memories.put(memoryModuleType, entry.getValue()); ++ } ++ } ++ // Paper end - Port 20w15a pathfinder optimizations + return behaviorcontroller; + } + +@@ -185,14 +187,14 @@ public class BehaviorController implements MinecraftSeri + public void b(WorldServer worldserver, E e0) { + long i = e0.world.getTime(); + +- this.d().forEach((behavior) -> { ++ for(Behavior behavior : this.d()) { // Paper - Port 20w15a pathfinder optimizations + behavior.e(worldserver, e0, i); +- }); ++ } + } + + @Override + public T a(DynamicOps dynamicops) { +- T t0 = dynamicops.createMap((Map) this.memories.entrySet().stream().filter((entry) -> { ++ T t0 = dynamicops.createMap(this.memories.entrySet().stream().filter((entry) -> { // Paper - decompile fix + return ((MemoryModuleType) entry.getKey()).getSerializer().isPresent() && ((Optional) entry.getValue()).isPresent(); + }).map((entry) -> { + return Pair.of(dynamicops.createString(IRegistry.MEMORY_MODULE_TYPE.getKey(entry.getKey()).toString()), ((MinecraftSerializable) ((Optional) entry.getValue()).get()).a(dynamicops)); +@@ -209,33 +211,45 @@ public class BehaviorController implements MinecraftSeri + + private void d(WorldServer worldserver, E e0) { + long i = worldserver.getTime(); +- +- this.c.values().stream().flatMap((map) -> { +- return map.entrySet().stream(); +- }).filter((entry) -> { +- return this.g.contains(entry.getKey()); +- }).map(Entry::getValue).flatMap(Collection::stream).filter((behavior) -> { +- return behavior.a() == Behavior.Status.STOPPED; +- }).forEach((behavior) -> { +- behavior.b(worldserver, e0, i); +- }); ++ // Paper start - Port 20w15a pathfinder optimizations ++ for (final Map>> map : this.c.values()) { ++ for (final Map.Entry>> entry : map.entrySet()) { ++ final Activity activity = entry.getKey(); ++ if (this.g.contains(activity)) { ++ final Set> set = entry.getValue(); ++ for (final Behavior behavior : set) { ++ if (behavior.a() == Behavior.Status.STOPPED) { ++ behavior.b(worldserver, e0, i); ++ } ++ } ++ } ++ } ++ } ++ // Paper end - Port 20w15a pathfinder optimizations + } + + private void e(WorldServer worldserver, E e0) { + long i = worldserver.getTime(); + +- this.d().forEach((behavior) -> { ++ for (final Behavior behavior : this.d()) { // Paper - Port 20w15a pathfinder optimizations + behavior.c(worldserver, e0, i); +- }); ++ } + } + + private boolean d(Activity activity) { +- return ((Set) this.e.get(activity)).stream().allMatch((pair) -> { +- MemoryModuleType memorymoduletype = (MemoryModuleType) pair.getFirst(); +- MemoryStatus memorystatus = (MemoryStatus) pair.getSecond(); +- +- return this.a(memorymoduletype, memorystatus); +- }); ++ // Paper start - Port 20w15a pathfinder optimizations ++ if (!this.e.containsKey(activity)) { ++ return false; ++ } ++ for (final Pair, MemoryStatus> pair : this.e.get(activity)) { ++ MemoryModuleType memorymoduletype = pair.getFirst(); ++ MemoryStatus memorystatus = pair.getSecond(); ++ if (!this.a(memorymoduletype, memorystatus)) { ++ return false; ++ } ++ } ++ return true; ++ // Paper end - Port 20w15a pathfinder optimizations + } + + private boolean a(Object object) { +-- +2.25.1 +