-
Notifications
You must be signed in to change notification settings - Fork 19
feat(AutoSign): Add AutoSign Module #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IceTank
wants to merge
2
commits into
lambda-client:1.21.11
Choose a base branch
from
IceTank:feature/module/AutoSign
base: 1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/kotlin/com/lambda/module/modules/player/AutoSign.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Copyright 2026 Lambda | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.lambda.module.modules.player | ||
|
|
||
| import com.ibm.icu.util.Calendar | ||
| import com.lambda.event.events.GuiEvent | ||
| import com.lambda.event.listener.SafeListener.Companion.listen | ||
| import com.lambda.module.Module | ||
| import com.lambda.module.tag.ModuleTag | ||
| import net.minecraft.block.entity.HangingSignBlockEntity | ||
| import net.minecraft.client.gui.screen.ingame.AbstractSignEditScreen | ||
| import net.minecraft.client.gui.screen.ingame.HangingSignEditScreen | ||
| import net.minecraft.client.gui.screen.ingame.SignEditScreen | ||
| import net.minecraft.network.packet.c2s.play.UpdateSignC2SPacket | ||
| import java.util.* | ||
|
|
||
|
|
||
| class AutoSign : Module( | ||
| name = "AutoSign", | ||
| description = """Auto fills signs with customizable text. Leave lines empty to skip them. Supports data formatting with: | ||
| |<d> - Day of month (1-31) | ||
| |<dd> - Day of month (01-31) | ||
| |<M> - Month (1-12) | ||
| |<MM> - Month (01-12) | ||
| |<MMM> - Month (short name, e.g., Jan) | ||
| |<MMMM> - Month (full name, e.g., January) | ||
| |<yy> - Year (last two digits, e.g., 26) | ||
| |<yyyy> - Year (e.g., 2026) | ||
| |<HH> - Hour (00-23) | ||
| |<mm> - Minute (00-59) | ||
| |<ss> - Second (00-59) | ||
| """.trimMargin(), | ||
| tag = ModuleTag.PLAYER | ||
| ) { | ||
| var autoWrite by setting("Auto Write", true) | ||
| var line1 by setting("Line 1", "Welcome to Lambda!") { autoWrite } | ||
| var line2 by setting("Line 2", "Enjoy your stay.") { autoWrite } | ||
| var line3 by setting("Line 3", "Have fun!") { autoWrite } | ||
| var line4 by setting("Line 4", "Lambda <dd>/<M>/<yy>") { autoWrite } | ||
| var writeOnFront by setting("Write Front", true, description = "Write on front side of the sign") { autoWrite } | ||
|
|
||
| var autoClose by setting("Auto Close", true) | ||
|
|
||
| init { | ||
| listen<GuiEvent.SignEditorOpen> { event -> | ||
| val lines = Array(4) { i -> event.component1().frontText.getMessages(false)[i].string } | ||
| if (autoWrite) { | ||
| var formatLines = arrayOf(line1, line2, line3, line4) | ||
| val calendar = Calendar.getInstance() | ||
| val month = calendar.get(Calendar.MONTH) + 1 // Months are 0-based in Calendar | ||
|
|
||
| for (i in 0 until 4) { | ||
| val formattedLine = formatLines[i] | ||
| .replace("<dd>", String.format($$"%1$td", Date())) | ||
| .replace("<d>", String.format($$"%1$te", Date())) | ||
| .replace("<M>", month.toString()) | ||
| .replace("<MM>", String.format("%02d", month)) | ||
| .replace("<MMM>", String.format($$"%1$tb", Date())) | ||
| .replace("<MMMM>", String.format($$"%1$tB", Date())) | ||
| .replace("<yy>", String.format($$"%1$ty", Date())) | ||
| .replace("<yyyy>", String.format($$"%1$tY", Date())) | ||
| .replace("<HH>", String.format($$"%1$tH", Date())) | ||
| .replace("<mm>", String.format($$"%1$tM", Date())) | ||
| .replace("<ss>", String.format($$"%1$tS", Date())) | ||
|
|
||
| if (formattedLine.isNotEmpty()) lines[i] = String.format(formattedLine, Date()) | ||
| } | ||
| } | ||
|
|
||
| var editor: AbstractSignEditScreen = if (event.sign is HangingSignBlockEntity) HangingSignEditScreen(event.sign, true, mc.shouldFilterText()) | ||
| else SignEditScreen(event.sign, true, mc.shouldFilterText()) | ||
| for (i in 0 until 4) editor.messages[i] = lines[i] | ||
| if (autoClose) { | ||
| if (writeOnFront) mc.networkHandler?.sendPacket(UpdateSignC2SPacket(event.sign.pos, true, editor.messages[0], editor.messages[1], editor.messages[2], editor.messages[3])) | ||
| else mc.networkHandler?.sendPacket(UpdateSignC2SPacket(event.sign.pos, false, editor.messages[0], editor.messages[1], editor.messages[2], editor.messages[3])) | ||
| } else { | ||
| mc.setScreen(editor) | ||
| } | ||
| event.cancel() | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,3 +123,5 @@ transitive-accessible method net/minecraft/item/BlockItem getPlacementState (Lne | |
| transitive-accessible method net/minecraft/block/AbstractBlock getPickStack (Lnet/minecraft/world/WorldView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Z)Lnet/minecraft/item/ItemStack; | ||
| transitive-accessible field net/minecraft/client/gui/screen/ingame/HandledScreen focusedSlot Lnet/minecraft/screen/slot/Slot; | ||
| transitive-accessible field net/minecraft/registry/SimpleRegistry frozen Z | ||
|
|
||
| transitive-accessible field net/minecraft/client/gui/screen/ingame/AbstractSignEditScreen messages [Ljava/lang/String; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prob just remove the white space above to move it into the # Other group |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SafeContext contains connection which should be used instead of mc.networkHandler. Also 2b2t doesnt allow sign editing so this doesnt seem to work. Would it be possible to close the sign automatically without using edit sign?