From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: ishland Date: Sat, 4 Dec 2021 12:09:59 +0100 Subject: [PATCH] vmp: spawn_density_cap Copyright (c) 2021-2022 ishland Original code by RelativityMC, licensed under MIT You can find the original code on https://github.com/RelativityMC/VMP-fabric (Yarn mappings) diff --git a/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java b/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java index 84c766e09898cfc07d6e07e80f4b9aa318050a62..9cb1acdfe2a514099e9517118c7cd448bd3c2d68 100644 --- a/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java +++ b/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java @@ -47,16 +47,25 @@ public class LocalMobCapCalculator { } static class MobCounts { - private final Object2IntMap counts = new Object2IntOpenHashMap<>(MobCategory.values().length); + // private final Object2IntMap counts = new Object2IntOpenHashMap<>(MobCategory.values().length); // Mirai + private final int[] spawnGroupDensities = new int[MobCategory.values().length]; // Mirai + // Mirai start + /** + * @author ishland + * @reason opt: replace with array access + */ public void add(MobCategory spawnGroup) { - this.counts.computeInt(spawnGroup, (group, density) -> { - return density == null ? 1 : density + 1; - }); + this.spawnGroupDensities[spawnGroup.ordinal()] ++; } + /** + * @author ishland + * @reason opt: replace with array access + */ public boolean canSpawn(MobCategory spawnGroup) { - return this.counts.getOrDefault(spawnGroup, 0) < spawnGroup.getMaxInstancesPerChunk(); + return this.spawnGroupDensities[spawnGroup.ordinal()] < spawnGroup.getMaxInstancesPerChunk(); } + // Mirai end } }