gradle changes
This commit is contained in:
parent
8565d6e5ea
commit
6dd6ef5a0f
@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id 'fabric-loom' version '0.5-SNAPSHOT'
|
||||
id 'fabric-loom' version '0.9.9'
|
||||
id 'maven-publish'
|
||||
}
|
||||
|
||||
@ -28,13 +28,13 @@ dependencies {
|
||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||
|
||||
// Serialization
|
||||
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.56'
|
||||
compile 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||
implementation group: 'com.alibaba', name: 'fastjson', version: '1.2.56'
|
||||
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||
|
||||
|
||||
implementation 'com.cedarsoftware:json-io:4.10.1'
|
||||
|
||||
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
|
||||
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
|
||||
|
||||
// includes
|
||||
include 'com.alibaba:fastjson:1.2.56'
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,5 @@
|
||||
#Sun Dec 20 14:49:23 CST 2020
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
2
gradlew
vendored
2
gradlew
vendored
@ -130,7 +130,7 @@ fi
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
|
21
gradlew.bat
vendored
21
gradlew.bat
vendored
@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
@ -54,7 +54,7 @@ goto fail
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
@ -64,21 +64,6 @@ echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
72
remappedSrc/com/josyf/commandbuttons/CommandButtons.java
Normal file
72
remappedSrc/com/josyf/commandbuttons/CommandButtons.java
Normal file
@ -0,0 +1,72 @@
|
||||
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<JSONObject> 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<objects> (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<JSONObject> getMasterCommList() {
|
||||
return masterCommList;
|
||||
}
|
||||
|
||||
public static void setMasterCommList(ArrayList<JSONObject> commList) {
|
||||
masterCommList = commList;
|
||||
}
|
||||
|
||||
}
|
||||
|
105
remappedSrc/com/josyf/commandbuttons/ConfigFile.java
Normal file
105
remappedSrc/com/josyf/commandbuttons/ConfigFile.java
Normal file
@ -0,0 +1,105 @@
|
||||
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 doesn't exist. Creating one...!");
|
||||
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<JSONObject> getArrayFromJsonFile() {
|
||||
ArrayList<JSONObject> 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 not yet initialized!");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addObjectToCommList(JSONObject jsonObject) {
|
||||
ArrayList<JSONObject> commListCopy = CommandButtons.getMasterCommList();
|
||||
commListCopy.add(jsonObject);
|
||||
CommandButtons.setMasterCommList(commListCopy);
|
||||
}
|
||||
|
||||
public static void removeObject(JSONObject objToRemove) {
|
||||
// get masterCommList and remove object from list
|
||||
ArrayList<JSONObject> commListCopy = CommandButtons.getMasterCommList();
|
||||
commListCopy.remove(objToRemove);
|
||||
|
||||
// get commands.json
|
||||
// remove corresponding button from json
|
||||
removeFromFile(objToRemove);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
166
remappedSrc/com/josyf/commandbuttons/gui/ButtonGUI.java
Normal file
166
remappedSrc/com/josyf/commandbuttons/gui/ButtonGUI.java
Normal file
@ -0,0 +1,166 @@
|
||||
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("No name and value entered!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 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("No name and value entered!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Array will contain String class types. Convert these to objects.
|
||||
private void addSavedButtons(WGridPanel root, WToggleButton toggle) {
|
||||
ArrayList<JSONObject> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.josyf.commandbuttons;
|
||||
|
||||
|
||||
|
||||
import com.josyf.commandbuttons.gui.ButtonGUI;
|
||||
import com.josyf.commandbuttons.gui.ButtonGUIScreen;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
@ -29,7 +29,7 @@
|
||||
"depends": {
|
||||
"fabricloader": ">=0.7.4",
|
||||
"fabric": "*",
|
||||
"minecraft": "1.16.x",
|
||||
"minecraft": "1.17.x",
|
||||
"fabric-key-binding-api-v1": "*"
|
||||
},
|
||||
"suggests": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user