diff --git a/build.gradle.kts b/build.gradle.kts index 7bb44be8..ba8c17a5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,6 +39,7 @@ stonecutter { } repositories { + mavenCentral() exclusiveContent { forRepository { maven { @@ -54,6 +55,18 @@ repositories { name = "WorldEdit Maven" url = uri("https://maven.enginehub.org/repo/") } + maven { + name = "kr1v" + url = uri("https://repo.repsy.io/kr1v/maven/") + } + maven { + name = "Sakura Ryoko" + url = uri("https://masa.dy.fi/maven/sakura-ryoko/") + } + maven { + name = "Fallen Breath" + url = uri("https://maven.fallenbreath.me/releases/") + } } dependencies { @@ -62,7 +75,17 @@ dependencies { modImplementation("net.fabricmc:fabric-loader:${project.property("loader_version")}") modImplementation("net.fabricmc.fabric-api:fabric-api:${project.property("fabric_version")}") modImplementation("com.sk89q.worldedit:worldedit-fabric-mc${project.property("worldedit_version")}") - modApi("maven.modrinth:malilib:${project.property("malilib_version")}") + modImplementation("fi.dy.masa.malilib:malilib-fabric-${project.property("malilib_version")}") + modImplementation("net.kr1v:malilib-api:${project.property("malilib_api_version")}") { + exclude(group = "net.fabricmc.fabric-api") // prevent 1.21.5 fabric api modules used by malilib from leaking into 1.21.4 + } + annotationProcessor("net.kr1v:malilib-api-processor:1.0.0") +} + +configurations.all { + resolutionStrategy { + force("com.google.code.gson:gson:2.13.2") + } } loom { @@ -92,20 +115,11 @@ tasks.processResources { } } -tasks.register("collectFile") { +tasks.register("collectFile") { group = "build" - mustRunAfter("build") - - doLast { - copy { - from( - file( - "build/libs/${project.property("archives_base_name")}-${project.property("mod_version")}+${project.property("minecraft_version")}.jar" - ) - ) - into(rootProject.file("build/libs")) - } - } + + from(tasks.remapJar) + into(rootProject.layout.buildDirectory.dir("libs/${project.property("mod_version")}")) } tasks.register("buildAndCollect") { @@ -124,6 +138,7 @@ java { } tasks.jar { + duplicatesStrategy = DuplicatesStrategy.INCLUDE from("LICENSE") { rename { "${it}_${project.property("archives_base_name")}" } } diff --git a/gradle.properties b/gradle.properties index 4b9d37cd..2842bd09 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ maven_group = tools.redstone archives_base_name = redstonetools loader_version=0.18.4 -mod_version = 3.2.0 +mod_version = 3.3.0 diff --git a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java index ebd3f488..660371ac 100644 --- a/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java +++ b/src/client/java/tools/redstone/redstonetools/RedstoneToolsClient.java @@ -1,13 +1,12 @@ package tools.redstone.redstonetools; -import fi.dy.masa.malilib.event.InitializationHandler; +import kr1v.malilibApi.MalilibApi; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientWorldEvents; -import tools.redstone.redstonetools.malilib.InitHandler; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.ClientData; import tools.redstone.redstonetools.packets.RedstoneToolsClientPackets; -import static tools.redstone.redstonetools.RedstoneTools.LOGGER; +import static tools.redstone.redstonetools.RedstoneTools.*; public class RedstoneToolsClient implements ClientModInitializer { private static boolean hasRanCommands = false; @@ -15,18 +14,18 @@ public class RedstoneToolsClient implements ClientModInitializer { @Override public void onInitializeClient() { LOGGER.info("Initializing Redstone Tools"); - InitializationHandler.getInstance().registerInitializationHandler(new InitHandler()); + MalilibApi.registerMod(MOD_ID, MOD_NAME); ClientWorldEvents.AFTER_CLIENT_WORLD_CHANGE.register((client, clientWorld) -> { if (client.getNetworkHandler() != null) { // dimension change - String dimensionChange = Configs.ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue(); + String dimensionChange = ClientData.AUTORUN_DIMENSION_CHANGE.getStringValue(); if (dimensionChange.startsWith("/")) { client.getNetworkHandler().sendChatCommand(dimensionChange.substring(1)); } else if (!dimensionChange.isEmpty()){ client.getNetworkHandler().sendChatMessage(dimensionChange); } } else { // world entry - String worldEntry = Configs.ClientData.AUTORUN_WORLD_ENTRY.getStringValue(); + String worldEntry = ClientData.AUTORUN_WORLD_ENTRY.getStringValue(); if (worldEntry.startsWith("/")) { client.send(() -> client.getNetworkHandler().sendChatCommand(worldEntry.substring(1))); } else if (!worldEntry.isEmpty()){ @@ -34,7 +33,7 @@ public void onInitializeClient() { } if (hasRanCommands) return; hasRanCommands = true; - String firstWorldEntry = Configs.ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue(); + String firstWorldEntry = ClientData.AUTORUN_FIRST_WORLD_ENTRY.getStringValue(); if (firstWorldEntry.startsWith("/")) { client.send(() -> client.getNetworkHandler().sendChatCommand(firstWorldEntry.substring(1))); } else if (!firstWorldEntry.isEmpty()) { diff --git a/src/client/java/tools/redstone/redstonetools/config/ClientData.java b/src/client/java/tools/redstone/redstonetools/config/ClientData.java new file mode 100644 index 00000000..51d05d86 --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/ClientData.java @@ -0,0 +1,23 @@ +package tools.redstone.redstonetools.config; + +import fi.dy.masa.malilib.config.options.ConfigBoolean; +import fi.dy.masa.malilib.config.options.ConfigString; +import kr1v.malilibApi.annotation.Config; +import tools.redstone.redstonetools.RedstoneTools; + +@Config(RedstoneTools.MOD_ID) +public class ClientData { + public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true, + """ + Whether or not to try to inject variables and math expressions into the command input suggester. + + With this enabled, Redstone tools will attempt to prevent chat suggestion from breaking if you're using variables and or math expressions inside of a command. + With this disabled, variables and math expressions will still be inserted upon sending a chat command"""); + public static final ConfigString VARIABLE_BEGIN_STRING = new ConfigString("Variable begin string", "'", "The string that should be used to denote the start of a variable. Can be empty"); + public static final ConfigString VARIABLE_END_STRING = new ConfigString("Variable end string", "'", "The string that should be used to denote the end of a variable. Can be empty"); + public static final ConfigString MATH_BEGIN_STRING = new ConfigString("Math begin string", "{", "The string that should be used to denote the start of a math expression. Can be empty, unsure if you'd want that though."); + public static final ConfigString MATH_END_STRING = new ConfigString("Math end string", "}", "The string that should be used to denote the end of a math expression. Can be empty, unsure if you'd want that though."); + public static final ConfigString AUTORUN_FIRST_WORLD_ENTRY = new ConfigString("First world entry", "", "Command/message that will be run/sent the first time you join a world in this session"); + public static final ConfigString AUTORUN_WORLD_ENTRY = new ConfigString("World entry", "", "Command/message that will be run/sent when you join a world"); + public static final ConfigString AUTORUN_DIMENSION_CHANGE = new ConfigString("Dimension change", "", "Command/message that will be run/sent after you change dimensions"); +} diff --git a/src/client/java/tools/redstone/redstonetools/config/General.java b/src/client/java/tools/redstone/redstonetools/config/General.java new file mode 100644 index 00000000..be53f7db --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/General.java @@ -0,0 +1,28 @@ +package tools.redstone.redstonetools.config; + +import fi.dy.masa.malilib.config.options.ConfigBoolean; +import fi.dy.masa.malilib.config.options.ConfigHotkey; +import fi.dy.masa.malilib.config.options.ConfigInteger; +import kr1v.malilibApi.MalilibApi; +import kr1v.malilibApi.annotation.Config; +import tools.redstone.redstonetools.RedstoneTools; + +@Config(value = RedstoneTools.MOD_ID, order = 0) +public class General { + public static final ConfigHotkey HOTKEY_OPEN_GUI = new ConfigHotkey("Hotkey to open menu", "V,C", "Hotkey to open menu"); + public static final ConfigBoolean BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS = new ConfigBoolean("Improved command suggestions", true, + """ + Enables/disables improved suggestions when typing commands. + + When typing "/give @s redstblock" in chat, with this disabled it will give no suggestions (default behaviour, or "prefix matching"), but with + this enabled it will give "redstone_block" as a suggestion (so called "fuzzy matching")."""); + public static final ConfigBoolean AIRPLACE_SHOW_OUTLINE = new ConfigBoolean("Airplace showOutline", true, "If enabled, will show a block outline for the block your holding"); + public static final ConfigInteger BIGDUST_HEIGHT_IN_PIXELS = new ConfigInteger("Bigdust heightInPixels", 3, 0, 16, "How tall the redstone hitbox should be"); + + static { + HOTKEY_OPEN_GUI.getKeybind().setCallback((action, key) -> { + MalilibApi.openScreenFor(RedstoneTools.MOD_ID); + return true; + }); + } +} diff --git a/src/client/java/tools/redstone/redstonetools/config/MacroManager.java b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java new file mode 100644 index 00000000..ec8b4c25 --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/MacroManager.java @@ -0,0 +1,62 @@ +package tools.redstone.redstonetools.config; + +import fi.dy.masa.malilib.hotkeys.KeybindSettings; +import tools.redstone.redstonetools.config.option.ConfigMacro; +import tools.redstone.redstonetools.macros.actions.CommandAction; + +import java.util.ArrayList; +import java.util.List; + +public class MacroManager { + public static boolean shouldMute; + + public static ConfigMacro getMacro(String name) { + for (ConfigMacro macro : Macros.getMacros()) { + if (macro.getMacroName().equals(name)) { + return macro; + } + } + + return null; + } + + public static boolean nameExists(String name, ConfigMacro exclude) { + for (ConfigMacro macro : Macros.getMacros()) { + if (macro == exclude) continue; + if (macro.getMacroName().equals(name)) return true; + } + return false; + } + + public static List getDefaultMacros() { + return new ArrayList<>(List.of( + createCommandMacro("redstoner", new String[]{ + "/gamerule doTileDrops false", + "/gamerule doTraderSpawning false", + "/gamerule doWeatherCycle false", + "/gamerule doDaylightCycle false", + "/gamerule doMobSpawning false", + //? if <1.21.11 + //"/gamerule doContainerDrops false", + "/time set noon", + "/weather clear" + }), + createCommandMacro("copystate", new String[]{"/copystate" }), + createCommandMacro("itembind", new String[]{"/itembind" }), + createCommandMacro("minsel", new String[]{"//minsel" }), + createCommandMacro("quicktp", new String[]{"/quicktp" }), + createCommandMacro("binaryblockread", new String[]{"//binaryblockread" }), + createCommandMacro("rstack", new String[]{"//rstack" }), + createCommandMacro("update", new String[]{"//update" }) + )); + } + + public static ConfigMacro createCommandMacro(String name, String[] commands) { + var actions = new CommandAction[commands.length]; + for (int i = 0; i < commands.length; i++) { + actions[i] = new CommandAction(commands[i]); + } + + return new ConfigMacro(name, true, false, List.of(actions), "", KeybindSettings.PRESS_ALLOWEXTRA); + } +} diff --git a/src/client/java/tools/redstone/redstonetools/config/Macros.java b/src/client/java/tools/redstone/redstonetools/config/Macros.java new file mode 100644 index 00000000..1a458334 --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/Macros.java @@ -0,0 +1,54 @@ +package tools.redstone.redstonetools.config; + +import fi.dy.masa.malilib.hotkeys.KeybindSettings; +import kr1v.malilibApi.InternalMalilibApi; +import kr1v.malilibApi.ModRepresentation; +import kr1v.malilibApi.annotation.Config; +import kr1v.malilibApi.config._new.ConfigList; +import tools.redstone.redstonetools.RedstoneTools; +import tools.redstone.redstonetools.config.option.ConfigMacro; + +import java.util.List; +import java.util.UUID; +import java.util.function.BiFunction; + +@Config(RedstoneTools.MOD_ID) +public class Macros { + public static final ConfigList MACROS = new ConfigList<>( + "Macros", + MacroManager.getDefaultMacros(), + () -> { + var newMacro = new ConfigMacro("macro " + (getMacros().size()), true, false, List.of(), "", KeybindSettings.PRESS_ALLOWEXTRA); + if (MacroManager.nameExists(newMacro.getName(), newMacro)) { + newMacro.setMacroName(newMacro.getName() + " " + UUID.randomUUID()); + } + return newMacro; + }, + "Edit macros" + ); + + public static List getMacros() { + //noinspection ConstantValue + if (MACROS == null) return List.of(); + return MACROS.getList(); + } + + private static ModRepresentation.Tab TAB; + + public static ModRepresentation.Tab getTab() { + if (TAB == null) TAB = initTab(); + return TAB; + } + + private static ModRepresentation.Tab initTab() { + ModRepresentation.Tab macrosTab = null; + for (ModRepresentation.Tab tab : InternalMalilibApi.getMod(RedstoneTools.MOD_ID).tabs) { + if (tab.translationKey().equals("Macros")) { + macrosTab = tab; + break; + } + } + if (macrosTab == null) throw new IllegalStateException("Macros tab not found"); + return macrosTab; + } +} diff --git a/src/client/java/tools/redstone/redstonetools/config/Toggles.java b/src/client/java/tools/redstone/redstonetools/config/Toggles.java new file mode 100644 index 00000000..56be5df1 --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/Toggles.java @@ -0,0 +1,37 @@ +package tools.redstone.redstonetools.config; + +import fi.dy.masa.malilib.config.options.ConfigBooleanHotkeyed; +import kr1v.malilibApi.annotation.Config; +import tools.redstone.redstonetools.RedstoneTools; + +@Config(RedstoneTools.MOD_ID) +public class Toggles { + public static final ConfigBooleanHotkeyed AIRPLACE = new ConfigBooleanHotkeyed("Airplace", false, "", "Whether or not airplace should be enabled"); + public static final ConfigBooleanHotkeyed AUTODUST = new ConfigBooleanHotkeyed("Autodust", false, "", "Whether or not autodust should be enabled"); + public static final ConfigBooleanHotkeyed AUTOROTATE = new ConfigBooleanHotkeyed("Autorotate", false, "", "Whether or not autorotate should be enabled"); + public static final ConfigBooleanHotkeyed BIGDUST = new ConfigBooleanHotkeyed("Bigdust", false, "", "Whether or not bigdust should be enabled"); + public static final ConfigBooleanHotkeyed CLICKCONTAINERS = new ConfigBooleanHotkeyed("Clickcontainers", false, "", "Whether or not clickcontainer should be enabled"); + + static { + AIRPLACE.getKeybind().setCallback((t, g) -> { + AIRPLACE.setBooleanValue(!AIRPLACE.getBooleanValue()); + return true; + }); + AUTODUST.getKeybind().setCallback((t, g) -> { + AUTODUST.setBooleanValue(!AUTODUST.getBooleanValue()); + return true; + }); + AUTOROTATE.getKeybind().setCallback((t, g) -> { + AUTOROTATE.setBooleanValue(!AUTOROTATE.getBooleanValue()); + return true; + }); + BIGDUST.getKeybind().setCallback((t, g) -> { + BIGDUST.setBooleanValue(!BIGDUST.getBooleanValue()); + return true; + }); + CLICKCONTAINERS.getKeybind().setCallback((t, g) -> { + CLICKCONTAINERS.setBooleanValue(!CLICKCONTAINERS.getBooleanValue()); + return true; + }); + } +} diff --git a/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java new file mode 100644 index 00000000..49eb13ca --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/config/option/ConfigMacro.java @@ -0,0 +1,221 @@ +package tools.redstone.redstonetools.config.option; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import fi.dy.masa.malilib.config.options.ConfigHotkey; +import fi.dy.masa.malilib.gui.GuiBase; +import fi.dy.masa.malilib.gui.button.ButtonGeneric; +import fi.dy.masa.malilib.hotkeys.IHotkey; +import fi.dy.masa.malilib.hotkeys.KeybindSettings; +import kr1v.malilibApi.MalilibApi; +import kr1v.malilibApi.config._new.CustomConfigBase; +import kr1v.malilibApi.interfaces.IHotkeyContainer; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; +import tools.redstone.redstonetools.config.MacroManager; +import tools.redstone.redstonetools.macros.actions.Action; +import tools.redstone.redstonetools.macros.actions.CommandAction; +import tools.redstone.redstonetools.malilib.GuiMacroEditor; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +public class ConfigMacro extends CustomConfigBase implements IHotkeyContainer { + private String macroName; + private boolean enabled; + private boolean muted; + private List actions; + private final IHotkey hotkey; + + public ConfigMacro(String macroName, boolean enabled, boolean muted, List actions, String keybind, KeybindSettings settings) { + this("", macroName, enabled, muted, actions, keybind, settings, "", "", ""); + } + + public ConfigMacro(String name, String macroName, boolean enabled, boolean muted, List actions, String keybind, KeybindSettings settings, String comment, String translatedName, String prettyName) { + super(name, comment, translatedName, prettyName); + this.macroName = macroName; + this.enabled = enabled; + this.muted = muted; + this.actions = new ArrayList<>(actions); + this.hotkey = new ConfigHotkey("", keybind, settings, "", "", ""); + this.hotkey.getKeybind().setCallback((t, g) -> { + this.run(); + return true; + }); + } + + @Override + public void setValueFromJsonElement(JsonElement element) { + try { + JsonObject object = element.getAsJsonObject(); + + boolean muted = object.get("muted").getAsBoolean(); + String name = object.get("name").getAsString(); + boolean enabled = object.get("enabled").getAsBoolean(); + List actions = object + .get("actions") + .getAsJsonArray() + .asList() + .stream() + .map(e -> new CommandAction(e.getAsString())) + .toList(); + KeybindSettings settings = KeybindSettings.fromJson(object.get("settings").getAsJsonObject()); + String keys = object.get("keys").getAsString(); + + this.setMuted(muted); + this.setMacroName(name); + this.setEnabled(enabled); + this.setActions(actions); + this.setSettings(settings); + this.setKeybind(keys); + } catch (Exception e) { + System.out.println("Couldn't set json value for " + this.getName() + e); + } + } + + @Override + public JsonElement getAsJsonElement() { + JsonObject object = new JsonObject(); + + JsonArray actionsArray = new JsonArray(); + actionsArray.asList().addAll(getActions().stream().map(action -> action.command).map(JsonPrimitive::new).toList()); + + object.addProperty("muted", isMuted()); + object.addProperty("name", getMacroName()); + object.addProperty("enabled", isEnabled()); + object.addProperty("keys", getKeybind()); + object.add("settings", getSettings().toJson()); + object.add("actions", actionsArray); + + return object; + } + + @Override + public boolean isModified() { + if (this.isMuted()) return true; + if (!this.getActions().isEmpty()) return true; + if (!this.isEnabled()) return true; + if (!this.getKeybind().isEmpty()) return true; + return false; + } + + @Override + public void resetToDefault() { + this.hotkey.resetToDefault(); + this.hotkey.getKeybind().resetSettingsToDefaults(); + this.actions = new ArrayList<>(); + this.muted = false; + this.enabled = true; + } + + static { + MalilibApi.registerButtonBasedConfigType(ConfigMacro.class, (widgetConfigOption, configMacro, x, y, configWidth, configHeight) -> new ButtonGeneric(x, y, configWidth, configHeight, configMacro.getMacroName()) { + @Override + protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/net.minecraft.client.gui.Click click, boolean doubleClick/*? } else {*//*int mouseX, int mouseY, int mouseButton*//*? }*/) { + super.onMouseClickedImpl(/*? if >=1.21.10 {*/click, doubleClick/*? } else {*//*mouseX, mouseY, mouseButton*//*? }*/); + GuiBase.openGui(new GuiMacroEditor(Text.of(configMacro.macroName), configMacro, MinecraftClient.getInstance().currentScreen)); + return true; + } + }); + } + + @Override + public List getHotkeys() { + return List.of(this.hotkey); + } + + @Override + public String toString() { + return this.getMacroName(); + } + + public boolean isMuted() { + return this.muted; + } + public void setMuted(boolean muted) { + this.muted = muted; + } + + public boolean isEnabled() { + return this.enabled; + } + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getMacroName() { + return this.macroName; + } + public void setMacroName(String name) { + this.macroName = name; + } + + public List getActions() { + return this.actions; + } + public void setActions(List actions) { + this.actions.clear(); + this.actions.addAll(actions); + } + + public String getKeybind() { + return this.hotkey.getStringValue(); + } + public void setKeybind(String keybind) { + this.hotkey.getKeybind().setValueFromString(keybind); + } + + public KeybindSettings getSettings() { + return this.hotkey.getKeybind().getSettings(); + } + public void setSettings(KeybindSettings settings) { + this.hotkey.getKeybind().setSettings(settings); + } + + private final AtomicInteger layers = new AtomicInteger(0); + + public void run() { + if (muted) MacroManager.shouldMute = true; + if (!enabled) return; + if (layers.getAndSet(layers.get() + 1) > 100) { + assert MinecraftClient.getInstance().player != null; + MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); + return; + } + try { + for (Action action : actions) { + action.run(); + } + } catch (StackOverflowError ignored) { + try { + assert MinecraftClient.getInstance().player != null; + MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); + } catch (NoClassDefFoundError e) { + // yeah we are absolutely cooked, there is no way to recover from this. I'm not even sure this can happen + // actually there's probably a better throwable to be thrown here. whatever. + throw new InternalError("Something has gone terribly wrong. Shouldn't have run a macro that runs itself.", e); + } + } finally { + layers.set(0); + } + if (muted) MacroManager.shouldMute = false; + } + + + @Override + public Void get() { + return null; + } + + @Override + public Void getDefault() { + return null; + } + + @Override + public void set(Void value) { + } +} diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java index ddf66b36..bf55d414 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/EditMacroFeature.java @@ -1,11 +1,14 @@ package tools.redstone.redstonetools.features.commands; import com.mojang.brigadier.CommandDispatcher; +import kr1v.malilibApi.InternalMalilibApi; +import kr1v.malilibApi.MalilibApi; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; -import tools.redstone.redstonetools.malilib.GuiMacroManager; +import tools.redstone.redstonetools.RedstoneTools; +import tools.redstone.redstonetools.config.Macros; public class EditMacroFeature { @@ -17,7 +20,11 @@ protected EditMacroFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("edit-macros") .executes(commandContext -> { - MinecraftClient.getInstance().send(() -> MinecraftClient.getInstance().setScreen(new GuiMacroManager())); + MinecraftClient.getInstance().send(() -> { + InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(Macros.getTab()); + MalilibApi.openScreenFor(RedstoneTools.MOD_ID); + }); + return 1; })); } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java index aba3a2ee..ce7e85d4 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/MacroFeature.java @@ -5,8 +5,8 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.command.CommandRegistryAccess; +import tools.redstone.redstonetools.config.option.ConfigMacro; import tools.redstone.redstonetools.features.commands.argument.MacroArgumentType; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; @@ -27,7 +27,7 @@ public void registerCommand(CommandDispatcher dispatc } protected int execute(CommandContext context) throws CommandSyntaxException { - MacroBase macro = MacroArgumentType.getMacro(context, "macro"); + ConfigMacro macro = MacroArgumentType.getMacro(context, "macro"); macro.run(); return 1; } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java index 26a851d4..8bcdf3b5 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/RstFeature.java @@ -1,11 +1,14 @@ package tools.redstone.redstonetools.features.commands; import com.mojang.brigadier.CommandDispatcher; +import kr1v.malilibApi.InternalMalilibApi; +import kr1v.malilibApi.MalilibApi; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.MinecraftClient; import net.minecraft.command.CommandRegistryAccess; -import tools.redstone.redstonetools.malilib.GuiConfigs; +import tools.redstone.redstonetools.RedstoneTools; +import tools.redstone.redstonetools.config.Macros; public class RstFeature { @@ -17,9 +20,12 @@ protected RstFeature() { public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("rst") .executes(commandContext -> { - MinecraftClient.getInstance().send(() -> MinecraftClient.getInstance().setScreen(new GuiConfigs())); - if (GuiConfigs.tab == GuiConfigs.ConfigGuiTab.MACROS) - GuiConfigs.tab = GuiConfigs.ConfigGuiTab.GENERAL; + MinecraftClient.getInstance().send(() -> { + if (InternalMalilibApi.getMod(RedstoneTools.MOD_ID).activeTab() == Macros.getTab()) { + InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(null); + } + MalilibApi.openScreenFor(RedstoneTools.MOD_ID); + }); return 1; })); } diff --git a/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java b/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java index 6b177149..1e8841b4 100644 --- a/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java +++ b/src/client/java/tools/redstone/redstonetools/features/commands/argument/MacroArgumentType.java @@ -9,16 +9,16 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.minecraft.command.CommandSource; import net.minecraft.text.Text; -import tools.redstone.redstonetools.malilib.config.MacroManager; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; +import tools.redstone.redstonetools.config.MacroManager; +import tools.redstone.redstonetools.config.Macros; +import tools.redstone.redstonetools.config.option.ConfigMacro; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.concurrent.CompletableFuture; -public class MacroArgumentType implements ArgumentType { - +public class MacroArgumentType implements ArgumentType { private static final Collection EXAMPLES = List.of(" "); public MacroArgumentType() { @@ -28,16 +28,16 @@ public static MacroArgumentType macro() { return new MacroArgumentType(); } - public static MacroBase getMacro(final CommandContext context, final String name) throws CommandSyntaxException { - return context.getArgument(name, MacroBase.class); + public static ConfigMacro getMacro(final CommandContext context, final String name) throws CommandSyntaxException { + return context.getArgument(name, ConfigMacro.class); } @Override - public MacroBase parse(final StringReader reader) throws CommandSyntaxException { + public ConfigMacro parse(final StringReader reader) throws CommandSyntaxException { final int start = reader.getCursor(); final String result = reader.getRemaining(); reader.setCursor(reader.getTotalLength()); - final MacroBase macro = MacroManager.getMacro(result); + final ConfigMacro macro = MacroManager.getMacro(result); if (macro == null) { reader.setCursor(start); throw new SimpleCommandExceptionType(Text.literal("Macro '" + result + "' doesn't exist!")).create(); @@ -58,7 +58,7 @@ public Collection getExamples() { @Override public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { List macroNamesList = new ArrayList<>(); - MacroManager.getMacros().forEach(macro -> macroNamesList.add(macro.getName())); + Macros.getMacros().forEach(macro -> macroNamesList.add(macro.getMacroName())); macroNamesList.sort(String.CASE_INSENSITIVE_ORDER); return CommandSource.suggestMatching(macroNamesList, builder); } diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java index d662e258..410de328 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AirPlaceFeature.java @@ -32,7 +32,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import tools.redstone.redstonetools.ClientCommands; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.General; +import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.mixin.features.WorldRendererInvoker; import tools.redstone.redstonetools.utils.ItemUtils; import tools.redstone.redstonetools.utils.RaycastUtils; @@ -45,7 +46,7 @@ public class AirPlaceFeature extends ClientToggleableFeature { public static final AirPlaceFeature INSTANCE = new AirPlaceFeature(); protected AirPlaceFeature() { - super(Configs.Toggles.AIRPLACE); + super(Toggles.AIRPLACE); } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { @@ -87,7 +88,7 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) { BiConsumer listener = (context, crosshairTarget) -> { if (!isEnabled()) return; - if (!Configs.General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) + if (!General.AIRPLACE_SHOW_OUTLINE.getBooleanValue()) return; MinecraftClient client = MinecraftClient.getInstance(); diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java index 325617a4..548c9567 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoDustClient.java @@ -4,11 +4,11 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.MinecraftClient; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; public class AutoDustClient { - public static ConfigBoolean isEnabled = Configs.Toggles.AUTODUST; + public static ConfigBoolean isEnabled = Toggles.AUTODUST; public static void registerHandler() { ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java index 2c16e036..36134b67 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/AutoRotateClient.java @@ -4,11 +4,11 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.MinecraftClient; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; public class AutoRotateClient { - public static ConfigBoolean isEnabled = Configs.Toggles.AUTOROTATE; + public static ConfigBoolean isEnabled = Toggles.AUTOROTATE; public static void registerHandler() { ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java index bd3c53cd..c74b4f50 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/BigDustFeature.java @@ -4,7 +4,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.command.CommandRegistryAccess; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.Toggles; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; @@ -13,7 +13,7 @@ public class BigDustFeature extends ClientToggleableFeature { public static final BigDustFeature INSTANCE = new BigDustFeature(); protected BigDustFeature() { - super(Configs.Toggles.BIGDUST); + super(Toggles.BIGDUST); } public void registerCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { diff --git a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java index 4dd3a67c..817d9326 100644 --- a/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java +++ b/src/client/java/tools/redstone/redstonetools/features/toggleable/ClickContainerClient.java @@ -4,11 +4,11 @@ import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.MinecraftClient; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.Toggles; import tools.redstone.redstonetools.packets.SetFeatureEnabledPayload; public class ClickContainerClient { - public static ConfigBoolean isEnabled = Configs.Toggles.CLICKCONTAINERS; + public static ConfigBoolean isEnabled = Toggles.CLICKCONTAINERS; public static void registerHandler() { ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { diff --git a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java index 92a0f628..27f6c9f6 100644 --- a/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java +++ b/src/client/java/tools/redstone/redstonetools/macros/actions/CommandAction.java @@ -1,10 +1,8 @@ package tools.redstone.redstonetools.macros.actions; -import com.mojang.serialization.Codec; import net.minecraft.client.MinecraftClient; public class CommandAction extends Action { - public static final Codec CODEC = Codec.STRING.xmap(CommandAction::new, action -> action.command); public String command; public CommandAction(String command) { diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiConfigs.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiConfigs.java deleted file mode 100644 index 8b74fdf0..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiConfigs.java +++ /dev/null @@ -1,121 +0,0 @@ -package tools.redstone.redstonetools.malilib; - -import fi.dy.masa.malilib.config.IConfigBase; -import fi.dy.masa.malilib.gui.GuiConfigsBase; -import fi.dy.masa.malilib.gui.button.ButtonBase; -import fi.dy.masa.malilib.gui.button.ButtonGeneric; -import fi.dy.masa.malilib.gui.button.IButtonActionListener; -import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.client.gui.DrawContext; -import tools.redstone.redstonetools.RedstoneTools; -import tools.redstone.redstonetools.malilib.config.Configs; - -import java.util.Collections; -import java.util.List; - -public class GuiConfigs extends GuiConfigsBase { - public static ConfigGuiTab tab = ConfigGuiTab.GENERAL; - - public GuiConfigs() { - super(10, 50, RedstoneTools.MOD_ID, null, "Configs", "0.0.0"); - } - - @Override - public void initGui() { - if (GuiConfigs.tab == ConfigGuiTab.MACROS) { - GuiConfigsBase.openGui(new GuiMacroManager()); - return; - } - super.initGui(); - this.clearOptions(); - - int x = 10; - int y = 26; - - for (ConfigGuiTab tab : ConfigGuiTab.values()) { - x += this.createButton(x, y, -1, tab); - } - } - - private int createButton(int x, int y, int width, ConfigGuiTab tab) { - ButtonGeneric button = new ButtonGeneric(x, y, width, 20, tab.getDisplayName()); - button.setEnabled(GuiConfigs.tab != tab); - this.addButton(button, new ButtonListener(tab, this)); - - return button.getWidth() + 2; - } - - @Override - protected int getConfigWidth() { - return this.width / 2; - } - - @Override - protected boolean useKeybindSearch() { - return false; - } - - @Override - public List getConfigs() { - List configs; - ConfigGuiTab tab = GuiConfigs.tab; - - if (tab == ConfigGuiTab.GENERAL) { - configs = Configs.General.OPTIONS; - } else if (tab == ConfigGuiTab.TOGGLES) { - configs = Configs.Toggles.TOGGLES; - } else if (tab == ConfigGuiTab.CLIENTDATA) { - configs = Configs.ClientData.OPTIONS; - } else { - return Collections.emptyList(); - } - - return ConfigOptionWrapper.createFor(configs); - } - - @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) { - if (this.client != null && this.client.world == null) this.renderPanoramaBackground(drawContext, partialTicks); - //? if <=1.21.5 { - /*this.applyBlur(); - *///?} else { - this.applyBlur(drawContext); - //?} - super.render(drawContext, mouseX, mouseY, partialTicks); - } - - static class ButtonListener implements IButtonActionListener { - private final GuiConfigs parent; - private final ConfigGuiTab tab; - - public ButtonListener(ConfigGuiTab tab, GuiConfigs parent) { - this.tab = tab; - this.parent = parent; - } - - @Override - public void actionPerformedWithButton(ButtonBase button, int mouseButton) { - GuiConfigs.tab = this.tab; - this.parent.reCreateListWidget(); // apply the new config width - if (this.parent.getListWidget() != null) this.parent.getListWidget().resetScrollbarPosition(); - this.parent.initGui(); - } - } - - public enum ConfigGuiTab { - GENERAL("General"), - TOGGLES("Toggles"), - CLIENTDATA("Chat"), - MACROS("Macros"); - - private final String translationKey; - - ConfigGuiTab(String translationKey) { - this.translationKey = translationKey; - } - - public String getDisplayName() { - return StringUtils.translate(this.translationKey); - } - } -} \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java index 6042a882..eec3cadd 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroEditor.java @@ -4,13 +4,16 @@ import fi.dy.masa.malilib.config.options.ConfigBoolean; import fi.dy.masa.malilib.event.InputEventHandler; import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.gui.GuiKeybindSettings; import fi.dy.masa.malilib.gui.button.ConfigButtonBoolean; import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; import fi.dy.masa.malilib.gui.widgets.WidgetKeybindSettings; //? if >=1.21.11 { import fi.dy.masa.malilib.render.GuiContext; //?} +import fi.dy.masa.malilib.hotkeys.IKeybind; +import fi.dy.masa.malilib.hotkeys.KeybindMulti; +import kr1v.malilibApi.InternalMalilibApi; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; @@ -20,55 +23,43 @@ import net.minecraft.client.input.KeyInput; import net.minecraft.client.input.CharInput;/*$}*/ import net.minecraft.text.Text; -import tools.redstone.redstonetools.malilib.config.MacroManager; +import tools.redstone.redstonetools.RedstoneTools; +import tools.redstone.redstonetools.config.MacroManager; +import tools.redstone.redstonetools.config.option.ConfigMacro; +import tools.redstone.redstonetools.malilib.widget.WidgetBaseWrapper; import tools.redstone.redstonetools.malilib.widget.action.CommandListWidget; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; import tools.redstone.redstonetools.utils.GuiUtils; import java.util.ArrayList; import java.util.List; public class GuiMacroEditor extends Screen { - public final MacroBase macro; - private final GuiMacroManager macroManager; + public final ConfigMacro macro; + private final Screen parent; public CommandListWidget commandList; - private ConfigButtonKeybind buttonKeybind; - private ConfigButtonBoolean buttonEnabled; - private ConfigButtonBoolean buttonMuted; - private WidgetKeybindSettings widgetAdvancedKeybindSettings; - private IConfigBoolean enabledConfigBoolean; - private IConfigBoolean mutedConfigBoolean; + private final IConfigBoolean enabledConfigBoolean; + private final IConfigBoolean mutedConfigBoolean; public TextFieldWidget nameWidget; private float errorCountDown; + private final IKeybind keybind; + private ConfigButtonKeybind buttonKeybind; - public GuiMacroEditor(Text title, MacroBase macro, GuiMacroManager macroManager) { + public GuiMacroEditor(Text title, ConfigMacro macro, Screen parent) { super(title); - this.macroManager = macroManager; + this.parent = parent; this.macro = macro; + + // todo: swap the booleans to be normal buttons + this.enabledConfigBoolean = new ConfigBoolean("", true, ""); + this.enabledConfigBoolean.setBooleanValue(this.macro.isEnabled()); + this.mutedConfigBoolean = new ConfigBoolean("", true, ""); + this.mutedConfigBoolean.setBooleanValue(this.macro.isMuted()); + this.keybind = KeybindMulti.fromStorageString(this.macro.getKeybind(), this.macro.getSettings()); } @Override public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) { super.render(context, mouseX, mouseY, deltaTicks); - buttonKeybind.updateDisplayString(); - buttonEnabled.updateDisplayString(); - buttonMuted.updateDisplayString(); - //? if <=1.21.5 { - /*buttonKeybind.render(mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY), context); - buttonEnabled.render(mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY), context); - buttonMuted.render(mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY), context); - widgetAdvancedKeybindSettings.render(mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY), context); - *///?} else if <=1.21.10 { - /*buttonKeybind.render(context, mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY)); - buttonEnabled.render(context, mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY)); - buttonMuted.render(context, mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY)); - widgetAdvancedKeybindSettings.render(context, mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY)); - *///?} else { - buttonKeybind.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonKeybind.isMouseOver(mouseX, mouseY)); - buttonEnabled.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonEnabled.isMouseOver(mouseX, mouseY)); - buttonMuted.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, buttonMuted.isMouseOver(mouseX, mouseY)); - widgetAdvancedKeybindSettings.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, widgetAdvancedKeybindSettings.isMouseOver(mouseX, mouseY)); - //?} if (errorCountDown > 0.0f) { context.drawText(this.textRenderer, "Name already exists!", mouseX, mouseY - 10, 0xFFFFFFFF, true); errorCountDown -= deltaTicks; @@ -91,171 +82,56 @@ protected void init() { GuiUtils.Layout buttonEnabledLayout = layouts.get(3); GuiUtils.Layout nameWidgetLayout = layouts.get(4); GuiUtils.Layout buttonMutedLayout = layouts.get(5); - this.commandList = this.addDrawableChild( - new CommandListWidget(this, this.client, this.width, this.height - 75, 0, 36, this.macro)); - this.addDrawableChild(ButtonWidget.builder(Text.of("Add command"), button -> - this.commandList.addEntry()) + + this.commandList = this.addDrawableChild(new CommandListWidget(this, this.client, this.width, this.height - 75, 0, 36, this.macro)); + this.addDrawableChild(ButtonWidget.builder(Text.of("Add command"), button -> this.commandList.addEntry()) .dimensions(addCommandLayout.x(), addCommandLayout.y(), addCommandLayout.width(), addCommandLayout.height()) .build()); - this.widgetAdvancedKeybindSettings = new WidgetKeybindSettings(keybindSettingsLayout.x(), keybindSettingsLayout.y(), keybindSettingsLayout.width(), keybindSettingsLayout.height(), macro.hotkey.getKeybind(), "", null, null) { - @Override - protected boolean onMouseClickedImpl(/*? if >=1.21.10 {*/Click click, boolean doubleClick/*?} else {*//*int mouseX, int mouseY, int button*//*?}*/) { - //? if >=1.21.10 { - int button = click.button(); - //?} - if (button == 0) { - GuiBase.openGui(new GuiKeybindSettings(this.keybind, this.keybindName, null, fi.dy.masa.malilib.util.GuiUtils.getCurrentScreen())); - return true; - } else return super.onMouseClickedImpl(/*? if >=1.21.10 {*/click, doubleClick/*?} else {*//*mouseX, mouseY, button*//*?}*/); - } - }; - this.buttonKeybind = new ConfigButtonKeybind(buttonKeybindLayout.x(), buttonKeybindLayout.y(), buttonKeybindLayout.width(), buttonKeybindLayout.height(), macro.hotkey.getKeybind(), null) { - @Override - public boolean onMouseClicked(/*? if >=1.21.10 {*/Click click, boolean doubleClick/*?} else {*//*int mouseX, int mouseY, int button*//*?}*/) { - if (!this.isMouseOver(/*? if >=1.21.10 {*/(int) click.x(), (int) click.y()/*?} else {*//*mouseX, mouseY*//*?}*/)) { - this.selected = false; - return false; - } else { - return super.onMouseClicked(/*? if >=1.21.10 {*/click, doubleClick/*?} else {*//*mouseX, mouseY, button*//*?}*/); - } - } - @Override - public void onClearSelection() { - this.firstKey = true; - super.onClearSelection(); - } - }; - this.enabledConfigBoolean = new ConfigBoolean("", true, ""); - this.enabledConfigBoolean.setBooleanValue(this.macro.isEnabled()); - this.mutedConfigBoolean = new ConfigBoolean("", true, ""); - this.mutedConfigBoolean.setBooleanValue(this.macro.muted); - this.buttonEnabled = new ConfigButtonBoolean(buttonEnabledLayout.x(), buttonEnabledLayout.y(), buttonEnabledLayout.width(), buttonEnabledLayout.height(), this.enabledConfigBoolean) { + + WidgetKeybindSettings widgetAdvancedKeybindSettings = new WidgetKeybindSettings(keybindSettingsLayout.x(), keybindSettingsLayout.y(), keybindSettingsLayout.width(), keybindSettingsLayout.height(), keybind, "", null, null); + this.buttonKeybind = new ConfigButtonKeybind(buttonKeybindLayout.x(), buttonKeybindLayout.y(), buttonKeybindLayout.width(), buttonKeybindLayout.height(), keybind, null); + + ConfigButtonBoolean buttonEnabled = new ConfigButtonBoolean(buttonEnabledLayout.x(), buttonEnabledLayout.y(), buttonEnabledLayout.width(), buttonEnabledLayout.height(), this.enabledConfigBoolean) { @Override public void updateDisplayString() { super.updateDisplayString(); this.displayString = "Enabled: " + this.displayString; } }; - this.buttonMuted = new ConfigButtonBoolean(buttonMutedLayout.x(), buttonMutedLayout.y(), buttonMutedLayout.width(), buttonMutedLayout.height(), this.mutedConfigBoolean) { + ConfigButtonBoolean buttonMuted = new ConfigButtonBoolean(buttonMutedLayout.x(), buttonMutedLayout.y(), buttonMutedLayout.width(), buttonMutedLayout.height(), this.mutedConfigBoolean) { @Override public void updateDisplayString() { super.updateDisplayString(); this.displayString = "Muted: " + this.displayString; } }; + + this.addDrawableChild(new WidgetBaseWrapper(buttonMuted)); + this.addDrawableChild(new WidgetBaseWrapper(widgetAdvancedKeybindSettings)); + this.addDrawableChild(new WidgetBaseWrapper(buttonKeybind)); + this.addDrawableChild(new WidgetBaseWrapper(buttonEnabled)); this.nameWidget = addDrawableChild(new TextFieldWidget(this.textRenderer, nameWidgetLayout.width(), nameWidgetLayout.height(), Text.of(""))); - this.nameWidget.setText(macro.getName()); + this.nameWidget.setText(macro.getMacroName()); this.nameWidget.setPosition(nameWidgetLayout.x(), nameWidgetLayout.y()); } - @Override - public boolean keyPressed(/*$ keyinput_params {*/KeyInput input/*$}*/) { - //? if >=1.21.10 { - int keyCode = input.key(); - //?} - if (this.commandList.keyPressed(/*$ keyinput_args {*/input/*$}*/)) return true; - buttonEnabled.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); - buttonMuted.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); - widgetAdvancedKeybindSettings.onKeyTyped(/*$ keyinput_args {*/input/*$}*/); - buttonKeybind.onKeyPressed(keyCode); - if (buttonKeybind.isSelected() && keyCode == 256) { - this.macro.hotkey.getKeybind().clearKeys(); - buttonKeybind.onClearSelection(); - return true; + //? if <=1.21.8 { + /*@Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (!this.buttonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { + this.buttonKeybind.onClearSelection(); } - return super.keyPressed(/*$ keyinput_args {*/input/*$}*/); + return super.mouseClicked(mouseX, mouseY, button); } - + *///? } else { @Override - public void mouseMoved(double mouseX, double mouseY) { - commandList.mouseMoved(mouseX, mouseY); - } - - @Override - public boolean mouseClicked(/*$ mouse_clicked_params {*/Click click, boolean doubleClick/*$}*/) { - if (super.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/)) return true; - boolean buttonKeybindClicked = buttonKeybind.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); - boolean buttonEnabledClicked = buttonEnabled.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); - boolean buttonMutedClicked = buttonMuted.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); - boolean widgetAdvancedKeybindSettingsClicked = widgetAdvancedKeybindSettings.onMouseClicked(/*$ on_mouse_clicked_args {*/click, doubleClick/*$}*/); - boolean commandListClicked = commandList.mouseClicked(/*$ mouse_clicked_args {*/click, doubleClick/*$}*/); - if (buttonKeybindClicked || buttonEnabledClicked || buttonMutedClicked || widgetAdvancedKeybindSettingsClicked || commandListClicked) { - if (this.getFocused() != null) { - this.setFocused(null); - } - return true; + public boolean mouseClicked(Click click, boolean doubled) { + if (!this.buttonKeybind.isMouseOver((int) click.x(), (int) click.y())) { + this.buttonKeybind.onClearSelection(); } - return false; - } - - @Override - public boolean mouseReleased(/*$ dragged_released_params {*/Click click/*$}*/) { - if (super.mouseReleased(/*$ dragged_released_args {*/click/*$}*/)) return true; - if (commandList.mouseReleased(/*$ dragged_released_args {*/click/*$}*/)) return true; - buttonKeybind.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - buttonEnabled.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - buttonMuted.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - widgetAdvancedKeybindSettings.onMouseReleased(/*$ on_released_args {*/click/*$}*/); - return false; - } - - @Override - public boolean mouseDragged(/*$ dragged_released_params {*/Click click/*$}*/, double deltaX, double deltaY) { - if (commandList.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY)) return true; - return super.mouseDragged(/*$ dragged_released_args {*/click/*$}*/, deltaX, deltaY); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { - if (commandList.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) return true; - - //? if <1.21.10 { - /*else if (buttonKeybind.onMouseScrolled((int) mouseX, (int) mouseY, horizontalAmount, verticalAmount)) - return true; - else if (widgetAdvancedKeybindSettings.onMouseScrolled((int) mouseX, (int) mouseY, horizontalAmount, verticalAmount)) - return true; - else if (buttonEnabled.onMouseScrolled((int) mouseX, (int) mouseY, horizontalAmount, verticalAmount)) - return true; - else if (buttonMuted.onMouseScrolled((int) mouseX, (int) mouseY, horizontalAmount, verticalAmount)) - return true; - *///?} else { - else if (buttonKeybind.onMouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) - return true; - else if (widgetAdvancedKeybindSettings.onMouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) - return true; - else if (buttonEnabled.onMouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) - return true; - else if (buttonMuted.onMouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)) - return true; - //?} - else return super.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount); - } - - @Override - public boolean keyReleased(/*$ keyinput_params {*/KeyInput input/*$}*/) { - if (commandList.keyReleased(/*$ keyinput_args {*/input/*$}*/)) return true; - else return super.keyReleased(/*$ keyinput_args {*/input/*$}*/); - } - - @Override - public boolean charTyped(/*$ charinput_params {*/CharInput input/*$}*/) { - if (commandList.charTyped(/*$ charinput_args {*/input/*$}*/)) return true; - else if (buttonKeybind.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; - else if (buttonEnabled.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; - else if (buttonMuted.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; - else if (widgetAdvancedKeybindSettings.onCharTyped(/*$ charinput_args {*/input/*$}*/)) return true; - else return super.charTyped(/*$ charinput_args {*/input/*$}*/); - } - - @Override - public boolean isMouseOver(double mouseX, double mouseY) { - if (commandList.isMouseOver(mouseX, mouseY)) return true; - else if (buttonKeybind.isMouseOver((int) mouseX, (int) mouseY)) return true; - else if (buttonEnabled.isMouseOver((int) mouseX, (int) mouseY)) return true; - else if (buttonMuted.isMouseOver((int) mouseX, (int) mouseY)) return true; - else if (widgetAdvancedKeybindSettings.isMouseOver((int) mouseX, (int) mouseY)) return true; - else return super.isMouseOver(mouseX, mouseY); + return super.mouseClicked(click, doubled); } + //? } @Override public void close() { @@ -263,15 +139,21 @@ public void close() { errorCountDown = 50.0f; return; } - this.macro.actions.clear(); - this.commandList.children().forEach(t -> this.macro.actions.add(t.command)); - this.macro.setEnabled(this.enabledConfigBoolean.getBooleanValue()); - this.macro.muted = this.mutedConfigBoolean.getBooleanValue(); - this.macro.setName(this.nameWidget.getText()); - MacroManager.saveChanges(); + + macro.setActions(this.commandList.children().stream().map(m -> m.command).toList()); + macro.setEnabled(this.enabledConfigBoolean.getBooleanValue()); + macro.setMuted(this.mutedConfigBoolean.getBooleanValue()); + macro.setMacroName(this.nameWidget.getText()); + macro.setKeybind(this.keybind.getStringValue()); + macro.setSettings(this.keybind.getSettings()); + InputEventHandler.getKeybindManager().updateUsedKeys(); - assert client != null; - macroManager.initGui(); - GuiBase.openGui(macroManager); + GuiBase.openGui(parent); + + // malilib forces a load of the configs from disk when joining a world, and + // if settings are changed while on the title screen, the settings are never saved + // hmmm... this also happens with normal configs, not just macros + // I'll just hope nobody notices + MinecraftClient.getInstance().send(() -> InternalMalilibApi.getMod(RedstoneTools.MOD_ID).configHandler.save()); } } diff --git a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java b/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java deleted file mode 100644 index d58a0e2d..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/GuiMacroManager.java +++ /dev/null @@ -1,153 +0,0 @@ -package tools.redstone.redstonetools.malilib; - -import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.gui.GuiListBase; -import fi.dy.masa.malilib.gui.button.ButtonBase; -import fi.dy.masa.malilib.gui.button.ButtonGeneric; -import fi.dy.masa.malilib.gui.button.IButtonActionListener; -import fi.dy.masa.malilib.gui.interfaces.ISelectionListener; -import fi.dy.masa.malilib.hotkeys.KeybindSettings; -import net.minecraft.client.gui.DrawContext; -import org.jetbrains.annotations.Nullable; -import tools.redstone.redstonetools.malilib.config.MacroManager; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; -import tools.redstone.redstonetools.malilib.widget.macro.WidgetListMacros; -import tools.redstone.redstonetools.malilib.widget.macro.WidgetMacroEntry; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; - -public class GuiMacroManager extends GuiListBase - implements ISelectionListener { - - public GuiMacroManager() { - super(10, 68); - this.title = "Macro manager"; - } - - @Override - public void render(DrawContext drawContext, int mouseX, int mouseY, float partialTicks) { - if (this.client != null && this.client.world == null) this.renderPanoramaBackground(drawContext, partialTicks); - this.applyBlur(/*? if >1.21.5 {*/drawContext/*?}*/); - super.render(drawContext, mouseX, mouseY, partialTicks); - } - - @Override - protected int getBrowserWidth() { - return this.width - 20; - } - - @Override - protected int getBrowserHeight() { - return this.height - this.getListY() - 6; - } - - @Override - public void initGui() { - GuiConfigs.tab = GuiConfigs.ConfigGuiTab.MACROS; - - super.initGui(); - - //? if <=1.21.10 { - /*this.clearWidgets(); - *///?} else { - this.clearChildren(); - //?} - this.clearButtons(); - this.createTabButtons(); - this.getListWidget().refreshEntries(); - } - - protected void createTabButtons() { - int x = 10; - int y = 26; - int rows = 1; - - for (GuiConfigs.ConfigGuiTab tab : GuiConfigs.ConfigGuiTab.values()) { - int width = this.getStringWidth(tab.getDisplayName()) + 10; - - if (x >= this.width - width - 10) { - x = 10; - y += 22; - ++rows; - } - - x += this.createTabButton(x, y, width, tab); - } - - String name = "Add macro"; - ButtonGeneric addMacroButton = new ButtonGeneric(this.width - 10, y, -1, true, name); - - // Check if there is enough space to put the dropdown widget and - // the button at the end of the last tab button row - if (rows < 2 || (this.width - 10 - x < (addMacroButton.getWidth() + 4))) { - y += 22; - } - - addMacroButton.setY(y); - - this.setListPosition(this.getListX(), y + 20); - this.reCreateListWidget(); - - this.addButton(addMacroButton, (btn, mbtn) -> { - String string = "macro "; - string += MacroManager.getAllMacros().size(); - MacroManager.addMacroToTop(new MacroBase(string, "", KeybindSettings.PRESS_ALLOWEXTRA, new ArrayList<>())); - MacroManager.saveChanges(); - this.getListWidget().refreshEntries(); - }); - } - - protected int createTabButton(int x, int y, int width, GuiConfigs.ConfigGuiTab tab) { - ButtonGeneric button = new ButtonGeneric(x, y, width, 20, tab.getDisplayName()); - button.setEnabled(GuiConfigs.tab != tab); - this.addButton(button, new ButtonListenerTab(tab)); - - return button.getWidth() + 2; - } - - @Override - protected WidgetListMacros createListWidget(int listX, int listY) { - return new WidgetListMacros(listX, listY, this.getBrowserWidth(), this.getBrowserHeight(), this, this); - } - - @Override - public void onSelectionChange(@Nullable MacroBase macroBase) { - - } - - public static class ButtonListenerTab implements IButtonActionListener { - private final GuiConfigs.ConfigGuiTab tab; - - public ButtonListenerTab(GuiConfigs.ConfigGuiTab tab) { - this.tab = tab; - } - - @Override - public void actionPerformedWithButton(ButtonBase button, int mouseButton) { - GuiConfigs.tab = this.tab; - GuiBase.openGui(new GuiConfigs()); - } - } - - @Override - public void onFilesDropped(List paths) { - for (Path path : paths) { - try { - String fileName = path.getFileName().toString().toLowerCase(); - if (!fileName.endsWith(".txt")) - continue; - List commands = Files.readAllLines(path); - String name = fileName.substring(0, fileName.length()-4); - MacroBase macro = MacroManager.createCommandMacro(name, commands.toArray(new String[]{})); - MacroManager.addMacroToTop(macro); - this.getListWidget().refreshEntries(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } -} \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/malilib/InitHandler.java b/src/client/java/tools/redstone/redstonetools/malilib/InitHandler.java deleted file mode 100644 index 66bb58fb..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/InitHandler.java +++ /dev/null @@ -1,29 +0,0 @@ -package tools.redstone.redstonetools.malilib; - -import fi.dy.masa.malilib.config.ConfigManager; -import fi.dy.masa.malilib.event.InputEventHandler; -import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.interfaces.IInitializationHandler; -import fi.dy.masa.malilib.registry.Registry; -import fi.dy.masa.malilib.util.data.ModInfo; -import tools.redstone.redstonetools.RedstoneTools; -import tools.redstone.redstonetools.malilib.config.Configs; -import tools.redstone.redstonetools.malilib.event.InputHandler; - -public class InitHandler implements IInitializationHandler { - @Override - public void registerModHandlers() { - ConfigManager.getInstance().registerConfigHandler(RedstoneTools.MOD_ID, new Configs()); - - Registry.CONFIG_SCREEN.registerConfigScreenFactory( - new ModInfo(RedstoneTools.MOD_ID, RedstoneTools.MOD_NAME, GuiConfigs::new) - ); - InputEventHandler.getKeybindManager().registerKeybindProvider(InputHandler.getInstance()); - InputEventHandler.getInputManager().registerKeyboardInputHandler(InputHandler.getInstance()); - InputEventHandler.getInputManager().registerMouseInputHandler(InputHandler.getInstance()); - Configs.General.HOTKEY_OPEN_GUI.getKeybind().setCallback((t, c) -> { - GuiBase.openGui(new GuiConfigs()); - return true; - }); - } -} \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/malilib/KeybindHandler.java b/src/client/java/tools/redstone/redstonetools/malilib/KeybindHandler.java deleted file mode 100644 index 11eceb8e..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/KeybindHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -package tools.redstone.redstonetools.malilib; - -import com.google.common.collect.ImmutableList; -import fi.dy.masa.malilib.hotkeys.*; -import tools.redstone.redstonetools.RedstoneTools; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; - -public class KeybindHandler implements IKeybindProvider, IKeyboardInputHandler, IMouseInputHandler { - private final MacroBase macro; - - public KeybindHandler(MacroBase macro) { - super(); - this.macro = macro; - } - - @Override - public void addKeysToMap(IKeybindManager manager) { - manager.addKeybindToMap(macro.hotkey.getKeybind()); - } - - @Override - public void addHotkeys(IKeybindManager manager) { - ImmutableList IL = ImmutableList.of(macro.hotkey); - manager.addHotkeysForCategory(RedstoneTools.MOD_NAME, macro.getName(), IL); - } -} \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java b/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java deleted file mode 100644 index 634b73e8..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/config/Configs.java +++ /dev/null @@ -1,149 +0,0 @@ -package tools.redstone.redstonetools.malilib.config; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import fi.dy.masa.malilib.config.ConfigUtils; -import fi.dy.masa.malilib.config.IConfigBase; -import fi.dy.masa.malilib.config.IConfigHandler; -import fi.dy.masa.malilib.config.options.*; -import fi.dy.masa.malilib.util.JsonUtils; -import net.minecraft.client.MinecraftClient; -import tools.redstone.redstonetools.RedstoneTools; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class Configs implements IConfigHandler { - private static final String CONFIG_FILE_NAME = RedstoneTools.MOD_ID + ".json"; - - public static class Toggles { - public static final ConfigBooleanHotkeyed AIRPLACE = new ConfigBooleanHotkeyed("Airplace", false, "", "Whether or not airplace should be enabled"); - public static final ConfigBooleanHotkeyed AUTODUST = new ConfigBooleanHotkeyed("Autodust", false, "", "Whether or not autodust should be enabled"); - public static final ConfigBooleanHotkeyed AUTOROTATE = new ConfigBooleanHotkeyed("Autorotate", false, "", "Whether or not autorotate should be enabled"); - public static final ConfigBooleanHotkeyed BIGDUST = new ConfigBooleanHotkeyed("Bigdust", false, "", "Whether or not bigdust should be enabled"); - public static final ConfigBooleanHotkeyed CLICKCONTAINERS = new ConfigBooleanHotkeyed("Clickcontainers", false, "", "Whether or not clickcontainer should be enabled"); - - public static final List TOGGLES = List.of( - AIRPLACE, - AUTODUST, - AUTOROTATE, - BIGDUST, - CLICKCONTAINERS - ); - - static { - AIRPLACE.getKeybind().setCallback((t, g) -> { - AIRPLACE.setBooleanValue(!AIRPLACE.getBooleanValue()); - return true; - }); - AUTODUST.getKeybind().setCallback((t, g) -> { - AUTODUST.setBooleanValue(!AUTODUST.getBooleanValue()); - return true; - }); - AUTOROTATE.getKeybind().setCallback((t, g) -> { - AUTOROTATE.setBooleanValue(!AUTOROTATE.getBooleanValue()); - return true; - }); - BIGDUST.getKeybind().setCallback((t, g) -> { - BIGDUST.setBooleanValue(!BIGDUST.getBooleanValue()); - return true; - }); - CLICKCONTAINERS.getKeybind().setCallback((t, g) -> { - CLICKCONTAINERS.setBooleanValue(!CLICKCONTAINERS.getBooleanValue()); - return true; - }); - } - } - - public static class ClientData { - public static final ConfigBoolean ENABLE_MATH_VARIABLES = new ConfigBoolean("Enable math and variables for the chat input suggester", true, - """ - Whether or not to try to inject variables and math expressions into the command input suggester. - - With this enabled, Redstone tools will attempt to prevent chat suggestion from breaking if you're using variables and or math expressions inside of a command. - With this disabled, variables and math expressions will still be inserted upon sending a chat command"""); - public static final ConfigString VARIABLE_BEGIN_STRING = new ConfigString("Variable begin string", "'", "The string that should be used to denote the start of a variable. Can be empty"); - public static final ConfigString VARIABLE_END_STRING = new ConfigString("Variable end string", "'", "The string that should be used to denote the end of a variable. Can be empty"); - public static final ConfigString MATH_BEGIN_STRING = new ConfigString("Math begin string", "{", "The string that should be used to denote the start of a math expression. Can be empty, unsure if you'd want that though."); - public static final ConfigString MATH_END_STRING = new ConfigString("Math end string", "}", "The string that should be used to denote the end of a math expression. Can be empty, unsure if you'd want that though."); - public static final ConfigString AUTORUN_FIRST_WORLD_ENTRY = new ConfigString("First world entry", "", "Command/message that will be run/sent the first time you join a world in this session"); - public static final ConfigString AUTORUN_WORLD_ENTRY = new ConfigString("World entry", "", "Command/message that will be run/sent when you join a world"); - public static final ConfigString AUTORUN_DIMENSION_CHANGE = new ConfigString("Dimension change", "", "Command/message that will be run/sent after you change dimensions"); - - public static final List OPTIONS = new ArrayList<>(); - - static { - OPTIONS.add(ENABLE_MATH_VARIABLES); - OPTIONS.add(VARIABLE_BEGIN_STRING); - OPTIONS.add(VARIABLE_END_STRING); - OPTIONS.add(MATH_BEGIN_STRING); - OPTIONS.add(MATH_END_STRING); - OPTIONS.add(AUTORUN_FIRST_WORLD_ENTRY); - OPTIONS.add(AUTORUN_WORLD_ENTRY); - OPTIONS.add(AUTORUN_DIMENSION_CHANGE); - } - } - - public static class General { - public static final ConfigHotkey HOTKEY_OPEN_GUI = new ConfigHotkey("Hotkey to open menu", "V,C", "Hotkey to open menu"); - public static final ConfigBoolean BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS = new ConfigBoolean("Improved command suggestions", true, - """ - Enables/disables improved suggestions when typing commands. - - When typing "/give @s redstblock" in chat, with this disabled it will give no suggestions (default behaviour, or "prefix matching"), but with - this enabled it will give "redstone_block" as a suggestion (so called "fuzzy matching")."""); - public static final ConfigBoolean AIRPLACE_SHOW_OUTLINE = new ConfigBoolean("Airplace showOutline", true, "If enabled, will show a block outline for the block your holding"); - public static final ConfigInteger BIGDUST_HEIGHT_IN_PIXELS = new ConfigInteger("Bigdust heightInPixels", 3, 0, 16, "How tall the redstone hitbox should be"); - public static final List OPTIONS = List.of( - HOTKEY_OPEN_GUI, - BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS, - AIRPLACE_SHOW_OUTLINE, - BIGDUST_HEIGHT_IN_PIXELS - ); - - public static int getHeightInPixels() { - return BIGDUST_HEIGHT_IN_PIXELS.getIntegerValue(); - } - } - - public static void loadFromFile() { - File configFile = new File(MinecraftClient.getInstance().runDirectory, "config/" + CONFIG_FILE_NAME); - - if (configFile.exists() && configFile.isFile() && configFile.canRead()) { - JsonElement element = JsonUtils.parseJsonFile(configFile); - - if (element != null && element.isJsonObject()) { - JsonObject root = element.getAsJsonObject(); - - ConfigUtils.readConfigBase(root, "Generic", General.OPTIONS); - ConfigUtils.readConfigBase(root, "Toggles", Toggles.TOGGLES); - ConfigUtils.readConfigBase(root, "ClientData", ClientData.OPTIONS); - } - } - } - - public static void saveToFile() { - File dir = new File(MinecraftClient.getInstance().runDirectory, "config"); - - if ((dir.exists() && dir.isDirectory()) || dir.mkdirs()) { - JsonObject root = new JsonObject(); - - ConfigUtils.writeConfigBase(root, "Generic", General.OPTIONS); - ConfigUtils.writeConfigBase(root, "Toggles", Toggles.TOGGLES); - ConfigUtils.writeConfigBase(root, "ClientData", ClientData.OPTIONS); - - JsonUtils.writeJsonToFile(root, new File(dir, CONFIG_FILE_NAME)); - } - } - - @Override - public void load() { - loadFromFile(); - } - - @Override - public void save() { - saveToFile(); - } -} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java b/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java deleted file mode 100644 index fe3a6341..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/config/MacroManager.java +++ /dev/null @@ -1,130 +0,0 @@ -package tools.redstone.redstonetools.malilib.config; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.mojang.serialization.JsonOps; -import fi.dy.masa.malilib.hotkeys.KeybindSettings; -import net.fabricmc.loader.api.FabricLoader; -import tools.redstone.redstonetools.macros.actions.CommandAction; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -public class MacroManager { - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - public static boolean shouldMute; - private static final Path MACROS_FILE_PATH = FabricLoader.getInstance().getConfigDir() - .resolve("redstonetools") - .resolve("macros.json"); - private static List macros = new ArrayList<>(); - - public static List getAllMacros() { - return macros; - } - - public static void saveChanges() { - JsonElement jsonElement = MacroBase.CODEC.listOf().encodeStart(JsonOps.INSTANCE, macros).getOrThrow(); - try { - if (MACROS_FILE_PATH.getParent() != null) Files.createDirectories(MACROS_FILE_PATH.getParent()); - - Path tmp = MACROS_FILE_PATH.resolveSibling(MACROS_FILE_PATH.getFileName().toString() + ".tmp"); - try (BufferedWriter writer = Files.newBufferedWriter(tmp, StandardCharsets.UTF_8)) { - GSON.toJson(jsonElement, writer); - } - Files.move(tmp, MACROS_FILE_PATH, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE); - } catch (IOException ignored) { - } - } - - public static void loadMacros() { - if (!Files.exists(MACROS_FILE_PATH)) { - macros = getDefaultMacros(); - return; - } - try (BufferedReader reader = Files.newBufferedReader(MACROS_FILE_PATH, StandardCharsets.UTF_8)) { - List macrosFromFile = MacroBase.CODEC.listOf().parse(JsonOps.INSTANCE, GSON.fromJson(reader, JsonElement.class)).result().orElse(null); - if (macrosFromFile == null) { - macros = getDefaultMacros(); - return; - } - macros.addAll(macrosFromFile); - } catch (IOException ignored) { - macros = getDefaultMacros(); - } - } - - public static List getMacros() { - return macros; - } - - public static MacroBase getMacro(String name) { - for (MacroBase macro : macros) { - if (macro.getName().equals(name)) { - return macro; - } - } - - return null; - } - - public static boolean nameExists(String name, MacroBase exclude) { - for (MacroBase macro : macros) { - if (macro == exclude) continue; - if (macro.getName().equals(name)) return true; - } - return false; - } - - public static List getDefaultMacros() { - return new ArrayList<>(List.of( - createCommandMacro("redstoner", new String[]{ - "/gamerule doTileDrops false", - "/gamerule doTraderSpawning false", - "/gamerule doWeatherCycle false", - "/gamerule doDaylightCycle false", - "/gamerule doMobSpawning false", - "/gamerule doContainerDrops false", - "/time set noon", - "/weather clear" - }), - createCommandMacro("copystate", new String[]{"/copystate" }), - createCommandMacro("itembind", new String[]{"/itembind" }), - createCommandMacro("minsel", new String[]{"//minsel" }), - createCommandMacro("quicktp", new String[]{"/quicktp" }), - createCommandMacro("binaryblockread", new String[]{"//binaryblockread" }), - createCommandMacro("rstack", new String[]{"//rstack" }), - createCommandMacro("update", new String[]{"//update" }) - )); - } - - public static MacroBase createCommandMacro(String name, String[] commands) { - var actions = new CommandAction[commands.length]; - for (int i = 0; i < commands.length; i++) { - actions[i] = new CommandAction(commands[i]); - } - - return new MacroBase(name, "", KeybindSettings.PRESS_ALLOWEXTRA, List.of(actions)); - } - - public static void removeMacro(MacroBase macro) { - macros.remove(macro); - } - - public static void addMacroToTop(MacroBase macroBase) { - if (MacroManager.nameExists(macroBase.getName(), null)) { - macroBase.setName(macroBase.getName() + " " + UUID.randomUUID()); - } - macros.addFirst(macroBase); - } - -} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/event/InputHandler.java b/src/client/java/tools/redstone/redstonetools/malilib/event/InputHandler.java deleted file mode 100644 index 5602022a..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/event/InputHandler.java +++ /dev/null @@ -1,46 +0,0 @@ -package tools.redstone.redstonetools.malilib.event; - -import fi.dy.masa.malilib.config.IConfigBase; -import fi.dy.masa.malilib.hotkeys.*; -import tools.redstone.redstonetools.RedstoneTools; -import tools.redstone.redstonetools.malilib.config.Configs; - -import java.util.List; - -public class InputHandler implements IKeybindProvider, IKeyboardInputHandler, IMouseInputHandler { - private static final InputHandler INSTANCE = new InputHandler(); - - private InputHandler() { - super(); - } - - public static InputHandler getInstance() { - return INSTANCE; - } - - @Override - public void addKeysToMap(IKeybindManager manager) { - for (IConfigBase config : Configs.General.OPTIONS) { - if (config instanceof IHotkey hotkey) - manager.addKeybindToMap(hotkey.getKeybind()); - } - for (IConfigBase config : Configs.Toggles.TOGGLES) { - if (config instanceof IHotkey hotkey) - manager.addKeybindToMap(hotkey.getKeybind()); - } - } - - @Override - public void addHotkeys(IKeybindManager manager) { - List hotkeysOptions = Configs.General.OPTIONS.stream() - .filter(IHotkey.class::isInstance) - .map(IHotkey.class::cast) - .toList(); - manager.addHotkeysForCategory(RedstoneTools.MOD_NAME, "Generic", hotkeysOptions); - List hotkeysToggles = Configs.Toggles.TOGGLES.stream() - .filter(IHotkey.class::isInstance) - .map(IHotkey.class::cast) - .toList(); - manager.addHotkeysForCategory(RedstoneTools.MOD_NAME, "Toggles", hotkeysToggles); - } -} \ No newline at end of file diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java new file mode 100644 index 00000000..351f2c1e --- /dev/null +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/WidgetBaseWrapper.java @@ -0,0 +1,149 @@ +package tools.redstone.redstonetools.malilib.widget; + +import fi.dy.masa.malilib.gui.button.ConfigButtonKeybind; +import fi.dy.masa.malilib.gui.widgets.WidgetBase; +//? if >=1.21.11 +import fi.dy.masa.malilib.render.GuiContext; +import net.minecraft.client.gui.*; +import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; +//? if >1.21.8 { +import net.minecraft.client.input.CharInput; +import net.minecraft.client.input.KeyInput; +//? } + +import java.util.Collection; + +public class WidgetBaseWrapper implements Element, Drawable, Selectable { + private final WidgetBase wrapped; + + public WidgetBaseWrapper(WidgetBase wrapped) { + this.wrapped = wrapped; + } + + //? if <=1.21.8 { + /*@Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { + if (configButtonKeybind.isMouseOver((int) mouseX, (int) mouseY)) { + boolean selectedPre = configButtonKeybind.isSelected(); + configButtonKeybind.onMouseClicked((int) mouseX, (int) mouseY, button); + if (!selectedPre) { + configButtonKeybind.onSelected(); + } + return true; + } else if (configButtonKeybind.isSelected()) { + configButtonKeybind.onClearSelection(); + return true; + } + } + return wrapped.onMouseClicked((int) mouseX, (int) mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + wrapped.onMouseReleased((int) mouseX, (int) mouseY, button); + return Element.super.mouseReleased(mouseX, mouseY, button); + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) configButtonKeybind.onKeyPressed(keyCode); + return wrapped.onKeyTyped(keyCode, scanCode, modifiers); + } + @Override + public boolean charTyped(char chr, int modifiers) { + return wrapped.onCharTyped(chr, modifiers); + } + *///? } else { + @Override + public boolean mouseClicked(Click click, boolean doubled) { + if (this.wrapped instanceof ConfigButtonKeybind configButtonKeybind) { + if (configButtonKeybind.isMouseOver((int) click.x(), (int) click.y())) { + boolean selectedPre = configButtonKeybind.isSelected(); + configButtonKeybind.onMouseClicked(click, doubled); + if (!selectedPre) { + configButtonKeybind.onSelected(); + } + return true; + } else if (configButtonKeybind.isSelected()) { + configButtonKeybind.onClearSelection(); + return true; + } + } + return wrapped.onMouseClicked(click, doubled); + } + + @Override + public boolean mouseReleased(Click click) { + wrapped.onMouseReleased(click); + return Element.super.mouseReleased(click); + } + + @Override + public boolean charTyped(CharInput input) { + return wrapped.onCharTyped(input); + } + + @Override + public boolean keyPressed(KeyInput input) { + if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) configButtonKeybind.onKeyPressed(input.getKeycode()); + return wrapped.onKeyTyped(input); + } + //? } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmount, double verticalAmount) { + return wrapped.onMouseScrolled((int) mouseX, (int) mouseY, horizontalAmount, verticalAmount); + } + + @Override + public boolean isMouseOver(double mouseX, double mouseY) { + return wrapped.isMouseOver((int) mouseX, (int) mouseY); + } + + @Override + public void setFocused(boolean focused) { + if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) { + if (focused) { + configButtonKeybind.onSelected(); + } else { + configButtonKeybind.onClearSelection(); + } + } + } + + @Override + public boolean isFocused() { + if (wrapped instanceof ConfigButtonKeybind configButtonKeybind) { + return configButtonKeybind.isSelected(); + } + return false; + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) { + //? if <=1.21.5 { + /*wrapped.render(mouseX, mouseY, this.isFocused(), context); + *///? } else if <=1.21.10 { + /*wrapped.render(context, mouseX, mouseY, this.isFocused()); + *///? } else { + wrapped.render(GuiContext.fromGuiGraphics(context), mouseX, mouseY, this.isFocused()); + //? } + } + + @Override + public SelectionType getType() { + if (this.isFocused()) return SelectionType.FOCUSED; + return SelectionType.NONE; + } + + @Override + public Collection getNarratedParts() { + return Selectable.super.getNarratedParts(); + } + + @Override + public void appendNarrations(NarrationMessageBuilder builder) { + + } +} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java index fa94792a..e1e32a78 100644 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java +++ b/src/client/java/tools/redstone/redstonetools/malilib/widget/action/CommandListWidget.java @@ -23,9 +23,9 @@ import net.minecraft.client.util.math.Rect2i; import net.minecraft.text.Text; import org.jetbrains.annotations.Nullable; +import tools.redstone.redstonetools.config.option.ConfigMacro; import tools.redstone.redstonetools.macros.actions.CommandAction; import tools.redstone.redstonetools.malilib.GuiMacroEditor; -import tools.redstone.redstonetools.malilib.widget.macro.MacroBase; import tools.redstone.redstonetools.mixin.features.ChatInputSuggestorAccessor; import tools.redstone.redstonetools.mixin.features.SuggestionWindowAccessor; //? if >=1.21.10 { @@ -37,13 +37,13 @@ public class CommandListWidget extends EntryListWidget=1.21.8 { context.getMatrices().pushMatrix(); //?} else - /*context.getMatrices().push();*/ + //context.getMatrices().push(); var x = 0; var y = entry.commandWidget.getY() + 20 - 72; context.getMatrices().translate(x, y/*? if <1.21.8 {*//*, 0*//*?}*/); @@ -96,7 +96,7 @@ public void renderMessages(DrawContext context) { //? if >=1.21.8 { context.getMatrices().popMatrix(); //?} else - /*context.getMatrices().pop();*/ + //context.getMatrices().pop(); } }; this.commandSuggester.setWindowActive(true); @@ -180,8 +180,8 @@ public int getRowWidth() { } public void addEntry() { - this.macro.actions.addFirst(new CommandAction("")); - CommandEntry entry = new CommandEntry(this.macro.actions.getFirst()); + this.macro.getActions().addFirst(new CommandAction("")); + CommandEntry entry = new CommandEntry(this.macro.getActions().getFirst()); this.addEntryToTop(entry); this.centerScrollOn(this.getFirst()); recalculateAllActionsPositions(); @@ -226,7 +226,7 @@ public CommandEntry(CommandAction command) { this.removeButton = new ButtonGeneric(0, 0, -1, 20, "Remove"); this.removeButton.setX(CommandListWidget.this.getX() + CommandListWidget.this.getRowWidth() - this.removeButton.getWidth() - 10 + 25); this.removeButton.setActionListener((button, mouseButton) -> { - CommandListWidget.this.macro.actions.remove(CommandListWidget.this.children().indexOf(this)); + CommandListWidget.this.macro.getActions().remove(CommandListWidget.this.children().indexOf(this)); CommandListWidget.this.removeEntryWithoutScrolling(this); recalculateAllActionsPositions(); }); diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java deleted file mode 100644 index aeb92f97..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/MacroBase.java +++ /dev/null @@ -1,116 +0,0 @@ -package tools.redstone.redstonetools.malilib.widget.macro; - -import com.google.gson.JsonElement; -import com.mojang.datafixers.util.Pair; -import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.DynamicOps; -import com.mojang.serialization.JsonOps; -import com.mojang.serialization.codecs.RecordCodecBuilder; -import fi.dy.masa.malilib.config.options.ConfigHotkey; -import fi.dy.masa.malilib.event.InputEventHandler; -import fi.dy.masa.malilib.hotkeys.KeybindSettings; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.Text; -import tools.redstone.redstonetools.macros.actions.Action; -import tools.redstone.redstonetools.macros.actions.CommandAction; -import tools.redstone.redstonetools.malilib.KeybindHandler; -import tools.redstone.redstonetools.malilib.config.MacroManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -public class MacroBase { - private static final Codec KEYBIND_SETTINGS_CODEC = new Codec<>() { - @Override - public DataResult encode(KeybindSettings keybindSettings, DynamicOps dynamicOps, T t) { - return DataResult.success(JsonOps.INSTANCE.convertTo(dynamicOps, keybindSettings.toJson())); - } - - @Override - public DataResult> decode(DynamicOps dynamicOps, T t) { - JsonElement jsonElement = dynamicOps.convertTo(JsonOps.INSTANCE, t); - KeybindSettings keybindSettings1 = !jsonElement.isJsonObject() ? KeybindSettings.PRESS_ALLOWEXTRA : KeybindSettings.fromJson(jsonElement.getAsJsonObject()); - return DataResult.success(Pair.of(keybindSettings1, dynamicOps.empty())); - } - }; - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - Codec.STRING.optionalFieldOf("name", "").forGetter(macro -> macro.name), - Codec.STRING.optionalFieldOf("keybind", "").forGetter(macro -> macro.hotkey.getStringValue()), - KEYBIND_SETTINGS_CODEC.optionalFieldOf("keybindSettings", KeybindSettings.PRESS_ALLOWEXTRA).forGetter(macro -> macro.hotkey.getKeybind().getSettings()), - CommandAction.CODEC.listOf().optionalFieldOf("actions", List.of()).forGetter(macro -> macro.actions), - Codec.BOOL.optionalFieldOf("enabled", true).forGetter(macro -> macro.enabled), - Codec.BOOL.optionalFieldOf("muted", false).forGetter(macro -> macro.muted) - ).apply(instance, MacroBase::new)); - - public ConfigHotkey hotkey; - public boolean muted; - protected String name; - protected boolean enabled; - public KeybindHandler handler; - public List actions; - - public MacroBase(String name, String keybind, KeybindSettings keybindSettings, List actions) { - this(name, keybind, keybindSettings, actions, true, false); - } - - public MacroBase(String name, String keybind, KeybindSettings keybindSettings, List actions, boolean enabled, boolean muted) { - this.actions = new ArrayList<>(actions); - this.hotkey = new ConfigHotkey("Hotkey", keybind, keybindSettings, "Pressing this hotkey will activate the macro"); - this.hotkey.getKeybind().setCallback((t, g) -> { - this.run(); - return true; - }); - this.name = name; - this.enabled = enabled; - this.muted = muted; - this.handler = new KeybindHandler(this); - InputEventHandler.getKeybindManager().registerKeybindProvider(this.handler); - InputEventHandler.getInputManager().registerKeyboardInputHandler(this.handler); - InputEventHandler.getInputManager().registerMouseInputHandler(this.handler); - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public boolean isEnabled() { - return this.enabled; - } - - private final AtomicInteger layers = new AtomicInteger(0); - - public void run() { - if (muted) MacroManager.shouldMute = true; - if (!enabled) return; - if (layers.getAndSet(layers.get() + 1) > 100) { - MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); - return; - } - try { - for (Action action : actions) { - action.run(); - } - } catch (StackOverflowError ignored) { - try { - MinecraftClient.getInstance().player.sendMessage(Text.of("Please don't cause a stackoverflow :("), false); - } catch (NoClassDefFoundError e) { - // yeah we are absolutely cooked, there is no way to recover from this. I'm not even sure this can happen - // actually there's probably a better throwable to be thrown here. whatever. - throw new InternalError("Something has gone terribly wrong. Shouldn't have run a macro that runs itself.", e); - } - } finally { - layers.set(0); - } - if (muted) MacroManager.shouldMute = false; - } -} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetListMacros.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetListMacros.java deleted file mode 100644 index 4cb138c4..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetListMacros.java +++ /dev/null @@ -1,30 +0,0 @@ -package tools.redstone.redstonetools.malilib.widget.macro; - -import fi.dy.masa.malilib.gui.interfaces.ISelectionListener; -import fi.dy.masa.malilib.gui.widgets.WidgetListBase; -import tools.redstone.redstonetools.malilib.GuiMacroManager; -import tools.redstone.redstonetools.malilib.config.MacroManager; - -import javax.annotation.Nullable; -import java.util.Collection; - -public class WidgetListMacros extends WidgetListBase { - public GuiMacroManager parent; - public WidgetListMacros(int x, int y, int width, int height, GuiMacroManager parent, - @Nullable ISelectionListener selectionListener) { - super(x, y, width, height, selectionListener); - this.parent = parent; - this.browserEntryHeight = 22; - } - - @Override - protected Collection getAllEntries() { - return MacroManager.getAllMacros(); - } - - @Override - protected WidgetMacroEntry createListEntryWidget(int x, int y, int listIndex, boolean isOdd, MacroBase entry) { - return new WidgetMacroEntry(x, y, this.browserEntryWidth, - this.getBrowserEntryHeightFor(entry), isOdd, entry, listIndex, this); - } -} diff --git a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java b/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java deleted file mode 100644 index 93532369..00000000 --- a/src/client/java/tools/redstone/redstonetools/malilib/widget/macro/WidgetMacroEntry.java +++ /dev/null @@ -1,145 +0,0 @@ -package tools.redstone.redstonetools.malilib.widget.macro; - -import fi.dy.masa.malilib.event.InputEventHandler; -import fi.dy.masa.malilib.gui.GuiBase; -import fi.dy.masa.malilib.gui.button.ButtonBase; -import fi.dy.masa.malilib.gui.button.ButtonGeneric; -import fi.dy.masa.malilib.gui.button.IButtonActionListener; -import fi.dy.masa.malilib.gui.widgets.WidgetListEntryBase; -import fi.dy.masa.malilib.render.RenderUtils; -import fi.dy.masa.malilib.util.StringUtils; -import net.minecraft.text.Text; -import tools.redstone.redstonetools.malilib.GuiMacroEditor; -import tools.redstone.redstonetools.malilib.config.MacroManager; -//? if >=1.21.10 { -import net.minecraft.client.gui.Click; -//?} -//? if <=1.21.10 { -/*import net.minecraft.client.gui.DrawContext; -*///?} else { -import fi.dy.masa.malilib.render.GuiContext; -//?} - -public class WidgetMacroEntry extends WidgetListEntryBase { - private final WidgetListMacros parent; - public final MacroBase macro; - protected final boolean isOdd; - protected final int buttonsStartX; - - //? if <1.21.10 { - /*@Override - public boolean canSelectAt(int mouseX, int mouseY, int mouseButton) { - return super.canSelectAt(mouseX, mouseY, mouseButton) && mouseX < this.buttonsStartX; - } - *///?} else { - @Override - public boolean canSelectAt(Click click) { - return super.canSelectAt(click) && click.x() < this.buttonsStartX; - } - //?} - - - //? if >=1.21.8 { - @Override - public void render(/*? if <=1.21.10 {*//*DrawContext*//*?} else {*/GuiContext/*?}*/ context, int mouseX, int mouseY, boolean selected) { - if (selected || this.isMouseOver(mouseX, mouseY)) { - RenderUtils.drawRect(context, this.x, this.y, this.width, this.height, 0x70FFFFFF); - } else if (this.isOdd) { - RenderUtils.drawRect(context, this.x, this.y, this.width, this.height, 0x20FFFFFF); - } else { - RenderUtils.drawRect(context, this.x, this.y, this.width, this.height, 0x50FFFFFF); - } - this.drawString(context, this.x + 4, this.y + 7, 0xFFFFFFFF, this.macro.getName()); - - super.render(context, mouseX, mouseY, selected); - } - - @Override - public void postRenderHovered(/*? if <=1.21.10 {*//*DrawContext*//*?} else {*/GuiContext/*?}*/ context, int mouseX, int mouseY, boolean selected) { - super.postRenderHovered(context, mouseX, mouseY, selected); - } - //?} else { - /*@Override - public void render(int mouseX, int mouseY, boolean selected, DrawContext context) { - if (selected || this.isMouseOver(mouseX, mouseY)) { - RenderUtils.drawRect(this.x, this.y, this.width, this.height, 0x70FFFFFF); - } else if (this.isOdd) { - RenderUtils.drawRect(this.x, this.y, this.width, this.height, 0x20FFFFFF); - } else { - RenderUtils.drawRect(this.x, this.y, this.width, this.height, 0x50FFFFFF); - } - this.drawString(this.x + 4, this.y + 7, 0xFFFFFFFF, this.macro.getName(), context); - - super.render(mouseX, mouseY, selected, context); - } - - @Override - public void postRenderHovered(int mouseX, int mouseY, boolean selected, DrawContext context) { - super.postRenderHovered(mouseX, mouseY, selected, context); - } - *///?} - - public WidgetMacroEntry(int x, int y, int width, int height, boolean isOdd, - MacroBase macro, int listIndex, WidgetListMacros parent) { - super(x, y, width, height, macro, listIndex); - this.macro = macro; - this.isOdd = isOdd; - this.parent = parent; - y += 1; - - int posX = x + width - 2; - - posX -= this.addButton(posX, y, ButtonListener.Type.REMOVE); - posX -= this.addButton(posX, y, ButtonListener.Type.CONFIGURE); - this.buttonsStartX = posX; - } - - protected int addButton(int x, int y, ButtonListener.Type type) { - ButtonGeneric button = new ButtonGeneric(x, y, -1, true, type.getDisplayName()); - this.addButton(button, new ButtonListener(type, this)); - - return button.getWidth() + 1; - } - - private static class ButtonListener implements IButtonActionListener { - private final Type type; - private final WidgetMacroEntry widget; - - public ButtonListener(Type type, WidgetMacroEntry widget) { - this.type = type; - this.widget = widget; - } - - @Override - public void actionPerformedWithButton(ButtonBase button, int mouseButton) { - if (this.type == Type.CONFIGURE) { - GuiMacroEditor gui = new GuiMacroEditor(Text.of(this.widget.macro.name), this.widget.macro, this.widget.parent.parent); - GuiBase.openGui(gui); - this.widget.parent.refreshEntries(); - } else if (this.type == Type.REMOVE) { - InputEventHandler.getKeybindManager().unregisterKeybindProvider(this.widget.macro.handler); - InputEventHandler.getInputManager().unregisterKeyboardInputHandler(this.widget.macro.handler); - InputEventHandler.getInputManager().unregisterMouseInputHandler(this.widget.macro.handler); - InputEventHandler.getKeybindManager().updateUsedKeys(); - MacroManager.removeMacro(this.widget.macro); - MacroManager.saveChanges(); - this.widget.parent.refreshEntries(); - } - } - - public enum Type { - CONFIGURE("Edit"), - REMOVE("Remove"); - - private final String name; - - Type(String name) { - this.name = name; - } - - public String getDisplayName(Object... args) { - return StringUtils.translate(this.name, args); - } - } - } -} diff --git a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java index 0da90781..ab8605b0 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/blocks/RedstoneHitboxMixin.java @@ -14,8 +14,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import tools.redstone.redstonetools.config.General; import tools.redstone.redstonetools.features.toggleable.BigDustFeature; -import tools.redstone.redstonetools.malilib.config.Configs; @Mixin(RedstoneWireBlock.class) public class RedstoneHitboxMixin { @@ -36,7 +36,7 @@ public void getOutlineShape(BlockState state, BlockView world, BlockPos pos, Sha throw new IllegalStateException("MaLiLib not present"); } if (BigDustFeature.INSTANCE.isEnabled()) { - cir.setReturnValue(SHAPES[Configs.General.getHeightInPixels()]); + cir.setReturnValue(SHAPES[General.BIGDUST_HEIGHT_IN_PIXELS.getIntegerValue()]); } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java index 90452fc0..b97f389c 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatHudMixin.java @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import tools.redstone.redstonetools.malilib.config.MacroManager; +import tools.redstone.redstonetools.config.MacroManager; @Mixin(ChatHud.class) public class ChatHudMixin { diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java index cef8814b..f1a2e97f 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/ChatInputSuggestorMixin.java @@ -10,8 +10,8 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArg; +import tools.redstone.redstonetools.config.ClientData; import tools.redstone.redstonetools.malilib.GuiMacroEditor; -import tools.redstone.redstonetools.malilib.config.Configs; import tools.redstone.redstonetools.utils.StringUtils; @Mixin(ChatInputSuggestor.class) @@ -26,7 +26,7 @@ public class ChatInputSuggestorMixin { @WrapMethod(method = "refresh") private void makeMethodSeeReplacedVariables(Operation original) { - boolean shouldReturn = !Configs.ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(textField.getText()).length() < textField.getText().length(); + boolean shouldReturn = !ClientData.ENABLE_MATH_VARIABLES.getBooleanValue() || StringUtils.insertVariablesAndMath(textField.getText()).length() < textField.getText().length(); if (shouldReturn) return; String originalCommand = textField.getText(); ((TextFieldWidgetAccessor) textField).setTextDirectly(StringUtils.insertVariablesAndMath(textField.getText())); diff --git a/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java index 0d907c46..a490fc86 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/features/CommandSourceMixin.java @@ -6,7 +6,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import tools.redstone.redstonetools.malilib.config.Configs; +import tools.redstone.redstonetools.config.General; import java.util.ArrayList; import java.util.List; @@ -17,7 +17,7 @@ public interface CommandSourceMixin { @Inject(method = "shouldSuggest", at = @At("HEAD"), cancellable = true) private static void meow(String remaining, String candidate, CallbackInfoReturnable cir) { - if (!Configs.General.BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS.getBooleanValue()) return; + if (!General.BOOLEAN_IMPROVED_COMMAND_SUGGESTIONS.getBooleanValue()) return; if (candidate == null) { cir.setReturnValue(false); return; diff --git a/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java index 570ebe9b..ba11bacf 100644 --- a/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java +++ b/src/client/java/tools/redstone/redstonetools/mixin/macros/AddMacroButtonMixin.java @@ -1,5 +1,7 @@ package tools.redstone.redstonetools.mixin.macros; +import kr1v.malilibApi.InternalMalilibApi; +import kr1v.malilibApi.MalilibApi; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.ControlsOptionsScreen; @@ -11,8 +13,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import tools.redstone.redstonetools.malilib.GuiConfigs; -import tools.redstone.redstonetools.malilib.GuiMacroManager; +import tools.redstone.redstonetools.RedstoneTools; +import tools.redstone.redstonetools.config.Macros; @Mixin(ControlsOptionsScreen.class) public abstract class AddMacroButtonMixin extends GameOptionsScreen { @@ -23,10 +25,8 @@ public AddMacroButtonMixin(Screen parent, GameOptions gameOptions, Text title) { @Inject(method = "addOptions", at = @At("TAIL")) public void addMacroButton(CallbackInfo ci) { this.body.addWidgetEntry(new ButtonWidget.Builder(Text.of("Macros..."), button -> { - - GuiConfigs.tab = GuiConfigs.ConfigGuiTab.MACROS; - MinecraftClient.getInstance().setScreen( - new GuiMacroManager()); + InternalMalilibApi.getMod(RedstoneTools.MOD_ID).setActiveTab(Macros.getTab()); + MalilibApi.openScreenFor(RedstoneTools.MOD_ID); }).build(), null); } } diff --git a/src/client/java/tools/redstone/redstonetools/mixin/macros/InitializeMacroManagerMixin.java b/src/client/java/tools/redstone/redstonetools/mixin/macros/InitializeMacroManagerMixin.java deleted file mode 100644 index 8d3c3317..00000000 --- a/src/client/java/tools/redstone/redstonetools/mixin/macros/InitializeMacroManagerMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package tools.redstone.redstonetools.mixin.macros; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.RunArgs; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import tools.redstone.redstonetools.malilib.config.MacroManager; - -@Mixin(MinecraftClient.class) -public class InitializeMacroManagerMixin { - @Inject(method = "", at = @At("TAIL")) - public void registerMacros(RunArgs args, CallbackInfo ci) { - MacroManager.loadMacros(); - } -} diff --git a/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java b/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java index 63bf0272..a38e38d0 100644 --- a/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java +++ b/src/client/java/tools/redstone/redstonetools/utils/StringUtils.java @@ -7,7 +7,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static tools.redstone.redstonetools.malilib.config.Configs.ClientData.*; +import static tools.redstone.redstonetools.config.ClientData.*; public class StringUtils { public static String insertVariablesAndMath(String command) { diff --git a/src/client/resources/redstonetools.client.mixins.json b/src/client/resources/redstonetools.client.mixins.json index 5f71a0b2..4ff774fc 100644 --- a/src/client/resources/redstonetools.client.mixins.json +++ b/src/client/resources/redstonetools.client.mixins.json @@ -30,7 +30,6 @@ "features.SuggestionWindowMixin", "features.TextFieldWidgetAccessor", "features.WorldRendererInvoker", - "macros.AddMacroButtonMixin", - "macros.InitializeMacroManagerMixin" + "macros.AddMacroButtonMixin" ] } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 9feb17dd..f3a1bfc5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -41,6 +41,7 @@ }, "recommends": { "worldedit": "*", - "malilib": "*" + "malilib": "*", + "malilib-api": "*" } } diff --git a/versions/1.21.10/gradle.properties b/versions/1.21.10/gradle.properties index d1c86d30..7928fcff 100644 --- a/versions/1.21.10/gradle.properties +++ b/versions/1.21.10/gradle.properties @@ -3,5 +3,6 @@ minecraft_version_out=1.21.10 yarn_mappings=1.21.10+build.3 fabric_version=0.138.4+1.21.10 -malilib_version=0.26.8 +malilib_version=1.21.10:0.26.8 +malilib_api_version=0.8.2-1.21.10 worldedit_version=1.21.10:7.4.0-SNAPSHOT diff --git a/versions/1.21.11/gradle.properties b/versions/1.21.11/gradle.properties index decf2eb2..d6011f6a 100644 --- a/versions/1.21.11/gradle.properties +++ b/versions/1.21.11/gradle.properties @@ -3,5 +3,6 @@ minecraft_version_out=1.21.11 yarn_mappings=1.21.11+build.4 fabric_version=0.141.2+1.21.11 -malilib_version=0.27.5 +malilib_version=1.21.11:0.27.7 +malilib_api_version=0.8.2-1.21.11 worldedit_version=1.21.11:7.4.0-SNAPSHOT diff --git a/versions/1.21.4/gradle.properties b/versions/1.21.4/gradle.properties index a2f00f22..d86e2164 100644 --- a/versions/1.21.4/gradle.properties +++ b/versions/1.21.4/gradle.properties @@ -3,5 +3,6 @@ minecraft_version_out=1.21.4 yarn_mappings=1.21.4+build.8 fabric_version=0.119.4+1.21.4 -malilib_version=0.23.5 +malilib_version=1.21.4:0.23.5 +malilib_api_version=0.8.2-1.21.5 worldedit_version=1.21.4:7.3.11 diff --git a/versions/1.21.5/gradle.properties b/versions/1.21.5/gradle.properties index 419d70b9..d280224d 100644 --- a/versions/1.21.5/gradle.properties +++ b/versions/1.21.5/gradle.properties @@ -3,5 +3,6 @@ minecraft_version_out=1.21.5 yarn_mappings=1.21.5+build.1 fabric_version=0.128.2+1.21.5 -malilib_version=0.24.3 +malilib_version=1.21.5:0.24.3 +malilib_api_version=0.8.2-1.21.5 worldedit_version=1.21.5:7.3.14 \ No newline at end of file diff --git a/versions/1.21.8/gradle.properties b/versions/1.21.8/gradle.properties index 199c289e..e4f001bb 100644 --- a/versions/1.21.8/gradle.properties +++ b/versions/1.21.8/gradle.properties @@ -3,5 +3,6 @@ minecraft_version_out=1.21.8 yarn_mappings=1.21.8+build.1 fabric_version=0.136.1+1.21.8 -malilib_version=0.25.7 +malilib_version=1.21.8:0.25.7 +malilib_api_version=0.8.2-1.21.8 worldedit_version=1.21.7:7.3.16