Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic brain activation #9712

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions patches/server/0005-Paper-config-files.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,10 @@ index 0000000000000000000000000000000000000000..f0d4ec73bc8872a85e34f5c6b4d342e7
+}
diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
new file mode 100644
index 0000000000000000000000000000000000000000..da7c899fbab162ee197a0593f455ebd9c5286d3c
index 0000000000000000000000000000000000000000..f5dd8ad4c97b8ce4db0d530c34926b465985ef26
--- /dev/null
+++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java
@@ -0,0 +1,530 @@
@@ -0,0 +1,566 @@
+package io.papermc.paper.configuration;
+
+import com.google.common.collect.HashBasedTable;
Expand Down Expand Up @@ -1513,6 +1513,7 @@ index 0000000000000000000000000000000000000000..da7c899fbab162ee197a0593f455ebd9
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import net.minecraft.Util;
+import net.minecraft.commands.arguments.NbtPathArgument;
+import net.minecraft.core.Holder;
Expand Down Expand Up @@ -1818,6 +1819,41 @@ index 0000000000000000000000000000000000000000..da7c899fbab162ee197a0593f455ebd9
+ return other.or(def);
+ }
+ }
+
+ public DynamicBrainActivation dynamicBrainActivation;
+
+ public class DynamicBrainActivation extends ConfigurationPart.Post {
+ public boolean enabled;
+ public int startDistance = 12;
+ public transient int startDistanceSquared;
+ public int maxTickDelay = 20;
+ public int distanceModifier = 8;
+ public Map<EntityType<?>, Boolean> enabledForEntities = Stream.of(
+ EntityType.ZOGLIN,
+ EntityType.PIGLIN_BRUTE,
+ EntityType.ALLAY,
+ EntityType.AXOLOTL,
+ EntityType.CAMEL,
+ EntityType.FROG,
+ EntityType.TADPOLE,
+ EntityType.GOAT,
+ EntityType.SNIFFER,
+ EntityType.HOGLIN,
+ EntityType.PIGLIN,
+ EntityType.WARDEN,
+ EntityType.VILLAGER
+ ).collect(Collectors.toMap(key -> key, key -> true));
+
+ @Override
+ public void postProcess() {
+ this.startDistanceSquared = this.startDistance * this.startDistance;
+ for (final Map.Entry<EntityType<?>, Boolean> entry : this.enabledForEntities.entrySet()) {
+ if (entry.getValue()) {
+ entry.getKey().dynamicBrainActivationEnabled = true;
+ }
+ }
+ }
+ }
+ }
+
+ public Lootables lootables;
Expand Down
59 changes: 59 additions & 0 deletions patches/server/0006-MC-Dev-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,65 @@ index 2dc801061025888192c3bf2c4c38b928c16a0165..ca788f0dcec4a117b410fe8348969e05
}

public static <T> SortedArraySet<T> create(Comparator<T> comparator) {
diff --git a/src/main/java/net/minecraft/world/entity/ai/Brain.java b/src/main/java/net/minecraft/world/entity/ai/Brain.java
index ef6e968ed2708272eab407a983928382a2f2049c..f34b3548990d4398123352c439b598d47a904a70 100644
--- a/src/main/java/net/minecraft/world/entity/ai/Brain.java
+++ b/src/main/java/net/minecraft/world/entity/ai/Brain.java
@@ -59,8 +59,8 @@ public class Brain<E extends LivingEntity> {
}

public static <E extends LivingEntity> Codec<Brain<E>> codec(final Collection<? extends MemoryModuleType<?>> memoryModules, final Collection<? extends SensorType<? extends Sensor<? super E>>> sensors) {
- final MutableObject<Codec<Brain<E>>> mutableObject = new MutableObject<>();
- mutableObject.setValue((new MapCodec<Brain<E>>() {
+ final MutableObject<Codec<Brain<E>>> mutableObject1 = new MutableObject<>(); // Paper - decompile fix
+ mutableObject1.setValue((new MapCodec<Brain<E>>() { // Paper - decompile fix
public <T> Stream<T> keys(DynamicOps<T> dynamicOps) {
return memoryModules.stream().flatMap((memoryType) -> {
return memoryType.getCodec().map((codec) -> {
@@ -81,7 +81,7 @@ public class Brain<E extends LivingEntity> {
mutableObject.setValue(mutableObject.getValue().apply2(ImmutableList.Builder::add, dataResult2));
});
ImmutableList<Brain.MemoryValue<?>> immutableList = mutableObject.getValue().resultOrPartial(Brain.LOGGER::error).map(ImmutableList.Builder::build).orElseGet(ImmutableList::of);
- return DataResult.success(new Brain<>(memoryModules, sensors, immutableList, mutableObject::getValue));
+ return DataResult.success(new Brain<>(memoryModules, sensors, immutableList, mutableObject1::getValue)); // Paper - decompile fix
}

private <T, U> DataResult<Brain.MemoryValue<U>> captureRead(MemoryModuleType<U> memoryType, DynamicOps<T> ops, T value) {
@@ -103,7 +103,7 @@ public class Brain<E extends LivingEntity> {
return recordBuilder;
}
}).fieldOf("memories").codec());
- return mutableObject.getValue();
+ return mutableObject1.getValue();
}

public Brain(Collection<? extends MemoryModuleType<?>> memories, Collection<? extends SensorType<? extends Sensor<? super E>>> sensors, ImmutableList<Brain.MemoryValue<?>> memoryEntries, Supplier<Codec<Brain<E>>> codecSupplier) {
@@ -181,14 +181,14 @@ public class Brain<E extends LivingEntity> {
if (optional == null) {
throw new IllegalStateException("Unregistered memory fetched: " + type);
} else {
- return optional.map(ExpirableValue::getValue);
+ return (Optional<U>) optional.map(ExpirableValue::getValue); // Paper - decompile fix
}
}

@Nullable
public <U> Optional<U> getMemoryInternal(MemoryModuleType<U> type) {
Optional<? extends ExpirableValue<?>> optional = this.memories.get(type);
- return optional == null ? null : optional.map(ExpirableValue::getValue);
+ return optional == null ? null : (Optional<U>) optional.map(ExpirableValue::getValue); // Paper - decompile fix
}

public <U> long getTimeUntilExpiry(MemoryModuleType<U> type) {
@@ -483,7 +483,7 @@ public class Brain<E extends LivingEntity> {
private final Optional<? extends ExpirableValue<U>> value;

static <U> Brain.MemoryValue<U> createUnchecked(MemoryModuleType<U> type, Optional<? extends ExpirableValue<?>> data) {
- return new Brain.MemoryValue<>(type, data);
+ return new Brain.MemoryValue<>(type, (Optional<? extends ExpirableValue<U>>) data); // Paper - decompile fix
}

MemoryValue(MemoryModuleType<U> type, Optional<? extends ExpirableValue<U>> data) {
diff --git a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java b/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
index d6e25c7f5dc6c219e2590aa8b1ffd51a2120d50e..40cdff9eaa1e78e02060d970e477d96f960cfed3 100644
--- a/src/main/java/net/minecraft/world/entity/animal/camel/Camel.java
Expand Down
Loading