Skip to content

Commit 1f924e1

Browse files
📝 Add docstrings to refactor/ui
Docstrings generation was requested by @Edouard127. * #98 (comment) The following files were modified: * `common/src/main/java/com/lambda/mixin/render/ChatHudMixin.java` * `common/src/main/java/com/lambda/mixin/render/ChatInputSuggestorMixin.java` * `common/src/main/java/com/lambda/mixin/render/ChatScreenMixin.java` * `common/src/main/java/com/lambda/mixin/render/DrawContextMixin.java` * `common/src/main/java/com/lambda/mixin/render/SplashOverlayMixin.java` * `common/src/main/kotlin/com/lambda/graphics/RenderMain.kt` * `common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/Buffer.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/IRenderContext.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/VertexPipeline.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/frame/CachedFrame.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/frame/FrameBuffer.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/frame/ScreenFrameBuffer.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/pixel/PixelBuffer.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/vertex/ElementBuffer.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/vertex/VertexArray.kt` * `common/src/main/kotlin/com/lambda/graphics/buffer/vertex/VertexBuffer.kt` * `common/src/main/kotlin/com/lambda/graphics/gl/GlStateUtils.kt` * `common/src/main/kotlin/com/lambda/graphics/gl/Matrices.kt` * `common/src/main/kotlin/com/lambda/graphics/gl/Memory.kt` * `common/src/main/kotlin/com/lambda/graphics/pipeline/ScissorAdapter.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/esp/ChunkedESP.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/esp/ESPRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/AbstractGUIRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/TextureRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/FontRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/core/LambdaAtlas.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/core/LambdaEmoji.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/core/LambdaFont.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/sdf/DistanceFieldTexture.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/FilledRectRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/renderer/gui/rect/OutlineRectRenderer.kt` * `common/src/main/kotlin/com/lambda/graphics/shader/Shader.kt` * `common/src/main/kotlin/com/lambda/graphics/shader/ShaderUtils.kt` * `common/src/main/kotlin/com/lambda/graphics/texture/AnimatedTexture.kt` * `common/src/main/kotlin/com/lambda/graphics/texture/Texture.kt` * `common/src/main/kotlin/com/lambda/graphics/texture/TextureOwner.kt` * `common/src/main/kotlin/com/lambda/graphics/texture/TextureUtils.kt` * `common/src/main/kotlin/com/lambda/gui/GuiManager.kt` * `common/src/main/kotlin/com/lambda/gui/LambdaScreen.kt` * `common/src/main/kotlin/com/lambda/gui/ScreenLayout.kt` * `common/src/main/kotlin/com/lambda/gui/component/DockingRect.kt` * `common/src/main/kotlin/com/lambda/gui/component/core/FilledRect.kt` * `common/src/main/kotlin/com/lambda/gui/component/core/OutlineRect.kt` * `common/src/main/kotlin/com/lambda/gui/component/core/TextField.kt` * `common/src/main/kotlin/com/lambda/gui/component/layout/Layout.kt` * `common/src/main/kotlin/com/lambda/gui/component/window/TitleBar.kt` * `common/src/main/kotlin/com/lambda/gui/component/window/Window.kt` * `common/src/main/kotlin/com/lambda/gui/component/window/WindowContent.kt` * `common/src/main/kotlin/com/lambda/gui/impl/clickgui/ModuleLayout.kt` * `common/src/main/kotlin/com/lambda/gui/impl/clickgui/ModuleWindow.kt` * `common/src/main/kotlin/com/lambda/gui/impl/clickgui/settings/BooleanButton.kt` * `common/src/main/kotlin/com/lambda/module/HudModule.kt` * `common/src/main/kotlin/com/lambda/module/Module.kt` * `common/src/main/kotlin/com/lambda/module/modules/client/LambdaMoji.kt` * `common/src/main/kotlin/com/lambda/module/modules/player/MapDownloader.kt`
1 parent 081b677 commit 1f924e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1477
-229
lines changed

common/src/main/java/com/lambda/mixin/render/ChatHudMixin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@
2828

2929
@Mixin(ChatHud.class)
3030
public class ChatHudMixin {
31+
/**
32+
* Redirects the chat HUD text rendering to apply custom text parsing and color adjustments.
33+
*
34+
* <p>This method intercepts calls to {@code DrawContext#drawTextWithShadow} during chat rendering.
35+
* It processes the text using {@code LambdaMoji.INSTANCE.parse} to incorporate custom formatting (e.g., emoji support),
36+
* overrides the x-coordinate by rendering at x = 0, and adjusts the text color by combining a white base (0xFFFFFF)
37+
* with an alpha value derived from the provided {@code color} parameter.
38+
*
39+
* @param text the text to be rendered, processed for custom formatting
40+
* @param x the original x-coordinate (ignored as rendering occurs at x = 0)
41+
* @param y the y-coordinate for rendering the text
42+
* @param color the original text color used to compute the alpha channel for the final rendered color
43+
* @return the result of the underlying text rendering call
44+
*/
3145
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTextWithShadow(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/OrderedText;III)I"))
3246
int redirectRenderCall(DrawContext instance, TextRenderer textRenderer, OrderedText text, int x, int y, int color) {
3347
return instance.drawTextWithShadow(textRenderer, LambdaMoji.INSTANCE.parse(text, x, y, color), 0, y, 16777215 + (color << 24));

common/src/main/java/com/lambda/mixin/render/ChatInputSuggestorMixin.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,56 @@ public abstract class ChatInputSuggestorMixin {
5555
@Shadow
5656
private @Nullable CompletableFuture<Suggestions> pendingSuggestions;
5757

58+
/**
59+
* Displays the current suggestion list.
60+
*
61+
* <p>This shadowed method should be overridden to update the suggestion display. If
62+
* {@code narrateFirstSuggestion} is {@code true}, the method should also provide narration
63+
* for the first suggestion to enhance accessibility.
64+
*
65+
* @param narrateFirstSuggestion if {@code true}, the first suggestion is narrated; otherwise, it is not
66+
*/
5867
@Shadow
5968
public abstract void show(boolean narrateFirstSuggestion);
6069

70+
/**
71+
* Determines if the current chat input text should be treated as a command.
72+
*
73+
* <p>This method overrides the provided <code>showCompletions</code> flag during the refresh
74+
* process by evaluating the text currently entered in the chat input field. It returns
75+
* <code>true</code> if the input is recognized as a command, and <code>false</code> otherwise.</p>
76+
*
77+
* @param showCompletions the initial flag indicating whether completions should be shown (its value is ignored)
78+
* @return <code>true</code> if the chat input text is recognized as a command, <code>false</code> otherwise
79+
*/
6180
@ModifyVariable(method = "refresh", at = @At(value = "STORE"), index = 3)
6281
private boolean refreshModify(boolean showCompletions) {
6382
return CommandManager.INSTANCE.isCommand(textField.getText());
6483
}
6584

85+
/**
86+
* Redirects the command dispatcher retrieval to use a custom dispatcher based on the current chat input.
87+
* <p>
88+
* Instead of invoking the default dispatcher from the network handler during a refresh, this method
89+
* fetches a dispatcher tailored to the chat input text from the CommandManager.
90+
*
91+
* @return a command dispatcher that reflects the current chat input context
92+
*/
6693
@Redirect(method = "refresh", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;getCommandDispatcher()Lcom/mojang/brigadier/CommandDispatcher;"))
6794
private CommandDispatcher<CommandSource> refreshRedirect(ClientPlayNetworkHandler instance) {
6895
return CommandManager.INSTANCE.currentDispatcher(textField.getText());
6996
}
7097

98+
/**
99+
* Injects emoji suggestion logic at the end of the chat refresh process.
100+
*
101+
* <p>This method verifies that emoji suggestions are enabled and that the current input is not a command.
102+
* It extracts text up to the cursor, identifies the last colon to determine the start of the emoji query,
103+
* and filters available emojis based on the subsequent substring. The resulting suggestions are then
104+
* prepared and, once completed, are displayed.
105+
*
106+
* @param ci the callback information for the injection point
107+
*/
71108
@Inject(method = "refresh", at = @At("TAIL"))
72109
private void refreshEmojiSuggestion(CallbackInfo ci) {
73110
if (!LambdaMoji.INSTANCE.isEnabled() ||
@@ -105,6 +142,16 @@ private void refreshEmojiSuggestion(CallbackInfo ci) {
105142
@Unique
106143
private static final Pattern COLON_PATTERN = Pattern.compile("(:[a-zA-Z0-9_]+)");
107144

145+
/**
146+
* Returns the index of the last occurrence of a colon that precedes valid emoji key characters.
147+
*
148+
* <p>The method uses a regular expression to identify sequences starting with a colon
149+
* followed by alphanumeric characters or underscores. If the input is null, empty, or no
150+
* matching sequence is found, it returns -1.</p>
151+
*
152+
* @param input the string to be searched for a colon pattern
153+
* @return the index of the last colon matching the pattern, or -1 if none is found
154+
*/
108155
@Unique
109156
private int neoLambda$getLastColon(String input) {
110157
if (Strings.isNullOrEmpty(input)) return -1;

common/src/main/java/com/lambda/mixin/render/ChatScreenMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626

2727
@Mixin(ChatScreen.class)
2828
public abstract class ChatScreenMixin {
29+
/**
30+
* Intercepts the chat message sending process to execute Lambda commands.
31+
*
32+
* <p>If the chat text is recognized as a Lambda command, the command is executed via the CommandManager,
33+
* and the default message sending is canceled by setting the callback's return value to true.</p>
34+
*
35+
* @param chatText the text of the chat message being processed
36+
* @param addToHistory flag indicating whether the message should be added to the chat history (not used for Lambda commands)
37+
* @param cir callback used to override the normal sending behavior of the chat message
38+
*/
2939
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
3040
void sendMessageInject(String chatText, boolean addToHistory, CallbackInfoReturnable<Boolean> cir) {
3141
if (!CommandManager.INSTANCE.isLambdaCommand(chatText)) return;

common/src/main/java/com/lambda/mixin/render/DrawContextMixin.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,35 @@
4545

4646
@Mixin(DrawContext.class)
4747
public abstract class DrawContextMixin {
48-
@Shadow protected abstract void drawTooltip(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner);
48+
/**
49+
* Renders a tooltip using the provided text renderer, tooltip components, and positioning strategy.
50+
*
51+
* <p>This shadowed method is implemented by the target class to draw tooltips at the specified coordinates.
52+
* The tooltip components determine the content displayed, while the positioner defines how the tooltip is positioned on the screen.</p>
53+
*
54+
* @param textRenderer the renderer used for drawing the tooltip's text
55+
* @param components the list of components forming the tooltip's content
56+
* @param x the x-coordinate for the tooltip's starting position
57+
* @param y the y-coordinate for the tooltip's starting position
58+
* @param positioner the strategy that determines the tooltip's placement
59+
*/
60+
@Shadow protected abstract void drawTooltip(TextRenderer textRenderer, List<TooltipComponent> components, int x, int y, TooltipPositioner positioner);
4961

62+
/**
63+
* Overrides the default tooltip rendering to include additional components.
64+
*
65+
* <p>This injected method converts a list of text components into tooltip components. If optional tooltip data
66+
* is present, it is inserted into the list, and if the currently focused item is a filled map, a map preview
67+
* component is added. It then calls the shadowed tooltip drawing method with the modified components and cancels
68+
* further execution of the original method.</p>
69+
*
70+
* @param textRenderer the renderer used to draw text
71+
* @param text the list of text elements to be converted into tooltip components
72+
* @param data an optional tooltip data element to be incorporated into the tooltip
73+
* @param x the x-coordinate for tooltip positioning
74+
* @param y the y-coordinate for tooltip positioning
75+
* @param ci the callback information used to cancel the original tooltip rendering
76+
*/
5077
@Inject(method = "drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;II)V", at = @At("HEAD"), cancellable = true)
5178
void drawItemTooltip(TextRenderer textRenderer, List<Text> text, Optional<TooltipData> data, int x, int y, CallbackInfo ci) {
5279
List<TooltipComponent> list = text.stream().map(Text::asOrderedText).map(TooltipComponent::of).collect(Collectors.toList());

common/src/main/java/com/lambda/mixin/render/SplashOverlayMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ public LogoTextureMixin(Identifier location) {
6060
super(location);
6161
}
6262

63+
/**
64+
* Redirects the default texture loading to supply a custom banner texture.
65+
*
66+
* <p>This method intercepts the call to load texture data from the default resource pack and returns
67+
* an InputSupplier that provides an InputStream for the custom texture located at "textures/lambda_banner.png".
68+
* The provided resource pack, resource type, and identifier are ignored.</p>
69+
*
70+
* @return an InputSupplier that supplies the custom banner texture's input stream
71+
*/
6372
@Redirect(method = "loadTextureData", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/DefaultResourcePack;open(Lnet/minecraft/resource/ResourceType;Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/InputSupplier;"))
6473
InputSupplier<InputStream> loadTextureData(DefaultResourcePack instance, ResourceType type, Identifier id) {
6574
return () -> LambdaResourceKt.getStream("textures/lambda_banner.png");

common/src/main/kotlin/com/lambda/graphics/RenderMain.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ object RenderMain {
3636
var screenSize = Vec2d.ZERO
3737
var scaleFactor = 1.0
3838

39+
/**
40+
* Renders the 2D interface elements.
41+
*
42+
* This function resets the transformation matrices with a translation along the z-axis to position the 2D
43+
* layer appropriately, then sets up the OpenGL state and posts rendering events for fixed GUI elements,
44+
* the HUD, and scaled elements using the default and current GUI scaling factors.
45+
*/
3946
@JvmStatic
4047
fun render2D() {
4148
resetMatrices(Matrix4f().translate(0f, 0f, -3000f))
@@ -50,6 +57,12 @@ object RenderMain {
5057
}
5158
}
5259

60+
/**
61+
* Prepares the 3D rendering context by resetting matrices with the given transformation,
62+
* updating the projection matrix, and posting a world render event.
63+
*
64+
* @param matrix the transformation matrix used to reset the rendering matrices.
65+
*/
5366
@JvmStatic
5467
fun render3D(matrix: Matrix4f) {
5568
resetMatrices(matrix)
@@ -60,6 +73,16 @@ object RenderMain {
6073
}
6174
}
6275

76+
/**
77+
* Recalculates the screen dimensions and updates the orthographic projection matrix based on a scaling factor.
78+
*
79+
* This function retrieves the current framebuffer dimensions, computes the scaled width and height
80+
* by dividing them by the provided factor, and then updates the global screen size and scale factor.
81+
* It sets the projection matrix to an orthographic projection using the calculated dimensions with a
82+
* near plane of 1000f and a far plane of 21000f.
83+
*
84+
* @param factor the scale factor used to adjust the framebuffer dimensions.
85+
*/
6386
private fun rescale(factor: Double) {
6487
val width = mc.window.framebufferWidth.toFloat()
6588
val height = mc.window.framebufferHeight.toFloat()

common/src/main/kotlin/com/lambda/graphics/animation/Animation.kt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,43 @@ class Animation(initialValue: Double, val update: (Double) -> Double) {
2727
private var prevValue = initialValue
2828
private var currValue = initialValue
2929

30-
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value()
31-
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
30+
/**
31+
* Retrieves the current interpolated animation value.
32+
*
33+
* This operator function enables property delegation by returning the animation's
34+
* current value as computed by the [value] method, which interpolates between the previous
35+
* and current states.
36+
*/
37+
operator fun getValue(thisRef: Any?, property: KProperty<*>) = value()
38+
/**
39+
* Delegated setter that updates the animation's value.
40+
*
41+
* This operator function is triggered when a delegated property is assigned a new value. It sets both the previous
42+
* and current values of the animation to the provided [valueIn].
43+
*
44+
* @param thisRef The object owning the delegated property (unused).
45+
* @param property Metadata for the property being assigned (unused).
46+
* @param valueIn The new value to set for the animation.
47+
*/
48+
operator fun setValue(thisRef: Any?, property: KProperty<*>, valueIn: Double) = setValue(valueIn)
3249

33-
fun value(): Double = lerp(mc.partialTicks, prevValue, currValue)
50+
/**
51+
* Computes and returns the current interpolated animation value.
52+
*
53+
* This function uses linear interpolation between the previous and current animation values,
54+
* leveraging the partial tick value from the rendering context (mc.partialTicks) to ensure smooth transitions.
55+
*
56+
* @return the interpolated animation value.
57+
*/
58+
fun value(): Double = lerp(mc.partialTicks, prevValue, currValue)
3459

60+
/**
61+
* Resets the animation state by updating both the previous and current values.
62+
*
63+
* This ensures that the animation starts from a consistent value without any interpolation.
64+
*
65+
* @param valueIn The new value to set as both the previous and current animation state.
66+
*/
3567
fun setValue(valueIn: Double) {
3668
prevValue = valueIn
3769
currValue = valueIn

0 commit comments

Comments
 (0)