Skip to content

Commit

Permalink
Store mob counts in an array
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jul 18, 2023
1 parent c29856f commit 8cf6bf0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
9 changes: 7 additions & 2 deletions patches/server/0004-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ index 35d2da9d91dcdd89de7c0f4af028fd182376ea8d..d73482fb1e71fe2951e96ae0593de268
.withRequiredArg()
diff --git a/src/main/java/top/leavesmc/leaves/LeavesConfig.java b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..98b93ea28c1f89d237bcc0494117c34025889f65
index 0000000000000000000000000000000000000000..deb8b7e2e71fc8308d28e5d2ad352c1292394202
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,866 @@
@@ -0,0 +1,871 @@
+package top.leavesmc.leaves;
+
+import com.destroystokyo.paper.util.SneakyThrow;
Expand Down Expand Up @@ -823,6 +823,11 @@ index 0000000000000000000000000000000000000000..98b93ea28c1f89d237bcc0494117c340
+ cacheCubeVoxelShapeShapeArray = getBoolean("settings.performance.cache-CubeVoxelShape-shape-array", cacheCubeVoxelShapeShapeArray);
+ }
+
+ public static boolean storeMobCountsInArray = true;
+ private static void storeMobCountsInArray() {
+ storeMobCountsInArray = getBoolean("settings.performance.store-mob-counts-in-array", storeMobCountsInArray);
+ }
+
+ public static final class WorldConfig {
+
+ public final String worldName;
Expand Down
44 changes: 44 additions & 0 deletions patches/server/0095-Store-mob-counts-in-an-array.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Tue, 18 Jul 2023 14:54:36 +0800
Subject: [PATCH] Store mob counts in an array

This patch is Powered by Gale(https://github.com/GaleMC/Gale)

diff --git a/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java b/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java
index 84c766e09898cfc07d6e07e80f4b9aa318050a62..a42098cc027ed3c1ec75542b800520514f87608a 100644
--- a/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java
+++ b/src/main/java/net/minecraft/world/level/LocalMobCapCalculator.java
@@ -48,15 +48,28 @@ public class LocalMobCapCalculator {

static class MobCounts {
private final Object2IntMap<MobCategory> counts = new Object2IntOpenHashMap<>(MobCategory.values().length);
+ public final int[] arrCounts = new int[MobCategory.values().length]; // Leaves - store mob counts in an array

public void add(MobCategory spawnGroup) {
- this.counts.computeInt(spawnGroup, (group, density) -> {
- return density == null ? 1 : density + 1;
- });
+ // Leaves start - store mob counts in an array
+ if (!top.leavesmc.leaves.LeavesConfig.storeMobCountsInArray) {
+ this.counts.computeInt(spawnGroup, (group, density) -> {
+ return density == null ? 1 : density + 1;
+ });
+ } else {
+ this.arrCounts[spawnGroup.ordinal()]++;
+ }
+ // Leaves end - store mob counts in an array
}

public boolean canSpawn(MobCategory spawnGroup) {
- return this.counts.getOrDefault(spawnGroup, 0) < spawnGroup.getMaxInstancesPerChunk();
+ // Leaves start - store mob counts in an array
+ if (!top.leavesmc.leaves.LeavesConfig.storeMobCountsInArray) {
+ return this.counts.getOrDefault(spawnGroup, 0) < spawnGroup.getMaxInstancesPerChunk();
+ } else {
+ return this.arrCounts[spawnGroup.ordinal()] < spawnGroup.getMaxInstancesPerChunk();
+ }
+ // Leaves end - store mob counts in an array
}
}
}

0 comments on commit 8cf6bf0

Please sign in to comment.