Skip to content

Commit 35e96a1

Browse files
committed
Add support for scaling Villager NPCs
1 parent d84f3c1 commit 35e96a1

File tree

6 files changed

+92
-4
lines changed

6 files changed

+92
-4
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.kd_gaming1.scaleme.client.mixin;
2+
3+
import com.github.kd_gaming1.scaleme.client.util.HypixelNpcUtil;
4+
import com.github.kd_gaming1.scaleme.client.util.ScaleManager;
5+
import com.github.kd_gaming1.scaleme.client.util.VillagerEntityRenderStateAccessor;
6+
import com.github.kd_gaming1.scaleme.config.ScaleMeConfig;
7+
import net.minecraft.client.render.entity.LivingEntityRenderer;
8+
import net.minecraft.client.render.entity.state.LivingEntityRenderState;
9+
import net.minecraft.client.render.entity.state.VillagerEntityRenderState;
10+
import net.minecraft.client.util.math.MatrixStack;
11+
import net.minecraft.entity.passive.VillagerEntity;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
17+
@Mixin(LivingEntityRenderer.class)
18+
public class LivingEntityRendererMixin {
19+
20+
@Inject(method = "scale(Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;)V",
21+
at = @At("HEAD"),
22+
cancellable = true)
23+
private void scaleVillagerNpc(LivingEntityRenderState renderState, MatrixStack matrixStack, CallbackInfo ci) {
24+
// Check if this is a villager render state
25+
if (renderState instanceof VillagerEntityRenderState villagerRenderState) {
26+
VillagerEntityRenderStateAccessor accessor = (VillagerEntityRenderStateAccessor) villagerRenderState;
27+
VillagerEntity villager = accessor.scaleme$getVillagerEntity();
28+
29+
// Check if this is a Hypixel NPC and scaling is enabled
30+
if (ScaleMeConfig.enableVillagerNpcScaling) {
31+
float scale = ScaleManager.getVillagerNpcScale();
32+
if (scale != 1.0f) {
33+
matrixStack.scale(scale, scale, scale);
34+
}
35+
ci.cancel(); // Prevent vanilla scaling
36+
return;
37+
}
38+
}
39+
}
40+
}

src/main/java/com/github/kd_gaming1/scaleme/client/mixin/PlayerEntityRendererMixin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ private void scalePlayerModel(PlayerEntityRenderState playerEntityRenderState, M
3434

3535
// --- Regular Hypixel NPC Scaling ---
3636
if (ScaleMeConfig.enableNpcScaling && HypixelNpcUtil.isHypixelNpc(player)) {
37-
float scale = ScaleMeConfig.npcPlayerScale;
37+
// Create a centralized method for NPC scaling with safety check
38+
float scale = ScaleManager.getNpcScale();
3839
if (scale != 1.0f) {
3940
matrixStack.scale(scale, scale, scale);
4041
}
4142
ci.cancel();
4243
return;
4344
}
4445

45-
// --- Normal Player Scaling ---
46+
// --- Normal Player Scaling (already has safety check in getCurrentScale) ---
4647
if (playerUUID != null) {
4748
float scale = ScaleManager.getCurrentScale(playerUUID);
4849
if (scale != 1.0f) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.kd_gaming1.scaleme.client.mixin;
2+
3+
import com.github.kd_gaming1.scaleme.client.util.VillagerEntityRenderStateAccessor;
4+
import net.minecraft.client.render.entity.state.VillagerEntityRenderState;
5+
import net.minecraft.entity.passive.VillagerEntity;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Unique;
8+
9+
@Mixin(VillagerEntityRenderState.class)
10+
public class VillagerEntityRenderStateMixin implements VillagerEntityRenderStateAccessor {
11+
12+
@Unique
13+
private VillagerEntity scaleme$villagerEntity;
14+
15+
@Override
16+
public void scaleme$setVillagerEntity(VillagerEntity villager) {
17+
this.scaleme$villagerEntity = villager;
18+
}
19+
20+
@Override
21+
public VillagerEntity scaleme$getVillagerEntity() {
22+
return this.scaleme$villagerEntity;
23+
}
24+
}

src/main/java/com/github/kd_gaming1/scaleme/client/util/ScaleManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.kd_gaming1.scaleme.client.util;
22

3+
import com.github.kd_gaming1.scaleme.config.ScaleMeConfig;
4+
35
import java.util.UUID;
46

57
/**
@@ -28,4 +30,18 @@ public static void tick() {
2830
public static float getCurrentScale(UUID playerUUID) {
2931
return PlayerPresetManager.getCurrentScale(playerUUID);
3032
}
33+
34+
/** Returns NPC scale with safety check including dungeons detection. */
35+
public static float getNpcScale() {
36+
// Disable NPC scaling in competitive modes AND dungeons
37+
38+
return ScaleMeConfig.npcPlayerScale;
39+
}
40+
41+
/** Returns Villager NPC scale with safety check including dungeons detection. */
42+
public static float getVillagerNpcScale() {
43+
// Disable Villager NPC scaling in competitive modes AND dungeons
44+
45+
return ScaleMeConfig.villagerNpcScale;
46+
}
3147
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.github.kd_gaming1.scaleme.client.util;
2+
3+
import net.minecraft.entity.passive.VillagerEntity;
4+
5+
public interface VillagerEntityRenderStateAccessor {
6+
void scaleme$setVillagerEntity(VillagerEntity villager);
7+
VillagerEntity scaleme$getVillagerEntity();
8+
}

src/main/resources/scaleme.mixins.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
"refmap": "scaleme.refmap.json",
77
"client": [
88
"LivingEntityRendererMixin",
9-
"LivingEntityRenderStateAccessor",
109
"MixinInGameHud",
1110
"PerspectiveMixin",
1211
"PlayerEntityRendererMixin",
1312
"PlayerEntityRenderStateMixin",
14-
"VillagerEntityRendererMixin"
13+
"VillagerEntityRenderStateMixin"
1514
],
1615
"injectors": {
1716
"defaultRequire": 1

0 commit comments

Comments
 (0)