Skip to content

Commit

Permalink
Merge branch 'refs/heads/mc1.21_ui' into mc1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
NotRyken committed Aug 14, 2024
2 parents c85e32e + 0e69d2e commit 4c865d6
Show file tree
Hide file tree
Showing 28 changed files with 1,349 additions and 1,261 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ subprojects {
"contact_url": contact_url
]

filesMatching(["pack.mcmeta", "*.mod.json", "META-INF/*mods.toml", "*.mixins.json", "assets/"+mod_id+"/lang/*.json"]) {
filesMatching(["pack.mcmeta", "*.mod.json", "META-INF/*mods.toml", "*.mixins.json"]) {
expand expandProps
}
inputs.properties(expandProps)
Expand Down
7 changes: 4 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Redesign GUI
- Allow activating multiple CommandKeys with a single keypress
- Experimental update, please report any issues you find
- Allow trailing whitespace on 'type' mode macros
- Add 'repeat' send mode
- Allow multi-send from profile screen
- Various GUI adjustments and fixes
68 changes: 16 additions & 52 deletions common/src/main/java/dev/terminalmc/commandkeys/CommandKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.platform.InputConstants;
import dev.terminalmc.commandkeys.config.Config;
import dev.terminalmc.commandkeys.config.Macro;
import dev.terminalmc.commandkeys.config.Profile;
import dev.terminalmc.commandkeys.gui.screen.OptionsScreen;
import dev.terminalmc.commandkeys.util.ModLogger;
Expand All @@ -13,42 +14,28 @@
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.network.chat.Component;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static dev.terminalmc.commandkeys.util.Localization.translationKey;

public class CommandKeys {
public static final String MOD_ID = "commandkeys";
public static final String MOD_NAME = "CommandKeys";
public static final ModLogger LOG = new ModLogger(MOD_NAME);
public static final KeyMapping CONFIG_KEY = new KeyMapping(
translationKey("key", "open_config"), InputConstants.Type.KEYSYM,
InputConstants.KEY_K, translationKey("key_group"));

translationKey("key", "main.edit"), InputConstants.Type.KEYSYM,
InputConstants.KEY_K, translationKey("key", "main"));
public static String lastConnection = "";

public static List<QueuedMessage> queuedMessages = new ArrayList<>();

public static void init() {
Config.getAndSave();
}

public static void onEndTick(Minecraft minecraft) {
public static void onEndTick(Minecraft mc) {
// Open config screen
while (CONFIG_KEY.consumeClick()) {
minecraft.setScreen(new OptionsScreen(minecraft.screen, true));
mc.setScreen(new OptionsScreen(mc.screen, true));
}

// Tick queued commands
Iterator<QueuedMessage> iter = queuedMessages.iterator();
while (iter.hasNext()) {
QueuedMessage qm = iter.next();
if (qm.tick()) {
send(qm.message, qm.addToHistory, qm.showHudMsg);
iter.remove();
}
if (mc.player != null && mc.level != null && !mc.isPaused()) {
Config.get().activeProfile().getMacros().forEach(Macro::tick);
}
}

Expand All @@ -70,44 +57,21 @@ public static boolean inGame() {
}

public static void send(String message, boolean addToHistory, boolean showHudMsg) {
Minecraft minecraft = Minecraft.getInstance();
Minecraft mc = Minecraft.getInstance();
if (mc.player == null) return;
// new ChatScreen("").handleChatInput(message, addToHistory)
// could be slightly better for compat but costs performance.
if (message.startsWith("/")) {
minecraft.player.connection.sendCommand(message.substring(1));
mc.player.connection.sendCommand(message.substring(1));
} else {
minecraft.player.connection.sendChat(message);
mc.player.connection.sendChat(message);
}
if (addToHistory) {
minecraft.gui.getChat().addRecentChat(message);
}
if (showHudMsg) {
minecraft.gui.setOverlayMessage(Component.literal(message)
.withStyle(ChatFormatting.GRAY), false);
}
}

public static void queue(int ticks, String message, boolean addToHistory, boolean showHudMsg) {
queuedMessages.add(new QueuedMessage(ticks, message, addToHistory, showHudMsg));
if (addToHistory) mc.gui.getChat().addRecentChat(message);
if (showHudMsg) mc.gui.setOverlayMessage(Component.literal(message)
.withStyle(ChatFormatting.GRAY), false);
}

public static void type(String message) {
Minecraft.getInstance().setScreen(new ChatScreen(message));
}

public static class QueuedMessage {
int ticks;
String message;
boolean addToHistory;
boolean showHudMsg;

public QueuedMessage(int ticks, String message, boolean addToHistory, boolean showHudMsg) {
this.ticks = ticks;
this.message = message;
this.addToHistory = addToHistory;
this.showHudMsg = showHudMsg;
}

public boolean tick() {
return ticks-- <= 0;
}
}
}
198 changes: 0 additions & 198 deletions common/src/main/java/dev/terminalmc/commandkeys/config/CommandKey.java

This file was deleted.

Loading

0 comments on commit 4c865d6

Please sign in to comment.