From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Tue, 9 Nov 2077 00:00:00 +0800 Subject: [PATCH] Remove stream in GolemSensor Stream operations in GolemSensor is really expensive and takes up 80% time per method call. Before: 192ms After: 17ms diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/GolemSensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/GolemSensor.java index 03485bcf2f25942bd2550b4855bf16bea9ef88b6..c7c8a1ae9ab8f406f5a807e5a56c110c9e0e832d 100644 --- a/src/main/java/net/minecraft/world/entity/ai/sensing/GolemSensor.java +++ b/src/main/java/net/minecraft/world/entity/ai/sensing/GolemSensor.java @@ -34,7 +34,15 @@ public class GolemSensor extends Sensor { public static void checkForNearbyGolem(LivingEntity entity) { Optional> optional = entity.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES); if (!optional.isEmpty()) { - boolean bl = optional.get().stream().anyMatch(seenEntity -> seenEntity.getType().equals(EntityType.IRON_GOLEM)); + // Leaf start - Remove stream in GolemSensor + boolean bl = false; + for (LivingEntity seenEntity : optional.get()) { + if (seenEntity.getType().equals(EntityType.IRON_GOLEM)) { + bl = true; + break; + } + } + // Leaf end - Remove stream in GolemSensor if (bl) { golemDetected(entity); }