Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 5a76dee

Browse files
committed
refactor ScreenshotUtils, add Freelook toggle
- add [Open] action - add Option for Automatic execution
1 parent ccc789e commit 5a76dee

File tree

4 files changed

+151
-21
lines changed

4 files changed

+151
-21
lines changed

src/main/java/io/github/axolotlclient/modules/freelook/Freelook.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ public class Freelook extends AbstractModule {
4646

4747
private final OptionCategory category = new OptionCategory("freelook");
4848
public final BooleanOption enabled = new BooleanOption("enabled", false);
49-
private final EnumOption perspective = new EnumOption("perspective", Perspective.values(), Perspective.THIRD_PERSON_BACK.toString());
49+
private final EnumOption perspective = new EnumOption("perspective", Perspective.values(),
50+
Perspective.THIRD_PERSON_BACK.toString());
5051
private final BooleanOption invert = new BooleanOption("invert", false);
5152

53+
private final BooleanOption toggle = new BooleanOption("toggle", false);
54+
5255
private Perspective previousPerspective;
5356

5457
public static Freelook getInstance(){
@@ -58,7 +61,7 @@ public static Freelook getInstance(){
5861
@Override
5962
public void init() {
6063
KeyBindingHelper.registerKeyBinding(KEY);
61-
category.add(enabled, perspective, invert);
64+
category.add(enabled, perspective, invert, toggle);
6265
AxolotlClient.CONFIG.addCategory(category);
6366
}
6467

@@ -67,11 +70,23 @@ public void tick() {
6770

6871
if(!enabled.get()) return;
6972

70-
if(KEY.isPressed()) {
71-
if(!active) {
72-
start();
73+
if(toggle.get()){
74+
if (KEY.wasPressed()) {
75+
if (active) {
76+
stop();
77+
} else {
78+
start();
79+
}
80+
}
81+
} else {
82+
if (KEY.isPressed()) {
83+
if (!active) {
84+
start();
85+
}
86+
} else if (active) {
87+
stop();
7388
}
74-
} else if(active) stop();
89+
}
7590
}
7691

7792
private void start() {

src/main/java/io/github/axolotlclient/modules/screenshotUtils/ScreenshotUtils.java

Lines changed: 115 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@
2424

2525
import io.github.axolotlclient.AxolotlClient;
2626
import io.github.axolotlclient.AxolotlclientConfig.options.BooleanOption;
27+
import io.github.axolotlclient.AxolotlclientConfig.options.EnumOption;
2728
import io.github.axolotlclient.AxolotlclientConfig.options.OptionCategory;
2829
import io.github.axolotlclient.modules.AbstractModule;
2930
import io.github.axolotlclient.util.Logger;
30-
import io.github.axolotlclient.util.Util;
31+
import lombok.AllArgsConstructor;
3132
import net.minecraft.client.resource.language.I18n;
3233
import net.minecraft.text.*;
3334
import net.minecraft.util.Formatting;
35+
import net.minecraft.util.Util;
36+
import org.jetbrains.annotations.Nullable;
3437

3538
import java.awt.*;
3639
import java.awt.datatransfer.DataFlavor;
3740
import java.awt.datatransfer.Transferable;
3841
import java.io.File;
3942
import java.nio.file.Files;
4043
import java.util.ArrayList;
44+
import java.util.List;
4145

4246
public class ScreenshotUtils extends AbstractModule {
4347
private static final ScreenshotUtils Instance = new ScreenshotUtils();
@@ -46,10 +50,58 @@ public class ScreenshotUtils extends AbstractModule {
4650

4751
private final BooleanOption enabled = new BooleanOption("enabled", false);
4852

53+
private final List<Action> actions = Util.make(() -> {
54+
List<Action> actions = new ArrayList<>();
55+
actions.add(new Action("copyAction",
56+
Formatting.AQUA,
57+
new HoverEvent(HoverEvent.Action.SHOW_TEXT,
58+
Text.translatable("copy_image")),
59+
new CustomClickEvent((file) -> {
60+
FileTransferable selection = new FileTransferable(file);
61+
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null);
62+
})
63+
));
64+
65+
actions.add(new Action("deleteAction",
66+
Formatting.LIGHT_PURPLE,
67+
new HoverEvent(HoverEvent.Action.SHOW_TEXT,
68+
Text.translatable("delete_image")),
69+
new CustomClickEvent((file) -> {
70+
try {
71+
Files.delete(file.toPath());
72+
io.github.axolotlclient.util.Util.sendChatMessage(
73+
Text.literal(I18n.translate("screenshot_deleted")
74+
.replace("<name>", file.getName())));
75+
} catch (Exception e) {
76+
Logger.warn("Couldn't delete Screenshot " + file.getName());
77+
}
78+
})
79+
));
80+
81+
actions.add(new Action("openAction",
82+
Formatting.WHITE,
83+
new HoverEvent(HoverEvent.Action.SHOW_TEXT,
84+
Text.translatable("open_image")),
85+
new CustomClickEvent((file) -> Util.getOperatingSystem().open(file.toURI()))
86+
));
87+
88+
// If you have further ideas to what actions could be added here, please let us know!
89+
90+
return actions;
91+
92+
});
93+
94+
private final EnumOption autoExec = new EnumOption("autoExec", Util.make(() -> {
95+
List<String> names = new ArrayList<>();
96+
names.add("off");
97+
actions.forEach(action -> names.add(action.getName()));
98+
return names.toArray(new String[0]);
99+
100+
}), "off");
101+
49102
@Override
50103
public void init() {
51-
52-
category.add(enabled);
104+
category.add(enabled, autoExec);
53105

54106
AxolotlClient.CONFIG.general.addSubCategory(category);
55107
}
@@ -59,13 +111,32 @@ public static ScreenshotUtils getInstance(){
59111
}
60112

61113
public Text onScreenshotTaken(MutableText text, File shot){
62-
if(enabled.get()){
63-
return text.append("\n").append(getUtilsText(shot));
114+
if (enabled.get()) {
115+
Text t = getUtilsText(shot);
116+
if (t != null) {
117+
return text.append("\n").append(t);
118+
}
64119
}
65120
return text;
66121
}
67122

68-
private Text getUtilsText(File file){
123+
private @Nullable Text getUtilsText(File file) {
124+
125+
if (!autoExec.get().equals("off")) {
126+
127+
actions.parallelStream().filter(action -> autoExec.get().equals(action.getName())).toList().get(0).clickEvent.setFile(file).doAction();
128+
return null;
129+
}
130+
131+
MutableText message = Text.empty().copy();
132+
actions.parallelStream().map(action -> action.getText(file)).iterator().forEachRemaining(text -> {
133+
message.append(text);
134+
message.append(" ");
135+
});
136+
return message;
137+
}
138+
139+
/*private Text getUtilsText(File file){
69140
70141
return Text.translatable("copyAction")
71142
.setStyle(Style.EMPTY
@@ -93,14 +164,33 @@ private Text getUtilsText(File file){
93164
}
94165
})))
95166
);
167+
}*/
168+
169+
@AllArgsConstructor
170+
public static class Action {
171+
172+
private final String translationKey;
173+
private final Formatting formatting;
174+
private final HoverEvent hoverEvent;
175+
private final CustomClickEvent clickEvent;
176+
177+
public Text getText(File file) {
178+
return Text.translatable(translationKey)
179+
.setStyle(Style.EMPTY
180+
.withFormatting(formatting)
181+
.withClickEvent(clickEvent.setFile(file))
182+
.withHoverEvent(hoverEvent));
183+
}
184+
185+
public String getName() {
186+
return translationKey;
187+
}
96188
}
97189

190+
@AllArgsConstructor
98191
protected static class FileTransferable implements Transferable {
99-
private final File file;
100192

101-
public FileTransferable(File file) {
102-
this.file = file;
103-
}
193+
private final File file;
104194

105195
@Override
106196
public DataFlavor[] getTransferDataFlavors() {
@@ -123,18 +213,30 @@ public Object getTransferData(DataFlavor flavor) {
123213
public static class CustomClickEvent extends ClickEvent {
124214

125215
private final OnActionCall action;
216+
private File file;
126217

127218
public CustomClickEvent(OnActionCall action) {
128219
super(Action.byName(""), "");
129220
this.action = action;
130221
}
131222

132-
public void doAction(){
133-
action.doAction();
223+
public void doAction() {
224+
if (file != null) {
225+
action.doAction(file);
226+
} else {
227+
Logger.warn("How'd you manage to do this? " +
228+
"Now there's a screenshot ClickEvent without a File attached to it!");
229+
}
230+
}
231+
232+
public CustomClickEvent setFile(File file) {
233+
this.file = file;
234+
return this;
134235
}
135236
}
136237

137238
interface OnActionCall {
138-
void doAction();
239+
240+
void doAction(File file);
139241
}
140242
}

src/main/java/io/github/axolotlclient/util/OSUtil.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
package io.github.axolotlclient.util;
2424

25+
import net.minecraft.util.Util;
26+
27+
import java.net.URI;
2528
import java.util.Locale;
2629

2730
public class OSUtil {
@@ -61,5 +64,9 @@ public String[] getStrings(){
6164
OperatingSystem(String... detection) {
6265
this.s = detection;
6366
}
67+
68+
public void open(URI uri){
69+
Util.getOperatingSystem().open(uri);
70+
}
6471
}
6572
}

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
"nightMode.tooltip": "Reduces blue colors.",
1313
"screenshotUtils": "Screenshot Utils",
1414
"copyAction": "[Copy]",
15-
"copy_image": "Copy Image",
15+
"copy_image": "Copy this Screenshot",
1616
"headless_exception": "Could not Copy Image because the jvm is somehow running in headless mode.\n Please fix this.",
1717
"deleteAction": "[Delete]",
18-
"delete_image": "Delete Image",
18+
"delete_image": "Delete this Screenshot",
1919
"screenshot_deleted": "Screenshot <name> has been deleted successfully!",
20+
"openAction": "[Open]",
21+
"open_image": "Open this Screenshot",
22+
"autoExec": "Automatic Execution",
23+
"autoExec.tooltip": "Automatically execute this action when taking a screenshot.",
2024

2125
"rendering": "Rendering",
2226
"rendering.tooltip": "Rendering Options",
@@ -302,6 +306,8 @@
302306
"THIRD_PERSON_BACK": "Third Person (Back)",
303307
"THIRD_PERSON_FRONT": "Third Person (Front)",
304308
"invert": "Invert",
309+
"toggle": "Toggle",
310+
"toggle.tooltip": "Use the set key to toggle whether Freelook is enabled.",
305311

306312
"credits": "Credits",
307313
"creditsBGM": "BGM",

0 commit comments

Comments
 (0)