From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrHua269 Date: Sat, 18 Apr 2026 12:27:21 +0800 Subject: [PATCH] Leaf: Replace brain maps with optimized collection Co-authored by: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> As part of: Leaf (https://github.com/Winds-Studio/Leaf/blob/7f3e240bbe0970683c40279a7a65f0fde47503b6/leaf-server/minecraft-patches/features/0070-Replace-brain-maps-with-optimized-collection.patch) Licensed under: MIT (https://github.com/Winds-Studio/Leaf/blob/7f3e240bbe0970683c40279a7a65f0fde47503b6/licenses/MIT.txt) diff --git a/net/minecraft/world/entity/ai/Brain.java b/net/minecraft/world/entity/ai/Brain.java index 16314f63fdf6f81819b2b660c48d0cf3025aa8c1..489648c4b8a00d3fd3bb474d4d178ca197df330c 100644 --- a/net/minecraft/world/entity/ai/Brain.java +++ b/net/minecraft/world/entity/ai/Brain.java @@ -37,14 +37,14 @@ import org.jspecify.annotations.Nullable; public class Brain { private static final int SCHEDULE_UPDATE_DELAY = 20; - private final Map, MemorySlot> memories = Maps.newHashMap(); - private final Map>, Sensor> sensors = Maps.newLinkedHashMap(); + private final Map, MemorySlot> memories = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(); // Leaf - Replace brain maps with optimized collection + private final Map>, Sensor> sensors = new it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap<>(); // Leaf - Replace brain maps with optimized collection private final Map>>> availableBehaviorsByPriority = Maps.newTreeMap(); private @Nullable EnvironmentAttribute schedule; - private final Map, MemoryStatus>>> activityRequirements = Maps.newHashMap(); - private final Map>> activityMemoriesToEraseWhenStopped = Maps.newHashMap(); - private Set coreActivities = Sets.newHashSet(); - private final Set activeActivities = Sets.newHashSet(); + private final Map, MemoryStatus>>> activityRequirements = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(); // Leaf - Replace brain maps with optimized collection + private final Map>> activityMemoriesToEraseWhenStopped = new it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap<>(); // Leaf - Replace brain maps with optimized collection + private Set coreActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(); // Leaf - Replace brain maps with optimized collection + private final Set activeActivities = new it.unimi.dsi.fastutil.objects.ObjectOpenHashSet<>(); // Leaf - Replace brain maps with optimized collection private Activity defaultActivity = Activity.IDLE; private long lastScheduleUpdate = -9999L;