Skip to content

Commit cc74aa4

Browse files
committed
Implement per entity type hiding
1 parent 396e66c commit cc74aa4

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/client/java/io/github/discusser/toomanyentities/TooManyEntitiesClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package io.github.discusser.toomanyentities;
22

3+
import com.sun.jna.Native;
34
import io.github.discusser.toomanyentities.config.MapGuiProvider;
45
import io.github.discusser.toomanyentities.config.TooManyEntitiesConfig;
56
import me.shedaniel.autoconfig.AutoConfig;
67
import me.shedaniel.autoconfig.gui.registry.GuiRegistry;
78
import me.shedaniel.autoconfig.serializer.GsonConfigSerializer;
89
import net.fabricmc.api.ClientModInitializer;
10+
import net.minecraft.entity.EntityType;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113

src/client/java/io/github/discusser/toomanyentities/config/TooManyEntitiesConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class TooManyEntitiesConfig implements ConfigData {
1717
public Integer maxEntityCount = 64;
1818
@ConfigEntry.Category(value = "general")
1919
@ConfigEntry.Gui.Tooltip()
20-
public Boolean applyMaxEntityCountGlobally = true;
20+
public Boolean applyMaxEntityCountGlobally = false;
2121

2222
@ConfigEntry.Category(value = "entities")
2323
public TreeMap<String, Integer> entityMaxCounts = new TreeMap<>(Comparator.naturalOrder());

src/client/java/io/github/discusser/toomanyentities/mixin/client/WorldRendererMixin.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.discusser.toomanyentities.mixin.client;
22

33
import com.llamalad7.mixinextras.sugar.Local;
4+
import io.github.discusser.toomanyentities.config.TooManyEntitiesConfig;
45
import net.minecraft.client.render.WorldRenderer;
56
import net.minecraft.entity.Entity;
67
import org.spongepowered.asm.mixin.Mixin;
@@ -14,20 +15,23 @@
1415
@Mixin(WorldRenderer.class)
1516
public class WorldRendererMixin {
1617
@Unique
17-
private final HashMap<Class<?>, Integer> entityCounts = new HashMap<>();
18+
private final HashMap<String, Integer> entityCounts = new HashMap<>();
1819

1920
@Inject(method = "renderEntity", at = @At(value = "HEAD"), cancellable = true)
2021
private void beforeEntityRender(CallbackInfo info, @Local(argsOnly = true) Entity entity) {
21-
int MAX_ENTITY_COUNT = 128;
22-
if (entityCounts.getOrDefault(entity.getClass(), 0) > MAX_ENTITY_COUNT) {
22+
String key = entity.getType().getTranslationKey();
23+
int maxEntityCount = TooManyEntitiesConfig.instance.applyMaxEntityCountGlobally
24+
? TooManyEntitiesConfig.instance.maxEntityCount
25+
: TooManyEntitiesConfig.instance.entityMaxCounts.get(key);
26+
if (maxEntityCount > 0 && entityCounts.getOrDefault(key, 0) > maxEntityCount) {
2327
info.cancel();
2428
}
2529
}
2630

2731
@Inject(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/WorldRenderer;regularEntityCount:I", ordinal = 1, shift = At.Shift.AFTER))
2832
private void afterEntityCountIncrement(CallbackInfo info, @Local Entity entity) {
29-
Class<? extends Entity> klass = entity.getClass();
30-
entityCounts.put(klass, entityCounts.getOrDefault(klass, 0) + 1);
33+
String key = entity.getType().getTranslationKey();
34+
entityCounts.put(key, entityCounts.getOrDefault(key, 0) + 1);
3135
}
3236

3337

src/main/resources/assets/too-many-entities/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"text.autoconfig.too-many-entities.option.maxEntityCount": "Max Entity Count",
66
"text.autoconfig.too-many-entities.option.maxEntityCount.@Tooltip": "The maximum number of entities of a specific type to render. If this is set to 0, the limit is removed",
77
"text.autoconfig.too-many-entities.option.applyMaxEntityCountGlobally": "Apply Max Entity Count Globally",
8-
"text.autoconfig.too-many-entities.option.applyMaxEntityCountGlobally.@Tooltip": "If this option is enabled, the maximum entity count defined above will be used for every single entity type. If this option is disabled, each entity type will use its own maximum entity count",
8+
"text.autoconfig.too-many-entities.option.applyMaxEntityCountGlobally.@Tooltip": "If this option is enabled, the maximum entity count defined above will be used for every single entity type. If this option is disabled, each entity type will use its own maximum entity count"
99
}

0 commit comments

Comments
 (0)