diff --git a/libs/awa (1).png b/libs/awa (1).png new file mode 100644 index 0000000..bcde15f Binary files /dev/null and b/libs/awa (1).png differ diff --git a/libs/awa (2).png b/libs/awa (2).png new file mode 100644 index 0000000..5b0c9d5 Binary files /dev/null and b/libs/awa (2).png differ diff --git a/remappedSrc/com/josyf/commandbuttons/CommandButtons.java b/remappedSrc/com/josyf/commandbuttons/CommandButtons.java deleted file mode 100644 index d93b887..0000000 --- a/remappedSrc/com/josyf/commandbuttons/CommandButtons.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.josyf.commandbuttons; - - -import com.josyf.commandbuttons.gui.ButtonGUI; -import com.josyf.commandbuttons.gui.ButtonGUIScreen; -import net.fabricmc.api.ModInitializer; -import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.KeyBinding; -import net.minecraft.client.util.InputUtil; -import org.json.simple.JSONObject; -import org.lwjgl.glfw.GLFW; - -import java.util.ArrayList; - -public class CommandButtons implements ModInitializer { - - public static final String MOD_ID = "mgbuttons"; - private static ArrayList masterCommList; - - public static void main(String[] args) { - - } - - @Override - public void onInitialize() { - assignGuiToKey(); - initArray(); - } - - - private void assignGuiToKey() { - // Currently assigns to the G key - KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( - "key.commandbuttons.opengui", // The translation key of the keybinding's name - InputUtil.Type.KEYSYM, // The type of the keybinding, KEYSYM for keyboard, MOUSE for mouse. - GLFW.GLFW_KEY_G, // The keycode of the key - "gui.commandbuttons.mgbuttons" // The translation key of the keybinding's category. - )); - - ClientTickEvents.END_CLIENT_TICK.register(client -> { - while (keyBinding.wasPressed()) { - MinecraftClient.getInstance().setScreen(new ButtonGUIScreen(new ButtonGUI())); - //client.player.closeScreen(); - } - }); - } - - public static void runCommand(String command) { - MinecraftClient.getInstance().player.sendChatMessage(command); - } - - // Assign masterCommList to JSONArray (from commands.json). Runs once. - static void initArray() { - masterCommList = ConfigFile.getArrayFromJsonFile(); - // If commands.json doesn't exist yet, start a global list variable for future creation - if (masterCommList == null) { - setMasterCommList(new ArrayList<>()); - } - } - - public static ArrayList getMasterCommList() { - return masterCommList; - } - - public static void setMasterCommList(ArrayList commList) { - masterCommList = commList; - } - -} - diff --git a/remappedSrc/com/josyf/commandbuttons/ConfigFile.java b/remappedSrc/com/josyf/commandbuttons/ConfigFile.java deleted file mode 100644 index 6db490d..0000000 --- a/remappedSrc/com/josyf/commandbuttons/ConfigFile.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.josyf.commandbuttons; - -import com.alibaba.fastjson.JSON; -import com.cedarsoftware.util.io.JsonWriter; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.parser.*; - -import java.io.*; -import java.util.ArrayList; - -public class ConfigFile { - - private static final JSONParser parser = new JSONParser(); - private static FileWriter fileWriter; - - // Read commands.json, convert it to an array, and append A JSON OBJECT - public static void appendToFile(JSONObject jsonObject) { - try { - Object obj = parser.parse(new FileReader("commands.json")); - JSONArray array = (JSONArray) obj; - array.add(jsonObject); - writeToFile(array); - } catch (IOException e) { - System.out.println("Commands.json 不存在。正在创建..."); - JSONArray jsonArray = new JSONArray(); - jsonArray.add(jsonObject); - writeToFile(jsonArray); - } catch (ParseException e) { - e.printStackTrace(); - } - } - - public static void removeFromFile(JSONObject jsonObject) { - try { - Object obj = parser.parse(new FileReader("commands.json")); - JSONArray array = (JSONArray) obj; - array.remove(jsonObject); - writeToFile(array); - } catch (IOException | ParseException e) { - e.printStackTrace(); - } - } - - // overwrites current commands.json w/ updated jsonArray - private static void writeToFile(JSONArray jsonArray) { - try { - fileWriter = new FileWriter("commands.json"); - String jArrayToString = JSON.toJSONString(jsonArray); - String formattedJson = JsonWriter.formatJson(jArrayToString); - fileWriter.write(formattedJson); - } catch (IOException e) { - e.printStackTrace(); - } finally { - try { - fileWriter.flush(); - fileWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - // parses commands.json into array, loop through array and add JSONObjects. returns array - public static ArrayList getArrayFromJsonFile() { - ArrayList commandObjects = new ArrayList<>(); - try { - // assign array to JSONArray using our commands.json as an object - Object obj = parser.parse(new FileReader("commands.json")); - JSONArray array = (JSONArray) obj; - // so "array" is now a JSONArray full of JSONObjects - // now we will iterate through the array and add COs to our local CO array - for (int i = 0; i < array.size(); i++) { - JSONObject childObject = (JSONObject)array.get(i); - commandObjects.add(childObject); - if (i >= 19) break; - } - return commandObjects; - } catch (IOException | ParseException e) { - System.out.println("Commands.json尚未初始化!"); - } - return null; - } - - public static void addObjectToCommList(JSONObject jsonObject) { - ArrayList commListCopy = CommandButtons.getMasterCommList(); - commListCopy.add(jsonObject); - CommandButtons.setMasterCommList(commListCopy); - } - - public static void removeObject(JSONObject objToRemove) { - // get masterCommList and remove object from list - ArrayList commListCopy = CommandButtons.getMasterCommList(); - commListCopy.remove(objToRemove); - - // get commands.json - // remove corresponding button from json - removeFromFile(objToRemove); - - } - - - - -} diff --git a/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUI.java b/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUI.java deleted file mode 100644 index 27f3756..0000000 --- a/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUI.java +++ /dev/null @@ -1,166 +0,0 @@ -package com.josyf.commandbuttons.gui; - -import com.josyf.commandbuttons.CommandButtons; -import com.josyf.commandbuttons.ConfigFile; -import io.github.cottonmc.cotton.gui.client.BackgroundPainter; -import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription; -import io.github.cottonmc.cotton.gui.widget.*; -import net.minecraft.client.MinecraftClient; -import net.minecraft.text.TranslatableText; -import org.json.simple.JSONObject; - -import java.util.ArrayList; - -public class ButtonGUI extends LightweightGuiDescription { - - int xValue = 0; - int yValue = 1; - - public ButtonGUI() { - - // initialize root panel of GUI - WGridPanel root = new WGridPanel(); - setupBackground(root); - addCloseButton(root); - - // Add delete toggle button - WToggleButton delToggle = new WToggleButton(new TranslatableText("Delete")); - root.add(delToggle, 0, 11, 3, 1); - - addSavedButtons(root, delToggle); - addCommandSection(root, delToggle); - root.validate(this); - } - - private void addCloseButton(WGridPanel root) { - WButton escButton = new WButton(new TranslatableText("x")); - escButton.setOnClick(() -> MinecraftClient.getInstance().player.closeScreen()); - root.add(escButton, 17, 1, 2, 2); - } - - private void addCommandSection(WGridPanel root, WToggleButton toggle) { - // Add text field for command NAME entry - WTextField nameTextField = new WTextField(); - nameTextField.setMaxLength(11); - nameTextField.setSuggestion("Name"); - root.add(nameTextField, 0, 12, 6, 1); - - // Add text field for command / entry - WTextField commandTextField = new WTextField(); - commandTextField.setSuggestion("/command"); - commandTextField.setMaxLength(300); - root.add(commandTextField, 6, 12, 11, 1); - - // Add button for command entry - WButton addCmdBtn = new WButton(new TranslatableText("+")); - addCmdBtn.setOnClick(() -> addGUIButton(root, nameTextField, commandTextField, toggle)); - root.add(addCmdBtn, 18, 12, 1, 1); - } - - // Function to save newly added buttons to commands.json - private void addGUIButton(WGridPanel root, WTextField name, WTextField command, WToggleButton isDeleteToggled) { - // Only add the button if there are contents in both - if (!name.getText().equals("") && !command.getText().equals("")) { - // Create a new Json object & append to masterCommList - JSONObject newJsonObject = new JSONObject(); - newJsonObject.put("name", name.getText()); - newJsonObject.put("command", command.getText()); - - if (!isListTooLong()) { - String commandString = command.getText(); - WButton button = new WButton(new TranslatableText(name.getText())); - button.setOnClick(() -> { - if (isDeleteToggled.getToggle()) { - ConfigFile.removeObject(newJsonObject); - root.remove(button); - } else { - CommandButtons.runCommand(commandString); - } - - }); - root.add(button, xValue, yValue, 4, 1); - - // append the buttons to masterList for future loading - ConfigFile.addObjectToCommList(newJsonObject); - ConfigFile.appendToFile(newJsonObject); - - adjustBounds(); - } - - name.setText(""); - command.setText(""); - - root.validate(this); - - } else { - System.out.println("未输入名称和数值!"); - } - - } - - // function to load buttons from commands.json - private void addGUIButton(WGridPanel root, String name, String command, WToggleButton isDeleteToggled, JSONObject object) { - if (!name.equals("") && !command.equals("")) { - WButton button = new WButton(new TranslatableText(name)); - button.setOnClick(() -> { - if (isDeleteToggled.getToggle()) { - ConfigFile.removeObject(object); - root.remove(button); - } else { - CommandButtons.runCommand(command); - } - - }); - root.add(button, xValue, yValue, 4, 1); - adjustBounds(); - root.validate(this); - } else { - System.out.println("未输入名称和数值!"); - } - } - - - // Array will contain String class types. Convert these to objects. - private void addSavedButtons(WGridPanel root, WToggleButton toggle) { - ArrayList commListCopy = CommandButtons.getMasterCommList(); - // Then convert the objects to buttons - if (commListCopy != null) { - for (int i = 0; i < commListCopy.size(); i++) { - JSONObject object = commListCopy.get(i); - String name = commListCopy.get(i).get("name").toString(); - String command = commListCopy.get(i).get("command").toString(); - addGUIButton(root, name, command, toggle, object); - if (i >= 19) break; - } - } - - } - - - private void adjustBounds() { - if (xValue % 12 == 0 && xValue != 0) { - yValue += 2; - xValue = 0; - } else { - xValue += 4; - } - } - - private boolean isListTooLong() { - return CommandButtons.getMasterCommList().size() > 19; - } - - // Change background panel color to transparent black - @Override - public void addPainters() { - super.addPainters(); - this.rootPanel.setBackgroundPainter(BackgroundPainter.createColorful(0x4D000000)); - } - - private void setupBackground(WGridPanel root) { - setRootPanel(root); - root.setSize(350, 240); - } - - -} diff --git a/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUIScreen.java b/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUIScreen.java deleted file mode 100644 index 55120e1..0000000 --- a/remappedSrc/com/josyf/commandbuttons/gui/ButtonGUIScreen.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.josyf.commandbuttons.gui; - -import io.github.cottonmc.cotton.gui.GuiDescription; -import io.github.cottonmc.cotton.gui.client.CottonClientScreen; - -public class ButtonGUIScreen extends CottonClientScreen { - public ButtonGUIScreen(GuiDescription description) { - super(description); - } - - -} - -