diff --git a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/EffectMCCore.java b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/EffectMCCore.java index f6a526f..3e467f3 100644 --- a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/EffectMCCore.java +++ b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/EffectMCCore.java @@ -1,6 +1,7 @@ package com.mosadie.effectmc.core; import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import com.google.gson.reflect.TypeToken; diff --git a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRawRequestHandler.java b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRawRequestHandler.java index 36eda0f..6fbc75d 100644 --- a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRawRequestHandler.java +++ b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRawRequestHandler.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; @@ -49,12 +50,11 @@ public void handle(HttpExchange exchange) throws IOException { // Read from Body - BufferedReader reader = new BufferedReader(new InputStreamReader(exchange.getRequestBody())); + BufferedReader reader = new BufferedReader(new InputStreamReader(exchange.getRequestBody(), StandardCharsets.UTF_8)); String body = null; try { body = reader.readLine(); - } catch (IOException e) { core.getExecutor().log("WARN: An IOException occurred reading body: " + e.toString()); String response = "Something went wrong reading the body of the request."; diff --git a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRequestHandler.java b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRequestHandler.java index 6d471ff..7d6c113 100644 --- a/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRequestHandler.java +++ b/MinecraftMod/core/src/main/java/com/mosadie/effectmc/core/handler/http/EffectRequestHandler.java @@ -14,6 +14,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.*; public class EffectRequestHandler implements HttpHandler { @@ -47,7 +48,7 @@ public void handle(HttpExchange exchange) throws IOException { // Read from Body - BufferedReader reader = new BufferedReader(new InputStreamReader(exchange.getRequestBody())); + BufferedReader reader = new BufferedReader(new InputStreamReader(exchange.getRequestBody(), StandardCharsets.UTF_8)); String body = null; try { diff --git a/MinecraftMod/fabric/1.20.1/build.gradle b/MinecraftMod/fabric/1.20.1/build.gradle index adc7a14..18f69f9 100644 --- a/MinecraftMod/fabric/1.20.1/build.gradle +++ b/MinecraftMod/fabric/1.20.1/build.gradle @@ -1,11 +1,8 @@ plugins { - id 'fabric-loom' version '1.3-SNAPSHOT' + id 'fabric-loom' version '1.8-SNAPSHOT' id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group @@ -37,10 +34,8 @@ dependencies { // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. // You may need to force-disable transitiveness on them. - shade ("com.mosadie.effectmc:core:${project.effectmc_core_version}") { - exclude(group: "com.google.code.gson", module: "gson") - exclude(group: "it.unimi.dsi", module: "fastutil") - } + implementation "com.mosadie.effectmc:core:${project.effectmc_core_version}" + include ("com.mosadie.effectmc:core:${project.effectmc_core_version}") } processResources { @@ -51,6 +46,12 @@ processResources { } } +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + tasks.withType(JavaCompile).configureEach { // ensure that the encoding is set to UTF-8, no matter what the system default is // this fixes some edge cases with special characters not displaying correctly @@ -67,18 +68,9 @@ java { // if it is present. // If you remove this line, sources will not be generated. withSourcesJar() -} - -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}"} - } - configurations.shade.each { dep -> - from(project.zipTree(dep)){ - exclude 'META-INF', 'META-INF/**' - } - } + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } // configure the maven publication diff --git a/MinecraftMod/fabric/1.20.1/gradle.properties b/MinecraftMod/fabric/1.20.1/gradle.properties index be164f3..c89f4d0 100644 --- a/MinecraftMod/fabric/1.20.1/gradle.properties +++ b/MinecraftMod/fabric/1.20.1/gradle.properties @@ -8,11 +8,11 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.14.21 # Mod Properties - mod_version = 2.3.0 + mod_version = 3.0.0 maven_group = com.mosadie.effectmc archives_base_name = effectmc-fabric-1.20.1 # Dependencies fabric_version=0.85.0+1.20.1 - effectmc_core_version=2.3 + effectmc_core_version=3.0 diff --git a/MinecraftMod/fabric/1.20.1/gradle/wrapper/gradle-wrapper.properties b/MinecraftMod/fabric/1.20.1/gradle/wrapper/gradle-wrapper.properties index 62f495d..ccc1a9b 100644 --- a/MinecraftMod/fabric/1.20.1/gradle/wrapper/gradle-wrapper.properties +++ b/MinecraftMod/fabric/1.20.1/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/MinecraftMod/fabric/1.20.1/gradlew b/MinecraftMod/fabric/1.20.1/gradlew index fcb6fca..f5feea6 100755 --- a/MinecraftMod/fabric/1.20.1/gradlew +++ b/MinecraftMod/fabric/1.20.1/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,7 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -201,11 +205,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/MinecraftMod/fabric/1.20.1/gradlew.bat b/MinecraftMod/fabric/1.20.1/gradlew.bat index 93e3f59..9d21a21 100644 --- a/MinecraftMod/fabric/1.20.1/gradlew.bat +++ b/MinecraftMod/fabric/1.20.1/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/MinecraftMod/fabric/1.20.1/settings.gradle b/MinecraftMod/fabric/1.20.1/settings.gradle index f91a4fe..56266b4 100644 --- a/MinecraftMod/fabric/1.20.1/settings.gradle +++ b/MinecraftMod/fabric/1.20.1/settings.gradle @@ -4,6 +4,7 @@ pluginManagement { name = 'Fabric' url = 'https://maven.fabricmc.net/' } + mavenCentral() gradlePluginPortal() } -} +} \ No newline at end of file diff --git a/MinecraftMod/fabric/1.20.1/src/main/java/com/mosadie/effectmc/EffectMC.java b/MinecraftMod/fabric/1.20.1/src/main/java/com/mosadie/effectmc/EffectMC.java index ce873ad..216a155 100644 --- a/MinecraftMod/fabric/1.20.1/src/main/java/com/mosadie/effectmc/EffectMC.java +++ b/MinecraftMod/fabric/1.20.1/src/main/java/com/mosadie/effectmc/EffectMC.java @@ -9,7 +9,13 @@ import java.util.List; import com.mosadie.effectmc.core.WorldState; +import com.mosadie.effectmc.core.effect.*; +import com.mosadie.effectmc.core.effect.internal.EffectRequest; +import com.mosadie.effectmc.core.handler.Device; +import com.mosadie.effectmc.core.handler.DeviceType; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.minecraft.server.integrated.IntegratedServer; +import net.minecraft.text.TranslatableTextContent; import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpResponse; @@ -29,12 +35,6 @@ import com.mojang.text2speech.Narrator; import com.mosadie.effectmc.core.EffectExecutor; import com.mosadie.effectmc.core.EffectMCCore; -import com.mosadie.effectmc.core.handler.ChatVisibilityHandler; -import com.mosadie.effectmc.core.handler.DisconnectHandler; -import com.mosadie.effectmc.core.handler.OpenScreenHandler; -import com.mosadie.effectmc.core.handler.SetPovHandler; -import com.mosadie.effectmc.core.handler.SetSkinHandler; -import com.mosadie.effectmc.core.handler.SkinLayerHandler; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; @@ -120,6 +120,10 @@ public void onInitializeClient() { } LOGGER.info("Server start result: " + result); + // Register game message handler + GameMessageHandler gameMessageHandler = new GameMessageHandler(); + ClientReceiveMessageEvents.ALLOW_GAME.register(gameMessageHandler); + // Register command ClientCommandRegistrationCallback.EVENT.register(this::registerClientCommand); @@ -132,7 +136,7 @@ public void onInitializeClient() { private void registerClientCommand(CommandDispatcher dispatcher, CommandRegistryAccess registryAccess) { dispatcher.register(ClientCommandManager.literal("effectmc") .then(ClientCommandManager.literal("trust").executes((context -> { - MinecraftClient.getInstance().send(core::setTrustNextRequest); + MinecraftClient.getInstance().send(core::setTrustFlag); receiveChatMessage("[EffectMC] Now prompting to trust the next request sent."); return 0; }))) @@ -175,8 +179,12 @@ private void registerClientCommand(CommandDispatcher showItemToast(tag.toString(), "Exported", MinecraftClient.getInstance().player.getMainHandStack().getName().getString()); receiveChatMessage("[EffectMC] Exported held item data to log file!"); return 0; + }))).then(ClientCommandManager.literal("exporteffect").executes((context -> { + core.setExportFlag(); + receiveChatMessage("[EffectMC] Will export the next triggered effect as JSON to the current log file."); + return 0; }))).executes((context -> { - receiveChatMessage("[EffectMC] Available subcommands: exportbook, exportitem, trust"); + receiveChatMessage("[EffectMC] Available subcommands: exportbook, exportitem, exporteffect, trust"); return 0; }))); } @@ -210,7 +218,7 @@ public boolean joinServer(String serverIp) { } @Override - public boolean setSkinLayer(SkinLayerHandler.SKIN_SECTION section, boolean visibility) { + public boolean setSkinLayer(SkinLayerEffect.SKIN_SECTION section, boolean visibility) { GameOptions options = MinecraftClient.getInstance().options; switch (section) { @@ -252,7 +260,7 @@ public boolean setSkinLayer(SkinLayerHandler.SKIN_SECTION section, boolean visib } @Override - public boolean toggleSkinLayer(SkinLayerHandler.SKIN_SECTION section) { + public boolean toggleSkinLayer(SkinLayerEffect.SKIN_SECTION section) { GameOptions options = MinecraftClient.getInstance().options; switch (section) { @@ -343,15 +351,15 @@ public boolean showActionMessage(String message) { } @Override - public void showTrustPrompt(String device) { + public void showTrustPrompt(Device device) { MinecraftClient.getInstance().send(() -> { - ConfirmScreen screen = new ConfirmScreen(new EffectMCCore.TrustBooleanConsumer(device, core), Text.of("EffectMC - Trust Prompt"), Text.of("Do you want to trust this device? (" + device + ")")); + ConfirmScreen screen = new ConfirmScreen(new EffectMCCore.TrustBooleanConsumer(device, core), Text.of("EffectMC - Trust Prompt"), Text.of("Do you want to trust this device?\n(Type: " + device.getType() + (device.getType() == DeviceType.OTHER ? " Device Id:" + device.getId() : "") + ")")); MinecraftClient.getInstance().setScreen(screen); }); } @Override - public boolean triggerDisconnect(DisconnectHandler.NEXT_SCREEN nextScreenType, String title, String message) { + public boolean triggerDisconnect(DisconnectEffect.NEXT_SCREEN nextScreenType, String title, String message) { MinecraftClient.getInstance().send(() -> { leaveIfNeeded(); @@ -513,7 +521,7 @@ public boolean loadWorld(String worldName) { } @Override - public boolean setSkin(URL skinUrl, SetSkinHandler.SKIN_TYPE skinType) { + public boolean setSkin(URL skinUrl, SetSkinEffect.SKIN_TYPE skinType) { if (skinUrl == null) { LOGGER.warn("Skin URL is null!"); return false; @@ -558,7 +566,7 @@ public void leaveIfNeeded() { } @Override - public boolean openScreen(OpenScreenHandler.SCREEN screen) { + public boolean openScreen(OpenScreenEffect.SCREEN screen) { MinecraftClient.getInstance().execute(() -> { leaveIfNeeded(); @@ -592,7 +600,7 @@ public boolean setFOV(int fov) { } @Override - public boolean setPOV(SetPovHandler.POV pov) { + public boolean setPOV(SetPovEffect.POV pov) { Perspective mcPov; switch (pov) { @@ -638,7 +646,7 @@ public boolean setGamma(double gamma) { } @Override - public boolean setChatVisibility(ChatVisibilityHandler.VISIBILITY visibility) { + public boolean setChatVisibility(ChatVisibilityEffect.VISIBILITY visibility) { ChatVisibility result; switch (visibility) { case SHOW: @@ -719,4 +727,30 @@ private void connectIfTrue(boolean connect) { MinecraftClient.getInstance().setScreen(new MultiplayerScreen(new TitleScreen())); } } + + public class GameMessageHandler implements ClientReceiveMessageEvents.AllowGame { + @Override + public boolean allowReceiveGameMessage(Text message, boolean overlay) { + if (message.getContent() instanceof TranslatableTextContent text) { + if (!text.getKey().equals(EffectMCCore.TRANSLATION_TRIGGER_KEY)) { + //LOGGER.error("Received non-trigger message!"); + return true; + } + if (text.getArgs().length == 0) { + LOGGER.error("Received trigger message with no arguments!"); + return false; + } + EffectRequest request = core.requestFromJson(String.valueOf(text.getArgs()[0])); + if (request == null) { + LOGGER.error("Failed to parse request!"); + return false; + } + String worldId = getWorldState() == WorldState.SINGLEPLAYER ? getSPWorldName() : getServerIP(); + Device device = new Device(worldId, getWorldState() == WorldState.SINGLEPLAYER ? DeviceType.WORLD : DeviceType.SERVER); + core.triggerEffect(device, request); + return false; + } + return true; + } + } } diff --git a/MinecraftMod/forge/1.20.1/gradle/wrapper/gradle-wrapper.properties b/MinecraftMod/forge/1.20.1/gradle/wrapper/gradle-wrapper.properties index 37aef8d..e90ad8f 100644 --- a/MinecraftMod/forge/1.20.1/gradle/wrapper/gradle-wrapper.properties +++ b/MinecraftMod/forge/1.20.1/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ +#Wed Oct 23 12:52:33 PDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip -networkTimeout=10000 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists