Skip to content

Commit 1288db2

Browse files
committed
Implement mod for fabric
1 parent b3bd65e commit 1288db2

File tree

26 files changed

+411
-73
lines changed

26 files changed

+411
-73
lines changed

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ subprojects {
2929
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
3030
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
3131
// for more information about repositories.
32+
// Other repositories can go above or below Modrinth's. We don't need priority :)
33+
exclusiveContent {
34+
forRepository {
35+
maven {
36+
name = "Modrinth"
37+
url = "https://api.modrinth.com/maven"
38+
}
39+
}
40+
filter {
41+
includeGroup "maven.modrinth"
42+
}
43+
}
44+
45+
maven { url "https://maven.shedaniel.me/" }
46+
maven { url "https://maven.terraformersmc.com/releases/" }
3247
}
3348

3449
dependencies {

common/src/main/java/io/github/discusser/toomanyentities/ExampleMod.java

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.discusser.toomanyentities;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import java.util.HashMap;
7+
8+
public final class TooManyEntities {
9+
public static final Logger LOGGER = LoggerFactory.getLogger("too-many-entities");
10+
public static final String MODID = "too-many-entities";
11+
public static final HashMap<String, Integer> entityCounts = new HashMap<>();
12+
13+
public static void init() {
14+
}
15+
16+
public static void initClient() {
17+
18+
}
19+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package io.github.discusser.toomanyentities.mixin;
2+
3+
import com.google.common.collect.ImmutableMap;
4+
import dev.architectury.platform.Platform;
5+
import org.objectweb.asm.tree.ClassNode;
6+
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
7+
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
8+
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.Set;
12+
import java.util.function.Supplier;
13+
14+
public class TooManyEntitiesMixinPlugin implements IMixinConfigPlugin {
15+
private static final Supplier<Boolean> entityCullingLoaded = () -> Platform.isModLoaded("entityculling");
16+
17+
private static final Map<String, Supplier<Boolean>> CONDITIONS = ImmutableMap.of(
18+
"io.github.discusser.toomanyentities.mixin.client.DebugHudMixin", entityCullingLoaded,
19+
"io.github.discusser.toomanyentities.fabric.mixin.client.EntityCullingWorldRendererMixin", entityCullingLoaded,
20+
"io.github.discusser.toomanyentities.mixin.client.WorldRendererMixin", () -> !entityCullingLoaded.get()
21+
);
22+
23+
@Override
24+
public void onLoad(String mixinPackage) {
25+
26+
}
27+
28+
@Override
29+
public String getRefMapperConfig() {
30+
return null;
31+
}
32+
33+
@Override
34+
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
35+
return CONDITIONS.getOrDefault(mixinClassName, () -> true).get();
36+
}
37+
38+
@Override
39+
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
40+
41+
}
42+
43+
@Override
44+
public List<String> getMixins() {
45+
return null;
46+
}
47+
48+
@Override
49+
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
50+
51+
}
52+
53+
@Override
54+
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
55+
56+
}
57+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.github.discusser.toomanyentities.mixin.client;
2+
3+
import io.github.discusser.toomanyentities.TooManyEntities;
4+
import net.minecraft.client.gui.hud.DebugHud;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.injection.At;
7+
import org.spongepowered.asm.mixin.injection.Inject;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
9+
10+
import java.util.List;
11+
12+
@Mixin(DebugHud.class)
13+
public class DebugHudMixin {
14+
@Inject(method = "getLeftText", at = @At(value = "TAIL"))
15+
public void getLeftText(CallbackInfoReturnable<List<String>> info) {
16+
TooManyEntities.entityCounts.clear();
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.discusser.toomanyentities.mixin.client;
2+
3+
import com.llamalad7.mixinextras.sugar.Local;
4+
import io.github.discusser.toomanyentities.TooManyEntities;
5+
import net.minecraft.client.render.WorldRenderer;
6+
import net.minecraft.entity.Entity;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(WorldRenderer.class)
13+
public class WorldRendererMixin {
14+
@Inject(method = "render", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/WorldRenderer;regularEntityCount:I", ordinal = 1, shift = At.Shift.AFTER))
15+
private void afterEntityCountIncrement(CallbackInfo info, @Local Entity entity) {
16+
String key = entity.getType().getTranslationKey();
17+
TooManyEntities.entityCounts.put(key, TooManyEntities.entityCounts.getOrDefault(key, 0) + 1);
18+
}
19+
}
5.98 KB
Loading
44 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"text.autoconfig.too-many-entities.title": "Too Many Entities",
3+
"text.autoconfig.too-many-entities.category.general": "General",
4+
"text.autoconfig.too-many-entities.category.entities": "Entities",
5+
"text.autoconfig.too-many-entities.option.enabled": "Enabled",
6+
"text.autoconfig.too-many-entities.option.enabled.@Tooltip": "Whether or not the mod is enabled",
7+
"text.autoconfig.too-many-entities.option.maxEntityCount": "Max Entity Count",
8+
"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",
9+
"text.autoconfig.too-many-entities.option.applyMaxEntityCountGlobally": "Apply Max Entity Count Globally",
10+
"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",
11+
"text.autoconfig.too-many-entities.option.useEntityCulling": "Use Entity Culling",
12+
"text.autoconfig.too-many-entities.option.useEntityCulling.@Tooltip": "If this option is enabled, and the mod Entity Culling is installed, the number of entities rendered will be taken from the entity culling mod. This allows you to have more visible entities without necessarily reducing performance. There can be flickering when using this option, so only enable it if you want to."
13+
}

common/src/main/resources/too-many-entities.mixins.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"package": "io.github.discusser.toomanyentities.mixin",
44
"compatibilityLevel": "JAVA_17",
55
"minVersion": "0.8",
6+
"plugin": "io.github.discusser.toomanyentities.mixin.TooManyEntitiesMixinPlugin",
67
"client": [
7-
],
8-
"mixins": [
8+
"client.DebugHudMixin",
9+
"client.WorldRendererMixin"
910
],
1011
"injectors": {
1112
"defaultRequire": 1

0 commit comments

Comments
 (0)