Skip to content

Commit 7465f8f

Browse files
committed
Add item scaling features and configuration options
1 parent 3fc7481 commit 7465f8f

File tree

8 files changed

+297
-9
lines changed

8 files changed

+297
-9
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ minecraft_version=1.21.5
66
yarn_mappings=1.21.5+build.1
77
loader_version=0.17.1
88
# Mod Properties
9-
mod_version=2.0.0+1.21.5
9+
mod_version=2.1.0+1.21.5
1010
maven_group=com.github.kd_gaming1
1111
archives_base_name=scaleme
1212
# Dependencies

src/main/java/com/github/kd_gaming1/scaleme/Scaleme.java

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

3-
import com.github.kd_gaming1.scaleme.config.ScaleMeConfig;
4-
import eu.midnightdust.lib.config.MidnightConfig;
53
import net.fabricmc.api.ModInitializer;
64

75
import org.slf4j.Logger;
@@ -13,6 +11,5 @@ public class Scaleme implements ModInitializer {
1311

1412
@Override
1513
public void onInitialize() {
16-
MidnightConfig.init(MOD_ID, ScaleMeConfig.class);
1714
}
1815
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.github.kd_gaming1.scaleme.client.mixin;
2+
3+
import com.github.kd_gaming1.scaleme.config.ScaleMeConfig;
4+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
5+
import com.llamalad7.mixinextras.sugar.Local;
6+
import net.minecraft.client.render.item.HeldItemRenderer;
7+
import net.minecraft.client.util.math.MatrixStack;
8+
import net.minecraft.item.ItemStack;
9+
import net.minecraft.util.Hand;
10+
import net.minecraft.util.math.RotationAxis;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
15+
16+
@Mixin(HeldItemRenderer.class)
17+
public class HeldItemRendererMixin {
18+
19+
@Inject(method = "renderFirstPersonItem",
20+
at = @At(value = "INVOKE",
21+
target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemDisplayContext;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"))
22+
private void scaleHeldItem(CallbackInfo ci,
23+
@Local(argsOnly = true) Hand hand,
24+
@Local(argsOnly = true) MatrixStack matrices,
25+
@Local ItemStack item) {
26+
27+
// Check if item scaling is enabled
28+
if (!ScaleMeConfig.enableItemScaleAndPosition || item.isEmpty()) {
29+
return;
30+
}
31+
32+
// Apply rotations first
33+
if (ScaleMeConfig.heldItemPitchRotation != 0.0f) {
34+
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(ScaleMeConfig.heldItemPitchRotation));
35+
}
36+
if (ScaleMeConfig.heldItemYawRotation != 0.0f) {
37+
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(ScaleMeConfig.heldItemYawRotation));
38+
}
39+
if (ScaleMeConfig.heldItemRollRotation != 0.0f) {
40+
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(ScaleMeConfig.heldItemRollRotation));
41+
}
42+
43+
// Apply scaling
44+
if (ScaleMeConfig.itemScale != 1.0f) {
45+
matrices.scale(ScaleMeConfig.itemScale, ScaleMeConfig.itemScale, ScaleMeConfig.itemScale);
46+
}
47+
48+
// Apply position adjustments
49+
if (ScaleMeConfig.heldItemXPosition != 0.0f ||
50+
ScaleMeConfig.heldItemYPosition != 0.0f ||
51+
ScaleMeConfig.heldItemZPosition != 0.0f) {
52+
53+
matrices.translate(
54+
ScaleMeConfig.heldItemXPosition / ScaleMeConfig.itemScale,
55+
ScaleMeConfig.heldItemYPosition / ScaleMeConfig.itemScale,
56+
ScaleMeConfig.heldItemZPosition / ScaleMeConfig.itemScale
57+
);
58+
}
59+
}
60+
61+
@ModifyExpressionValue(method = "updateHeldItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getAttackCooldownProgress(F)F"))
62+
private float preventSwingAnimationBobbing(float original) {
63+
if (ScaleMeConfig.enableItemScaleAndPosition || ScaleMeConfig.enableItemSwingModifications) {
64+
return ScaleMeConfig.disableSwingAnimationBobbing ? 1.0f : original;
65+
}
66+
return original;
67+
}
68+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.github.kd_gaming1.scaleme.client.mixin;
2+
3+
import com.github.kd_gaming1.scaleme.config.ScaleMeConfig;
4+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
5+
import net.minecraft.client.MinecraftClient;
6+
import net.minecraft.client.network.AbstractClientPlayerEntity;
7+
import net.minecraft.entity.Entity;
8+
import net.minecraft.entity.EntityType;
9+
import net.minecraft.entity.LivingEntity;
10+
import net.minecraft.world.World;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Unique;
13+
import org.spongepowered.asm.mixin.injection.At;
14+
15+
@Mixin(LivingEntity.class)
16+
public abstract class LivingEntityMixin extends Entity {
17+
18+
protected LivingEntityMixin(EntityType<?> type, World world) {
19+
super(type, world);
20+
}
21+
22+
@ModifyExpressionValue(method = "getHandSwingDuration",
23+
at = {
24+
@At(value = "INVOKE", target = "Lnet/minecraft/entity/effect/StatusEffectUtil;hasHaste(Lnet/minecraft/entity/LivingEntity;)Z"),
25+
@At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;hasStatusEffect(Lnet/minecraft/registry/entry/RegistryEntry;)Z")
26+
},
27+
require = 2
28+
)
29+
private boolean ignoreMiningEffects(boolean original) {
30+
return (!shouldEnableSwingModifications() || !ScaleMeConfig.ignoreMiningEffects) && original;
31+
}
32+
33+
@ModifyExpressionValue(method = "getHandSwingDuration", at = @At(value = "CONSTANT", args = "intValue=6"))
34+
private int modifySwingDuration(int original) {
35+
if (shouldEnableSwingModifications()) {
36+
int modified = Math.round(original / ScaleMeConfig.itemAnimationSpeed);
37+
return Math.max(1, Math.min(60, modified));
38+
}
39+
return original;
40+
}
41+
42+
@Unique
43+
private boolean shouldEnableSwingModifications() {
44+
if (!ScaleMeConfig.enableItemSwingModifications) return false;
45+
46+
MinecraftClient client = MinecraftClient.getInstance();
47+
if (client.player == null) return false;
48+
49+
if ((Object) this instanceof AbstractClientPlayerEntity p) {
50+
return p.isMainPlayer();
51+
}
52+
return false;
53+
}
54+
}

src/main/java/com/github/kd_gaming1/scaleme/config/ScaleMeConfig.java

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
public class ScaleMeConfig extends MidnightConfig {
66
public static final String SCALING = "scaling";
7+
public static final String ITEMSCALING = "item scaling";
78
public static final String VIEW = "view";
89

9-
// Own Player Scaling
10+
// Player Scaling
1011
@Comment(category = SCALING, name = "Adjust the visual size of your own player model")
1112
public static Comment ownPlayerDescription;
1213

@@ -52,6 +53,62 @@ public class ScaleMeConfig extends MidnightConfig {
5253
public static boolean showQuickAddButton = true;
5354
*/
5455

56+
// Item Scaling
57+
58+
@Comment(category = ITEMSCALING, name = "Adjust the visual size of items and there held positions and animation")
59+
public static Comment itemScalingDescription;
60+
61+
@Entry(category = ITEMSCALING, name = "Enable Item Scale & Position")
62+
public static boolean enableItemScaleAndPosition = false;
63+
64+
/*
65+
TODO: Add option to only affect weapons and tools
66+
@Entry(category = ITEMSCALING, name = "Only affect weapons and tools")
67+
public static boolean onlyAffectWeaponsAndTools = false;
68+
*/
69+
70+
@Entry(category = ITEMSCALING, name = "Item Scale", isSlider = true, min = 0.05f, max = 3.0f)
71+
public static float itemScale = 1.0f;
72+
73+
@Comment(category = ITEMSCALING, name = "Adjust the position of your held item")
74+
public static Comment heldItemPositionDescription;
75+
76+
@Entry(category = ITEMSCALING, name = "Held Item X Position", isSlider = true, min = -2.0f, max = 2.0f)
77+
public static float heldItemXPosition = 0.0f;
78+
79+
@Entry(category = ITEMSCALING, name = "Held Item Y Position", isSlider = true, min = -2.0f, max = 2.0f)
80+
public static float heldItemYPosition = 0.0f;
81+
82+
@Entry(category = ITEMSCALING, name = "Held Item Z Position", isSlider = true, min = -2.0f, max = 2.0f)
83+
public static float heldItemZPosition = 0.0f;
84+
85+
@Comment(category = ITEMSCALING, name = "Adjust the Rotation of held item")
86+
public static Comment heldItemRotationDescription;
87+
88+
@Entry(category = ITEMSCALING, name = "Held Item Yaw Rotation", isSlider = true, min = -180.0f, max = 180.0f)
89+
public static float heldItemYawRotation = 0.0f;
90+
91+
@Entry(category = ITEMSCALING, name = "Held Item Pitch Rotation", isSlider = true, min = -90.0f, max = 90.0f)
92+
public static float heldItemPitchRotation = 0.0f;
93+
94+
@Entry(category = ITEMSCALING, name = "Held Item Roll Rotation", isSlider = true, min = -180.0f, max = 180.0f)
95+
public static float heldItemRollRotation = 0.0f;
96+
97+
@Comment(category = ITEMSCALING, name = "Adjust swing/animation speed of items")
98+
public static Comment itemAnimationSpeedDescription;
99+
100+
@Entry(category = ITEMSCALING, name = "Enable Item Swing Modifications")
101+
public static boolean enableItemSwingModifications = false;
102+
103+
@Entry(category = ITEMSCALING, name = "Ignore mining effects")
104+
public static boolean ignoreMiningEffects = true;
105+
106+
@Entry(category = ITEMSCALING, name = "Disable swing animation bobbing")
107+
public static boolean disableSwingAnimationBobbing = true;
108+
109+
@Entry(category = ITEMSCALING, name = "Item Animation Speed", isSlider = true, min = 0.05f, max = 3.0f)
110+
public static float itemAnimationSpeed = 1.0f;
111+
55112
// View (Crosshair + Camera)
56113
@Comment(category = VIEW, name = "Configure crosshair and camera options")
57114
public static Comment viewDescription;

src/main/resources/assets/scaleme/lang/en_us.json

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
{
22
"scaleme.midnightconfig.title": "ScaleMe - Visual Scaling",
33
"scaleme.midnightconfig.category.scaling": "Player Scaling Controls",
4+
"scaleme.midnightconfig.category.item scaling": "Item Scaling Controls",
45
"scaleme.midnightconfig.category.view": "View & Camera",
56

67
"scaleme.midnightconfig.ownPlayerDescription.label": "Adjust the visual size of your own player model",
78
"scaleme.midnightconfig.ownPlayerScale.label": "Own Player Scale",
89
"scaleme.midnightconfig.ownPlayerScale.tooltip": "Controls how large or small your own player appears visually",
910

10-
"scaleme.midnightconfig.smoothScaling.label": "Smooth Scaling",
11-
"scaleme.midnightconfig.smoothScaling.tooltip": "Gradually transition between scale changes for your own player",
12-
1311
"scaleme.midnightconfig.playersDescription.label": "Adjust the visual size of other players",
1412
"scaleme.midnightconfig.enableOtherPlayersScaling.label": "Enable Scaling for Other Players",
1513
"scaleme.midnightconfig.enableOtherPlayersScaling.tooltip": "Allow scaling of other players' models (visual only)",
@@ -29,6 +27,42 @@
2927
"scaleme.midnightconfig.villagerNpcScale.tooltip": "Controls how large or small Hypixel Villager NPCs appear visually",
3028

3129
"scaleme.midnightconfig.smoothedScalingDescription.label": "Make changes between scale levels appear smooth",
30+
"scaleme.midnightconfig.smoothScaling.label": "Smooth Scaling",
31+
"scaleme.midnightconfig.smoothScaling.tooltip": "Gradually transition between scale changes for your own player",
32+
33+
"scaleme.midnightconfig.itemScalingDescription.label": "Adjust the visual size of items and their held positions and animation",
34+
"scaleme.midnightconfig.enableItemScaleAndPosition.label": "Enable Item Scale & Position",
35+
"scaleme.midnightconfig.enableItemScaleAndPosition.tooltip": "Enable scaling and position adjustments for held items (does not affect animation speed).",
36+
"scaleme.midnightconfig.onlyAffectWeaponsAndTools.label": "Only affect weapons and tools",
37+
"scaleme.midnightconfig.onlyAffectWeaponsAndTools.tooltip": "Only scale weapons and tools, not all items. (Some weapons on Hypixel skyblock may not scale properly, as hypixel don't use a normal weapon or tool item for them.)",
38+
"scaleme.midnightconfig.itemScale.label": "Item Scale",
39+
"scaleme.midnightconfig.itemScale.tooltip": "Controls how large or small held items appear visually",
40+
41+
"scaleme.midnightconfig.heldItemPositionDescription.label": "Adjust the position of your held item",
42+
"scaleme.midnightconfig.heldItemXPosition.label": "Held Item X Position",
43+
"scaleme.midnightconfig.heldItemXPosition.tooltip": "Adjust the X position of your held item. Higher values will move the item further to the right.",
44+
"scaleme.midnightconfig.heldItemYPosition.label": "Held Item Y Position",
45+
"scaleme.midnightconfig.heldItemYPosition.tooltip": "Adjust the Y position of your held item. Higher values will move the item further up.",
46+
"scaleme.midnightconfig.heldItemZPosition.label": "Held Item Z Position",
47+
"scaleme.midnightconfig.heldItemZPosition.tooltip": "Adjust the Z position of your held item. Higher values will move the item further away from you.",
48+
49+
"scaleme.midnightconfig.heldItemRotationDescription.label": "Adjust the Rotation of held item",
50+
"scaleme.midnightconfig.heldItemYawRotation.label": "Held Item Yaw Rotation",
51+
"scaleme.midnightconfig.heldItemYawRotation.tooltip": "Adjust the yaw rotation of your held item. Higher values will rotate the item to the right.",
52+
"scaleme.midnightconfig.heldItemPitchRotation.label": "Held Item Pitch Rotation",
53+
"scaleme.midnightconfig.heldItemPitchRotation.tooltip": "Adjust the pitch rotation of your held item. Higher values will rotate the item upwards.",
54+
"scaleme.midnightconfig.heldItemRollRotation.label": "Held Item Roll Rotation",
55+
"scaleme.midnightconfig.heldItemRollRotation.tooltip": "Adjust the roll rotation of your held item. Higher values will roll the item to the right.",
56+
57+
"scaleme.midnightconfig.itemAnimationSpeedDescription.label": "Adjust swing/animation speed of items",
58+
"scaleme.midnightconfig.enableItemSwingModifications.label": "Enable Item Swing Modifications",
59+
"scaleme.midnightconfig.enableItemSwingModifications.tooltip": "Enable modifications to the swing/animation of held items.",
60+
"scaleme.midnightconfig.ignoreMiningEffects.label": "Ignore mining effects",
61+
"scaleme.midnightconfig.ignoreMiningEffects.tooltip": "If enabled, ignores the mining effects increase to animation speed.",
62+
"scaleme.midnightconfig.disableSwingAnimationBobbing.label": "Disable swing animation bobbing",
63+
"scaleme.midnightconfig.disableSwingAnimationBobbing.tooltip": "If enabled, disables the bobbing effect during item swing animations. Only works if the option 'Item Swing Modifications' or 'Item Scale & Position' is enabled.",
64+
"scaleme.midnightconfig.itemAnimationSpeed.label": "Item Animation Speed",
65+
"scaleme.midnightconfig.itemAnimationSpeed.tooltip": "Controls the animation speed of held items, 1.0 is normal speed / disabled.",
3266

3367
"scaleme.midnightconfig.viewDescription.label": "Configure crosshair and camera options",
3468
"scaleme.midnightconfig.enableCrosshairInThirdPerson.label": "Show Crosshair in Third Person (Back)",

0 commit comments

Comments
 (0)