Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/patches/removed/1.16/No longer Needed/0468-Port-20w15a-Villager-AI-optimizations-DROP-1.16.patch

196 Zeilen
9.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-04-09 01:02:26 +02:00
From: Callahan <mr.callahhh@gmail.com>
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 7c6e687707cdf32638eee41e549818a494cd45ab..396b64ea0fc8a04d9e0aac289033d3d82385b86e 100644
2020-04-09 01:02:26 +02:00
--- 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<E extends EntityLiving> 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<? extends Sensor<? super E>> sensorType : collection1) {
+ this.sensors.put(sensorType, sensorType.a());
+ }
+ for (final Sensor<? super E> 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<T>, Dynamic<T>> 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<T>, Dynamic<T>> 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<E extends EntityLiving> implements MinecraftSeri
}
private <T, U> void a(MemoryModuleType<U> memorymoduletype, Dynamic<T> 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 <U> void removeMemory(MemoryModuleType<U> memorymoduletype) {
@@ -113,13 +105,21 @@ public class BehaviorController<E extends EntityLiving> implements MinecraftSeri
this.f = set;
}
+ // Paper start - Port 20w15a pathfinder optimizations
@Deprecated
- public Stream<Behavior<? super E>> 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<Behavior<? super E>> d() {
+ final java.util.List<Behavior<? super E>> behaviorList = (java.util.List<Behavior<? super E>>) new it.unimi.dsi.fastutil.objects.ObjectArrayList();
+ for (final Map<Activity, Set<Behavior<? super E>>> map : this.c.values()) {
+ for (final Set<Behavior<? super E>> set : map.values()) {
+ for (final Behavior<? super E> behavior : set) {
+ if (behavior.a() == Behavior.Status.RUNNING) {
+ behaviorList.add(behavior);
+ }
+ }
+ }
+ }
+ return behaviorList;
+ // Paper end - Port 20w15a pathfinder optimizations
}
public void a(Activity activity) {
Entity Activation Range 2.0! Major improvements to restoring behavior Calling this 2.0 as it's a pretty major improvement with more knobs to twist. This update fixes many things. The goal here is to restore vanilla behavior to some degree. Instead of permanent inactive pools of animals, let them show some signs of life some.... Yes this may reduce performance compared to before, but I hope it is minimal. Got to find a balance. Previous EAR logic really compromised vanilla behavior of mobs. This tries to restore it. Changes: 1) All monsters are now classed as Monster. Mojang has an interface, we should use it. - This now includes Shulker, Slimes, see #2 for Phantom and Ghast 2) Villagers and Flying Monsters now have their own separate activation range configs. - Villagers will default to your Animals config 3) Added a bunch of more immunities - Brand new entities are immune for a few seconds - Entities that recently traveled by portal are immune for few seconds - Entities that are leashed to a player are immune - Ender Signals are immune - Entities that are jumping, climbing, dying (lol) are immune - Minecarts are now always immune to the movement restriction 4) Villagers immunity received major overhaul... - Now has many immunities for Villager activities to let them do their work then go back inactive - Such as interacting with doors and workstations should be more normal now - Raids will trigger immunities, in that villagers will run and hide when bell rings. - Raid should keep the entire village immune during the raid to keep gameplay mechanics You can disable raids by game rule if you dont want raids Then the big one..... Wake Up Inactive Entities: One issue plagueing "farms" is that we no longer even let entities move now. Entities become lifeless. A new system has been introduced to wake up inactive entities every so often, to let them stretch their legs, eat some food, play with each other and experience the good entity life. Animals, Villagers, Monsters (Includes Pillagers), and Flying Monsters will now wake up every so often after staying inactive for a very long. This grants them a temporary immunity, that the goal is they will then find "stuff to do" by having a longer activity window. How many to wake up, how often they wake up, and for how long they wake up are all configurable. Current EAR Immunities really don't give some entities enough of a window to find work to then keep them immune for the work to even start. This system should help that. We will only wake up a few entities per tick on the first wave, restoring 1 per type per world per tick. So say you have 10 monsters qualify for inactive wake up, all 8 will wake up on the first eligible tick, and then the 9th will wake up on next tick, 10th on next tick. If for 5 ticks no more inactive wake up, our buffer will have built back up to 5, and then 5 can go next needed tick. This basically incrementally wakes them up, preventing too many from waking up in a single tick, to reduce impact to TPS.
2020-04-27 06:34:51 +02:00
@@ -168,12 +168,14 @@ public class BehaviorController<E extends EntityLiving> implements MinecraftSeri
2020-04-09 01:02:26 +02:00
public BehaviorController<E> f() {
BehaviorController<E> 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<MemoryModuleType<?>, 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;
}
Entity Activation Range 2.0! Major improvements to restoring behavior Calling this 2.0 as it's a pretty major improvement with more knobs to twist. This update fixes many things. The goal here is to restore vanilla behavior to some degree. Instead of permanent inactive pools of animals, let them show some signs of life some.... Yes this may reduce performance compared to before, but I hope it is minimal. Got to find a balance. Previous EAR logic really compromised vanilla behavior of mobs. This tries to restore it. Changes: 1) All monsters are now classed as Monster. Mojang has an interface, we should use it. - This now includes Shulker, Slimes, see #2 for Phantom and Ghast 2) Villagers and Flying Monsters now have their own separate activation range configs. - Villagers will default to your Animals config 3) Added a bunch of more immunities - Brand new entities are immune for a few seconds - Entities that recently traveled by portal are immune for few seconds - Entities that are leashed to a player are immune - Ender Signals are immune - Entities that are jumping, climbing, dying (lol) are immune - Minecarts are now always immune to the movement restriction 4) Villagers immunity received major overhaul... - Now has many immunities for Villager activities to let them do their work then go back inactive - Such as interacting with doors and workstations should be more normal now - Raids will trigger immunities, in that villagers will run and hide when bell rings. - Raid should keep the entire village immune during the raid to keep gameplay mechanics You can disable raids by game rule if you dont want raids Then the big one..... Wake Up Inactive Entities: One issue plagueing "farms" is that we no longer even let entities move now. Entities become lifeless. A new system has been introduced to wake up inactive entities every so often, to let them stretch their legs, eat some food, play with each other and experience the good entity life. Animals, Villagers, Monsters (Includes Pillagers), and Flying Monsters will now wake up every so often after staying inactive for a very long. This grants them a temporary immunity, that the goal is they will then find "stuff to do" by having a longer activity window. How many to wake up, how often they wake up, and for how long they wake up are all configurable. Current EAR Immunities really don't give some entities enough of a window to find work to then keep them immune for the work to even start. This system should help that. We will only wake up a few entities per tick on the first wave, restoring 1 per type per world per tick. So say you have 10 monsters qualify for inactive wake up, all 8 will wake up on the first eligible tick, and then the 9th will wake up on next tick, 10th on next tick. If for 5 ticks no more inactive wake up, our buffer will have built back up to 5, and then 5 can go next needed tick. This basically incrementally wakes them up, preventing too many from waking up in a single tick, to reduce impact to TPS.
2020-04-27 06:34:51 +02:00
@@ -186,14 +188,14 @@ public class BehaviorController<E extends EntityLiving> implements MinecraftSeri
2020-04-09 01:02:26 +02:00
public void b(WorldServer worldserver, E e0) {
long i = e0.world.getTime();
- this.d().forEach((behavior) -> {
+ for(Behavior<? super E> behavior : this.d()) { // Paper - Port 20w15a pathfinder optimizations
behavior.e(worldserver, e0, i);
- });
+ }
}
@Override
public <T> T a(DynamicOps<T> 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));
Entity Activation Range 2.0! Major improvements to restoring behavior Calling this 2.0 as it's a pretty major improvement with more knobs to twist. This update fixes many things. The goal here is to restore vanilla behavior to some degree. Instead of permanent inactive pools of animals, let them show some signs of life some.... Yes this may reduce performance compared to before, but I hope it is minimal. Got to find a balance. Previous EAR logic really compromised vanilla behavior of mobs. This tries to restore it. Changes: 1) All monsters are now classed as Monster. Mojang has an interface, we should use it. - This now includes Shulker, Slimes, see #2 for Phantom and Ghast 2) Villagers and Flying Monsters now have their own separate activation range configs. - Villagers will default to your Animals config 3) Added a bunch of more immunities - Brand new entities are immune for a few seconds - Entities that recently traveled by portal are immune for few seconds - Entities that are leashed to a player are immune - Ender Signals are immune - Entities that are jumping, climbing, dying (lol) are immune - Minecarts are now always immune to the movement restriction 4) Villagers immunity received major overhaul... - Now has many immunities for Villager activities to let them do their work then go back inactive - Such as interacting with doors and workstations should be more normal now - Raids will trigger immunities, in that villagers will run and hide when bell rings. - Raid should keep the entire village immune during the raid to keep gameplay mechanics You can disable raids by game rule if you dont want raids Then the big one..... Wake Up Inactive Entities: One issue plagueing "farms" is that we no longer even let entities move now. Entities become lifeless. A new system has been introduced to wake up inactive entities every so often, to let them stretch their legs, eat some food, play with each other and experience the good entity life. Animals, Villagers, Monsters (Includes Pillagers), and Flying Monsters will now wake up every so often after staying inactive for a very long. This grants them a temporary immunity, that the goal is they will then find "stuff to do" by having a longer activity window. How many to wake up, how often they wake up, and for how long they wake up are all configurable. Current EAR Immunities really don't give some entities enough of a window to find work to then keep them immune for the work to even start. This system should help that. We will only wake up a few entities per tick on the first wave, restoring 1 per type per world per tick. So say you have 10 monsters qualify for inactive wake up, all 8 will wake up on the first eligible tick, and then the 9th will wake up on next tick, 10th on next tick. If for 5 ticks no more inactive wake up, our buffer will have built back up to 5, and then 5 can go next needed tick. This basically incrementally wakes them up, preventing too many from waking up in a single tick, to reduce impact to TPS.
2020-04-27 06:34:51 +02:00
@@ -210,33 +212,45 @@ public class BehaviorController<E extends EntityLiving> implements MinecraftSeri
2020-04-09 01:02:26 +02:00
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<Activity, Set<Behavior<? super E>>> map : this.c.values()) {
+ for (final Map.Entry<Activity, Set<Behavior<? super E>>> entry : map.entrySet()) {
+ final Activity activity = entry.getKey();
+ if (this.g.contains(activity)) {
+ final Set<Behavior<? super E>> set = entry.getValue();
+ for (final Behavior<? super E> 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<? super E> 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<MemoryModuleType<?>, 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) {