Skip to content

Commit 29d95e9

Browse files
committed
view model base
1 parent 2db56bf commit 29d95e9

File tree

3 files changed

+231
-0
lines changed

3 files changed

+231
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lambda.mixin.render;
2+
3+
import com.lambda.module.modules.render.ViewModel;
4+
import net.minecraft.client.network.AbstractClientPlayerEntity;
5+
import net.minecraft.client.render.VertexConsumerProvider;
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 org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Inject;
13+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14+
15+
@Mixin(HeldItemRenderer.class)
16+
public class HeldItemRendererMixin {
17+
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderArmHoldingItem(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IFFLnet/minecraft/util/Arm;)V"))
18+
private void onRenderArmHoldingItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
19+
if (ViewModel.INSTANCE.isEnabled()) ViewModel.INSTANCE.transform(itemStack, hand, matrices);
20+
}
21+
22+
@Inject(method = "renderFirstPersonItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/HeldItemRenderer;renderItem(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformationMode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V"))
23+
private void onRenderFirstPersonItem(AbstractClientPlayerEntity player, float tickDelta, float pitch, Hand hand, float swingProgress, ItemStack itemStack, float equipProgress, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, CallbackInfo ci) {
24+
if (ViewModel.INSTANCE.isEnabled()) ViewModel.INSTANCE.transform(itemStack, hand, matrices);
25+
}
26+
}
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
package com.lambda.module.modules.render
2+
3+
import com.lambda.Lambda.mc
4+
import com.lambda.module.Module
5+
import com.lambda.module.tag.ModuleTag
6+
import net.minecraft.client.util.math.MatrixStack
7+
import net.minecraft.item.ItemStack
8+
import net.minecraft.util.Arm
9+
import net.minecraft.util.Hand
10+
import net.minecraft.util.math.RotationAxis
11+
import org.joml.Vector3f
12+
import org.joml.Vector3i
13+
14+
object ViewModel : Module(
15+
name = "View Model",
16+
description = "Adjusts hand and held item rendering",
17+
defaultTags = setOf(ModuleTag.RENDER)
18+
) {
19+
private val page by setting("Page", Page.General)
20+
21+
//ToDo: implement the rest of the settings and maybe add a couple more
22+
23+
private val ignoreHand by setting("Ignore Hand", false, "Prevents adjusting the players hand", visibility = { page == Page.General })
24+
val oldSwingAnimation by setting("Old Swing Animation", false, "Adjusts the swing animation to what it looked like in 1.8", visibility = { page == Page.General })
25+
val swapAnimation by setting("Swap Animation", true, "If disabled, it removes the drop down animation when swapping item", visibility = { page == Page.General })
26+
val shadow by setting("Shadows", true, "If disabled, it removes shadows on the model", visibility = { page == Page.General })
27+
28+
private val linkedScale by setting("Linked", true, "Links both hands scale settings", visibility = { page == Page.Scale })
29+
private val leftXScale by setting("Left X Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightXScale = to } }
30+
private val leftYScale by setting("Left Y Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightYScale = to } }
31+
private val leftZScale by setting("Left Z Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale }).apply { onValueChange { _, to -> if (linkedScale) rightZScale = to } }
32+
private var rightXScale by setting("Right X Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
33+
private var rightYScale by setting("Right Y Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
34+
private var rightZScale by setting("Right Z Scale", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Scale && !linkedScale })
35+
36+
private val linkedPosition by setting("Linked", true, "Links both hands position settings", visibility = { page == Page.Position })
37+
private val leftXPosition by setting("Left X Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position }).apply { onValueChange { _, to -> if (linkedPosition) rightXPosition = to } }
38+
private val leftYPosition by setting("Left Y Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position }).apply { onValueChange { _, to -> if (linkedPosition) rightYPosition = to } }
39+
private val leftZPosition by setting("Left Z Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position }).apply { onValueChange { _, to -> if (linkedPosition) rightZPosition = to } }
40+
private var rightXPosition by setting("Right X Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position && !linkedPosition })
41+
private var rightYPosition by setting("Right Y Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position && !linkedPosition })
42+
private var rightZPosition by setting("Right Z Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Position && !linkedPosition })
43+
44+
private val linkedRotation by setting("Linked", true, "Links both hands rotation settings", visibility = { page == Page.Rotation })
45+
private val leftXRotation by setting("Left X Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation }).apply { onValueChange { _, to -> if (linkedRotation) rightXRotation = to } }
46+
private val leftYRotation by setting("Left Y Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation }).apply { onValueChange { _, to -> if (linkedRotation) rightYRotation = to } }
47+
private val leftZRotation by setting("Left Z Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation }).apply { onValueChange { _, to -> if (linkedRotation) rightZRotation = to } }
48+
private var rightXRotation by setting("Right X Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation && !linkedRotation })
49+
private var rightYRotation by setting("Right Y Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation && !linkedRotation })
50+
private var rightZRotation by setting("Right Z Rotation", 0, -180..180, 1, visibility = { page == Page.Rotation && !linkedRotation })
51+
52+
private val linkedFOV by setting("Linked FOV", true, "Links both hands FOV settings", visibility = { page == Page.FOV })
53+
private val leftFOV by setting ("Left FOV", 80, 10..180, 1, visibility = { page == Page.FOV }).apply { onValueChange { _, to -> if (linkedFOV) rightFOV = to } }
54+
private var rightFOV by setting ("Right FOV", 80, 10..180, 1, visibility = { page == Page.FOV && !linkedFOV })
55+
56+
private val handXScale by setting("Hand X Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
57+
private val handYScale by setting("Hand Y Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
58+
private val handZScale by setting("Hand Z Scale", 1.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
59+
private val handXPosition by setting("Hand X Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
60+
private val handYPosition by setting("Hand Y Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
61+
private val handZPosition by setting("Hand Z Position", 0.0f, -1.0f..1.0f, 0.025f, visibility = { page == Page.Hand })
62+
private var handXRotation by setting("Hand X Rotation", 0, -180..180, 1, visibility = { page == Page.Hand })
63+
private var handYRotation by setting("Hand Y Rotation", 0, -180..180, 1, visibility = { page == Page.Hand })
64+
private var handZRotation by setting("Hand Z Rotation", 0, -180..180, 1, visibility = { page == Page.Hand })
65+
private val handFOV by setting("Hand FOV", 80, 10..180, 1, visibility = { page == Page.Hand })
66+
67+
private enum class Page {
68+
General, Scale, Position, Rotation, FOV, Hand
69+
}
70+
71+
private enum class Side {
72+
Left, Right
73+
}
74+
75+
fun transform(itemStack: ItemStack, hand: Hand, matrices: MatrixStack) {
76+
val side = if (mc.options.mainArm.value == Arm.LEFT) {
77+
if (hand == Hand.MAIN_HAND) Side.Left else Side.Right
78+
} else {
79+
if (hand == Hand.MAIN_HAND) Side.Right else Side.Left
80+
}
81+
82+
val emptyHand = itemStack.isEmpty
83+
if (ignoreHand && emptyHand) return
84+
85+
scale(side, matrices, emptyHand)
86+
position(side, matrices, emptyHand)
87+
rotate(side, matrices, emptyHand)
88+
}
89+
90+
private fun scale(side: Side, matrices: MatrixStack, emptyHand: Boolean) {
91+
val scaleVec = getScaleVec(side, emptyHand)
92+
matrices.scale(scaleVec.x, scaleVec.y, scaleVec.z)
93+
}
94+
95+
private fun getScaleVec(side: Side, emptyHand: Boolean): Vector3f {
96+
if (emptyHand) {
97+
return Vector3f(
98+
handXScale,
99+
handYScale,
100+
handZScale
101+
)
102+
}
103+
104+
when (side) {
105+
Side.Left -> {
106+
return Vector3f(
107+
leftXScale,
108+
leftYScale,
109+
leftZScale
110+
)
111+
}
112+
Side.Right -> {
113+
return Vector3f(
114+
rightXScale,
115+
rightYScale,
116+
rightZScale
117+
)
118+
}
119+
}
120+
}
121+
122+
private fun position(side: Side, matrices: MatrixStack, emptyHand: Boolean) {
123+
val positionVec = getPositionVec(side, emptyHand)
124+
matrices.translate(positionVec.x, positionVec.y, positionVec.z)
125+
}
126+
127+
private fun getPositionVec(side: Side, emptyHand: Boolean): Vector3f {
128+
when (side) {
129+
Side.Left -> {
130+
return if (emptyHand) {
131+
Vector3f(
132+
-handXPosition,
133+
handYPosition,
134+
handZPosition
135+
)
136+
} else {
137+
Vector3f(
138+
-leftXPosition,
139+
leftYPosition,
140+
leftZPosition
141+
)
142+
}
143+
}
144+
Side.Right -> {
145+
return if (emptyHand) {
146+
Vector3f(
147+
handXPosition,
148+
handYPosition,
149+
handZPosition
150+
)
151+
} else {
152+
Vector3f(
153+
rightXPosition,
154+
rightYPosition,
155+
rightZPosition
156+
)
157+
}
158+
}
159+
}
160+
}
161+
162+
private fun rotate(side: Side, matrices: MatrixStack, emptyHand: Boolean) {
163+
val rotationVec = getRotationVec(side, emptyHand)
164+
165+
matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(rotationVec.x.toFloat()))
166+
matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(rotationVec.y.toFloat()))
167+
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(rotationVec.z.toFloat()))
168+
}
169+
170+
private fun getRotationVec(side: Side, emptyHand: Boolean): Vector3i {
171+
when (side) {
172+
Side.Left -> {
173+
return if (emptyHand) {
174+
Vector3i(
175+
handXRotation,
176+
-handYRotation,
177+
-handZRotation
178+
)
179+
} else {
180+
Vector3i(
181+
leftXRotation,
182+
-leftYRotation,
183+
-leftZRotation
184+
)
185+
}
186+
}
187+
Side.Right -> {
188+
return if (emptyHand) {
189+
Vector3i(
190+
handXRotation,
191+
handYRotation,
192+
handZRotation
193+
)
194+
} else {
195+
Vector3i(
196+
rightXRotation,
197+
rightYRotation,
198+
rightZRotation
199+
)
200+
}
201+
}
202+
}
203+
}
204+
}

common/src/main/resources/lambda.mixins.common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"render.DebugHudMixin",
2525
"render.GameRendererMixin",
2626
"render.GlStateManagerMixin",
27+
"render.HeldItemRendererMixin",
2728
"render.InGameHudMixin",
2829
"render.InGameOverlayRendererMixin",
2930
"render.LightmapTextureManagerMixin",

0 commit comments

Comments
 (0)