diff --git a/gradle.properties b/gradle.properties index 1f070ca87..760b2978b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ name=OneConfig mod_id=oneconfig version_major=1 version_minor=0 -version_patch=0-alpha4 +version_patch=0-alpha5 polyfrost.defaults.loom=2 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 50cf39cc4..b941b1ae4 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] kotlin = "1.9.23" -kotlinx-coroutines = "1.8.0" +kotlinx-coroutines = "1.8.1" kotlinx-atomicfu = "0.24.0" kotlinx-abi = "0.14.0" @@ -18,6 +18,7 @@ nightconfig = "3.6.6" lwjgl = "3.3.3" universalcraft = "296" mixin = "0.7.11-SNAPSHOT" +hypixel-modapi = "0.4.0" junit-bom = "5.10.2" @@ -27,6 +28,8 @@ junit-bom = { module = "org.junit:junit-bom", version.ref = "junit-bom" } mixin = { module = "org.spongepowered:mixin", version.ref = "mixin" } +hypixel-modapi = { module = "net.hypixel:mod-api", version.ref = "hypixel-modapi" } + polyui = { module = "org.polyfrost:polyui", version.ref = "polyui" } annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c4..e6441136f 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23a4..a4413138c 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 0adc8e1a5..1aa94a426 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,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 @@ -153,7 +153,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 @@ -202,11 +202,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/gradlew.bat b/gradlew.bat index 93e3f59f1..25da30dbd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,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 +57,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/modules/commands/api/commands.api b/modules/commands/api/commands.api index 8ea2cfaf5..21c7d778a 100644 --- a/modules/commands/api/commands.api +++ b/modules/commands/api/commands.api @@ -21,7 +21,7 @@ public class org/polyfrost/oneconfig/api/commands/v1/CommandTree : org/polyfrost public fun getDedupedCommands ()Ljava/util/Map; public fun getHelp ()[Ljava/lang/String; public fun getTree ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree; - public fun getWithArgs ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/util/Pair; + public fun getWithArgs ([Ljava/lang/String;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree$Result; public fun init ()V public fun isInitialized ()Z public fun onExecs (Ljava/util/function/Consumer;[Ljava/lang/String;)V @@ -31,6 +31,11 @@ public class org/polyfrost/oneconfig/api/commands/v1/CommandTree : org/polyfrost public fun toString ()Ljava/lang/String; } +public final class org/polyfrost/oneconfig/api/commands/v1/CommandTree$Result { + public final field args [Ljava/lang/String; + public final field nodes Ljava/util/List; +} + public class org/polyfrost/oneconfig/api/commands/v1/Executable : org/polyfrost/oneconfig/api/commands/v1/Node { public final field arity I public final field function Ljava/util/function/Function; @@ -38,6 +43,7 @@ public class org/polyfrost/oneconfig/api/commands/v1/Executable : org/polyfrost/ public final field parameters [Lorg/polyfrost/oneconfig/api/commands/v1/Executable$Param; public fun ([Ljava/lang/String;Ljava/lang/String;[Lorg/polyfrost/oneconfig/api/commands/v1/Executable$Param;ZLjava/util/function/Function;)V public fun equals (Ljava/lang/Object;)Z + public fun execute ()Ljava/lang/Object; public fun execute ([Ljava/lang/String;)Ljava/lang/Object; public fun hashCode ()I public fun toString ()Ljava/lang/String; @@ -266,9 +272,3 @@ public final class org/polyfrost/oneconfig/api/commands/v1/factories/dsl/DSLFact public fun create (Ljava/util/Map;Ljava/lang/Object;)Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree; } -public class org/polyfrost/oneconfig/api/commands/v1/util/Pair { - public field first Ljava/lang/Object; - public field second Ljava/lang/Object; - public fun (Ljava/lang/Object;Ljava/lang/Object;)V -} - diff --git a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/CommandTree.java b/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/CommandTree.java index 702450b42..4eef12808 100644 --- a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/CommandTree.java +++ b/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/CommandTree.java @@ -31,7 +31,6 @@ import org.polyfrost.oneconfig.api.commands.v1.arguments.ArgumentParser; import org.polyfrost.oneconfig.api.commands.v1.exceptions.CommandCreationException; import org.polyfrost.oneconfig.api.commands.v1.exceptions.CommandExecutionException; -import org.polyfrost.oneconfig.api.commands.v1.util.Pair; import java.util.ArrayList; import java.util.Arrays; @@ -42,7 +41,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.function.Consumer; -import java.util.stream.Collectors; /** * Internal representation of a command in OneConfig. @@ -238,7 +236,7 @@ public List get(String path) { * * @see #get(String...) */ - public Pair<@Nullable List, @NotNull String[]> getWithArgs(String... path) { + public Result getWithArgs(String... path) { CommandTree self = this; List ls = null; int i = 1; @@ -276,7 +274,7 @@ public List get(String path) { } String[] rest = new String[Math.max(0, path.length - i)]; if (rest.length != 0) System.arraycopy(path, i, rest, 0, rest.length); - return new Pair<>(ls, rest); + return new Result(ls, rest); } /** @@ -303,19 +301,15 @@ public void onExecs(Consumer func, String... path) { */ public Object execute(String... usage) { if (usage.length == 0) usage = new String[]{""}; - Pair, String[]> pair = getWithArgs(usage); - if (pair.first == null) throw new CommandExecutionException("Command not found!"); - String[] args = pair.second; - List ls = pair.first.stream().filter(node -> node instanceof Executable && (((Executable) node).isGreedy || ((Executable) node).arity == args.length)) - .collect(Collectors.toList()); - if (ls.isEmpty()) throw new CommandExecutionException("Command not found!"); - if (ls.size() == 1) { - Executable exe = (Executable) ls.get(0); - return exe.execute(args); - } + Result res = getWithArgs(usage); + if (res.nodes == null || res.nodes.isEmpty()) throw new CommandExecutionException("Command not found!"); + List nodes = res.nodes; + String[] args = res.args; loop: - for (Node node : ls) { + for (Node node : nodes) { + if (!(node instanceof Executable)) continue; Executable exe = (Executable) node; + if (!exe.isGreedy && args.length != exe.arity) continue; if (exe.arity == 0 && args.length == 0) { return exe.execute(); } @@ -352,8 +346,8 @@ public List autocomplete(String... current) { if (current.length == 0) return null; Node n; String thisArg = current[current.length - 1]; - Pair, String[]> res = getWithArgs(current); - if (res == null) { + Result res = getWithArgs(current); + if (res.nodes == null) { String[] last = new String[current.length - 1]; System.arraycopy(current, 0, last, 0, last.length); // move back, check if we have something valid available on the last @@ -361,7 +355,7 @@ public List autocomplete(String... current) { n = getTree(last); if (n == null) return null; } else { - n = res.first.get(0); + n = res.nodes.get(0); } if (n instanceof CommandTree) { CommandTree c = (CommandTree) n; @@ -374,11 +368,11 @@ public List autocomplete(String... current) { } return ls.isEmpty() ? null : ls; } else { - if (res.second.length == 0) thisArg = ""; + if (res.args.length == 0) thisArg = ""; Executable e = (Executable) n; // fast path: we already past the end of this command, don't try - if (res.second.length > e.parameters.length || e.parameters.length == 0) return null; - Executable.Param param = e.parameters[Math.max(0, res.second.length - 1)]; + if (res.args.length > e.parameters.length || e.parameters.length == 0) return null; + Executable.Param param = e.parameters[Math.max(0, res.args.length - 1)]; List l = param.tryAutoComplete(thisArg); if (l == null || l.isEmpty()) return null; if (l.contains(thisArg)) { @@ -387,4 +381,19 @@ public List autocomplete(String... current) { } else return l; } } + + /** + * Represents a result from a {@link #getWithArgs(String...)} call. This class is a wrapper around a set of possible candidates for the given path, and their arguments. + */ + public static final class Result { + @Nullable + public final List<@NotNull Node> nodes; + @NotNull + public final String[] args; + + Result(@Nullable List<@NotNull Node> nodes, @NotNull String[] args) { + this.nodes = nodes; + this.args = args; + } + } } diff --git a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/Executable.java b/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/Executable.java index 1373c1f2c..ef1aa5b4e 100644 --- a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/Executable.java +++ b/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/Executable.java @@ -58,6 +58,11 @@ public Executable(@NotNull String[] names, @Nullable String description, @NotNul this.arity = arity; } + public Object execute() { + if(arity != 0) throw new CommandExecutionException("Invalid number of arguments!"); + return function.apply(null); + } + public Object execute(String... args) { if (!isGreedy && args.length != arity) throw new CommandExecutionException("Invalid number of arguments!"); Object[] parsed = new Object[parameters.length]; diff --git a/modules/commands/src/main/kotlin/org/polyfrost/oneconfig/api/commands/v1/factories/dsl/CommandDSL.kt b/modules/commands/src/main/kotlin/org/polyfrost/oneconfig/api/commands/v1/factories/dsl/CommandDSL.kt index cb86f73c7..439dcafe8 100644 --- a/modules/commands/src/main/kotlin/org/polyfrost/oneconfig/api/commands/v1/factories/dsl/CommandDSL.kt +++ b/modules/commands/src/main/kotlin/org/polyfrost/oneconfig/api/commands/v1/factories/dsl/CommandDSL.kt @@ -67,7 +67,7 @@ class CommandDSL @JvmOverloads constructor(private val parsers: Map, Ar description, mapParams(method, paramData, parsers), greedy - ) { m.invokeWithArguments(*it) } + ) { if (it == null) m.invoke() else m.invokeWithArguments(*it) } ) } diff --git a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/Visualizer.kt b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/Visualizer.kt index e0f1fe9db..98c877152 100644 --- a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/Visualizer.kt +++ b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/Visualizer.kt @@ -48,7 +48,7 @@ fun interface Visualizer { size = Vec2(300f, 32f), text = text ?: "oneconfig.button.default", ).events { - Event.Mouse.Clicked then { + Event.Mouse.Companion.Clicked then { action.run() } } @@ -111,7 +111,7 @@ fun interface Visualizer { visibleSize = Vec2(300f, 32f), text = prop.getAs().toString(), ).events { - Event.Change.Text then { + Event.Change.Companion.Text then { if (it.text.isEmpty()) return@then try { val v = it.text.toFloat() @@ -140,7 +140,7 @@ fun interface Visualizer { initial = prop.type.enumConstants.indexOf(prop.get()), optionLateralPadding = 20f, ).events { - Event.Change.Number then { + Event.Change.Companion.Number then { prop.setAs(it.amount) } } @@ -156,7 +156,7 @@ fun interface Visualizer { initial = prop.getAs(), optionLateralPadding = 20f, ).events { - Event.Change.Number then { + Event.Change.Companion.Number then { prop.setAs(it.amount) } } @@ -175,7 +175,7 @@ fun interface Visualizer { max = max, initialValue = prop.getAs().toFloat(), ).events { - Event.Change.Number then { + Event.Change.Companion.Number then { prop.setAs(it.amount) } } @@ -191,7 +191,7 @@ fun interface Visualizer { size = 21f, state = state, ).events { - Event.Change.State then { + Event.Change.Companion.State then { prop.setAs(it.state) } } @@ -207,7 +207,7 @@ fun interface Visualizer { visibleSize = Vec2(200f, 12f), text = prop.getAs(), ).events { - Event.Change.Text then { + Event.Change.Companion.Text then { prop.setAs(it.text) } } diff --git a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt index f27791651..0a8a3a384 100644 --- a/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt +++ b/modules/config-impl/src/main/kotlin/org/polyfrost/oneconfig/api/config/v1/internal/ConfigVisualizer.kt @@ -155,7 +155,7 @@ open class ConfigVisualizer { return Group( children = categories.mapToArray { (category, options) -> Button(text = category).events { - Event.Mouse.Clicked then { + Event.Mouse.Companion.Clicked then { parent[0] = options } } @@ -179,7 +179,7 @@ open class ConfigVisualizer { wrap(Image("chevron-down.svg".image()).also { it.rotation = PI }, title, desc, icon).events { self.color = PolyColor.TRANSPARENT.toAnimatable() var open = false - Event.Mouse.Clicked then { + Event.Mouse.Companion.Clicked then { open = !open Rotate(this[1], if (!open) PI else 0.0, false, Animations.EaseOutQuad.create(0.2.seconds)).add() val value = parent[1].height diff --git a/modules/events/api/events.api b/modules/events/api/events.api index 2fc0a1611..6208aed46 100644 --- a/modules/events/api/events.api +++ b/modules/events/api/events.api @@ -30,9 +30,10 @@ public final class org/polyfrost/oneconfig/api/event/v1/EventManager { } public class org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - public field message Ljava/lang/Object; public fun (Ljava/lang/Object;)V public fun getFullyUnformattedMessage ()Ljava/lang/String; + public fun getMessage ()Ljava/lang/Object; + public fun setMessage (Ljava/lang/Object;)V } public class org/polyfrost/oneconfig/api/event/v1/events/ChatSendEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { @@ -68,6 +69,11 @@ public class org/polyfrost/oneconfig/api/event/v1/events/HudRenderEvent : org/po public fun component2 ()F } +public class org/polyfrost/oneconfig/api/event/v1/events/HypixelLocationEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { + public static final field INSTANCE Lorg/polyfrost/oneconfig/api/event/v1/events/HypixelLocationEvent; + public fun getLocation ()Lorg/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$Location; +} + public class org/polyfrost/oneconfig/api/event/v1/events/InitializationEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { public static final field INSTANCE Lorg/polyfrost/oneconfig/api/event/v1/events/InitializationEvent; } @@ -86,12 +92,6 @@ public class org/polyfrost/oneconfig/api/event/v1/events/KeyInputEvent : org/pol public fun isPressed ()Z } -public class org/polyfrost/oneconfig/api/event/v1/events/LocrawEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { - public final field info Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo; - public fun (Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo;)V - public fun component1 ()Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo; -} - public class org/polyfrost/oneconfig/api/event/v1/events/MouseInputEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { public final field button I public final field state I @@ -101,8 +101,8 @@ public class org/polyfrost/oneconfig/api/event/v1/events/MouseInputEvent : org/p } public class org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - public final field packet Ljava/lang/Object; public fun (Ljava/lang/Object;)V + public fun getPacket ()Ljava/lang/Object; } public abstract class org/polyfrost/oneconfig/api/event/v1/events/RenderEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { @@ -128,13 +128,13 @@ public class org/polyfrost/oneconfig/api/event/v1/events/ResizeEvent : org/polyf } public class org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - public final field screen Ljava/lang/Object; public fun (Ljava/lang/Object;)V + public fun getScreen ()Ljava/lang/Object; } public class org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - public final field packet Ljava/lang/Object; public fun (Ljava/lang/Object;)V + public fun getPacket ()Ljava/lang/Object; } public class org/polyfrost/oneconfig/api/event/v1/events/ShutdownEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { @@ -153,7 +153,8 @@ public class org/polyfrost/oneconfig/api/event/v1/events/TickEvent$Start : org/p } public class org/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { - public static final field INSTANCE Lorg/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent; + public fun (Ljava/lang/Object;)V + public fun getWorld ()Ljava/lang/Object; } public abstract interface class org/polyfrost/oneconfig/api/event/v1/invoke/EventCollector { @@ -170,6 +171,7 @@ public abstract class org/polyfrost/oneconfig/api/event/v1/invoke/EventHandler { public static fun of (Ljava/lang/Class;Ljava/lang/Runnable;)Lorg/polyfrost/oneconfig/api/event/v1/invoke/EventHandler; public static fun of (Ljava/lang/Class;Ljava/util/function/Consumer;)Lorg/polyfrost/oneconfig/api/event/v1/invoke/EventHandler; public static fun of (Ljava/lang/reflect/Method;Ljava/lang/Object;)Lorg/polyfrost/oneconfig/api/event/v1/invoke/EventHandler; + public final fun onError ()Z public final fun register ()Lorg/polyfrost/oneconfig/api/event/v1/invoke/EventHandler; } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/EventManager.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/EventManager.java index 43904455d..3a78b91f4 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/EventManager.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/EventManager.java @@ -195,7 +195,11 @@ public void post(E event) { } catch (EventException e) { throw e; } catch (Throwable throwable) { - LOGGER.error("Failed to invoke event handler!", throwable); + LOGGER.error("Failed to invoke event handler for {}", event.getClass().getName(), throwable); + if(ev.onError()) { + LOGGER.error("removing {} as it has failed too many times", ev); + set.remove(ev); + } } } } catch (ConcurrentModificationException ignored0) { diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java index 0cab75e98..df4d80803 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java @@ -26,23 +26,54 @@ package org.polyfrost.oneconfig.api.event.v1.events; -import org.polyfrost.oneconfig.api.DeclaredInPlatform; +import org.polyfrost.oneconfig.api.platform.v1.Platform; /** * Called when a chat message is received. */ -@DeclaredInPlatform public class ChatReceiveEvent extends Event.Cancellable { /** * The message that was received. */ - public Object message; + private Object message; public ChatReceiveEvent(Object message) { this.message = message; } + /** + * @see org.polyfrost.oneconfig.api.platform.v1.I18nPlatform#getUnformattedText(Object) Platform.i18n().getUnformattedText() + */ public String getFullyUnformattedMessage() { - return ""; + return Platform.i18n().getUnformattedText(message); + } + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version. + *
    + *
  • For legacy forge, this will be a ITextComponent.
  • + *
  • For modern forge, this will be a Component.
  • + *
  • For fabric, this will be a Text.
  • + *
+ * Note: the toString() method on the returned object will always be the correct text of the message. + * @see org.polyfrost.oneconfig.api.platform.v1.I18nPlatform#getUnformattedText(Object) Platform.i18n().getUnformattedText() + * @see #getFullyUnformattedMessage() + */ + @SuppressWarnings("unchecked") + public T getMessage() { + return (T) message; + } + + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it expects a different type for different minecraft versions. + *
    + *
  • For legacy forge, this will be a ITextComponent.
  • + *
  • For modern forge, this will be a Component.
  • + *
  • For fabric, this will be a Text.
  • + *
+ */ + public void setMessage(T message) { + this.message = message; } } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/HypixelLocationEvent.java similarity index 66% rename from versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java rename to modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/HypixelLocationEvent.java index 323dac9a2..4f56594a9 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/HypixelLocationEvent.java @@ -26,25 +26,27 @@ package org.polyfrost.oneconfig.api.event.v1.events; -import net.minecraft.util.IChatComponent; -import org.polyfrost.oneconfig.api.PlatformDeclaration; -import org.polyfrost.universal.wrappers.message.UTextComponent; +import org.jetbrains.annotations.ApiStatus; +import org.polyfrost.oneconfig.api.hypixel.v0.HypixelAPI; /** - * Called when a chat message is received. + * Event that is fired when the player's location is changed. */ -@PlatformDeclaration -public class ChatReceiveEvent extends Event.Cancellable { - /** - * The message that was received. - */ - public IChatComponent message; +@ApiStatus.Experimental +public class HypixelLocationEvent implements Event { + public static final HypixelLocationEvent INSTANCE = new HypixelLocationEvent(); - public ChatReceiveEvent(IChatComponent message) { - this.message = message; + private HypixelLocationEvent() { + // call on HypixelAPI + HypixelAPI.getLocation(); } - public String getFullyUnformattedMessage() { - return UTextComponent.Companion.stripFormatting(message.getUnformattedText()); + /** + * Get the location of the player when the event was fired. + * @return the same as {@link HypixelAPI#getLocation()}. + */ + public HypixelAPI.Location getLocation() { + return HypixelAPI.getLocation(); } + } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java index bf3f8fedc..193bbf69c 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java @@ -26,13 +26,23 @@ package org.polyfrost.oneconfig.api.event.v1.events; -import org.polyfrost.oneconfig.api.DeclaredInPlatform; - -@DeclaredInPlatform public class ReceivePacketEvent extends Event.Cancellable { - public final Object packet; + private final Object packet; public ReceivePacketEvent(Object packet) { this.packet = packet; } + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version. + *
    + *
  • For legacy forge, this will be a IPacket.
  • + *
  • For modern forge, this will be a Packet.
  • + *
  • For fabric, this will be a Packet.
  • + *
+ */ + @SuppressWarnings("unchecked") + public T getPacket() { + return (T) packet; + } } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java index b558e6f91..452c57e15 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java @@ -27,18 +27,30 @@ package org.polyfrost.oneconfig.api.event.v1.events; import org.jetbrains.annotations.Nullable; -import org.polyfrost.oneconfig.api.DeclaredInPlatform; /** * Called when a screen is opened or closed. * If the screen is closed, {@link ScreenOpenEvent#screen} will be null. */ -@DeclaredInPlatform public class ScreenOpenEvent extends Event.Cancellable { @Nullable - public final Object screen; + private final Object screen; public ScreenOpenEvent(@Nullable Object screen) { this.screen = screen; } + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version. + *
    + *
  • For legacy forge, this will be a GuiScreen.
  • + *
  • For modern forge, this will be a Screen.
  • + *
  • For fabric, this will be a Screen.
  • + *
+ */ + @SuppressWarnings("unchecked") + @Nullable + public T getScreen() { + return (T) screen; + } } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java index b617fa604..eb8c16c3a 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java @@ -26,13 +26,23 @@ package org.polyfrost.oneconfig.api.event.v1.events; -import org.polyfrost.oneconfig.api.DeclaredInPlatform; - -@DeclaredInPlatform public class SendPacketEvent extends Event.Cancellable { - public final Object packet; + private final Object packet; public SendPacketEvent(Object packet) { this.packet = packet; } + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version. + *
    + *
  • For legacy forge, this will be a IPacket.
  • + *
  • For modern forge, this will be a Packet.
  • + *
  • For fabric, this will be a Packet.
  • + *
+ */ + @SuppressWarnings("unchecked") + public T getPacket() { + return (T) packet; + } } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent.java index 3f254cd14..c25cde6fb 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/WorldLoadEvent.java @@ -30,8 +30,21 @@ * Called when the world is loaded. */ public class WorldLoadEvent implements Event { - public static final WorldLoadEvent INSTANCE = new WorldLoadEvent(); + private final Object world; - private WorldLoadEvent() { + public WorldLoadEvent(Object world) { + this.world = world; + } + + /** + * Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version. + *
    + *
  • For modern forge, this will be a ClientLevel.
  • + *
  • For fabric & forge pre-1.17, this will be a ClientWorld.
  • + *
+ */ + @SuppressWarnings("unchecked") + public T getWorld() { + return (T) world; } } diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/invoke/EventHandler.java b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/invoke/EventHandler.java index ea094a379..1f82fdd67 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/invoke/EventHandler.java +++ b/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/invoke/EventHandler.java @@ -42,6 +42,9 @@ * @see #of(Class, Consumer) */ public abstract class EventHandler { + private static final int ERROR_THRESHOLD = 5; + private int errors = 0; + /** * Create an event handler from a consumer, in a fabric-style way. * @@ -125,6 +128,10 @@ public final EventHandler register() { return this; } + public final boolean onError() { + return !(errors++ > ERROR_THRESHOLD); + } + @Override public final boolean equals(Object obj) { if (obj == this) return true; diff --git a/modules/hud/api/hud.api b/modules/hud/api/hud.api index 25ea1241c..4a24531e8 100644 --- a/modules/hud/api/hud.api +++ b/modules/hud/api/hud.api @@ -43,7 +43,7 @@ public final class org/polyfrost/oneconfig/api/hud/v1/HudManager { public final fun getPolyUI ()Lorg/polyfrost/polyui/PolyUI; public final fun getSlinex ()F public final fun getSliney ()F - public final fun getWithEditor ()Lorg/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen; + public final fun getWithEditor ()Ljava/lang/Object; public final fun initialize ()V public final fun openHudEditor (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)V public static final fun register (Lorg/polyfrost/oneconfig/api/hud/v1/Hud;)V diff --git a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt index ac10ae73d..c49c31e43 100644 --- a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt +++ b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt @@ -36,9 +36,9 @@ import org.polyfrost.oneconfig.api.hud.v1.internal.HudsPage import org.polyfrost.oneconfig.api.hud.v1.internal.alignC import org.polyfrost.oneconfig.api.hud.v1.internal.build import org.polyfrost.oneconfig.api.hud.v1.internal.createInspectionsScreen +import org.polyfrost.oneconfig.api.platform.v1.Platform +import org.polyfrost.oneconfig.api.ui.v1.PolyUIBuilder import org.polyfrost.oneconfig.api.ui.v1.UIManager -import org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreen -import org.polyfrost.oneconfig.utils.v1.GuiUtils import org.polyfrost.oneconfig.utils.v1.MHUtils import org.polyfrost.polyui.PolyUI import org.polyfrost.polyui.animate.Animations @@ -60,7 +60,6 @@ import org.polyfrost.polyui.unit.seconds import org.polyfrost.polyui.utils.fastEach import org.polyfrost.polyui.utils.ref import org.polyfrost.polyui.utils.rgba -import org.polyfrost.universal.UResolution import kotlin.math.PI object HudManager { @@ -102,7 +101,7 @@ object HudManager { if (parent.parent[2] !== hudsPage) { parent.parent[2] = hudsPage } else { - GuiUtils.closeScreen() + Platform.screen().close() } }, Block( @@ -151,7 +150,7 @@ object HudManager { Event.Mouse.Exited then { Fade(this[0], 0.1f, false, Animations.EaseInOutQuad.create(0.08.seconds)).add() } - Event.Mouse.Clicked then { + Event.Mouse.Companion.Clicked then { // asm: makes close button easier to use if (polyUI.mouseY < 40f) { false @@ -202,18 +201,18 @@ object HudManager { } ).also { it.master.rawResize = true - it.resize(UResolution.windowWidth.toFloat(), UResolution.windowHeight.toFloat()) + it.resize(Platform.screen().windowWidth().toFloat(), Platform.screen().windowHeight().toFloat()) } init { initialize() } - fun getWithEditor(): PolyUIScreen { - return PolyUIScreen(polyUI.also { + fun getWithEditor(): Any { + return PolyUIBuilder.DEFAULT.create(polyUI.also { toggleHudPicker() panelExists = true - }).closeCallback(this::editorClose) + }, null, false, true) { editorClose() } } private fun editorClose() { diff --git a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hudpages.kt b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hudpages.kt index 58931d397..2f6dda385 100644 --- a/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hudpages.kt +++ b/modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/internal/hudpages.kt @@ -24,6 +24,8 @@ * */ +@file:Suppress("UnstableApiUsage") + package org.polyfrost.oneconfig.api.hud.v1.internal import org.polyfrost.oneconfig.api.hud.v1.Hud @@ -217,10 +219,10 @@ private fun interactiveAlignment(hud: Hud): Drawable { ).apply { rotation = hud.get().parent.rotation }.events { - Event.Mouse.Pressed then { + Event.Mouse.Companion.Pressed then { this[0].accept(it) } - Event.Mouse.Released then { + Event.Mouse.Companion.Released then { this[0].accept(it) } Event.Mouse.Entered then { diff --git a/modules/internal/build.gradle.kts b/modules/internal/build.gradle.kts index 51300453e..c45843e36 100644 --- a/modules/internal/build.gradle.kts +++ b/modules/internal/build.gradle.kts @@ -29,5 +29,4 @@ dependencies { api(project(":modules:events")) api(project(":modules:commands")) compileOnly("org.polyfrost:universalcraft-1.8.9-forge:${libs.versions.universalcraft.get()}") - compileOnly("com.google.code.gson:gson:2.2.4") } \ No newline at end of file diff --git a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigUI.kt b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigUI.kt index 053ff9e8e..11e963581 100644 --- a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigUI.kt +++ b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/ui/OneConfigUI.kt @@ -31,11 +31,10 @@ package org.polyfrost.oneconfig.internal.ui import org.polyfrost.oneconfig.api.config.v1.ConfigManager import org.polyfrost.oneconfig.api.hud.v1.HudManager import org.polyfrost.oneconfig.api.platform.v1.Platform -import org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreen +import org.polyfrost.oneconfig.api.ui.v1.PolyUIBuilder import org.polyfrost.oneconfig.internal.ui.pages.FeedbackPage import org.polyfrost.oneconfig.internal.ui.pages.ModsPage import org.polyfrost.oneconfig.internal.ui.pages.ThemesPage -import org.polyfrost.oneconfig.utils.v1.GuiUtils import org.polyfrost.polyui.animate.Animations import org.polyfrost.polyui.component.* import org.polyfrost.polyui.component.impl.* @@ -52,7 +51,7 @@ import org.polyfrost.polyui.utils.rgba object OneConfigUI { private val playerHead = PolyImage( - "https://mc-heads.net/avatar/${Platform.getPlayerPlatform().playerName}/24", + "https://mc-heads.net/avatar/${Platform.player().playerName}/24", type = PolyImage.Type.Raster, ).also { it.size = (24f by 24f).immutable() @@ -60,12 +59,15 @@ object OneConfigUI { lateinit var ui: Drawable - fun create(): PolyUIScreen { + fun open() { val vertical = Align(cross = Align.Cross.Start, mode = Align.Mode.Vertical) - - return PolyUIScreen( - null, null, null, null, null, rgba(21, 21, 21), - 1920f by 1080f, 1400f by 700f, + val builder = PolyUIBuilder.builder().blurs().backgroundColor(rgba(21, 21, 21)).atResolution(1920f by 1080f).size(1400f by 700f) + builder.onClose { _ -> + for (t in ConfigManager.active().trees()) { + ConfigManager.active().save(t) + } + } + builder.makeAndOpen( Group( Block( size = Vec2(225f, 32f), @@ -111,7 +113,7 @@ object OneConfigUI { ), Spacer(size = Vec2(200f, 170f)), SidebarButton0("assets/oneconfig/ico/hud.svg".image(), "oneconfig.edithud").onClick { - GuiUtils.displayScreen(HudManager.getWithEditor()) + Platform.screen().display(HudManager.getWithEditor()) }, size = Vec2(273f, 700f), alignment = Align(mode = Align.Mode.Vertical, padding = Vec2(12f, 16f)), @@ -135,7 +137,7 @@ object OneConfigUI { Image(playerHead, radii = 6f.radii()).named("ProfileImage").withBoarder( rgba(255, 255, 255, 0.14f), width = 1f, - ).addHoverInfo(Platform.getPlayerPlatform().playerName.ifEmpty { "null" }), + ).addHoverInfo(Platform.player().playerName.ifEmpty { "null" }), alignment = Align(padding = Vec2(16f, 8f)), ), Block( @@ -149,7 +151,7 @@ object OneConfigUI { ).named("SearchField"), Image( "assets/oneconfig/ico/close.svg".image(), - ).named("Close").onClick { GuiUtils.closeScreen() }.withStates().setDestructivePalette(), + ).named("Close").onClick { Platform.screen().close() }.withStates().setDestructivePalette(), alignment = Align(padding = Vec2(24f, 8f)), ), size = Vec2(1130f, 64f), @@ -160,12 +162,8 @@ object OneConfigUI { alignment = Align(padding = Vec2.ZERO), ) ).also { - ui = it.polyUI!!.master + ui = it.master (ui as Block).radii.assign(8f) - }.closeCallback { - for (t in ConfigManager.active().trees()) { - ConfigManager.active().save(t) - } } } diff --git a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/util/LocrawUtil.java b/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/util/LocrawUtil.java deleted file mode 100644 index 309e5070c..000000000 --- a/modules/internal/src/main/kotlin/org/polyfrost/oneconfig/internal/util/LocrawUtil.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -/* - * Co-author: lyndseyy (Lyndsey Winter) - * Co-author: asbyth (deleted GitHub account) - * Co-author: Moire9 (Moiré) (non-copyrightable contribution) - * Co-author: Sk1er (Mitchell Katz) - * Co-author: Cubxity (non-copyrightable contribution) - * Co-author: UserTeemu (non-copyrightable contribution) - * Co-author: PyICoder (Befell) (non-copyrightable contribution) - */ - -package org.polyfrost.oneconfig.internal.util; - -import com.google.gson.Gson; -import org.polyfrost.oneconfig.api.event.v1.EventDelay; -import org.polyfrost.oneconfig.api.event.v1.EventManager; -import org.polyfrost.oneconfig.api.event.v1.events.ChatReceiveEvent; -import org.polyfrost.oneconfig.api.event.v1.events.ChatSendEvent; -import org.polyfrost.oneconfig.api.event.v1.events.LocrawEvent; -import org.polyfrost.oneconfig.api.event.v1.events.TickEvent; -import org.polyfrost.oneconfig.api.event.v1.events.WorldLoadEvent; -import org.polyfrost.oneconfig.api.event.v1.invoke.EventHandler; -import org.polyfrost.oneconfig.api.platform.v1.Platform; -import org.polyfrost.oneconfig.utils.v1.hypixel.HypixelUtils; -import org.polyfrost.oneconfig.utils.v1.hypixel.LocrawInfo; -import org.polyfrost.universal.UChat; - -public final class LocrawUtil { - public static final LocrawUtil INSTANCE = new LocrawUtil(); - private static final Gson GSON = new Gson(); - - private LocrawInfo locrawInfo; - private LocrawInfo lastLocrawInfo; - private boolean listening; - private int tick; - private boolean playerSentCommand = false; - - public static void init() { - // ; - } - - private LocrawUtil() { - EventHandler.of(TickEvent.End.class, (event) -> { - if (!Platform.getPlayerPlatform().doesPlayerExist() || !HypixelUtils.isHypixel()) { - return; - } - this.tick++; - if (this.tick == 40 || this.tick % 520 == 0) { - sendLocraw(false); - } - }).register(); - - EventHandler.of(WorldLoadEvent.class, (event) -> { - if (locrawInfo != null) { - lastLocrawInfo = locrawInfo; - } - locrawInfo = null; - tick = 0; - }).register(); - - EventHandler.of(ChatSendEvent.class, (event) -> { - if (event.message.startsWith("/locraw") && !this.listening) { - playerSentCommand = true; - } - }).register(); - - EventHandler.of(ChatReceiveEvent.class, this::onMessageReceived).register(); - } - - private void sendLocraw(boolean delay) { - EventDelay.tick((delay ? 20 : 0), () -> { - this.listening = true; - UChat.say("/locraw"); - }); - } - - private void onMessageReceived(ChatReceiveEvent event) { - if (HypixelUtils.isHypixel()) return; - try { - // Had some false positives while testing, so this is here just to be safe. - final String msg = event.getFullyUnformattedMessage(); - if (msg.startsWith("You are sending too many commands! Please try again in a few seconds.")) { - sendLocraw(true); - return; - } - if (msg.startsWith("{")) { - // Parse the json, and make sure that it's not null. - LocrawInfo locrawInfo = GSON.fromJson(msg, LocrawInfo.class); - if (locrawInfo != null) { - // Gson does not want to parse the GameType, as some stuff is different so this - // is just a way around that to make it properly work :) - locrawInfo.previous = lastLocrawInfo; - - // Stop listening for locraw and cancel the message. - if (!this.playerSentCommand) { - event.cancelled = true; - } - EventManager.INSTANCE.post(new LocrawEvent(locrawInfo)); - - this.playerSentCommand = false; - this.listening = false; - } - } - } catch (Exception ignored) { - } - } -} diff --git a/modules/root.gradle.kts b/modules/root.gradle.kts index ec6264a3e..81e38d362 100644 --- a/modules/root.gradle.kts +++ b/modules/root.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName - // Shared build logic between all OneConfig modules to reduce boilerplate. plugins { @@ -17,6 +15,7 @@ subprojects { mavenLocal() mavenCentral() maven("https://repo.polyfrost.org/releases") + maven("https://repo.hypixel.net/repository/Hypixel") } dependencies { @@ -41,10 +40,6 @@ subprojects { (this as CoreJavadocOptions).addBooleanOption("Xdoclint:none", true) } } - - withType(Jar::class.java) { - exclude("**/internal/**") - } } base.archivesName = "${project.name}-api" @@ -70,7 +65,7 @@ publishing { if (project.name == "internal") return@publications register(project.name) { groupId = rootProject.group.toString() - artifactId = project.archivesName.get() + artifactId = project.base.archivesName.get() version = rootProject.version.toString() from(components["java"]) @@ -110,5 +105,6 @@ apiValidation { for (project in subprojects) { ignoredPackages.add("org.polyfrost.oneconfig.api.${project.name}.v1.internal") } + ignoredPackages.add("org.polyfrost.oneconfig.api.hypixel.v0.internal") ignoredProjects.add("internal") } diff --git a/modules/ui/api/ui.api b/modules/ui/api/ui.api index c45a4f48a..e3dcee259 100644 --- a/modules/ui/api/ui.api +++ b/modules/ui/api/ui.api @@ -1,3 +1,24 @@ +public final class org/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder { + public static final field DEFAULT Lorg/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider; + public fun align (Lorg/polyfrost/polyui/unit/Align;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun atResolution (Lorg/polyfrost/polyui/unit/Vec2;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun backgroundColor (Lorg/polyfrost/polyui/color/PolyColor;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun blurs ()Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public static fun builder ()Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public static fun builder (Lorg/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun colors (Lorg/polyfrost/polyui/color/Colors;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun input (Lorg/polyfrost/polyui/event/InputManager;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun make ([Lorg/polyfrost/polyui/component/Drawable;)Lorg/polyfrost/polyui/PolyUI; + public fun makeAndOpen ([Lorg/polyfrost/polyui/component/Drawable;)Lorg/polyfrost/polyui/PolyUI; + public fun onClose (Ljava/lang/Runnable;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun onClose (Ljava/util/function/Consumer;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun pauses ()Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun renderer (Lorg/polyfrost/polyui/renderer/Renderer;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun settings (Lorg/polyfrost/polyui/property/Settings;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun size (Lorg/polyfrost/polyui/unit/Vec2;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; + public fun translator (Lorg/polyfrost/polyui/input/Translator;)Lorg/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder; +} + public abstract interface class org/polyfrost/oneconfig/api/ui/v1/TinyFD { public static final field ERROR_ICON Ljava/lang/String; public static final field INFO_ICON Ljava/lang/String; @@ -91,21 +112,7 @@ public abstract interface class org/polyfrost/oneconfig/api/ui/v1/screen/BlurScr public abstract fun hasBackgroundBlur ()Z } -public class org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen { - public field blurs Z - public final field desiredResolution Lorg/polyfrost/polyui/unit/Vec2; - public final field inputManager Lorg/polyfrost/polyui/event/InputManager; - public field pauses Z - public final field polyUI Lorg/polyfrost/polyui/PolyUI; - public fun (Lorg/polyfrost/polyui/PolyUI;)V - public fun (Lorg/polyfrost/polyui/event/InputManager;)V - public fun (Lorg/polyfrost/polyui/property/Settings;Lorg/polyfrost/polyui/event/InputManager;Lorg/polyfrost/polyui/input/Translator;Lorg/polyfrost/polyui/unit/Align;Lorg/polyfrost/polyui/color/Colors;Lorg/polyfrost/polyui/color/PolyColor;Lorg/polyfrost/polyui/unit/Vec2;Lorg/polyfrost/polyui/unit/Vec2;[Lorg/polyfrost/polyui/component/Drawable;)V - public fun (Lorg/polyfrost/polyui/unit/Align;Lorg/polyfrost/polyui/unit/Vec2;[Lorg/polyfrost/polyui/component/Drawable;)V - public fun ([Lorg/polyfrost/polyui/component/Drawable;)V - public final fun closeCallback (Ljava/lang/Runnable;)Lorg/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen; -} - -public abstract interface class org/polyfrost/oneconfig/api/ui/v1/screen/UIPause { - public abstract fun doesUIPauseGame ()Z +public abstract interface class org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider { + public abstract fun create (Lorg/polyfrost/polyui/PolyUI;Lorg/polyfrost/polyui/unit/Vec2;ZZLjava/util/function/Consumer;)Ljava/lang/Object; } diff --git a/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder.java b/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder.java new file mode 100644 index 000000000..8324a4358 --- /dev/null +++ b/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/PolyUIBuilder.java @@ -0,0 +1,151 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.api.ui.v1; + +import org.polyfrost.oneconfig.api.platform.v1.Platform; +import org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreenProvider; +import org.polyfrost.polyui.PolyUI; +import org.polyfrost.polyui.color.Colors; +import org.polyfrost.polyui.color.DarkTheme; +import org.polyfrost.polyui.color.PolyColor; +import org.polyfrost.polyui.component.Drawable; +import org.polyfrost.polyui.event.InputManager; +import org.polyfrost.polyui.input.Translator; +import org.polyfrost.polyui.property.Settings; +import org.polyfrost.polyui.renderer.Renderer; +import org.polyfrost.polyui.unit.Align; +import org.polyfrost.polyui.unit.Vec2; + +import java.util.ServiceLoader; +import java.util.function.Consumer; + +public final class PolyUIBuilder { + public static final PolyUIScreenProvider DEFAULT = ServiceLoader.load(PolyUIScreenProvider.class, PolyUIScreenProvider.class.getClassLoader()).iterator().next(); + private final PolyUIScreenProvider provider; + private InputManager manager; + private Renderer renderer; + private Translator translator; + private Align alignment = new Align(Align.Main.Center, Align.Cross.Start, Align.Mode.Horizontal, Vec2.ZERO, 50); + private Colors colors = new DarkTheme(); + private PolyColor backgroundColor; + private Vec2 desiredResolution; + private Consumer onClose; + private Settings settings; + private Vec2 size; + private boolean pauses, blurs; + + private PolyUIBuilder(PolyUIScreenProvider provider) { + this.provider = provider; + settings = new Settings(); + settings.enableInitCleanup(false); + settings.enableForceSettingInitialSize(true); + } + + public PolyUIBuilder input(InputManager manager) { + this.manager = manager; + return this; + } + + public PolyUIBuilder translator(Translator translator) { + this.translator = translator; + return this; + } + + public PolyUIBuilder align(Align alignment) { + this.alignment = alignment; + return this; + } + + public PolyUIBuilder pauses() { + pauses = true; + return this; + } + + public PolyUIBuilder blurs() { + blurs = true; + return this; + } + + public PolyUIBuilder colors(Colors colors) { + this.colors = colors; + return this; + } + + public PolyUIBuilder backgroundColor(PolyColor color) { + this.backgroundColor = color; + return this; + } + + public PolyUIBuilder settings(Settings settings) { + this.settings = settings; + return this; + } + + public PolyUIBuilder renderer(Renderer renderer) { + this.renderer = renderer; + return this; + } + + public PolyUIBuilder size(Vec2 size) { + this.size = size; + return this; + } + + public PolyUIBuilder onClose(Consumer onClose) { + this.onClose = onClose; + return this; + } + + public PolyUIBuilder onClose(Runnable onClose) { + this.onClose = (p) -> onClose.run(); + return this; + } + + public PolyUIBuilder atResolution(Vec2 desiredResolution) { + this.desiredResolution = desiredResolution; + return this; + } + + public PolyUI make(Drawable... drawables) { + return new PolyUI(drawables, renderer == null ? UIManager.INSTANCE.getRenderer() : renderer, settings, manager, translator, backgroundColor, alignment, colors, size); + } + + public PolyUI makeAndOpen(Drawable... drawables) { + PolyUI p = make(drawables); + Object screen = provider.create(p, desiredResolution, pauses, blurs, onClose); + Platform.screen().display(screen); + return p; + } + + public static PolyUIBuilder builder() { + return new PolyUIBuilder(DEFAULT); + } + + public static PolyUIBuilder builder(PolyUIScreenProvider provider) { + return new PolyUIBuilder(provider); + } +} diff --git a/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java b/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java deleted file mode 100644 index 918010229..000000000 --- a/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.ui.v1.screen; - -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.polyfrost.oneconfig.api.DeclaredInPlatform; -import org.polyfrost.polyui.PolyUI; -import org.polyfrost.polyui.color.Colors; -import org.polyfrost.polyui.color.PolyColor; -import org.polyfrost.polyui.component.Drawable; -import org.polyfrost.polyui.event.InputManager; -import org.polyfrost.polyui.input.Translator; -import org.polyfrost.polyui.property.Settings; -import org.polyfrost.polyui.unit.Align; -import org.polyfrost.polyui.unit.Vec2; - -@DeclaredInPlatform -public class PolyUIScreen { - // PolyUIScreen.h - // version-specific workaround // - // see versions/src/main/java/org/polyfrost/oneconfig/ui/screen/PolyUIScreen.java for the actual implementation // - @NotNull - public final InputManager inputManager; - @Nullable - public final PolyUI polyUI; - @Nullable - public final Vec2 desiredResolution; - public boolean pauses, blurs; - - @Contract("_, null, _, _, _, _, _, _, null -> fail") - public PolyUIScreen(@Nullable Settings settings, - @Nullable InputManager inputManager, - @Nullable Translator translator, - @Nullable Align alignment, - @Nullable Colors colors, - @Nullable PolyColor backgroundColor, - @Nullable Vec2 desiredResolution, - @Nullable Vec2 size, - Drawable... drawables) { - throw new UnsupportedOperationException("implementation is intrinsic"); - } - - public PolyUIScreen(Drawable... drawables) { - this(null, null, null, null, null, null, null, null, drawables); - } - - public PolyUIScreen(@Nullable Align alignment, Vec2 size, Drawable... drawables) { - this(null, null, null, alignment, null, null, null, size, drawables); - } - - public PolyUIScreen(@NotNull InputManager inputManager) { - this(null, inputManager, null, null, null, null, null, null); - } - - public PolyUIScreen(@NotNull PolyUI polyUI) { - this((Settings) null, null, null, null, null, null, null, null); - } - - public final PolyUIScreen closeCallback(Runnable r) { - return this; - } -} diff --git a/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/UIPause.java b/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider.java similarity index 81% rename from modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/UIPause.java rename to modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider.java index bf32f5971..d49f31b5d 100644 --- a/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/UIPause.java +++ b/modules/ui/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreenProvider.java @@ -26,11 +26,12 @@ package org.polyfrost.oneconfig.api.ui.v1.screen; -/** - * Hack that allows GUIs to set whether the game should pause when the GUI is displayed without depending on - * Minecraft itself. - */ -public interface UIPause { - @SuppressWarnings("unused") - boolean doesUIPauseGame(); +import org.polyfrost.polyui.PolyUI; +import org.polyfrost.polyui.unit.Vec2; + +import java.util.function.Consumer; + +@FunctionalInterface +public interface PolyUIScreenProvider { + Object create(PolyUI polyUI, Vec2 desiredResolution, boolean pauses, boolean blurs, Consumer onClose); } diff --git a/modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/keybind/KeybindManager.kt b/modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/keybind/KeybindManager.kt index d43c5afe2..7f887e891 100644 --- a/modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/keybind/KeybindManager.kt +++ b/modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/keybind/KeybindManager.kt @@ -53,11 +53,11 @@ object KeybindManager { eventHandler { (key, char, state): KeyInputEvent -> if (state == 2) return@eventHandler // keybindings only work when in game (todo maybe change)? - if (Platform.getGuiPlatform().currentScreen == null) { +// if (Platform.getGuiPlatform().currentScreen == null) { translateKey(inputManager, key, char, state == 1) @Suppress("UnstableApiUsage") keyBinder.update(0L, inputManager.mods) - } +// } }.register() eventHandler { _: TickEvent.End -> @Suppress("UnstableApiUsage") diff --git a/modules/utils/api/utils.api b/modules/utils/api/utils.api index 40a1c816c..0b94dd49b 100644 --- a/modules/utils/api/utils.api +++ b/modules/utils/api/utils.api @@ -1,28 +1,57 @@ -public abstract interface annotation class org/polyfrost/oneconfig/api/DeclaredInPlatform : java/lang/annotation/Annotation { +public abstract interface annotation class org/polyfrost/oneconfig/api/ClassHasOverwrites : java/lang/annotation/Annotation { + public abstract fun value ()[Ljava/lang/String; } -public abstract interface annotation class org/polyfrost/oneconfig/api/PlatformDeclaration : java/lang/annotation/Annotation { +public final class org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI { + public static fun getLocation ()Lorg/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$Location; + public static fun getPartyInfo ()Lorg/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$PartyInfo; + public static fun getPlayerInfo ()Lorg/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$PlayerInfo; +} + +public abstract class org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$InfoBase { + protected field packet Lnet/hypixel/modapi/packet/impl/VersionedPacket; + public fun ()V + public final fun toString ()Ljava/lang/String; + public abstract fun update ()V +} + +public final class org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$Location : org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$InfoBase { + public fun getGameType ()Ljava/util/Optional; + public fun getLobbyName ()Ljava/util/Optional; + public fun getMapName ()Ljava/util/Optional; + public fun getMode ()Ljava/util/Optional; + public fun getServerType ()Ljava/util/Optional; + public fun isGame ()Z + public fun isLobby ()Z + public fun update ()V +} + +public final class org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$PartyInfo : org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$InfoBase { + public fun getMembers ()Ljava/util/Map; + public fun getPartySize ()I + public fun isInParty ()Z + public fun update ()V +} + +public final class org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$PlayerInfo : org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI$InfoBase { + public fun getMonthlyPackageRank ()Lnet/hypixel/data/rank/MonthlyPackageRank; + public fun getPackageRank ()Lnet/hypixel/data/rank/PackageRank; + public fun getPrefix ()Ljava/util/Optional; + public fun getRank ()Lnet/hypixel/data/rank/PlayerRank; + public fun update ()V } public abstract interface class org/polyfrost/oneconfig/api/platform/v1/GLPlatform { - public abstract fun drawRect (FFFFI)V - public fun drawText (Ljava/lang/String;FFIZ)F + public abstract fun drawRect (Lorg/polyfrost/universal/UMatrixStack;DDDDI)V public abstract fun drawText (Lorg/polyfrost/universal/UMatrixStack;Ljava/lang/String;FFIZ)F public abstract fun getFunctionAddress (Ljava/lang/String;)J public abstract fun getStringWidth (Ljava/lang/String;)I } -public abstract interface class org/polyfrost/oneconfig/api/platform/v1/GuiPlatform { - public abstract fun getCurrentScreen ()Ljava/lang/Object; - public abstract fun isInChat ()Z - public abstract fun isInDebug ()Z - public abstract fun playClickSound ()V - public abstract fun setCurrentScreen (Ljava/lang/Object;)V -} - public abstract interface class org/polyfrost/oneconfig/api/platform/v1/I18nPlatform { public abstract fun format (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; public abstract fun getKeyName (II)Ljava/lang/String; + public abstract fun getUnformattedText (Ljava/lang/Object;)Ljava/lang/String; } public abstract interface class org/polyfrost/oneconfig/api/platform/v1/LoaderPlatform { @@ -52,20 +81,33 @@ public final class org/polyfrost/oneconfig/api/platform/v1/LoaderPlatform$Loader } public final class org/polyfrost/oneconfig/api/platform/v1/Platform { - public static fun getGLPlatform ()Lorg/polyfrost/oneconfig/api/platform/v1/GLPlatform; - public static fun getGuiPlatform ()Lorg/polyfrost/oneconfig/api/platform/v1/GuiPlatform; - public static fun getI18nPlatform ()Lorg/polyfrost/oneconfig/api/platform/v1/I18nPlatform; - public static fun getLoaderPlatform ()Lorg/polyfrost/oneconfig/api/platform/v1/LoaderPlatform; - public static fun getPlayerPlatform ()Lorg/polyfrost/oneconfig/api/platform/v1/PlayerPlatform; + public static fun gl ()Lorg/polyfrost/oneconfig/api/platform/v1/GLPlatform; + public static fun i18n ()Lorg/polyfrost/oneconfig/api/platform/v1/I18nPlatform; + public static fun loader ()Lorg/polyfrost/oneconfig/api/platform/v1/LoaderPlatform; + public static fun player ()Lorg/polyfrost/oneconfig/api/platform/v1/PlayerPlatform; + public static fun screen ()Lorg/polyfrost/oneconfig/api/platform/v1/ScreenPlatform; } public abstract interface class org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform { public abstract fun doesPlayerExist ()Z - public abstract fun getClientBrand ()Ljava/lang/String; public abstract fun getPlayerName ()Ljava/lang/String; public abstract fun inMultiplayer ()Z } +public abstract interface class org/polyfrost/oneconfig/api/platform/v1/ScreenPlatform { + public fun close ()V + public abstract fun current ()Ljava/lang/Object; + public fun display (Ljava/lang/Object;)V + public abstract fun display (Ljava/lang/Object;I)V + public abstract fun isInChat ()Z + public abstract fun isInDebug ()Z + public abstract fun playClickSound ()V + public abstract fun viewportHeight ()I + public abstract fun viewportWidth ()I + public abstract fun windowHeight ()I + public abstract fun windowWidth ()I +} + public final class org/polyfrost/oneconfig/utils/v1/ArrayCastUtils { public static fun b2b ([Ljava/lang/Object;)[B public static fun b2i ([B)[I @@ -102,12 +144,6 @@ public final class org/polyfrost/oneconfig/utils/v1/Deprecator { public static fun markDeprecated ()V } -public final class org/polyfrost/oneconfig/utils/v1/GuiUtils { - public static fun closeScreen ()V - public static fun displayScreen (Ljava/lang/Object;)V - public static fun displayScreen (Ljava/lang/Object;I)V -} - public final class org/polyfrost/oneconfig/utils/v1/IOUtils { public static fun copyImageToClipboard (Ljava/awt/Image;)V public static fun copyStringToClipboard (Ljava/lang/String;)V @@ -292,63 +328,7 @@ public final class org/polyfrost/oneconfig/utils/v1/dsl/MultithreadingKt { } public final class org/polyfrost/oneconfig/utils/v1/dsl/NetworkKt { - public static final fun browseLink (Lorg/polyfrost/universal/UDesktop;Ljava/lang/String;)V public static final fun download (Ljava/nio/file/Path;Ljava/lang/String;Ljava/lang/String;IZ)Z public static synthetic fun download$default (Ljava/nio/file/Path;Ljava/lang/String;Ljava/lang/String;IZILjava/lang/Object;)Z } -public final class org/polyfrost/oneconfig/utils/v1/hypixel/HypixelUtils { - public static fun isHypixel ()Z -} - -public class org/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo : java/io/Serializable { - public field previous Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo; - public fun equals (Ljava/lang/Object;)Z - public fun getGameMode ()Ljava/lang/String; - public fun getGameType ()Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public fun getMapName ()Ljava/lang/String; - public fun getRawGameType ()Ljava/lang/String; - public fun getServerId ()Ljava/lang/String; - public fun hashCode ()I - public fun isInGame ()Z - public fun toString ()Ljava/lang/String; -} - -public final class org/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType : java/lang/Enum { - public static final field ARCADE_GAMES Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field ARENA Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field BEDWARS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field BLITZ_SG Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field BUILD_BATTLE Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field CLASSIC_GAMES Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field COPS_AND_CRIMS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field DROPPER Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field DUELS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field HOUSING Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field LIMBO Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field MAIN Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field MEGA_WALLS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field MURDER_MYSTERY Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field PAINTBALL Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field PIT Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field PROTOTYPE Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field QUAKE Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field REPLAY Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field SKYBLOCK Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field SKYWARS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field SMASH_HEROES Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field SPEED_UHC Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field TNT_GAMES Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field TURBO_KART_RACERS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field UHC_CHAMPIONS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field UNKNOWN Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field VAMPIREZ Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field WALLS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field WARLORDS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static final field WOOL_WARS Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static fun fromString (Ljava/lang/String;)Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public fun getServerName ()Ljava/lang/String; - public static fun valueOf (Ljava/lang/String;)Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; - public static fun values ()[Lorg/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo$GameType; -} - diff --git a/modules/utils/build.gradle.kts b/modules/utils/build.gradle.kts index ddf1e7636..0a51a0463 100644 --- a/modules/utils/build.gradle.kts +++ b/modules/utils/build.gradle.kts @@ -26,4 +26,5 @@ dependencies { compileOnly("org.polyfrost:universalcraft-1.8.9-forge:${libs.versions.universalcraft.get()}") + api(libs.hypixel.modapi) } \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/ClassHasOverwrites.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/ClassHasOverwrites.java similarity index 91% rename from versions/src/main/java/org/polyfrost/oneconfig/internal/ClassHasOverwrites.java rename to modules/utils/src/main/java/org/polyfrost/oneconfig/api/ClassHasOverwrites.java index d3d9f274e..18482419d 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/ClassHasOverwrites.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/ClassHasOverwrites.java @@ -24,7 +24,10 @@ * */ -package org.polyfrost.oneconfig.internal; +package org.polyfrost.oneconfig.api; + +import kotlin.annotation.MustBeDocumented; +import org.jetbrains.annotations.ApiStatus; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -34,11 +37,12 @@ /** * This annotation is for codebase navigation - it indicates that the given class has overwrites for different versions of Minecraft. - * @see org.polyfrost.oneconfig.api.DeclaredInPlatform */ @Retention(RetentionPolicy.SOURCE) @Target(ElementType.TYPE) @Documented +@MustBeDocumented +@ApiStatus.Internal public @interface ClassHasOverwrites { String[] value(); } diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/DeclaredInPlatform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/DeclaredInPlatform.java deleted file mode 100644 index 7ec046187..000000000 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/DeclaredInPlatform.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api; - -import kotlin.annotation.MustBeDocumented; -import org.jetbrains.annotations.ApiStatus; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Internal marker for the 'header; classes in the modules/ directory, with their - * real implementation being found in the platform/ directory. - * This is used for API validation reasons and for improved readability of the codebase. - * - * @see PlatformDeclaration - */ -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.TYPE) -@Documented -@MustBeDocumented -@ApiStatus.Internal -public @interface DeclaredInPlatform { -} diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/PlatformDeclaration.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/PlatformDeclaration.java deleted file mode 100644 index 9863c2c6f..000000000 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/PlatformDeclaration.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api; - -import kotlin.annotation.MustBeDocumented; -import org.jetbrains.annotations.ApiStatus; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Internal marker for the real implementation of classes in the modules/ directory, with their - * headers being found in the platform/ directory. - * This is used for API validation reasons and for improved readability of the codebase. - * - * @see DeclaredInPlatform - */ -@Retention(RetentionPolicy.SOURCE) -@Target(ElementType.TYPE) -@Documented -@MustBeDocumented -@ApiStatus.Internal -public @interface PlatformDeclaration { -} diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI.java new file mode 100644 index 000000000..b25032714 --- /dev/null +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/HypixelAPI.java @@ -0,0 +1,215 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.api.hypixel.v0; + +import net.hypixel.data.rank.MonthlyPackageRank; +import net.hypixel.data.rank.PackageRank; +import net.hypixel.data.rank.PlayerRank; +import net.hypixel.data.type.GameType; +import net.hypixel.data.type.LobbyType; +import net.hypixel.data.type.ServerType; +import net.hypixel.modapi.HypixelModAPI; +import net.hypixel.modapi.handler.ClientboundPacketHandler; +import net.hypixel.modapi.packet.ClientboundHypixelPacket; +import net.hypixel.modapi.packet.impl.VersionedPacket; +import net.hypixel.modapi.packet.impl.clientbound.ClientboundPartyInfoPacket; +import net.hypixel.modapi.packet.impl.clientbound.ClientboundPlayerInfoPacket; +import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket; +import net.hypixel.modapi.packet.impl.serverbound.ServerboundPlayerInfoPacket; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; +import org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternals; + +import java.util.Map; +import java.util.Optional; +import java.util.ServiceLoader; +import java.util.UUID; + +/** + * Hypixel API wrapper for OneConfig. + *

+ * When this class is first referenced, it will set up the Hypixel API handlers for you. After that, all the methods for sending and receiving packets + * are available directly from their classes, such as {@link HypixelModAPI#registerHandler(ClientboundPacketHandler)}. + *

+ * This class is a simple wrapper around this functionality, providing a simple way to access the Hypixel API. + * + * @implNote the actual registration of the packet handlers is done in HypixelApiInternals. Note that this is lazily initialized, + * and so this class, or HypixelApiInternals, needs to be referenced in order for the packet handlers to be registered. + */ +@SuppressWarnings("unused") +public final class HypixelAPI { + private static final Logger LOGGER = LogManager.getLogger("OneConfig/HypixelAPI"); + private static final HypixelAPI INSTANCE = new HypixelAPI(); + private static final HypixelApiInternals internals = ServiceLoader.load(HypixelApiInternals.class, HypixelApiInternals.class.getClassLoader()).iterator().next(); + private PlayerInfo info; + private PartyInfo partyInfo; + private Location location; + + private HypixelAPI() { + } + + public static PlayerInfo getPlayerInfo() { + return INSTANCE.info == null ? INSTANCE.info = new PlayerInfo() : INSTANCE.info; + } + + public static PartyInfo getPartyInfo() { + return INSTANCE.partyInfo == null ? INSTANCE.partyInfo = new PartyInfo() : INSTANCE.partyInfo; + } + + public static Location getLocation() { + return INSTANCE.location == null ? INSTANCE.location = new Location() : INSTANCE.location; + } + + public static abstract class InfoBase { + protected T packet; + @ApiStatus.Internal + public abstract void update(); + + @Override + public final String toString() { + return packet.toString(); + } + } + + + public static final class PartyInfo extends InfoBase { + private PartyInfo() { + LOGGER.info("Registering party info packet handler"); + HypixelModAPI.getInstance().registerHandler(new ClientboundPacketHandler() { + @Override + public void onPartyInfoPacket(ClientboundPartyInfoPacket packet) { + PartyInfo.this.packet = packet; + } + }); + update(); + } + + @Override + public void update() { + HypixelModAPI.getInstance().sendPacket(new ServerboundPlayerInfoPacket()); + } + + public boolean isInParty() { + return packet.isInParty(); + } + + public int getPartySize() { + return getMembers().size(); + } + + public Map getMembers() { + return packet.getMemberMap(); + } + } + + public static final class PlayerInfo extends InfoBase { + private PlayerInfo() { + LOGGER.info("Registering player info handler"); + HypixelModAPI.getInstance().registerHandler(new ClientboundPacketHandler() { + @Override + public void onPlayerInfoPacket(ClientboundPlayerInfoPacket packet) { + PlayerInfo.this.packet = packet; + } + }); + update(); + } + + @Override + public void update() { + HypixelModAPI.getInstance().sendPacket(new ServerboundPlayerInfoPacket()); + } + + public PlayerRank getRank() { + return packet.getPlayerRank(); + } + + public PackageRank getPackageRank() { + return packet.getPackageRank(); + } + + public MonthlyPackageRank getMonthlyPackageRank() { + return packet.getMonthlyPackageRank(); + } + + public Optional getPrefix() { + return packet.getPrefix(); + } + } + + public static final class Location extends InfoBase { + private Location() { + LOGGER.info("Registering location packet handler"); + HypixelModAPI.getInstance().registerHandler(new ClientboundPacketHandler() { + @Override + public void onLocationEvent(ClientboundLocationPacket packet) { + Location.this.packet = packet; + // cannot access the EventManager from here, so we do it like this instead. + internals.postLocationEvent(); + } + }); + HypixelModAPI.getInstance().subscribeToEventPacket(ClientboundLocationPacket.class); + } + + @Override + public void update() { + // no-op as event based + } + + public Optional getLobbyName() { + return packet.getLobbyName(); + } + + public Optional getMapName() { + return packet.getMap(); + } + + public Optional getMode() { + return packet.getMode(); + } + + public Optional getServerType() { + return packet.getServerType(); + } + + public boolean isLobby() { + Optional type = getServerType(); + return type.isPresent() && type.get() instanceof LobbyType; + } + + public boolean isGame() { + return !isLobby(); + } + + public Optional getGameType() { + Optional type = getServerType(); + if (!type.isPresent()) return Optional.empty(); + ServerType t = type.get(); + return t instanceof GameType ? Optional.of((GameType) t) : Optional.empty(); + } + } +} diff --git a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/util/Pair.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternals.java similarity index 85% rename from modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/util/Pair.java rename to modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternals.java index f00588f15..67ee80ac5 100644 --- a/modules/commands/src/main/java/org/polyfrost/oneconfig/api/commands/v1/util/Pair.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternals.java @@ -24,14 +24,11 @@ * */ -package org.polyfrost.oneconfig.api.commands.v1.util; +package org.polyfrost.oneconfig.api.hypixel.v0.internal; -public class Pair { - public A first; - public B second; +import org.jetbrains.annotations.ApiStatus; - public Pair(A f, B s) { - first = f; - second = s; - } +@ApiStatus.Internal +public interface HypixelApiInternals { + void postLocationEvent(); } diff --git a/versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/DebugHudAccessor.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/package-info.java similarity index 78% rename from versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/DebugHudAccessor.java rename to modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/package-info.java index 30a8b6a9c..fbf750f53 100644 --- a/versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/DebugHudAccessor.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/package-info.java @@ -24,14 +24,12 @@ * */ -package org.polyfrost.oneconfig.internal.mixin; - -import net.minecraft.client.gui.hud.DebugHud; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; +/** + * Experimental implementation of the Hypixel Mod API in OneConfig. + *
+ * This will remain experimental as long as upstream is experimental. + */ +@ApiStatus.Experimental +package org.polyfrost.oneconfig.api.hypixel.v0; -@Mixin(DebugHud.class) -public interface DebugHudAccessor { - @Accessor - boolean isShowDebugHud(); -} +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GLPlatform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GLPlatform.java index 0d2cbab6c..a118868aa 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GLPlatform.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GLPlatform.java @@ -29,13 +29,9 @@ import org.polyfrost.universal.UMatrixStack; public interface GLPlatform { - void drawRect(float x, float y, float x2, float y2, int color); + void drawRect(UMatrixStack stack, double x, double y, double x2, double y2, int color); - default float drawText(String text, float x, float y, int color, boolean shadow) { - return drawText(null, text, x, y, color, shadow); - } - - float drawText(UMatrixStack matrixStack, String text, float x, float y, int color, boolean shadow); + float drawText(UMatrixStack stack, String text, float x, float y, int color, boolean shadow); int getStringWidth(String text); diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/I18nPlatform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/I18nPlatform.java index bd1f7a94b..fd34b0003 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/I18nPlatform.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/I18nPlatform.java @@ -33,4 +33,9 @@ public interface I18nPlatform { * Return the localized name of the key given. */ String getKeyName(int key, int scanCode); + + /** + * Return the given component with all formatting codes removed. + */ + String getUnformattedText(Object component); } diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/Platform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/Platform.java index ef172c7c0..3c0a42f42 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/Platform.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/Platform.java @@ -38,26 +38,26 @@ private Platform() { private static LoaderPlatform loaderPlatform; private static PlayerPlatform playerPlatform; private static GLPlatform glPlatform; - private static GuiPlatform guiPlatform; + private static ScreenPlatform screenPlatform; private static I18nPlatform i18nPlatform; - public static LoaderPlatform getLoaderPlatform() { + public static LoaderPlatform loader() { return loaderPlatform == null ? loaderPlatform = load(LoaderPlatform.class) : loaderPlatform; } - public static PlayerPlatform getPlayerPlatform() { + public static PlayerPlatform player() { return playerPlatform == null ? playerPlatform = load(PlayerPlatform.class) : playerPlatform; } - public static GLPlatform getGLPlatform() { + public static GLPlatform gl() { return glPlatform == null ? glPlatform = load(GLPlatform.class) : glPlatform; } - public static GuiPlatform getGuiPlatform() { - return guiPlatform == null ? guiPlatform = load(GuiPlatform.class) : guiPlatform; + public static ScreenPlatform screen() { + return screenPlatform == null ? screenPlatform = load(ScreenPlatform.class) : screenPlatform; } - public static I18nPlatform getI18nPlatform() { + public static I18nPlatform i18n() { return i18nPlatform == null ? i18nPlatform = load(I18nPlatform.class) : i18nPlatform; } diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform.java index d9b0819a2..f49b11931 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform.java @@ -29,8 +29,6 @@ public interface PlayerPlatform { boolean inMultiplayer(); - String getClientBrand(); - boolean doesPlayerExist(); String getPlayerName(); diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GuiPlatform.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/ScreenPlatform.java similarity index 76% rename from modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GuiPlatform.java rename to modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/ScreenPlatform.java index 16f9094c3..8521ff5e9 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/GuiPlatform.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/api/platform/v1/ScreenPlatform.java @@ -26,14 +26,33 @@ package org.polyfrost.oneconfig.api.platform.v1; -public interface GuiPlatform { - Object getCurrentScreen(); - - void setCurrentScreen(Object screen); +import org.jetbrains.annotations.Nullable; +public interface ScreenPlatform { boolean isInChat(); boolean isInDebug(); void playClickSound(); + + int viewportWidth(); + + int viewportHeight(); + + int windowWidth(); + + int windowHeight(); + + void display(@Nullable Object screen, int ticks); + + default void display(Object screen) { + display(screen, 1); + } + + default void close() { + display(null, 0); + } + + @Nullable + T current(); } diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java deleted file mode 100644 index 2e1f5b217..000000000 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.utils.v1; - -import org.polyfrost.oneconfig.api.DeclaredInPlatform; - -/** - * A class containing utility methods for working with GuiScreens. - */ -@SuppressWarnings("unused") -@DeclaredInPlatform -public final class GuiUtils { - // GuiUtils.h -- version specific workaround - // see versions/src/main/java/org/polyfrost/oneconfig/utils/GuiUtils.java for the real implementation - - private GuiUtils() { - } - - /** - * Displays a screen after a tick, preventing mouse sync issues. - * - * @param screen the screen to display. - */ - public static void displayScreen(Object screen) { - displayScreen(screen, 1); - } - - /** - * Displays a screen after the specified amount of ticks. - * - * @param screen the screen to display. - * @param ticks the amount of ticks to wait for before displaying the screen. - */ - public static void displayScreen(Object screen, int ticks) { - } - - - /** - * Close the current open GUI screen. - */ - public static void closeScreen() { - displayScreen(null, 0); - } -} diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/LogScanner.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/LogScanner.java index c0a8dd466..70bf77c6f 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/LogScanner.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/LogScanner.java @@ -172,7 +172,7 @@ public static Set identifyFromClass(String className) */ @NotNull public static Set identifyFromClass(Class clazz) { - List modMap = Platform.getLoaderPlatform().getLoadedMods(); + List modMap = Platform.loader().getLoadedMods(); modMap.removeIf(Objects::isNull); try { @@ -193,7 +193,7 @@ public static Set identifyFromClass(Class clazz) { String s = uri.toString(); uri = new URL(s.substring(4, s.lastIndexOf("!"))).toURI(); } - if (uri.toString().endsWith(".class") && Platform.getLoaderPlatform().isDevelopmentEnvironment()) { + if (uri.toString().endsWith(".class") && Platform.loader().isDevelopmentEnvironment()) { LOGGER.error("The mod you are currently developing caused this issue, or another class file. Returning 'this'."); LOGGER.error("Class: {}", clazz.getName()); return Collections.singleton(new LoaderPlatform.ActiveMod("this", "this", "Unknown", null)); @@ -208,7 +208,7 @@ public static Set identifyFromClass(Class clazz) { private static Set getModsAt(Path path, List modMap) { Set mods = modMap.stream().filter(m -> m.source.equals(path)).collect(Collectors.toSet()); if (!mods.isEmpty()) return mods; - else if (Platform.getLoaderPlatform().isDevelopmentEnvironment()) { + else if (Platform.loader().isDevelopmentEnvironment()) { // For some reason, in dev, the mod being tested has the 'resources' folder as the origin instead of the 'classes' folder. String resourcesPathString = path.toString().replace("\\", "/") // Make it work with Architectury as well diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/NetworkUtils.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/NetworkUtils.java index f99cdb89c..f048909b3 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/NetworkUtils.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/NetworkUtils.java @@ -99,7 +99,7 @@ public static String getString(String url) { * @return Whether the download was successful. */ public static boolean downloadFile(String url, Path path, String userAgent, int timeout, boolean useCaches) { - try (BufferedInputStream in = new BufferedInputStream(setupConnection(URLEncoder.encode(url, "UTF-8"), userAgent, timeout, useCaches))) { + try (BufferedInputStream in = new BufferedInputStream(setupConnection(url, userAgent, timeout, useCaches))) { Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { LOGGER.error("Failed to download file from {}", url, e); @@ -132,7 +132,7 @@ public static void browseLink(String uri) { } public static InputStream setupConnection(String url, String userAgent, int timeout, boolean useCaches) throws IOException { - HttpURLConnection connection = ((HttpURLConnection) new URL(url).openConnection()); + HttpURLConnection connection = ((HttpURLConnection) new URL(URLEncoder.encode(url, "UTF-8")).openConnection()); connection.setRequestMethod("GET"); connection.setUseCaches(useCaches); connection.addRequestProperty("User-Agent", userAgent); diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/OneConfigUpdate.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/OneConfigUpdate.java index 09f2f5f1b..5e632d4ce 100644 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/OneConfigUpdate.java +++ b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/OneConfigUpdate.java @@ -75,7 +75,7 @@ public boolean hasChecked() { } private synchronized void fetchUpdateStatus() { - LoaderPlatform.ActiveMod self = Platform.getLoaderPlatform().getLoadedMod("oneconfig"); + LoaderPlatform.ActiveMod self = Platform.loader().getLoadedMod("oneconfig"); if (self == null) { LOGGER.warn("version check failed: failed to determine current version"); return; @@ -87,7 +87,7 @@ private synchronized void fetchUpdateStatus() { sb.append(ONECONFIG_REPO); if (snapshot) sb.append("snapshot/"); else sb.append("releases/"); - sb.append(GROUP).append(Platform.getLoaderPlatform().getLoaderString()); + sb.append(GROUP).append(Platform.loader().getLoaderString()); sb.append("/maven-metadata.xml"); try (InputStream stream = NetworkUtils.setupConnection(sb.toString(), NetworkUtils.DEF_AGENT, 2000, false)) { if (stream == null) { diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/HypixelUtils.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/HypixelUtils.java deleted file mode 100644 index 7aa18b7a2..000000000 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/HypixelUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.utils.v1.hypixel; - -import org.polyfrost.oneconfig.api.platform.v1.Platform; - -import java.util.Locale; - -/** - * Various utilities for Hypixel. - */ -public final class HypixelUtils { - - private HypixelUtils() { - } - - /** - * Checks whether the player is on Hypixel. - * - * @return Whether the player is on Hypixel. - * @see this discord message from discord.gg/essential - */ - public static boolean isHypixel() { - if (!Platform.getPlayerPlatform().inMultiplayer()) return false; - - String serverBrand = Platform.getPlayerPlatform().getClientBrand(); - - if (serverBrand == null) return false; - - return serverBrand.toLowerCase(Locale.ENGLISH).contains("hypixel"); - } -} diff --git a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo.java b/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo.java deleted file mode 100644 index 8cf4a6031..000000000 --- a/modules/utils/src/main/java/org/polyfrost/oneconfig/utils/v1/hypixel/LocrawInfo.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.utils.v1.hypixel; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.Serializable; -import java.util.Objects; - -/** - * Represents the location of the player in Hypixel. - * - * @see HypixelUtils - */ -@SuppressWarnings({"ConstantConditions", "ConstantValue"} /*, reason = "this class is serialized by GSON so values are changed by that."*/) -public class LocrawInfo implements Serializable { - /** - * Represents the previous location info that was used. - */ - @Nullable - public transient LocrawInfo previous; - - @Nullable - private final String server = null; - @NotNull - private final String mode = "lobby"; - @Nullable - private final String map = null; - @Nullable - private final String gametype = null; - @NotNull - private transient final GameType gameType; - - // called by gson - private LocrawInfo() { - gameType = GameType.fromString(gametype); - } - - /** - * @return The serverID of the server you are currently on, ex: mini121 - */ - @Nullable - public String getServerId() { - return server; - } - - /** - * @return The GameType of the server as a String. - */ - @Nullable - public String getRawGameType() { - return gametype; - } - - /** - * @return The GameMode of the server, ex: solo_insane - */ - @NotNull - public String getGameMode() { - return mode; - } - - /** - * @return The GameType of the server as an Enum. - */ - public @NotNull GameType getGameType() { - return gameType; - } - - /** - * @return The map of the server, ex: Shire. - */ - @Nullable - public String getMapName() { - return map; - } - - public boolean isInGame() { - return !"lobby".equals(mode); - } - - @Override - public String toString() { - return "LocrawInfo{" + "serverId='" + server + '\'' + ", gameMode='" + mode + '\'' + ", mapName='" + map + '\'' + ", rawGameType='" + gametype + '\'' + '}'; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - LocrawInfo that = (LocrawInfo) o; - return Objects.equals(server, that.server) && Objects.equals(mode, that.mode) && Objects.equals(map, that.map) && Objects.equals(gametype, that.gametype); - } - - @Override - public int hashCode() { - return Objects.hash(server, mode, map, gametype); - } - - public enum GameType { - UNKNOWN(""), LIMBO("LIMBO"), BEDWARS("BEDWARS"), SKYWARS("SKYWARS"), PROTOTYPE("PROTOTYPE"), SKYBLOCK("SKYBLOCK"), MAIN("MAIN"), MURDER_MYSTERY("MURDER_MYSTERY"), HOUSING("HOUSING"), ARCADE_GAMES("ARCADE"), BUILD_BATTLE("BUILD_BATTLE"), DUELS("DUELS"), PIT("PIT"), UHC_CHAMPIONS("UHC"), SPEED_UHC("SPEED_UHC"), TNT_GAMES("TNTGAMES"), CLASSIC_GAMES("LEGACY"), COPS_AND_CRIMS("MCGO"), BLITZ_SG("SURVIVAL_GAMES"), MEGA_WALLS("WALLS3"), SMASH_HEROES("SUPER_SMASH"), WARLORDS("BATTLEGROUND"), - /** - * @see #getGameMode() - * @deprecated Moved to a PROTOTYPE gamemode - */ - @Deprecated - DROPPER(""), - WOOL_WARS("WOOL_GAMES"), VAMPIREZ("VAMPIREZ"), PAINTBALL("PAINTBALL"), QUAKE("QUAKECRAFT"), WALLS("WALLS"), TURBO_KART_RACERS("GINGERBREAD"), ARENA("ARENA"), REPLAY("REPLAY"); - - private final String serverName; - - GameType(String serverName) { - this.serverName = serverName; - } - - public static GameType fromString(String gameType) { - if (gameType == null) return UNKNOWN; - for (GameType value : values()) { - if (value.serverName.equals(gameType)) { - return value; - } - } - - return UNKNOWN; - } - - public String getServerName() { - return serverName; - } - } -} diff --git a/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/MHUtils.kt b/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/MHUtils.kt index 680299740..9b52db2f3 100644 --- a/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/MHUtils.kt +++ b/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/MHUtils.kt @@ -29,13 +29,6 @@ package org.polyfrost.oneconfig.utils.v1 import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.jetbrains.annotations.ApiStatus -import org.polyfrost.oneconfig.utils.v1.MHUtils.getField -import org.polyfrost.oneconfig.utils.v1.MHUtils.getFieldGetter -import org.polyfrost.oneconfig.utils.v1.MHUtils.getFieldSetter -import org.polyfrost.oneconfig.utils.v1.MHUtils.getMethodHandle -import org.polyfrost.oneconfig.utils.v1.MHUtils.invoke -import org.polyfrost.oneconfig.utils.v1.MHUtils.setAccessible -import org.polyfrost.oneconfig.utils.v1.MHUtils.setField import sun.misc.Unsafe import java.lang.invoke.LambdaMetafactory import java.lang.invoke.MethodHandle diff --git a/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/dsl/network.kt b/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/dsl/network.kt index e7a760b73..184005af2 100644 --- a/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/dsl/network.kt +++ b/modules/utils/src/main/kotlin/org/polyfrost/oneconfig/utils/v1/dsl/network.kt @@ -27,7 +27,6 @@ package org.polyfrost.oneconfig.utils.v1.dsl import org.polyfrost.oneconfig.utils.v1.NetworkUtils -import org.polyfrost.universal.UDesktop import java.nio.file.Path /** @@ -36,12 +35,4 @@ import java.nio.file.Path * @see NetworkUtils.downloadFile */ fun Path.download(url: String, userAgent: String = "OneConfig/1.0.0", timeout: Int = 5000, useCaches: Boolean = false) = - NetworkUtils.downloadFile(url, this, userAgent, timeout, useCaches) - -/** - * Launches a URL in the default browser. - * - * @see NetworkUtils.browseLink - */ -@Suppress("unused", "UnusedReceiverParameter") -fun UDesktop.browseLink(uri: String) = NetworkUtils.browseLink(uri) \ No newline at end of file + NetworkUtils.downloadFile(url, this, userAgent, timeout, useCaches) \ No newline at end of file diff --git a/versions/1.16.5-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java b/versions/1.16.5-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java index 6357ca4c7..1f828143a 100644 --- a/versions/1.16.5-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java +++ b/versions/1.16.5-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java @@ -54,15 +54,15 @@ public abstract class NetHandlerPlayClientMixin { @Redirect(method = "onGameMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/play/GameMessageS2CPacket;getMessage()Lnet/minecraft/text/Text;")) private Text ocfg$modifyMessage(GameMessageS2CPacket packet) { if ( - //#if MC<11700 - !packet.isNonChat() - //#else - //$$ packet.getLocation() == net.minecraft.network.MessageType.CHAT - //#endif + //#if MC<11700 + !packet.isNonChat() + //#else + //$$ packet.getLocation() == net.minecraft.network.MessageType.CHAT + //#endif ) { ocfg$chatEvent = new ChatReceiveEvent(packet.getMessage()); EventManager.INSTANCE.post(ocfg$chatEvent); - return ocfg$chatEvent.message; + return ocfg$chatEvent.getMessage(); } return packet.getMessage(); } diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java index 6ab549d51..4ad8524ab 100644 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java @@ -42,6 +42,7 @@ import com.mojang.brigadier.suggestion.Suggestions; import com.mojang.brigadier.suggestion.SuggestionsBuilder; import com.mojang.brigadier.tree.CommandNode; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; import net.minecraft.command.arguments.BlockPosArgument; import net.minecraft.command.arguments.EntityArgument; import net.minecraft.command.arguments.GameProfileArgument; @@ -59,7 +60,6 @@ import org.polyfrost.oneconfig.api.commands.v1.arguments.ArgumentParser; import org.polyfrost.oneconfig.api.commands.v1.factories.PlatformCommandFactory; import org.polyfrost.oneconfig.api.event.v1.invoke.EventHandler; -import org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandSource; import org.polyfrost.universal.UChat; import java.util.ArrayList; @@ -76,7 +76,7 @@ @ApiStatus.Internal public class PlatformCommandFactoryImpl implements PlatformCommandFactory { private static final Map, Supplier>> argTypeMap = new HashMap<>(); - private static List> nodes = new ArrayList<>(); + private static final List> nodes = new ArrayList<>(); static { @@ -94,23 +94,28 @@ public class PlatformCommandFactoryImpl implements PlatformCommandFactory { //#if MC<11900 argTypeMap.put(ItemStack.class, ItemArgument::item); //#else + //#if FABRIC //$$ net.minecraft.command.CommandRegistryAccess a = net.minecraft.server.command.CommandManager.createRegistryAccess( //$$ net.minecraft.registry.BuiltinRegistries.createWrapperLookup()); //$$ argTypeMap.put(ItemStack.class, () -> ItemStackArgumentType.itemStack(a)); + //#else + //$$ net.minecraft.commands.CommandBuildContext a = net.minecraft.commands.Commands.createValidationContext( + //$$ net.minecraft.data.registries.VanillaRegistries.createLookup()); + //$$ argTypeMap.put(ItemStack.class, () -> ItemArgument.item(a)); + //#endif //#endif EventHandler.of(RegisterCommandsEvent.class, e -> { - for (CommandNode n : nodes) { + for (CommandNode n : nodes) { e.dispatcher.getRoot().addChild(n); } - nodes = null; }).register(); } @Override public boolean createCommand(CommandTree command) { - LiteralArgumentBuilder master = literal(command.name()); - LiteralArgumentBuilder help = literal("help"); + LiteralArgumentBuilder master = literal(command.name()); + LiteralArgumentBuilder help = literal("help"); help.executes(context -> { for (String s : command.getHelp()) { UChat.chat(s); @@ -124,7 +129,7 @@ public boolean createCommand(CommandTree command) { return true; } - private static void _create(ArgumentBuilder parent, Collection> nodesCollection) { + private static void _create(ArgumentBuilder parent, Collection> nodesCollection) { for (List nodes : nodesCollection) { for (Node n : nodes) { String[] names = n.names(); diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/RegisterCommandsEvent.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/RegisterCommandsEvent.java index 5a887d820..48db1d0ac 100644 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/RegisterCommandsEvent.java +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/RegisterCommandsEvent.java @@ -27,13 +27,13 @@ package org.polyfrost.oneconfig.api.commands.v1.internal; import com.mojang.brigadier.CommandDispatcher; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; import org.polyfrost.oneconfig.api.event.v1.events.Event; -import org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandSource; public class RegisterCommandsEvent implements Event { - public final CommandDispatcher dispatcher; + public final CommandDispatcher dispatcher; - public RegisterCommandsEvent(CommandDispatcher dispatcher) { + public RegisterCommandsEvent(CommandDispatcher dispatcher) { this.dispatcher = dispatcher; } } diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java index 3fed1bb05..30c70f57c 100644 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java @@ -32,9 +32,11 @@ public class UIManagerImpl implements UIManager { private static final TinyFD impl = new TinyFDImpl(); - static { - RendererImpl.INSTANCE.setGl3(true); - } + //#if MC>=11700 + //$$ static { + //$$ RendererImpl.INSTANCE.setGl3(true); + //$$ } + //#endif @Override public Renderer getRenderer() { diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandInternals.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandInternals.java index 6fabd44fb..33e616f02 100644 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandInternals.java +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandInternals.java @@ -26,32 +26,25 @@ package org.polyfrost.oneconfig.internal.libs.fabric; -import com.google.common.collect.Iterables; -import com.mojang.brigadier.AmbiguityConsumer; import com.mojang.brigadier.CommandDispatcher; -import com.mojang.brigadier.ParseResults; -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.ArgumentBuilder; -import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import com.mojang.brigadier.builder.RequiredArgumentBuilder; -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.context.ParsedCommandNode; import com.mojang.brigadier.exceptions.BuiltInExceptionProvider; import com.mojang.brigadier.exceptions.CommandExceptionType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.tree.CommandNode; import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientSuggestionProvider; +import net.minecraft.profiler.IProfiler; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentUtils; -import net.minecraft.util.text.TranslationTextComponent; -import org.jetbrains.annotations.Nullable; -import org.polyfrost.oneconfig.internal.mixin.commands.HelpCommandAccessor; -import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.Nullable; +import org.polyfrost.oneconfig.api.commands.v1.internal.RegisterCommandsEvent; +import org.polyfrost.oneconfig.api.event.v1.EventManager; +import org.polyfrost.universal.UChat; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -62,33 +55,15 @@ */ public final class ClientCommandInternals { private static final Logger LOGGER = LogManager.getLogger("OneConfig/Commands"); - private static final String API_COMMAND_NAME = "ocfgcmds"; - private static CommandDispatcher activeDispatcher; + private static CommandDispatcher activeDispatcher; - public static void setActiveDispatcher(@Nullable CommandDispatcher dispatcher) { + private static void setup(@Nullable CommandDispatcher dispatcher) { activeDispatcher = dispatcher; - } - - /** - * Creates a literal argument builder. - * - * @param name the literal name - * @return the created argument builder - */ - public static LiteralArgumentBuilder literal(String name) { - return LiteralArgumentBuilder.literal(name); - } - - /** - * Creates a required argument builder. - * - * @param name the name of the argument - * @param type the type of the argument - * @param the type of the parsed argument value - * @return the created argument builder - */ - public static RequiredArgumentBuilder argument(String name, ArgumentType type) { - return RequiredArgumentBuilder.argument(name, type); + EventManager.INSTANCE.post(new RegisterCommandsEvent(dispatcher)); + // noinspection CodeBlock2Expr + activeDispatcher.findAmbiguities((parent, child, sibling, inputs) -> { + LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", activeDispatcher.getPath(child), activeDispatcher.getPath(sibling), inputs); + }); } /** @@ -98,16 +73,19 @@ public static RequiredArgumentBuilder argument(Strin * @return true if the command should not be sent to the server, false otherwise */ public static boolean executeCommand(String command) { - if(command.startsWith("/")) { + if (command.charAt(0) == '/') { command = command.substring(1); } Minecraft client = Minecraft.getInstance(); + if (client.getConnection() == null) { + LOGGER.warn("skipping execution of {} as cannot access suggestions provider", command); + return false; + } - // The interface is implemented on ClientCommandSource with a mixin. - // noinspection ConstantConditions - ClientCommandSource commandSource = (ClientCommandSource) client.getConnection().getSuggestionProvider(); + ClientSuggestionProvider commandSource = client.getConnection().getSuggestionProvider(); - client.getProfiler().startSection(command); + IProfiler profiler = client.getProfiler(); + profiler.startSection(command); try { // TODO: Check for server commands before executing. @@ -124,14 +102,14 @@ public static boolean executeCommand(String command) { } LOGGER.warn("Syntax exception for client-sided command '{}'", command, e); - commandSource.sendError(getErrorMessage(e)); + UChat.chat("&c" + getErrorMessage(e)); return true; } catch (Exception e) { LOGGER.warn("Error while executing client-sided command '{}'", command, e); - commandSource.sendError(ITextComponent.getTextComponentOrEmpty(e.getMessage())); + UChat.chat("&c" + e.getLocalizedMessage()); return true; } finally { - client.getProfiler().endSection(); + profiler.endSection(); } } @@ -158,61 +136,21 @@ private static ITextComponent getErrorMessage(CommandSyntaxException e) { return context != null ? //#if MC<11900 - new TranslationTextComponent + new net.minecraft.util.text.TranslationTextComponent + //#else + //#if FABRIC + //$$ Text //#else - //$$ Text.translatable + //$$ Component + //#endif + //$$ .translatable //#endif ("command.context.parse_error", message.getString(), e.getCursor(), context) : message; } - /** - * Runs final initialization tasks such as {@link CommandDispatcher#findAmbiguities(AmbiguityConsumer)} - * on the command dispatcher. Also registers a {@code /fcc help} command if there are other commands present. - */ - public static void finalizeInit() { - if (!activeDispatcher.getRoot().getChildren().isEmpty()) { - // Register an API command if there are other commands; - // these helpers are not needed if there are no client commands - LiteralArgumentBuilder help = literal("help"); - help.executes(ClientCommandInternals::executeRootHelp); - help.then(argument("command", StringArgumentType.greedyString()).executes(ClientCommandInternals::executeArgumentHelp)); - - activeDispatcher.register(literal(API_COMMAND_NAME).then(help)); - } - - // noinspection CodeBlock2Expr - activeDispatcher.findAmbiguities((parent, child, sibling, inputs) -> { - LOGGER.warn("Ambiguity between arguments {} and {} with inputs: {}", activeDispatcher.getPath(child), activeDispatcher.getPath(sibling), inputs); - }); - } - - private static int executeRootHelp(CommandContext context) { - return executeHelp(activeDispatcher.getRoot(), context); - } - - private static int executeArgumentHelp(CommandContext context) throws CommandSyntaxException { - ParseResults parseResults = activeDispatcher.parse(StringArgumentType.getString(context, "command"), context.getSource()); - List> nodes = parseResults.getContext().getNodes(); - - if (nodes.isEmpty()) { - throw HelpCommandAccessor.getFailedException().create(); - } - - return executeHelp(Iterables.getLast(nodes).getNode(), context); - } - - private static int executeHelp(CommandNode startNode, CommandContext context) { - Map, String> commands = activeDispatcher.getSmartUsage(startNode, context.getSource()); - - for (String command : commands.values()) { - context.getSource().sendFeedback(ITextComponent.getTextComponentOrEmpty("/" + command)); - } - - return commands.size(); - } - - public static void addCommands(CommandDispatcher target, ClientCommandSource source) { - Map, CommandNode> originalToCopy = new HashMap<>(); + public static void addCommands(CommandDispatcher target, ClientSuggestionProvider source) { + setup(new CommandDispatcher<>()); + Map, CommandNode> originalToCopy = new HashMap<>(); originalToCopy.put(activeDispatcher.getRoot(), target.getRoot()); copyChildren(activeDispatcher.getRoot(), target.getRoot(), source, originalToCopy); } @@ -228,15 +166,15 @@ public static void addCommands(CommandDispatcher target, Cl * should contain a mapping from origin to target */ private static void copyChildren( - CommandNode origin, - CommandNode target, - ClientCommandSource source, - Map, CommandNode> originalToCopy + CommandNode origin, + CommandNode target, + ClientSuggestionProvider source, + Map, CommandNode> originalToCopy ) { - for (CommandNode child : origin.getChildren()) { + for (CommandNode child : origin.getChildren()) { if (!child.canUse(source)) continue; - ArgumentBuilder builder = child.createBuilder(); + ArgumentBuilder builder = child.createBuilder(); // Reset the unnecessary non-completion stuff from the builder builder.requires(s -> true); // This is checked with the if check above. @@ -250,7 +188,7 @@ private static void copyChildren( builder.redirect(originalToCopy.get(builder.getRedirect())); } - CommandNode result = builder.build(); + CommandNode result = builder.build(); originalToCopy.put(child, result); target.addChild(result); diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandSource.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandSource.java deleted file mode 100644 index d64e9cd28..000000000 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/libs/fabric/ClientCommandSource.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.internal.libs.fabric; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.command.CommandSource; -import net.minecraft.command.ISuggestionProvider; -import net.minecraft.entity.Entity; -import net.minecraft.util.math.vector.Vector2f; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.text.ITextComponent; - -/** - * Fabric Client-side command manager implementation. - * Extensions to {@link CommandSource} for client-sided commands. - *
- * Taken from the Fabric API under the Apache 2.0 License; - * Click here for source - */ -@SuppressWarnings("unused") -public interface ClientCommandSource extends ISuggestionProvider { - /** - * Sends a feedback message to the player. - * - * @param message the feedback message - */ - void sendFeedback(ITextComponent message); - - /** - * Sends an error message to the player. - * - * @param message the error message - */ - void sendError(ITextComponent message); - - /** - * Gets the client instance used to run the command. - * - * @return the client - */ - Minecraft getClient(); - - /** - * Gets the player that used the command. - * - * @return the player - */ - ClientPlayerEntity getPlayer(); - - /** - * Gets the entity that used the command. - * - * @return the entity - */ - default Entity getEntity() { - return getPlayer(); - } - - /** - * Gets the position from where the command has been executed. - * - * @return the position - */ - default Vector3d getPosition() { - return getPlayer().getPositionVec(); - } - - /** - * Gets the rotation of the entity that used the command. - * - * @return the rotation - */ - default Vector2f getRotation() { - return getPlayer().getPitchYaw(); - } - - /** - * Gets the world where the player used the command. - * - * @return the world - */ - ClientWorld getWorld(); - - /** - * Gets the meta property under {@code key} that was assigned to this source. - * - *

This method should return the same result for every call with the same {@code key}. - * - * @param key the meta key - * @return the meta - */ - default Object getMeta(String key) { - return null; - } -} \ No newline at end of file diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java new file mode 100644 index 000000000..680740905 --- /dev/null +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java @@ -0,0 +1,46 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.internal.mixin; + +import net.minecraftforge.client.gui.ForgeIngameGui; +import org.polyfrost.oneconfig.api.ClassHasOverwrites; +import org.polyfrost.oneconfig.api.event.v1.EventManager; +import org.polyfrost.oneconfig.api.event.v1.events.HudRenderEvent; +import org.polyfrost.universal.UMatrixStack; +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; + +@Mixin(value = ForgeIngameGui.class, remap = false) +@ClassHasOverwrites({"1.8.9-fabric", "1.16.5-fabric", "1.16.5-forge"}) +public abstract class GuiIngameMixin { + @Inject(method = "renderIngameGui", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/gui/ForgeIngameGui;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;Lcom/mojang/blaze3d/matrix/MatrixStack;)V", shift = At.Shift.AFTER, remap = false), remap = true) + private void ocfg$postRenderHudEvent(com.mojang.blaze3d.matrix.MatrixStack matrices, float partialTicks, CallbackInfo ci) { + EventManager.INSTANCE.post(new HudRenderEvent(new UMatrixStack(matrices), partialTicks)); + } +} diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientCommandSourceMixin.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientCommandSourceMixin.java deleted file mode 100644 index 4a7abc710..000000000 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientCommandSourceMixin.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.internal.mixin.commands; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.player.ClientPlayerEntity; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextFormatting; -import org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandSource; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -/** - * Fabric Client-side command manager implementation. - *
- * Taken from the Fabric API under the Apache 2.0 License; - * Click here for source - */ -@SuppressWarnings("AddedMixinMembersNamePattern") -@Mixin(net.minecraft.client.multiplayer.ClientSuggestionProvider.class) -abstract class ClientCommandSourceMixin implements ClientCommandSource { - @Shadow - @Final - private Minecraft mc; - - @Override - public void sendFeedback(ITextComponent message) { - this.mc.ingameGUI.getChatGUI().printChatMessage(message); -// this.client.getNarratorManager().narrate(message); - } - - @Override - public void sendError(ITextComponent message) { - sendFeedback( - //#if MC<11900 - new net.minecraft.util.text.StringTextComponent("") - //#else - //#if FORGE - //$$ net.minecraft.network.chat.Component - //#else - //$$ net.minecraft.text.Text - //#endif - //$$ .empty() - //#endif - .append(message).mergeStyle(TextFormatting.RED)); - } - - @Override - public Minecraft getClient() { - return this.mc; - } - - @Override - public ClientPlayerEntity getPlayer() { - return this.mc.player; - } - - @Override - public ClientWorld getWorld() { - return this.mc.world; - } -} \ No newline at end of file diff --git a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientPlayNetworkHandlerMixin.java b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientPlayNetworkHandlerMixin.java index 5ba3d3331..612652da7 100644 --- a/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientPlayNetworkHandlerMixin.java +++ b/versions/1.16.5-forge/src/main/java/org/polyfrost/oneconfig/internal/mixin/commands/ClientPlayNetworkHandlerMixin.java @@ -28,13 +28,9 @@ import com.mojang.brigadier.CommandDispatcher; import net.minecraft.client.network.play.ClientPlayNetHandler; -import net.minecraft.command.CommandSource; +import net.minecraft.command.ISuggestionProvider; import net.minecraft.network.play.server.SCommandListPacket; -import net.minecraft.network.play.server.SJoinGamePacket; -import org.polyfrost.oneconfig.api.event.v1.EventManager; -import org.polyfrost.oneconfig.api.commands.v1.internal.RegisterCommandsEvent; import org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandInternals; -import org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandSource; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -48,26 +44,18 @@ public class ClientPlayNetworkHandlerMixin { // Modified from Fabric API under the Apache 2.0 License // // Source: https://github.com/FabricMC/fabric/blob/1.20.2/fabric-command-api-v2/src/client/java/net/fabricmc/fabric/mixin/command/client/ClientPlayNetworkHandlerMixin.java // @Shadow - private CommandDispatcher commandDispatcher; + private CommandDispatcher commandDispatcher; @Shadow @Final private net.minecraft.client.multiplayer.ClientSuggestionProvider clientSuggestionProvider; - @Inject(method = "handleJoinGame", at = @At("RETURN")) - private void ocfg$commands$setup(SJoinGamePacket packet, CallbackInfo info) { - final CommandDispatcher dispatcher = new CommandDispatcher<>(); - ClientCommandInternals.setActiveDispatcher(dispatcher); - EventManager.INSTANCE.post(new RegisterCommandsEvent(dispatcher)); - ClientCommandInternals.finalizeInit(); - } - @SuppressWarnings({"unchecked", "rawtypes"}) @Inject(method = "handleCommandList", at = @At("RETURN")) - private void ocfg$commands$setupCompletion(SCommandListPacket packet, CallbackInfo info) { + private void ocfg$commands$setup(SCommandListPacket packet, CallbackInfo info) { // Add the commands to the vanilla dispatcher for completion. // It's done here because both the server and the client commands have // to be in the same dispatcher and completion results. - ClientCommandInternals.addCommands((CommandDispatcher) this.commandDispatcher, (ClientCommandSource) this.clientSuggestionProvider); + ClientCommandInternals.addCommands((CommandDispatcher) this.commandDispatcher, this.clientSuggestionProvider); } } diff --git a/versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/hypixel/CustomPayloadS2CPacketMixin.java b/versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/hypixel/CustomPayloadS2CPacketMixin.java new file mode 100644 index 000000000..1af448fda --- /dev/null +++ b/versions/1.20.4-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/hypixel/CustomPayloadS2CPacketMixin.java @@ -0,0 +1,48 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.internal.mixin.hypixel; + +import net.hypixel.modapi.HypixelModAPI; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.packet.CustomPayload; +import net.minecraft.network.packet.s2c.common.CustomPayloadS2CPacket; +import net.minecraft.util.Identifier; +import org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternalsImpl; +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.CallbackInfoReturnable; + +@Mixin(CustomPayloadS2CPacket.class) +public class CustomPayloadS2CPacketMixin { + @Inject(method = "readPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/packet/s2c/common/CustomPayloadS2CPacket;readUnknownPayload(Lnet/minecraft/util/Identifier;Lnet/minecraft/network/PacketByteBuf;)Lnet/minecraft/network/packet/UnknownCustomPayload;"), cancellable = true) + private static void oneconfig$captureHypixelPacket(Identifier id, PacketByteBuf buf, CallbackInfoReturnable cir) { + if (HypixelModAPI.getInstance().getRegistry().isRegistered(id.toString())) { + cir.setReturnValue(new HypixelApiInternalsImpl.Payload(id, buf)); + } + } +} diff --git a/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler.java b/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler.java index 073239468..c592e8a46 100644 --- a/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler.java +++ b/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler.java @@ -25,7 +25,6 @@ */ package org.polyfrost.oneconfig.api.commands.v1.internal; -//#if MC<=11202 import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ChatScreen; @@ -149,5 +148,4 @@ public void autoComplete(String leftOfCursor) { //$$ return net.minecraft.client.MinecraftClient.getInstance().getServer(); //$$ } //#endif -} -//#endif \ No newline at end of file +} \ No newline at end of file diff --git a/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java b/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java index a1bf21b09..596f91232 100644 --- a/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java +++ b/versions/1.8.9-fabric/src/main/java/org/polyfrost/oneconfig/internal/mixin/fabric/NetHandlerPlayClientMixin.java @@ -69,7 +69,7 @@ public abstract class NetHandlerPlayClientMixin { ) { ocfg$chatEvent = new ChatReceiveEvent(packet.getMessage()); EventManager.INSTANCE.post(ocfg$chatEvent); - return ocfg$chatEvent.message; + return ocfg$chatEvent.getMessage(); } return packet.getMessage(); } diff --git a/versions/api/platform.api b/versions/api/platform.api index 8a7a52d70..fae8e9f8d 100644 --- a/versions/api/platform.api +++ b/versions/api/platform.api @@ -7,250 +7,6 @@ public class org/polyfrost/oneconfig/api/commands/v1/arguments/PlayerArgumentPar public synthetic fun parse (Ljava/lang/String;)Ljava/lang/Object; } -@1.12.2-fabric,1.8.9-fabric -public class org/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler : net/minecraft/server/command/CommandRegistry { - public static final field instance Lorg/polyfrost/oneconfig/api/commands/v1/internal/ClientCommandHandler; - public field latestAutoComplete [Ljava/lang/String; - public fun ()V - public fun autoComplete (Ljava/lang/String;)V - public fun execute (Lnet/minecraft/command/CommandSource;Ljava/lang/String;)I - @1.12.2-fabric - protected fun getServer ()Lnet/minecraft/server/MinecraftServer; -} - -public class org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl : org/polyfrost/oneconfig/api/commands/v1/factories/PlatformCommandFactory { - public fun ()V - public fun createCommand (Lorg/polyfrost/oneconfig/api/commands/v1/CommandTree;)Z -} - -@1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.17.1-forge,1.18.1-fabric,1.18.1-forge,1.19.4-fabric,1.19.4-forge,1.20.4-fabric,1.20.4-forge -public class org/polyfrost/oneconfig/api/commands/v1/internal/RegisterCommandsEvent : org/polyfrost/oneconfig/api/event/v1/events/Event { - public final field dispatcher Lcom/mojang/brigadier/CommandDispatcher; - public fun (Lcom/mojang/brigadier/CommandDispatcher;)V -} - -public class org/polyfrost/oneconfig/api/event/v1/events/ChatReceiveEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - @1.8.9-forge - public field message Lnet/minecraft/util/IChatComponent; - @1.8.9-forge - public fun (Lnet/minecraft/util/IChatComponent;)V - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public field message Lnet/minecraft/network/chat/Component; - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun (Lnet/minecraft/network/chat/Component;)V - @1.12.2-forge,1.16.5-forge - public field message Lnet/minecraft/util/text/ITextComponent; - @1.12.2-forge,1.16.5-forge - public fun (Lnet/minecraft/util/text/ITextComponent;)V - @1.12.2-fabric,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public field message Lnet/minecraft/text/Text; - @1.12.2-fabric,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public fun (Lnet/minecraft/text/Text;)V - public fun getFullyUnformattedMessage ()Ljava/lang/String; -} - -public class org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - @1.19.4-fabric,1.20.4-fabric - public final field packet Lnet/minecraft/network/packet/Packet; - @1.19.4-fabric,1.20.4-fabric - public fun (Lnet/minecraft/network/packet/Packet;)V - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public final field packet Lnet/minecraft/network/protocol/Packet; - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun (Lnet/minecraft/network/protocol/Packet;)V - @1.16.5-forge - public final field packet Lnet/minecraft/network/IPacket; - @1.16.5-forge - public fun (Lnet/minecraft/network/IPacket;)V - @1.12.2-fabric,1.12.2-forge,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.8.9-fabric,1.8.9-forge - public final field packet Lnet/minecraft/network/Packet; - @1.12.2-fabric,1.12.2-forge,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.8.9-fabric,1.8.9-forge - public fun (Lnet/minecraft/network/Packet;)V -} - -public class org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public final field screen Lnet/minecraft/client/gui/screens/Screen; - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun (Lnet/minecraft/client/gui/screens/Screen;)V - @1.12.2-forge,1.8.9-forge - public final field screen Lnet/minecraft/client/gui/GuiScreen; - @1.12.2-forge,1.8.9-forge - public fun (Lnet/minecraft/client/gui/GuiScreen;)V - @1.12.2-fabric,1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public final field screen Lnet/minecraft/client/gui/screen/Screen; - @1.12.2-fabric,1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public fun (Lnet/minecraft/client/gui/screen/Screen;)V -} - -public class org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent : org/polyfrost/oneconfig/api/event/v1/events/Event$Cancellable { - @1.19.4-fabric,1.20.4-fabric - public final field packet Lnet/minecraft/network/packet/Packet; - @1.19.4-fabric,1.20.4-fabric - public fun (Lnet/minecraft/network/packet/Packet;)V - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public final field packet Lnet/minecraft/network/protocol/Packet; - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun (Lnet/minecraft/network/protocol/Packet;)V - @1.16.5-forge - public final field packet Lnet/minecraft/network/IPacket; - @1.16.5-forge - public fun (Lnet/minecraft/network/IPacket;)V - @1.12.2-fabric,1.12.2-forge,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.8.9-fabric,1.8.9-forge - public final field packet Lnet/minecraft/network/Packet; - @1.12.2-fabric,1.12.2-forge,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.8.9-fabric,1.8.9-forge - public fun (Lnet/minecraft/network/Packet;)V -} - -public class org/polyfrost/oneconfig/api/platform/v1/internal/GLPlatformImpl : org/polyfrost/oneconfig/api/platform/v1/GLPlatform { - public fun ()V - public fun drawRect (FFFFI)V - public fun drawText (Lorg/polyfrost/universal/UMatrixStack;Ljava/lang/String;FFIZ)F - public fun getFunctionAddress (Ljava/lang/String;)J - public fun getStringWidth (Ljava/lang/String;)I -} - -public class org/polyfrost/oneconfig/api/platform/v1/internal/GuiPlatformImpl : org/polyfrost/oneconfig/api/platform/v1/GuiPlatform { - public fun ()V - public synthetic fun getCurrentScreen ()Ljava/lang/Object; - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun getCurrentScreen ()Lnet/minecraft/client/gui/screens/Screen; - @1.12.2-forge,1.8.9-forge - public fun getCurrentScreen ()Lnet/minecraft/client/gui/GuiScreen; - @1.12.2-fabric,1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public fun getCurrentScreen ()Lnet/minecraft/client/gui/screen/Screen; - public fun isInChat ()Z - public fun isInDebug ()Z - public fun playClickSound ()V - public fun setCurrentScreen (Ljava/lang/Object;)V -} - -public class org/polyfrost/oneconfig/api/platform/v1/internal/I18nPlatformImpl : org/polyfrost/oneconfig/api/platform/v1/I18nPlatform { - public fun ()V - public fun format (Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String; - public fun getKeyName (II)Ljava/lang/String; -} - -public class org/polyfrost/oneconfig/api/platform/v1/internal/LoaderPlatformImpl : org/polyfrost/oneconfig/api/platform/v1/LoaderPlatform { - public fun ()V - public fun getLoadedMods ()Ljava/util/List; - public fun getLoader ()Lorg/polyfrost/oneconfig/api/platform/v1/LoaderPlatform$Loaders; - public fun getMinecraftVersion ()I - public fun isDevelopmentEnvironment ()Z - public fun isModLoaded (Ljava/lang/String;)Z - public fun toActiveMod (Ljava/lang/Object;)Lorg/polyfrost/oneconfig/api/platform/v1/LoaderPlatform$ActiveMod; -} - -public class org/polyfrost/oneconfig/api/platform/v1/internal/PlayerPlatformImpl : org/polyfrost/oneconfig/api/platform/v1/PlayerPlatform { - public fun ()V - public fun doesPlayerExist ()Z - public fun getClientBrand ()Ljava/lang/String; - public fun getPlayerName ()Ljava/lang/String; - public fun inMultiplayer ()Z -} - -public final class org/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler { - public static final field INSTANCE Lorg/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler; - public static fun init ()V - public static fun isBlurring ()Z - public fun isShaderActive ()Z -} - -@1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.17.1-forge,1.18.1-fabric,1.18.1-forge,1.19.4-fabric,1.19.4-forge,1.20.4-fabric,1.20.4-forge -public class org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl : org/polyfrost/oneconfig/api/ui/v1/UIManager { - public fun ()V - public fun getRenderer ()Lorg/polyfrost/polyui/renderer/Renderer; - public fun getTinyFD ()Lorg/polyfrost/oneconfig/api/ui/v1/TinyFD; -} - -@1.12.2-fabric,1.12.2-forge,1.8.9-fabric,1.8.9-forge -public class org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl : java/net/URLClassLoader, org/polyfrost/oneconfig/api/ui/v1/UIManager { - public fun ()V - public fun (Z)V - protected fun findClass (Ljava/lang/String;)Ljava/lang/Class; - public fun getRenderer ()Lorg/polyfrost/polyui/renderer/Renderer; - public fun getTinyFD ()Lorg/polyfrost/oneconfig/api/ui/v1/TinyFD; - protected fun loadClass (Ljava/lang/String;Z)Ljava/lang/Class; -} - -public class org/polyfrost/oneconfig/api/ui/v1/screen/MCWindow : org/polyfrost/polyui/renderer/Window { - @1.12.2-forge,1.16.5-forge,1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge,1.8.9-forge - public fun (Lnet/minecraft/client/Minecraft;)V - @1.12.2-fabric,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public fun (Lnet/minecraft/client/MinecraftClient;)V - public fun close ()V - public fun getClipboard ()Ljava/lang/String; - public fun getKeyName (I)Ljava/lang/String; - public fun open (Lorg/polyfrost/polyui/PolyUI;)Lorg/polyfrost/polyui/renderer/Window; - public fun setClipboard (Ljava/lang/String;)V - public fun setCursor (Lorg/polyfrost/polyui/renderer/data/Cursor;)V - public fun supportsRenderPausing ()Z -} - -public class org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen : org/polyfrost/universal/UScreen, org/polyfrost/oneconfig/api/ui/v1/screen/BlurScreen, org/polyfrost/oneconfig/api/ui/v1/screen/UIPause { - public field blurs Z - public final field desiredResolution Lorg/polyfrost/polyui/unit/Vec2; - public final field inputManager Lorg/polyfrost/polyui/event/InputManager; - public field pauses Z - public final field polyUI Lorg/polyfrost/polyui/PolyUI; - public fun (Lorg/polyfrost/polyui/PolyUI;)V - public fun (Lorg/polyfrost/polyui/event/InputManager;)V - public fun (Lorg/polyfrost/polyui/property/Settings;Lorg/polyfrost/polyui/event/InputManager;Lorg/polyfrost/polyui/input/Translator;Lorg/polyfrost/polyui/unit/Align;Lorg/polyfrost/polyui/color/Colors;Lorg/polyfrost/polyui/color/PolyColor;Lorg/polyfrost/polyui/unit/Vec2;Lorg/polyfrost/polyui/unit/Vec2;[Lorg/polyfrost/polyui/component/Drawable;)V - public fun (Lorg/polyfrost/polyui/unit/Align;Lorg/polyfrost/polyui/unit/Vec2;[Lorg/polyfrost/polyui/component/Drawable;)V - public fun ([Lorg/polyfrost/polyui/component/Drawable;)V - protected final fun adjustResolution (FFZ)V - public final fun closeCallback (Ljava/lang/Runnable;)Lorg/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen; - @1.12.2-forge,1.8.9-forge - public fun doesGuiPauseGame ()Z - public fun doesUIPauseGame ()Z - public final fun getMaster ()Lorg/polyfrost/polyui/component/Drawable; - public fun hasBackgroundBlur ()Z - public final fun height ()F - @1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public fun isPauseScreen ()Z - public fun mouseMoved (DD)V - public fun onDrawScreen (Lorg/polyfrost/universal/UMatrixStack;IIF)V - @1.12.2-forge,1.8.9-forge - public final fun onResize (Lnet/minecraft/client/Minecraft;II)V - public fun onScreenClose ()V - @1.16.5-forge,1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public final fun resize (Lnet/minecraft/client/Minecraft;II)V - @1.12.2-fabric,1.16.5-fabric,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public final fun resize (Lnet/minecraft/client/MinecraftClient;II)V - public final fun scale ()F - public fun shouldCloseOnEsc ()Z - @1.18.1-fabric,1.19.4-fabric,1.20.4-fabric - public fun shouldPause ()Z - @1.12.2-fabric,1.8.9-fabric - public fun shouldPauseGame ()Z - public fun uCharTyped (CLorg/polyfrost/universal/UKeyboard$Modifiers;)Z - public fun uKeyPressed (IILorg/polyfrost/universal/UKeyboard$Modifiers;)Z - public fun uKeyReleased (IILorg/polyfrost/universal/UKeyboard$Modifiers;)Z - public fun uMouseClicked (DDI)Z - public fun uMouseReleased (DDI)Z - public fun uMouseScrolled (D)Z - public fun useMinecraftUIScaling ()Z - public final fun width ()F -} - -public final class org/polyfrost/oneconfig/utils/v1/GuiUtils { - public fun ()V - public static fun closeScreen ()V - public static fun displayScreen (Ljava/lang/Object;)V - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public static fun displayScreen (Lnet/minecraft/client/gui/screens/Screen;)V - @1.17.1-forge,1.18.1-forge,1.19.4-forge,1.20.4-forge - public static fun displayScreen (Lnet/minecraft/client/gui/screens/Screen;I)V - @1.12.2-forge,1.8.9-forge - public static fun displayScreen (Lnet/minecraft/client/gui/GuiScreen;)V - @1.12.2-forge,1.8.9-forge - public static fun displayScreen (Lnet/minecraft/client/gui/GuiScreen;I)V - @1.12.2-fabric,1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public static fun displayScreen (Lnet/minecraft/client/gui/screen/Screen;)V - @1.12.2-fabric,1.16.5-fabric,1.16.5-forge,1.17.1-fabric,1.18.1-fabric,1.19.4-fabric,1.20.4-fabric,1.8.9-fabric - public static fun displayScreen (Lnet/minecraft/client/gui/screen/Screen;I)V -} - @1.12.2-forge,1.8.9-forge public class org/polyfrost/oneconfig/utils/v1/forge/KotlinLanguageAdapter : net/minecraftforge/fml/common/ILanguageAdapter { public fun ()V diff --git a/versions/build.gradle.kts b/versions/build.gradle.kts index a17710410..aa083c906 100644 --- a/versions/build.gradle.kts +++ b/versions/build.gradle.kts @@ -56,6 +56,7 @@ repositories { mavenLocal() mavenCentral() maven("https://repo.polyfrost.org/releases") + maven("https://repo.hypixel.net/repository/Hypixel") } val shade: Configuration by configurations.creating { @@ -91,8 +92,10 @@ dependencies { shade(libs.bundles.kotlin) shade(libs.bundles.kotlinx) + shade(libs.hypixel.modapi) + for (project in rootProject.project(":modules").subprojects) { - // TODO: ModLauncher (forge-1.17+) fail to to module export issues + // TODO: ModLauncher (forge-1.17+) fails due to module export issues shade(project(project.path)) { isTransitive = false } diff --git a/versions/mappings/fabric-1.17.1-1.16.5.txt b/versions/mappings/fabric-1.17.1-1.16.5.txt index 52912254d..7a2d77f5a 100644 --- a/versions/mappings/fabric-1.17.1-1.16.5.txt +++ b/versions/mappings/fabric-1.17.1-1.16.5.txt @@ -1,2 +1,2 @@ +com.mojang.blaze3d.platform.GlStateManager _glFramebufferTexture2D() framebufferTexture2D() com.mojang.blaze3d.platform.GlStateManager _texImage2D() texImage2D() -com.mojang.blaze3d.platform.GlStateManager _glFramebufferTexture2D() framebufferTexture2D() \ No newline at end of file diff --git a/versions/mappings/fabric-1.19.4-1.18.1.txt b/versions/mappings/fabric-1.19.4-1.18.1.txt index 6412996e7..03057a564 100644 --- a/versions/mappings/fabric-1.19.4-1.18.1.txt +++ b/versions/mappings/fabric-1.19.4-1.18.1.txt @@ -1,2 +1,2 @@ +net.minecraft.network.packet.s2c.play.GameMessageS2CPacket content() getMessage() net.minecraft.text.Text getString() asString() -net.minecraft.network.packet.s2c.play.GameMessageS2CPacket content() getMessage() \ No newline at end of file diff --git a/versions/mappings/fabric-forge-1.16.5.txt b/versions/mappings/fabric-forge-1.16.5.txt index 0666f1703..d402a0348 100644 --- a/versions/mappings/fabric-forge-1.16.5.txt +++ b/versions/mappings/fabric-forge-1.16.5.txt @@ -1,2 +1,2 @@ net.minecraft.util.profiler.Profiler net.minecraft.profiler.Profiler -net.minecraft.util.registry.RegistryKey net.minecraft.util.RegistryKey \ No newline at end of file +net.minecraft.util.registry.RegistryKey net.minecraft.util.RegistryKey diff --git a/versions/mappings/fabric-forge-1.8.9.txt b/versions/mappings/fabric-forge-1.8.9.txt index 8272834d8..2455bf64f 100644 --- a/versions/mappings/fabric-forge-1.8.9.txt +++ b/versions/mappings/fabric-forge-1.8.9.txt @@ -1,12 +1,13 @@ +org.objectweb.asm.tree.AbstractInsnNode org.spongepowered.asm.lib.tree.AbstractInsnNode org.objectweb.asm.tree.ClassNode org.spongepowered.asm.lib.tree.ClassNode +org.objectweb.asm.commons.ClassRemapper org.objectweb.asm.commons.RemappingClassAdapter +org.objectweb.asm.tree.FieldInsnNode org.spongepowered.asm.lib.tree.FieldInsnNode org.objectweb.asm.tree.FieldNode org.spongepowered.asm.lib.tree.FieldNode -org.objectweb.asm.tree.MethodNode org.spongepowered.asm.lib.tree.MethodNode -org.objectweb.asm.tree.AbstractInsnNode org.spongepowered.asm.lib.tree.AbstractInsnNode org.objectweb.asm.tree.InsnList org.spongepowered.asm.lib.tree.InsnList +org.objectweb.asm.tree.InsnNode org.spongepowered.asm.lib.tree.InsnNode +org.objectweb.asm.tree.JumpInsnNode org.spongepowered.asm.lib.tree.JumpInsnNode org.objectweb.asm.tree.LabelNode org.spongepowered.asm.lib.tree.LabelNode org.objectweb.asm.tree.LineNumberNode org.spongepowered.asm.lib.tree.LineNumberNode +org.objectweb.asm.tree.MethodInsnNode org.spongepowered.asm.lib.tree.MethodInsnNode +org.objectweb.asm.tree.MethodNode org.spongepowered.asm.lib.tree.MethodNode org.objectweb.asm.tree.VarInsnNode org.spongepowered.asm.lib.tree.VarInsnNode -org.objectweb.asm.tree.FieldInsnNode org.spongepowered.asm.lib.tree.FieldInsnNode -org.objectweb.asm.tree.InsnNode org.spongepowered.asm.lib.tree.InsnNode -org.objectweb.asm.tree.JumpInsnNode org.spongepowered.asm.lib.tree.JumpInsnNode -org.objectweb.asm.tree.MethodInsnNode org.spongepowered.asm.lib.tree.MethodInsnNode \ No newline at end of file diff --git a/versions/mappings/forge-1.12.2-1.8.9.txt b/versions/mappings/forge-1.12.2-1.8.9.txt index ac9c64283..c578c2bdf 100644 --- a/versions/mappings/forge-1.12.2-1.8.9.txt +++ b/versions/mappings/forge-1.12.2-1.8.9.txt @@ -1,5 +1,12 @@ -net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent -net.minecraft.util.math.BlockPos net.minecraft.util.BlockPos net.minecraft.client.renderer.BufferBuilder net.minecraft.client.renderer.WorldRenderer + net.minecraft.command.ICommand getName() getCommandName() -net.minecraft.command.ICommand getUsage() getCommandUsage() \ No newline at end of file +net.minecraft.command.ICommand getUsage() getCommandUsage() + +net.minecraft.network.play.client.CPacketCustomPayload net.minecraft.network.play.client.C17PacketCustomPayload +net.minecraft.network.play.server.SPacketCustomPayload net.minecraft.network.play.server.S3FPacketCustomPayload + +net.minecraft.util.math.BlockPos net.minecraft.util.BlockPos + +net.minecraft.util.text.ITextComponent net.minecraft.util.IChatComponent +net.minecraft.util.text.TextFormatting net.minecraft.util.EnumChatFormatting \ No newline at end of file diff --git a/versions/mappings/forge-1.16.5-1.12.2.txt b/versions/mappings/forge-1.16.5-1.12.2.txt index 6cd16b6a3..20fca3ef6 100644 --- a/versions/mappings/forge-1.16.5-1.12.2.txt +++ b/versions/mappings/forge-1.16.5-1.12.2.txt @@ -1,35 +1,60 @@ -net.minecraft.util.text.ITextComponent getUnformattedComponentText() getUnformattedText() -net.minecraft.network.IPacket net.minecraft.network.Packet -net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen -net.minecraft.client.gui.screen.Screen resize() onResize() -net.minecraft.client.gui.screen.Screen isPauseScreen() doesGuiPauseGame() -net.minecraft.client.gui.screen.ChatScreen net.minecraft.client.gui.GuiChat +net.minecraft.client.Minecraft gameRenderer entityRenderer net.minecraft.client.Minecraft getInstance() getMinecraft() net.minecraft.client.Minecraft isOnExecutionThread() isCallingFromMinecraftThread() + net.minecraft.client.entity.EntityPlayerSP getServerBrand() getClientBrand() net.minecraft.client.entity.player.ClientPlayerEntity net.minecraft.client.entity.EntityPlayerSP -net.minecraft.client.Minecraft gameRenderer entityRenderer + +net.minecraft.client.gui.screen.ChatScreen net.minecraft.client.gui.GuiChat + +net.minecraft.client.gui.screen.Screen isPauseScreen() doesGuiPauseGame() +net.minecraft.client.gui.screen.Screen net.minecraft.client.gui.GuiScreen +net.minecraft.client.gui.screen.Screen resize() onResize() + +net.minecraft.client.gui.widget.button.Button net.minecraft.client.gui.GuiButton +net.minecraft.client.gui.widget.button.Button playDownSound() playPressSound() + +net.minecraft.client.network.play.ClientPlayNetHandler net.minecraft.client.network.NetHandlerPlayClient +net.minecraft.client.network.play.NetworkPlayerInfo net.minecraft.client.network.NetworkPlayerInfo + net.minecraft.client.shader.ShaderDefault net.minecraft.client.shader.ShaderUniform +net.minecraft.client.shader.ShaderInstance net.minecraft.client.shader.ShaderManager + net.minecraft.client.world.ClientWorld net.minecraft.client.multiplayer.WorldClient -net.minecraft.client.network.play.NetworkPlayerInfo net.minecraft.client.network.NetworkPlayerInfo -net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent net.minecraftforge.fml.common.event.FMLInitializationEvent -net.minecraftforge.fml.common.Loader get() instance() -net.minecraftforge.fml.common.Loader getActiveContainer() activeModContainer() -net.minecraftforge.fml.ModLoadingContext net.minecraftforge.fml.common.Loader -net.minecraftforge.fml.ModContainer net.minecraftforge.fml.common.ModContainer +net.minecraft.network.IPacket net.minecraft.network.Packet + +net.minecraft.network.play.client.CCustomPayloadPacket net.minecraft.network.play.client.CPacketCustomPayload +net.minecraft.network.play.server.SCustomPayloadPlayPacket net.minecraft.network.play.server.SPacketCustomPayload + +net.minecraft.profiler.IProfiler net.minecraft.profiler.Profiler + +net.minecraft.util.text.ITextComponent getUnformattedComponentText() getUnformattedText() + +net.minecraftforge.client.event.ClientPlayerNetworkEvent getNetworkManager() getManager() +net.minecraftforge.client.event.ClientPlayerNetworkEvent net.minecraftforge.fml.common.network.FMLNetworkEvent +net.minecraftforge.client.event.ClientPlayerNetworkEvent$LoggedInEvent net.minecraftforge.fml.common.network.FMLNetworkEvent$ClientConnectedToServerEvent net.minecraftforge.client.gui.ForgeIngameGui net.minecraftforge.client.GuiIngameForge + net.minecraftforge.eventbus.EventBus net.minecraftforge.fml.common.eventhandler.EventBus net.minecraftforge.eventbus.api.Event net.minecraftforge.fml.common.eventhandler.Event +net.minecraftforge.eventbus.api.SubscribeEvent net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +net.minecraftforge.fml.ModContainer net.minecraftforge.fml.common.ModContainer +net.minecraftforge.fml.ModLoadingContext net.minecraftforge.fml.common.Loader +net.minecraftforge.fml.common.Loader get() instance() +net.minecraftforge.fml.common.Loader getActiveContainer() activeModContainer() + +net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent net.minecraftforge.fml.common.event.FMLInitializationEvent org.objectweb.asm.tree.ClassNode org.spongepowered.asm.lib.tree.ClassNode +org.objectweb.asm.tree.FieldInsnNode org.spongepowered.asm.lib.tree.FieldInsnNode org.objectweb.asm.tree.FieldNode org.spongepowered.asm.lib.tree.FieldNode -org.objectweb.asm.tree.MethodNode org.spongepowered.asm.lib.tree.MethodNode +org.objectweb.asm.tree.InsnList org.spongepowered.asm.lib.tree.InsnList +org.objectweb.asm.tree.InsnNode org.spongepowered.asm.lib.tree.InsnNode +org.objectweb.asm.tree.JumpInsnNode org.spongepowered.asm.lib.tree.JumpInsnNode org.objectweb.asm.tree.LabelNode org.spongepowered.asm.lib.tree.LabelNode org.objectweb.asm.tree.LineNumberNode org.spongepowered.asm.lib.tree.LineNumberNode -org.objectweb.asm.tree.VarInsnNode org.spongepowered.asm.lib.tree.VarInsnNode -org.objectweb.asm.tree.FieldInsnNode org.spongepowered.asm.lib.tree.FieldInsnNode org.objectweb.asm.tree.MethodInsnNode org.spongepowered.asm.lib.tree.MethodInsnNode -org.objectweb.asm.tree.InsnList org.spongepowered.asm.lib.tree.InsnList -org.objectweb.asm.tree.InsnNode org.spongepowered.asm.lib.tree.InsnNode -org.objectweb.asm.tree.JumpInsnNode org.spongepowered.asm.lib.tree.JumpInsnNode \ No newline at end of file +org.objectweb.asm.tree.MethodNode org.spongepowered.asm.lib.tree.MethodNode +org.objectweb.asm.tree.VarInsnNode org.spongepowered.asm.lib.tree.VarInsnNode diff --git a/versions/mappings/forge-1.17.1-1.16.5.txt b/versions/mappings/forge-1.17.1-1.16.5.txt new file mode 100644 index 000000000..273cd1109 --- /dev/null +++ b/versions/mappings/forge-1.17.1-1.16.5.txt @@ -0,0 +1,177 @@ +com.mojang.blaze3d.pipeline.RenderTarget blitToScreen() framebufferRender() +com.mojang.blaze3d.pipeline.RenderTarget net.minecraft.client.shader.Framebuffer + +com.mojang.blaze3d.platform.InputConstants getKey() getInputByCode() +com.mojang.blaze3d.platform.InputConstants net.minecraft.client.util.InputMappings +com.mojang.blaze3d.platform.InputConstants$Key getDisplayName() func_237520_d_() + +com.mojang.blaze3d.platform.Window getWindow() getHandle() +com.mojang.blaze3d.platform.Window getScreenWidth() getWidth() +com.mojang.blaze3d.platform.Window getScreenHeight() getHeight() +com.mojang.blaze3d.platform.Window getWidth() getFramebufferWidth() +com.mojang.blaze3d.platform.Window getHeight() getFramebufferHeight() + +com.mojang.blaze3d.platform.Window net.minecraft.client.MainWindow + +com.mojang.blaze3d.shaders.AbstractUniform net.minecraft.client.shader.ShaderDefault + +com.mojang.blaze3d.vertex.BufferBuilder net.minecraft.client.renderer.BufferBuilder +com.mojang.blaze3d.vertex.BufferBuilder vertex() pos() + +com.mojang.blaze3d.vertex.DefaultVertexFormat net.minecraft.client.renderer.vertex.DefaultVertexFormats +com.mojang.blaze3d.vertex.PoseStack com.mojang.blaze3d.matrix.MatrixStack + +com.mojang.blaze3d.vertex.Tesselator end() draw() +com.mojang.blaze3d.vertex.Tesselator getBuilder() getBuffer() +com.mojang.blaze3d.vertex.Tesselator net.minecraft.client.renderer.Tessellator + +net.minecraft.ChatFormatting net.minecraft.util.text.TextFormatting +net.minecraft.ChatFormatting stripFormatting() getTextWithoutFormattingCodes() + +net.minecraft.CrashReport net.minecraft.crash.CrashReport + +net.minecraft.client.KeyboardHandler charTyped() onCharEvent() +net.minecraft.client.KeyboardHandler keyPress() onKeyEvent() +net.minecraft.client.KeyboardHandler net.minecraft.client.KeyboardListener + +net.minecraft.client.Minecraft destroy() shutdownMinecraftApplet() +net.minecraft.client.Minecraft font fontRenderer +net.minecraft.client.Minecraft getSoundManager() getSoundHandler() +net.minecraft.client.Minecraft getUser() getSession() +net.minecraft.client.Minecraft getWindow() getMainWindow() +net.minecraft.client.Minecraft gui ingameGUI +net.minecraft.client.Minecraft hasSingleplayerServer() isSingleplayer() +net.minecraft.client.Minecraft level world +net.minecraft.client.Minecraft mouseHandler mouseHelper +net.minecraft.client.Minecraft options gameSettings +net.minecraft.client.Minecraft resizeDisplay() updateWindowSize() +net.minecraft.client.Minecraft runTick() runGameLoop() +net.minecraft.client.Minecraft screen currentScreen +net.minecraft.client.Minecraft setScreen() displayGuiScreen() + +net.minecraft.client.MouseHandler net.minecraft.client.MouseHelper +net.minecraft.client.MouseHandler xpos() getMouseX() +net.minecraft.client.MouseHandler ypos() getMouseY() + +net.minecraft.client.Options net.minecraft.client.GameSettings +net.minecraft.client.Options renderDebug showDebugInfo + +net.minecraft.client.Timer net.minecraft.util.Timer +net.minecraft.client.Timer partialTick renderPartialTicks + +net.minecraft.client.User getName() getUsername() +net.minecraft.client.User net.minecraft.util.Session + +net.minecraft.client.gui.Font draw() drawString() +net.minecraft.client.gui.Font drawShadow() drawStringWithShadow() +net.minecraft.client.gui.Font net.minecraft.client.gui.FontRenderer +net.minecraft.client.gui.Font width() getStringWidth() + +net.minecraft.client.gui.Gui getChat() getChatGUI() +net.minecraft.client.gui.Gui net.minecraft.client.gui.IngameGui + +net.minecraft.client.gui.components.Button net.minecraft.client.gui.widget.button.Button +net.minecraft.client.gui.components.ChatComponent addMessage() printChatMessage() +net.minecraft.client.gui.components.ChatComponent net.minecraft.client.gui.NewChatGui + +net.minecraft.client.gui.screens.ChatScreen net.minecraft.client.gui.screen.ChatScreen +net.minecraft.client.gui.screens.Screen net.minecraft.client.gui.screen.Screen + +net.minecraft.client.multiplayer.ClientLevel$ClientLevelData net.minecraft.client.multiplayer.ClientLevel$ClientWorldInfo +net.minecraft.client.multiplayer.ClientLevel net.minecraft.client.world.ClientWorld + +net.minecraft.client.multiplayer.ClientPacketListener commands commandDispatcher +net.minecraft.client.multiplayer.ClientPacketListener getSuggestionsProvider() getSuggestionProvider() +net.minecraft.client.multiplayer.ClientPacketListener handleCommands() handleCommandList() +net.minecraft.client.multiplayer.ClientPacketListener handleLogin() handleJoinGame() +net.minecraft.client.multiplayer.ClientPacketListener net.minecraft.client.network.play.ClientPlayNetHandler +net.minecraft.client.multiplayer.ClientPacketListener send() sendPacket() +net.minecraft.client.multiplayer.ClientPacketListener suggestionsProvider clientSuggestionProvider +net.minecraft.client.multiplayer.ClientSuggestionProvider minecraft mc + +net.minecraft.client.player.LocalPlayer chat() sendChatMessage() +net.minecraft.client.player.LocalPlayer net.minecraft.client.entity.player.ClientPlayerEntity + +net.minecraft.client.renderer.EffectInstance getUniform() getShaderUniform() +net.minecraft.client.renderer.EffectInstance net.minecraft.client.shader.ShaderInstance + +net.minecraft.client.renderer.GameRenderer currentEffect() getShaderGroup() +net.minecraft.client.renderer.GameRenderer loadEffect() loadShader() +net.minecraft.client.renderer.GameRenderer render() updateCameraAndRender() +net.minecraft.client.renderer.GameRenderer shutdownEffect() stopUseShader() + +net.minecraft.client.renderer.LevelRenderer net.minecraft.client.renderer.WorldRenderer + +net.minecraft.client.renderer.PostChain getName() getShaderGroupName() +net.minecraft.client.renderer.PostChain net.minecraft.client.shader.ShaderGroup +net.minecraft.client.renderer.PostChain passes listShaders +net.minecraft.client.renderer.PostPass getEffect() getShaderManager() +net.minecraft.client.renderer.PostPass net.minecraft.client.shader.Shader + +net.minecraft.client.resources.language.I18n get() format() +net.minecraft.client.resources.language.I18n net.minecraft.client.resources.I18n + +net.minecraft.commands.SharedSuggestionProvider net.minecraft.command.ISuggestionProvider + +net.minecraft.commands.arguments.EntityArgument net.minecraft.command.arguments.EntityArgument +net.minecraft.commands.arguments.GameProfileArgument net.minecraft.command.arguments.GameProfileArgument +net.minecraft.commands.arguments.coordinates.BlockPosArgument net.minecraft.command.arguments.BlockPosArgument +net.minecraft.commands.arguments.item.ItemArgument net.minecraft.command.arguments.ItemArgument + +net.minecraft.core.BlockPos net.minecraft.util.math.BlockPos + +net.minecraft.resources.ResourceKey net.minecraft.util.RegistryKey + +net.minecraft.network.Connection net.minecraft.network.NetworkManager +net.minecraft.network.Connection send() sendPacket() + +net.minecraft.network.FriendlyByteBuf net.minecraft.network.PacketBuffer + +net.minecraft.network.chat.ChatType net.minecraft.util.text.ChatType + +net.minecraft.network.chat.Component getContents() getUnformattedComponentText() +net.minecraft.network.chat.Component net.minecraft.util.text.ITextComponent +net.minecraft.network.chat.Component nullToEmpty() getTextComponentOrEmpty() +net.minecraft.network.chat.ComponentUtils fromMessage() toTextComponent() +net.minecraft.network.chat.ComponentUtils net.minecraft.util.text.TextComponentUtils + +net.minecraft.network.chat.MutableComponent net.minecraft.util.text.IFormattableTextComponent +net.minecraft.network.chat.MutableComponent withStyle() mergeStyle() +net.minecraft.network.chat.TextComponent net.minecraft.util.text.StringTextComponent +net.minecraft.network.chat.TranslatableComponent net.minecraft.util.text.TranslationTextComponent + +net.minecraft.network.protocol.Packet net.minecraft.network.IPacket + +net.minecraft.network.protocol.game.ClientboundCommandsPacket net.minecraft.network.play.server.SCommandListPacket +net.minecraft.network.protocol.game.ClientboundLoginPacket net.minecraft.network.play.server.SJoinGamePacket +net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket getData() getBufferData() +net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket getIdentifier() getChannelName() +net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket net.minecraft.network.play.server.SCustomPayloadPlayPacket +net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket net.minecraft.network.play.client.CCustomPayloadPacket + +net.minecraft.resources.ResourceLocation net.minecraft.util.ResourceLocation + +net.minecraft.server.commands.HelpCommand ERROR_FAILED FAILED_EXCEPTION +net.minecraft.server.commands.HelpCommand net.minecraft.command.impl.HelpCommand + +net.minecraft.util.datafix.DataFixers createFixerUpper() createFixer() +net.minecraft.util.datafix.DataFixers net.minecraft.util.datafix.DataFixesManager + +net.minecraft.util.profiling.ProfilerFiller net.minecraft.profiler.IProfiler +net.minecraft.util.profiling.ProfilerFiller pop() endSection() +net.minecraft.util.profiling.ProfilerFiller push() startSection() + +net.minecraft.world.level.dimension.DimensionType net.minecraft.world.DimensionType + +net.minecraft.world.entity.Entity getRotationVector() getPitchYaw() +net.minecraft.world.entity.Entity net.minecraft.entity.Entity +net.minecraft.world.entity.Entity position() getPositionVec() + +net.minecraft.world.entity.player.Player net.minecraft.entity.player.PlayerEntity + +net.minecraft.world.item.ItemStack net.minecraft.item.ItemStack + +net.minecraft.world.phys.Vec2 net.minecraft.util.math.vector.Vector2f +net.minecraft.world.phys.Vec3 net.minecraft.util.math.vector.Vector3d + +net.minecraftforge.client.gui.ForgeIngameGui render() renderIngameGui() diff --git a/versions/mappings/forge-1.18.1-1.17.1.txt b/versions/mappings/forge-1.18.1-1.17.1.txt index 5563d9848..90b8b98ab 100644 --- a/versions/mappings/forge-1.18.1-1.17.1.txt +++ b/versions/mappings/forge-1.18.1-1.17.1.txt @@ -1,3 +1,6 @@ -net.minecraftforge.client.loading.ClientModLoader net.minecraftforge.fmlclient.ClientModLoader +net.minecraftforge.client.event.ClientPlayerNetworkEvent getConnection() getNetworkManager() + +net.minecraftforge.client.event.ScreenOpenEvent getScreen() getGui() net.minecraftforge.client.event.ScreenOpenEvent net.minecraftforge.client.event.GuiOpenEvent -net.minecraftforge.client.event.ScreenOpenEvent getScreen() getGui() \ No newline at end of file + +net.minecraftforge.client.loading.ClientModLoader net.minecraftforge.fmlclient.ClientModLoader diff --git a/versions/mappings/forge-1.19.4-1.18.1.txt b/versions/mappings/forge-1.19.4-1.18.1.txt new file mode 100644 index 000000000..bc5780ac2 --- /dev/null +++ b/versions/mappings/forge-1.19.4-1.18.1.txt @@ -0,0 +1,6 @@ +net.minecraftforge.client.event.ClientPlayerNetworkEvent$LoggingIn net.minecraftforge.client.event.ClientPlayerNetworkEvent$LoggedInEvent + +net.minecraftforge.client.gui.overlay.ForgeGui net.minecraftforge.client.gui.ForgeIngameGui + +net.minecraftforge.client.event.ScreenOpenEvent getNewScreen() getScreen() +net.minecraftforge.client.event.ScreenEvent$Opening net.minecraftforge.client.event.ScreenOpenEvent diff --git a/versions/mappings/forge-1.20.4-1.19.4.txt b/versions/mappings/forge-1.20.4-1.19.4.txt new file mode 100644 index 000000000..bac901447 --- /dev/null +++ b/versions/mappings/forge-1.20.4-1.19.4.txt @@ -0,0 +1,3 @@ +net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket +net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket +net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket getInternalData() getData() \ No newline at end of file diff --git a/versions/preprocessor.gradle.kts b/versions/preprocessor.gradle.kts index 4e25026ab..1011d081a 100644 --- a/versions/preprocessor.gradle.kts +++ b/versions/preprocessor.gradle.kts @@ -20,42 +20,33 @@ preprocess { val forge11904 = createNode("1.19.4-forge", 11904, "srg") val fabric11904 = createNode("1.19.4-fabric", 11904, "yarn") val fabric12004 = createNode("1.20.4-fabric", 12004, "yarn") - val forge120004 = createNode("1.20.4-forge", 12004, "srg") + val forge12004 = createNode("1.20.4-forge", 12004, "srg") - // graph of the mappings: - // forge 1.8.9 - // -> fabric 1.8.9 - // -> fabric 1.12.2 - // -> forge 1.12.2 - // -> forge 1.16.5 - // -> fabric 1.16.5 - // -> fabric 1.17.1 - // -> forge 1.17.1 - // -> forge 1.18.1 - // -> fabric 1.18.1 - // -> fabric 1.19.4 - // -> forge 1.19.4 - // -> fabric 1.20.4 - // -> forge 1.20.4 - - forge120004.link(fabric12004) fabric12004.link(fabric11904) - forge11904.link(fabric11904) fabric11904.link(fabric11801, file("mappings/fabric-1.19.4-1.18.1.txt")) - forge11801.link(forge11701, file("mappings/forge-1.18.1-1.17.1.txt")) fabric11801.link(fabric11701) - forge11701.link(fabric11701) fabric11701.link(fabric11605, file("mappings/fabric-1.17.1-1.16.5.txt")) fabric11605.link(forge11605, file("mappings/fabric-forge-1.16.5.txt")) - forge11605.link(forge11202, file("mappings/forge-1.16.5-1.12.2.txt")) fabric11202.link(fabric10809) fabric10809.link(forge10809, file("mappings/fabric-forge-1.8.9.txt")) + + forge12004.link(forge11904, file("mappings/forge-1.20.4-1.19.4.txt")) + forge11904.link(forge11801, file("mappings/forge-1.19.4-1.18.1.txt")) + forge11801.link(forge11701, file("mappings/forge-1.18.1-1.17.1.txt")) + forge11701.link(forge11605, file("mappings/forge-1.17.1-1.16.5.txt")) + forge11605.link(forge11202, file("mappings/forge-1.16.5-1.12.2.txt")) forge11202.link(forge10809, file("mappings/forge-1.12.2-1.8.9.txt")) } apiValidation { nonPublicMarkers.add("org.polyfrost.oneconfig.api.PlatformDeclaration") ignoredPackages.add("org.polyfrost.oneconfig.internal") + ignoredPackages.add("org.polyfrost.oneconfig.api.platform.v1.internal") + ignoredPackages.add("org.polyfrost.oneconfig.api.hypixel.v0.internal") ignoredPackages.add("org.polyfrost.oneconfig.test") + for (proj in rootProject.project(":modules").subprojects) { + ignoredPackages.add("org.polyfrost.oneconfig.api.${proj.name}.v1.internal") + } } + diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java index 33bbcc0d0..3ccda24a3 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/commands/v1/internal/PlatformCommandFactoryImpl.java @@ -24,7 +24,6 @@ * */ -//#if MC<=11202 package org.polyfrost.oneconfig.api.commands.v1.internal; import net.minecraft.command.CommandBase; @@ -33,6 +32,7 @@ import org.polyfrost.oneconfig.api.commands.v1.exceptions.CommandExecutionException; import org.polyfrost.oneconfig.api.commands.v1.CommandTree; import org.polyfrost.oneconfig.api.commands.v1.factories.PlatformCommandFactory; +import org.polyfrost.oneconfig.api.ClassHasOverwrites; import org.polyfrost.universal.UChat; import org.polyfrost.oneconfig.api.commands.v1.arguments.PlayerArgumentParser; import org.apache.logging.log4j.Logger; @@ -45,6 +45,7 @@ import net.minecraftforge.client.ClientCommandHandler; //#endif +@ClassHasOverwrites("1.16.5-forge") public class PlatformCommandFactoryImpl implements PlatformCommandFactory { private static final Logger LOGGER = LogManager.getLogger("OneConfig/Commands"); @@ -75,9 +76,9 @@ public String getCommandUsage(net.minecraft.command.ICommandSender sender) { //$$ execute(net.minecraft.server.MinecraftServer server, net.minecraft.command.ICommandSender sender, String[] args) //#endif { - if(args.length == 1 && args[0].equals("help")) { - for(String s : tree.getHelp()) { - UChat.chat(s); + if (args.length == 1 && args[0].equals("help")) { + for (String s : tree.getHelp()) { + chat(s); } return; } @@ -86,16 +87,16 @@ public String getCommandUsage(net.minecraft.command.ICommandSender sender) { if (out == null) return; if (out.getClass().isArray()) { for (Object o : (Object[]) out) { - UChat.chat(o.toString()); + chat(o.toString()); } } else { - UChat.chat(out.toString()); + chat(out.toString()); } } catch (CommandExecutionException c) { - UChat.chat("&c" + c.getMessage()); + chat("&c" + c.getMessage()); LOGGER.warn(c.getMessage()); } catch (Exception e) { - UChat.chat("&cAn unknown error occurred while executing this command, please report this to the mod author!"); + chat("&cAn unknown error occurred while executing this command, please report this to the mod author!"); LOGGER.error("failed to run command method", e); } } @@ -125,5 +126,8 @@ public int getRequiredPermissionLevel() { }); return true; } -} -//#endif \ No newline at end of file + + private static void chat(String s) { + UChat.chat(s); + } +} \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java b/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java deleted file mode 100644 index 6bea1c9aa..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ReceivePacketEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.event.v1.events; - -import net.minecraft.network.Packet; -import org.polyfrost.oneconfig.api.PlatformDeclaration; - -@PlatformDeclaration -public class ReceivePacketEvent extends Event.Cancellable { - public final Packet packet; - - public ReceivePacketEvent(Packet packet) { - this.packet = packet; - } -} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java b/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java deleted file mode 100644 index 064068d93..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/ScreenOpenEvent.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.event.v1.events; - -import net.minecraft.client.gui.GuiScreen; -import org.jetbrains.annotations.Nullable; -import org.polyfrost.oneconfig.api.PlatformDeclaration; - -/** - * Called when a screen is opened or closed. - * If the screen is closed, {@link org.polyfrost.oneconfig.api.event.v1.events.ScreenOpenEvent#screen} will be null. - */ -@PlatformDeclaration -public class ScreenOpenEvent extends Event.Cancellable { - @Nullable - public final GuiScreen screen; - - public ScreenOpenEvent(@Nullable GuiScreen screen) { - this.screen = screen; - } -} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java b/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java deleted file mode 100644 index 6858aeeaa..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/SendPacketEvent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.event.v1.events; - -import net.minecraft.network.Packet; -import org.polyfrost.oneconfig.api.PlatformDeclaration; - -@PlatformDeclaration -public class SendPacketEvent extends Event.Cancellable { - public final Packet packet; - - public SendPacketEvent(Packet packet) { - this.packet = packet; - } -} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternalsImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternalsImpl.java new file mode 100644 index 000000000..1ac4dfb88 --- /dev/null +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/hypixel/v0/internal/HypixelApiInternalsImpl.java @@ -0,0 +1,153 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.api.hypixel.v0.internal; + +import io.netty.buffer.Unpooled; +import net.hypixel.modapi.HypixelModAPI; +import net.hypixel.modapi.serializer.PacketSerializer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.client.C17PacketCustomPayload; +import net.minecraft.network.play.server.S3FPacketCustomPayload; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.jetbrains.annotations.ApiStatus; +import org.polyfrost.oneconfig.api.event.v1.EventDelay; +import org.polyfrost.oneconfig.api.event.v1.EventManager; +import org.polyfrost.oneconfig.api.event.v1.events.HypixelLocationEvent; +import org.polyfrost.oneconfig.api.event.v1.events.ReceivePacketEvent; + +/** + * Heavily adapted from Hypixel/ForgeModAPI under the MIT licence. + * See here + */ +@ApiStatus.Internal +public final class HypixelApiInternalsImpl implements HypixelApiInternals { + private static final Logger LOGGER = LogManager.getLogger("OneConfig/HypixelAPI"); + + public HypixelApiInternalsImpl() { + registerHypixelApi(); + } + + + private void registerHypixelApi() { + LOGGER.info("Registering Hypixel API packet handlers"); + HypixelModAPI.getInstance().setPacketSender((packet) -> { + NetHandlerPlayClient net = Minecraft.getMinecraft().getNetHandler(); + if (net == null) { + LOGGER.warn("dropping packet {} because no net handler is available, retrying in 1s", packet); + EventDelay.tick(20, () -> HypixelModAPI.getInstance().sendPacket(packet)); + return false; + } + PacketBuffer buf = new PacketBuffer(Unpooled.buffer()); + packet.write(new PacketSerializer(buf)); + net.addToSendQueue(new C17PacketCustomPayload( + //#if MC>12000 + //#if FORGE + //$$ new net.minecraft.network.protocol.common.custom.DiscardedPayload( + //#else + //$$ new Payload( + //#endif + //#endif + //#if MC<=11202 + packet.getIdentifier(), + //#else + //$$ new net.minecraft.util.ResourceLocation(packet.getIdentifier()), + //#endif + buf + //#if MC>12000 + //$$ ) + //#endif + ) + ); + return true; + }); + EventManager.register(ReceivePacketEvent.class, (ev) -> { + if (!(ev.getPacket() instanceof S3FPacketCustomPayload)) { + return; + } + + S3FPacketCustomPayload packet = ev.getPacket(); + //#if MC>12000 + //$$ String identifier = packet.payload().id().toString(); + //#else + //noinspection StringOperationCanBeSimplified + String identifier = packet.getChannelName().toString(); + //#endif + if (!HypixelModAPI.getInstance().getRegistry().isRegistered(identifier)) { + return; + } + + try { + PacketSerializer s = new PacketSerializer( + //#if MC>12000 && FABRIC + //$$ ((Payload) packet.payload()).data() + //#else + packet.getBufferData() + //#endif + ); + HypixelModAPI.getInstance().handle(identifier, s); + } catch (Exception e) { + LOGGER.warn("Failed to handle packet {}", identifier, e); + } + }); + } + + @ApiStatus.Internal + public void postLocationEvent() { + EventManager.INSTANCE.post(HypixelLocationEvent.INSTANCE); + } + + //#if MC>12000 && FABRIC + //$$ public static final class Payload implements net.minecraft.network.packet.CustomPayload { + //$$ private final net.minecraft.util.Identifier id; + //$$ private final io.netty.buffer.ByteBuf data; + //$$ + //$$ public Payload(net.minecraft.util.Identifier id, io.netty.buffer.ByteBuf data) { + //$$ this.id = id; + //$$ this.data = data.copy(); + //$$ data.skipBytes(data.readableBytes()); + //$$ } + //$$ + //$$ public void write(net.minecraft.network.PacketByteBuf arg) { + //$$ if (this.data != null) { + //$$ arg.writeBytes(this.data.slice()); + //$$ } + //$$ } + //$$ + //$$ public net.minecraft.util.Identifier id() { + //$$ return this.id; + //$$ } + //$$ + //$$ public io.netty.buffer.ByteBuf data() { + //$$ return this.data; + //$$ } + //$$ + //$$ } + //#endif +} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GLPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GLPlatformImpl.java index 820b1df21..16d885cb3 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GLPlatformImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GLPlatformImpl.java @@ -26,78 +26,75 @@ package org.polyfrost.oneconfig.api.platform.v1.internal; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; +import org.polyfrost.oneconfig.api.platform.v1.GLPlatform; import org.polyfrost.oneconfig.utils.v1.MHUtils; import org.polyfrost.universal.UGraphics; import org.polyfrost.universal.UMatrixStack; -import org.polyfrost.universal.UMinecraft; -import org.polyfrost.oneconfig.api.platform.v1.GLPlatform; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; public class GLPlatformImpl implements GLPlatform { @Override - @SuppressWarnings("deprecation") - public void drawRect(float x, float y, float x2, float y2, int color) { + public void drawRect(UMatrixStack stack, double x, double y, double x2, double y2, int color) { if (x < x2) { - float i = x; + double i = x; x = x2; x2 = i; } if (y < y2) { - float i = y; + double i = y; y = y2; y2 = i; } - float f = (float) (color >> 24 & 0xFF) / 255.0F; - float g = (float) (color >> 16 & 0xFF) / 255.0F; - float h = (float) (color >> 8 & 0xFF) / 255.0F; - float j = (float) (color & 0xFF) / 255.0F; - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer worldRenderer = tessellator.getWorldRenderer(); - UGraphics.enableBlend(); - UGraphics.disableTexture2D(); + float r = (float) (color >> 16 & 0xFF) / 255.0F; + float g = (float) (color >> 8 & 0xFF) / 255.0F; + float b = (float) (color & 0xFF) / 255.0F; + float a = (float) (color >> 24 & 0xFF) / 255.0F; + UGraphics graphics = new UGraphics(Tessellator.getInstance().getWorldRenderer()); + graphics.beginWithDefaultShader(UGraphics.DrawMode.QUADS, DefaultVertexFormats.POSITION); UGraphics.tryBlendFuncSeparate(770, 771, 1, 0); - UGraphics.color4f(g, h, j, f); - worldRenderer.begin( - //#if MC<11700 - 7, - //#else - //$$ net.minecraft.client.render.VertexFormat.DrawMode.QUADS, - //#endif - DefaultVertexFormats.POSITION); - worldRenderer.pos(x, y2, 0.0).endVertex(); - worldRenderer.pos(x2, y2, 0.0).endVertex(); - worldRenderer.pos(x2, y, 0.0).endVertex(); - worldRenderer.pos(x, y, 0.0).endVertex(); - tessellator.draw(); - UGraphics.enableTexture2D(); + UGraphics.enableBlend(); + UGraphics.disableAlpha(); + graphics.color(r, g, b, a); + graphics.pos(stack, x, y2, 0.0).endVertex(); + graphics.pos(stack, x2, y2, 0.0).endVertex(); + graphics.pos(stack, x2, y, 0.0).endVertex(); + graphics.pos(stack, x, y, 0.0).endVertex(); + graphics.drawDirect(); UGraphics.disableBlend(); + UGraphics.enableAlpha(); } @Override - public float drawText(UMatrixStack matrixStack, String text, float x, float y, int color, boolean shadow) { + public float drawText(UMatrixStack stack, String text, float x, float y, int color, boolean shadow) { + FontRenderer fr = Minecraft.getMinecraft().fontRendererObj; //#if MC>12000 - //$$ return UMinecraft.getFontRenderer().draw(text, x, y, color, shadow, - //$$ matrixStack.toMC().peek().getPositionMatrix(), UMinecraft.getMinecraft().getBufferBuilders().getEntityVertexConsumers(), + //#if FABRIC + //$$ return fr.draw(text, x, y, color, shadow, + //$$ stack.toMC().peek().getPositionMatrix(), MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), //$$ net.minecraft.client.font.TextRenderer.TextLayerType.NORMAL, 0, 15728880); //#else - //#if MC<=11202 - return UMinecraft.getFontRenderer().drawString(text, x, y, color, shadow); + //$$ return fr.drawInBatch(text, x, y, color, shadow, + //$$ stack.toMC().last().pose(), Minecraft.getInstance().renderBuffers().bufferSource(), + //$$ net.minecraft.client.gui.Font.DisplayMode.NORMAL, 0, 15728880); + //#endif + //#elseif MC<=11202 + return fr.drawString(text, x, y, color, shadow); //#else //$$ if(shadow) { - //$$ return UMinecraft.getFontRenderer().drawStringWithShadow(matrixStack.toMC(), text, x, y, color); - //$$ } else return UMinecraft.getFontRenderer().drawString(matrixStack.toMC(), text, x, y, color); - //#endif + //$$ return fr.drawStringWithShadow(stack.toMC(), text, x, y, color); + //$$ } else return fr.drawString(stack.toMC(), text, x, y, color); //#endif } @Override public int getStringWidth(String text) { - return UMinecraft.getFontRenderer().getStringWidth(text); + return Minecraft.getMinecraft().fontRendererObj.getStringWidth(text); } //#if MC<=11202 diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GuiPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GuiPlatformImpl.java deleted file mode 100644 index aeacbd602..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/GuiPlatformImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.platform.v1.internal; - -import org.polyfrost.universal.UMinecraft; -import org.polyfrost.universal.UScreen; -import org.polyfrost.oneconfig.api.platform.v1.GuiPlatform; -import net.minecraft.client.gui.GuiChat; -import net.minecraft.client.gui.GuiScreen; -//#if MC<=11202 -import net.minecraft.client.gui.GuiButton; -//#elseif MC<=11605 -//$$ import net.minecraft.client.gui.widget.button.Button; -//#endif - -public class GuiPlatformImpl implements GuiPlatform { - - @Override - public GuiScreen getCurrentScreen() { - return UScreen.getCurrentScreen(); - } - - @Override - public void setCurrentScreen(Object screen) { - UScreen.displayScreen((GuiScreen) screen); - } - - @Override - public boolean isInChat() { - return getCurrentScreen() instanceof GuiChat; - } - - @Override - public boolean isInDebug() { - //#if MC<12000 - return UMinecraft.getSettings().showDebugInfo; - //#else - //$$ return ((org.polyfrost.oneconfig.internal.mixin.DebugHudAccessor) UMinecraft.getMinecraft().getDebugHud()).isShowDebugHud(); - //#endif - } - - @Override - public void playClickSound() { - //#if MC<=11202 - new GuiButton(-1, -1, -1, "") - .playPressSound(UMinecraft.getMinecraft().getSoundHandler()); - //#elseif MC<=11605 - //$$ new Button(-1, -1, -1, -1, null, (button) -> {}) - //$$ .playDownSound(UMinecraft.getMinecraft().getSoundHandler()); - //#endif - } -} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/I18nPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/I18nPlatformImpl.java index 118f626b6..9d9ae55c6 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/I18nPlatformImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/I18nPlatformImpl.java @@ -27,6 +27,8 @@ package org.polyfrost.oneconfig.api.platform.v1.internal; import net.minecraft.client.resources.I18n; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IChatComponent; import org.polyfrost.oneconfig.api.platform.v1.I18nPlatform; public class I18nPlatformImpl implements I18nPlatform { @@ -38,21 +40,25 @@ public String format(String key, Object... args) { @Override public String getKeyName(int key, int scanCode) { - //#if MC>=11600 - //#if FABRIC - //$$ final String s = net.minecraft.client.util.InputUtil.fromKeyCode(key, scanCode).getLocalizedText().asString(); + //@formatter:off + String s = + //#if MC>=11600 + //$$ net.minecraft.client.util.InputMappings.getInputByCode(key, scanCode).toString(); //#else - //#if MC>=11700 - //$$ final String s = com.mojang.blaze3d.platform.InputConstants.getKey(key, scanCode).getDisplayName().getString(); - //#else - //$$ final String s = net.minecraft.client.util.InputMappings.getInputByCode(key, scanCode).func_237520_d_().getString(); - //#endif + net.minecraft.client.settings.GameSettings.getKeyDisplayString(key); //#endif - //$$ if (s == null) return "Unknown"; - //$$ else return s.length() == 1 ? s.toUpperCase() : s; - //#else - final String s = net.minecraft.client.settings.GameSettings.getKeyDisplayString(key); - return s == null ? "Unknown" : s; - //#endif + //@formatter:on + if (s == null) return "Unknown"; + else return s.length() == 1 ? s.toUpperCase() : s; + } + + @Override + public String getUnformattedText(Object component) { + String s; + if (component instanceof IChatComponent) { + //noinspection StringOperationCanBeSimplified + s = ((IChatComponent) component).getUnformattedText().toString(); + } else s = component.toString(); + return EnumChatFormatting.getTextWithoutFormattingCodes(s); } } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/LoaderPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/LoaderPlatformImpl.java index 9aacab708..d4cb36e2d 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/LoaderPlatformImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/LoaderPlatformImpl.java @@ -83,7 +83,7 @@ public int getMinecraftVersion() { static { boolean dev; try { - Class.forName("net.minecraft.block.BlockDirt"); + Class.forName("net.minecraft.block.BlockDirt", false, LoaderPlatformImpl.class.getClassLoader()); dev = true; } catch (Exception ignored) { dev = false; diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/PlayerPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/PlayerPlatformImpl.java index c4f38b2a1..44c788989 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/PlayerPlatformImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/PlayerPlatformImpl.java @@ -27,37 +27,24 @@ package org.polyfrost.oneconfig.api.platform.v1.internal; import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; -import org.polyfrost.universal.UMinecraft; +import net.minecraft.util.Session; import org.polyfrost.oneconfig.api.platform.v1.PlayerPlatform; public class PlayerPlatformImpl implements PlayerPlatform { @Override public boolean inMultiplayer() { - return UMinecraft.getWorld() != null && !UMinecraft.getMinecraft().isSingleplayer(); - } - - @Override - public String getClientBrand() { - EntityPlayerSP player = UMinecraft.getPlayer(); - if (player == null) - return null; - //#if MC<12000 - return player.getClientBrand(); - //#else - //$$ net.minecraft.server.MinecraftServer server = player.getServer(); - //$$ return server == null ? null : server.getName(); - //#endif + return Minecraft.getMinecraft().theWorld != null && !Minecraft.getMinecraft().isSingleplayer(); } @Override public boolean doesPlayerExist() { - return UMinecraft.getPlayer() != null; + return Minecraft.getMinecraft().thePlayer != null; } @Override public String getPlayerName() { - return Minecraft.getMinecraft().getSession().getUsername(); + Session s = Minecraft.getMinecraft().getSession(); + return s.getUsername(); } } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/ScreenPlatformImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/ScreenPlatformImpl.java new file mode 100644 index 000000000..5ecc494a3 --- /dev/null +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/platform/v1/internal/ScreenPlatformImpl.java @@ -0,0 +1,121 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.api.platform.v1.internal; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.gui.GuiScreen; +import org.jetbrains.annotations.Nullable; +import org.polyfrost.oneconfig.api.event.v1.EventDelay; +import org.polyfrost.oneconfig.api.platform.v1.Platform; +import org.polyfrost.oneconfig.api.platform.v1.ScreenPlatform; + +public class ScreenPlatformImpl implements ScreenPlatform { + //#if MC<11300 + private static final net.minecraft.client.gui.GuiButton btn = new net.minecraft.client.gui.GuiButton(-1, -1, -1, ""); + //#elseif MC>=11900 + //#if FABRIC + //$$ private static final net.minecraft.client.gui.widget.ButtonWidget btn = new net.minecraft.client.gui.widget.ButtonWidget.Builder(net.minecraft.text.Text.empty(), (b) -> {}).build(); + //#else + //$$ private static final net.minecraft.client.gui.components.Button btn = new net.minecraft.client.gui.components.Button.Builder(net.minecraft.network.chat.Component.empty(), (b) -> {}).build(); + //#endif + //#else + //$$ private static final net.minecraft.client.gui.widget.button.Button btn = new net.minecraft.client.gui.widget.button.Button(-1, -1, -1, -1, null, (b) -> {}); + //#endif + + @Override + public boolean isInChat() { + return Platform.screen().current() instanceof GuiChat; + } + + @Override + public boolean isInDebug() { + //@formatter:off + return Minecraft.getMinecraft() + //#if MC<12000 + .gameSettings.showDebugInfo; + //#elseif FABRIC + //$$ .getDebugHud().shouldShowDebugHud(); + //#else + //$$ .getDebugOverlay().showDebugScreen(); + //#endif + //@formatter:on + } + + @Override + public void playClickSound() { + btn.playPressSound(Minecraft.getMinecraft().getSoundHandler()); + } + + @Override + public int viewportWidth() { + //#if MC>=11502 + //$$ return Minecraft.getInstance().getMainWindow().getFramebufferWidth(); + //#else + return Minecraft.getMinecraft().displayWidth; + //#endif + } + + @Override + public int viewportHeight() { + //#if MC>=11502 + //$$ return Minecraft.getInstance().getMainWindow().getFramebufferHeight(); + //#else + return Minecraft.getMinecraft().displayHeight; + //#endif + } + + @Override + public int windowWidth() { + //#if MC>=11502 + //$$ return Minecraft.getInstance().getMainWindow().getWidth(); + //#else + return Minecraft.getMinecraft().displayWidth; + //#endif + } + + @Override + public int windowHeight() { + //#if MC>=11502 + //$$ return Minecraft.getInstance().getMainWindow().getHeight(); + //#else + return Minecraft.getMinecraft().displayHeight; + //#endif + } + + @Override + public void display(@Nullable Object screen, int ticks) { + if (ticks < 1) Minecraft.getMinecraft().displayGuiScreen((GuiScreen) screen); + else EventDelay.tick(ticks, () -> Minecraft.getMinecraft().displayGuiScreen((GuiScreen) screen)); + } + + @Override + @SuppressWarnings("unchecked" /*, reason = "reduces friction between versions" */) + public @Nullable T current() { + return (T) Minecraft.getMinecraft().currentScreen; + } +} diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler.java index d71d85f01..6eef6278e 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/BlurHandler.java @@ -26,16 +26,17 @@ package org.polyfrost.oneconfig.api.ui.v1.internal; +import net.minecraft.client.Minecraft; import net.minecraft.client.shader.Shader; import net.minecraft.client.shader.ShaderGroup; +import net.minecraft.client.shader.ShaderManager; import net.minecraft.client.shader.ShaderUniform; import net.minecraft.util.ResourceLocation; import org.polyfrost.oneconfig.api.event.v1.events.RenderEvent; import org.polyfrost.oneconfig.api.event.v1.events.ScreenOpenEvent; import org.polyfrost.oneconfig.api.event.v1.invoke.EventHandler; +import org.polyfrost.oneconfig.api.platform.v1.Platform; import org.polyfrost.oneconfig.internal.mixin.ShaderGroupAccessor; -import org.polyfrost.universal.UMinecraft; -import org.polyfrost.universal.UScreen; import org.polyfrost.oneconfig.api.ui.v1.screen.BlurScreen; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; @@ -59,7 +60,7 @@ public final class BlurHandler { public static final BlurHandler INSTANCE = new BlurHandler(); private static final Logger LOGGER = LogManager.getLogger("OneConfig/Blur"); - private final ResourceLocation blurShader = new ResourceLocation("shaders/post/fade_in_blur.json"); + private final ResourceLocation blurShader = new ResourceLocation("oneconfig", "shaders/post/fade_in_blur.json"); private ShaderUniform su; private long start; private float progress = 0; @@ -69,9 +70,9 @@ public static void init() { } private BlurHandler() { - EventHandler.of(ScreenOpenEvent.class, e -> reloadBlur(e.screen)).register(); + EventHandler.of(ScreenOpenEvent.class, e -> reloadBlur(e.getScreen())).register(); EventHandler.of(RenderEvent.End.class, e -> { - if (UScreen.getCurrentScreen() == null) { + if (Platform.screen().current() == null) { return; } if (!isShaderActive()) { @@ -89,7 +90,7 @@ private BlurHandler() { */ private void reloadBlur(Object gui) { // Don't do anything if no world is loaded - if (UMinecraft.getWorld() == null) { + if (Minecraft.getMinecraft().theWorld == null) { return; } if (gui == null) { @@ -102,21 +103,15 @@ private void reloadBlur(Object gui) { if (gui instanceof BlurScreen && ((BlurScreen) gui).hasBackgroundBlur()) { if (!isShaderActive()) { //#if FABRIC - //$$ ((org.polyfrost.oneconfig.internal.mixin.fabric.GameRendererAccessor) UMinecraft.getMinecraft().gameRenderer).invokeLoadShader(this.blurShader); + //$$ ((org.polyfrost.oneconfig.internal.mixin.fabric.GameRendererAccessor) MinecraftClient.getInstance().gameRenderer).invokeLoadShader(this.blurShader); //#else - UMinecraft.getMinecraft().entityRenderer. - //#if MC<11700 - loadShader - //#else - //$$ loadEffect - //#endif - (this.blurShader); + Minecraft.getMinecraft().entityRenderer.loadShader(this.blurShader); //#endif this.start = System.currentTimeMillis(); this.progress = 0; try { - final List listShaders = ((ShaderGroupAccessor) UMinecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); + final List listShaders = ((ShaderGroupAccessor) Minecraft.getMinecraft().entityRenderer.getShaderGroup()).getListShaders(); // Should not happen. Something bad happened. if (listShaders == null) { @@ -125,7 +120,8 @@ private void reloadBlur(Object gui) { // Iterate through the list of shaders. for (Shader shader : listShaders) { - ShaderUniform su = shader.getShaderManager().getShaderUniform("Progress"); + ShaderManager sm = shader.getShaderManager(); + ShaderUniform su = sm.getShaderUniform("Progress"); if (su == null) continue; this.su = su; @@ -141,7 +137,7 @@ private void reloadBlur(Object gui) { } private void tryStop() { - ShaderGroup sg = UMinecraft.getMinecraft().entityRenderer.getShaderGroup(); + ShaderGroup sg = Minecraft.getMinecraft().entityRenderer.getShaderGroup(); if (sg == null) return; String name = sg.getShaderGroupName(); @@ -150,11 +146,11 @@ private void tryStop() { return; } su = null; - UMinecraft.getMinecraft().entityRenderer.stopUseShader(); + Minecraft.getMinecraft().entityRenderer.stopUseShader(); } public static boolean isBlurring() { - return (UScreen.getCurrentScreen() instanceof BlurScreen && ((BlurScreen) UScreen.getCurrentScreen()).hasBackgroundBlur()); + return (Platform.screen().current() instanceof BlurScreen && ((BlurScreen) Platform.screen().current()).hasBackgroundBlur()); } /** @@ -168,7 +164,7 @@ private float getBlurStrengthProgress() { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean isShaderActive() { - return UMinecraft.getMinecraft().entityRenderer.getShaderGroup() != null + return Minecraft.getMinecraft().entityRenderer.getShaderGroup() != null //#if MC<=11202 && net.minecraft.client.renderer.OpenGlHelper.shadersSupported //#endif diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/MCWindow.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/MCWindow.java similarity index 84% rename from versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/MCWindow.java rename to versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/MCWindow.java index 3f5ac2172..29bc89c65 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/MCWindow.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/MCWindow.java @@ -24,19 +24,17 @@ * */ -package org.polyfrost.oneconfig.api.ui.v1.screen; +package org.polyfrost.oneconfig.api.ui.v1.internal; import net.minecraft.client.Minecraft; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.polyfrost.oneconfig.api.platform.v1.Platform; -import org.polyfrost.oneconfig.utils.v1.GuiUtils; import org.polyfrost.oneconfig.utils.v1.IOUtils; import org.polyfrost.polyui.PolyUI; import org.polyfrost.polyui.renderer.Window; import org.polyfrost.polyui.renderer.data.Cursor; -import org.polyfrost.universal.UResolution; //#if MC>=11300 //$$ import static org.lwjgl.glfw.GLFW.*; @@ -49,27 +47,21 @@ public class MCWindow extends Window { //#endif public MCWindow(Minecraft mc) { - super(UResolution.getViewportWidth(), UResolution.getViewportHeight(), 1f); + super(Platform.screen().viewportWidth(), Platform.screen().viewportHeight(), (float) Platform.screen().viewportWidth() / Platform.screen().windowWidth()); //#if MC>=11300 - //$$ this.handle = mc - //#if MC>=11700 - //$$ .getWindow() - //#else - //$$ .getMainWindow() - //#endif - //$$ .getHandle(); + //$$ this.handle = mc.getMainWindow().getHandle(); //#endif } @Override public void close() { - GuiUtils.closeScreen(); + Platform.screen().close(); } @NotNull @Override public Window open(@NotNull PolyUI polyUI) { - GuiUtils.displayScreen(new PolyUIScreen(polyUI)); + Platform.screen().display(new PolyUIScreen(polyUI, null, false, false, null)); return this; } @@ -116,7 +108,7 @@ public void setCursor(@NotNull Cursor cursor) { @NotNull @Override public String getKeyName(int i) { - String k = Platform.getI18nPlatform().getKeyName(i, 0); + String k = Platform.i18n().getKeyName(i, 0); return k == null ? "Unknown" : k; } } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreen.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreen.java new file mode 100644 index 000000000..3fb3d1fa0 --- /dev/null +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreen.java @@ -0,0 +1,210 @@ +/* + * This file is part of OneConfig. + * OneConfig - Next Generation Config Library for Minecraft: Java Edition + * Copyright (C) 2021~2024 Polyfrost. + * + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * OneConfig is licensed under the terms of version 3 of the GNU Lesser + * General Public License as published by the Free Software Foundation, AND + * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, + * either version 1.0 of the Additional Terms, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License. If not, see . You should + * have also received a copy of the Additional Terms Applicable + * to OneConfig, as published by Polyfrost. If not, see + * + */ + +package org.polyfrost.oneconfig.api.ui.v1.internal; + +import net.minecraft.client.Minecraft; +import org.jetbrains.annotations.MustBeInvokedByOverriders; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.polyfrost.oneconfig.api.platform.v1.Platform; +import org.polyfrost.oneconfig.api.ui.v1.screen.BlurScreen; +import org.polyfrost.polyui.PolyUI; +import org.polyfrost.polyui.renderer.data.Cursor; +import org.polyfrost.polyui.unit.Vec2; +import org.polyfrost.universal.UKeyboard; +import org.polyfrost.universal.UMatrixStack; +import org.polyfrost.universal.UScreen; + +import java.util.function.Consumer; + +import static org.lwjgl.opengl.GL11.glViewport; +import static org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager.translateKey; + +@SuppressWarnings("unused") +public class PolyUIScreen extends UScreen implements BlurScreen { + @NotNull + public final PolyUI polyUI; + + @Nullable + public final Vec2 desiredResolution; + + private final boolean pauses, blurs; + + private final MCWindow window; + + private final Consumer close; + + //#if MC<=11300 + private int mx, my; + //#endif + + public PolyUIScreen(@NotNull PolyUI polyUI, @Nullable Vec2 desiredResolution, boolean pauses, boolean blurs, Consumer onClose) { + super(true); + this.polyUI = polyUI; + this.window = new MCWindow(Minecraft.getMinecraft()); + this.polyUI.setWindow(window); + this.desiredResolution = desiredResolution; + this.blurs = blurs; + this.pauses = pauses; + this.close = onClose; + adjustResolution(Platform.screen().windowWidth(), Platform.screen().windowHeight(), true); + } + + protected final void adjustResolution(float w, float h, boolean force) { + // asm: normally, a polyui instance is as big as its window and that is it. + // however, inside minecraft, the actual content is smaller than the window size, so resizing it directly would just fuck it up. + // so instead, the developer specifies a resolution that their UI was designed for, and we resize accordingly. + if (desiredResolution == null) return; + float sx = w / desiredResolution.getX(); + float sy = h / desiredResolution.getY(); + if (sx == 1f && sy == 1f) return; + Vec2 size = polyUI.getMaster().getSize(); + polyUI.resize(size.getX() * sx, size.getY() * sy, force); + } + + @Override + public void onDrawScreen(@NotNull UMatrixStack matrices, int mouseX, int mouseY, float delta) { + Vec2 size = polyUI.getMaster().getSize(); + float scale = window.getPixelRatio(); + float ox = (Platform.screen().windowWidth() / 2f - size.getX() / 2f) * scale; + float oy = (Platform.screen().windowHeight() / 2f - size.getY() / 2f) * scale; + glViewport((int) ox, (int) oy, (int) (size.getX() * scale), (int) (size.getY() * scale)); + + //#if MC<11300 + if (mouseX != mx || mouseY != my) { + mx = mouseX; + my = mouseY; + this.mouseMoved(mx, my); + } + //#endif + + matrices.runReplacingGlobalState(polyUI::render); + + glViewport(0, 0, Platform.screen().viewportWidth(), Platform.screen().viewportHeight()); + } + + @Override + @MustBeInvokedByOverriders + public final void onResize(Minecraft client, int width, int height) { + float w = (float) Platform.screen().viewportWidth(); + float h = (float) Platform.screen().viewportHeight(); + adjustResolution(w, h, false); + } + + @Override + @MustBeInvokedByOverriders + public boolean uKeyPressed(int keyCode, int scanCode, @Nullable UKeyboard.Modifiers modifiers) { + if (keyCode == UKeyboard.KEY_ESCAPE && shouldCloseOnEsc()) { + Platform.screen().close(); + return true; + } + translateKey(polyUI.getInputManager(), keyCode, (char) 0, true); + return true; + } + + @Override + @MustBeInvokedByOverriders + public boolean uKeyReleased(int keyCode, int scanCode, @Nullable UKeyboard.Modifiers modifiers) { + translateKey(polyUI.getInputManager(), keyCode, (char) 0, false); + return true; + } + + @Override + @MustBeInvokedByOverriders + public boolean uCharTyped(char c, @Nullable UKeyboard.Modifiers modifiers) { + translateKey(polyUI.getInputManager(), 0, c, true); + return true; + } + + @Override + @MustBeInvokedByOverriders + public boolean uMouseClicked(double mouseX, double mouseY, int mouseButton) { + polyUI.getInputManager().mousePressed(mouseButton); + return true; + } + + @Override + @MustBeInvokedByOverriders + public boolean uMouseReleased(double mouseX, double mouseY, int mouseButton) { + polyUI.getInputManager().mouseReleased(mouseButton); + return true; + } + + @Override + @MustBeInvokedByOverriders + public boolean uMouseScrolled(double delta) { + polyUI.getInputManager().mouseScrolled(0f, (float) delta); + return true; + } + + //#if MC>=11300 + //$$ @Override + //#endif + public boolean shouldCloseOnEsc() { + return true; + } + + //#if MC<=11300 + @Override + //#endif + public boolean doesGuiPauseGame() { + return pauses; + } + + @Override + public boolean hasBackgroundBlur() { + return blurs; + } + + + //#if MC>=11300 + //$$ @Override + //#endif + @MustBeInvokedByOverriders + public void mouseMoved(double mouseX, double mouseY) { + Vec2 size = polyUI.getMaster().getSize(); + float ox = (float) Platform.screen().windowWidth() / 2f - size.getX() / 2f; + float oy = (float) Platform.screen().windowHeight() / 2f - size.getY() / 2f; + float mx, my; + //#if MC>=11300 + //$$ mx = (float) Minecraft.getInstance().mouseHelper.getMouseX(); + //$$ my = (float) Minecraft.getInstance().mouseHelper.getMouseY(); + //#else + mx = org.lwjgl.input.Mouse.getX(); + my = Platform.screen().windowHeight() - org.lwjgl.input.Mouse.getY() - 1; + //#endif + polyUI.getInputManager().mouseMoved(mx - ox, my - oy); + } + + @Override + @MustBeInvokedByOverriders + public void onScreenClose() { + if (close != null) close.accept(polyUI); + // noinspection DataFlowIssue + this.polyUI.getWindow().setCursor(Cursor.Pointer); + } +} \ No newline at end of file diff --git a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/LocrawEvent.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreenProviderImpl.java similarity index 69% rename from modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/LocrawEvent.java rename to versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreenProviderImpl.java index 203c512f6..3d431e782 100644 --- a/modules/events/src/main/java/org/polyfrost/oneconfig/api/event/v1/events/LocrawEvent.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/PolyUIScreenProviderImpl.java @@ -24,25 +24,17 @@ * */ -package org.polyfrost.oneconfig.api.event.v1.events; +package org.polyfrost.oneconfig.api.ui.v1.internal; -import org.polyfrost.oneconfig.utils.v1.hypixel.HypixelUtils; -import org.polyfrost.oneconfig.utils.v1.hypixel.LocrawInfo; +import org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreenProvider; +import org.polyfrost.polyui.PolyUI; +import org.polyfrost.polyui.unit.Vec2; -/** - * Called when the player's location in Hypixel is received via the /locraw command. - * - * @see LocrawInfo - * @see HypixelUtils - */ -public class LocrawEvent implements Event { - public final LocrawInfo info; - - public LocrawEvent(LocrawInfo info) { - this.info = info; - } +import java.util.function.Consumer; - public LocrawInfo component1() { - return info; +public final class PolyUIScreenProviderImpl implements PolyUIScreenProvider { + @Override + public Object create(PolyUI polyUI, Vec2 desiredResolution, boolean pauses, boolean blurs, Consumer onClose) { + return new PolyUIScreen(polyUI, desiredResolution, pauses, blurs, onClose); } } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java index 772bffd4d..39ee555b2 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/internal/UIManagerImpl.java @@ -26,11 +26,14 @@ package org.polyfrost.oneconfig.api.ui.v1.internal; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; import org.objectweb.asm.commons.Remapper; +import org.objectweb.asm.commons.RemappingClassAdapter; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.InsnList; import org.objectweb.asm.tree.InsnNode; @@ -38,12 +41,11 @@ import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.TypeInsnNode; import org.objectweb.asm.tree.VarInsnNode; -import org.polyfrost.oneconfig.api.ui.v1.UIManager; +import org.polyfrost.oneconfig.api.ClassHasOverwrites; import org.polyfrost.oneconfig.api.ui.v1.TinyFD; +import org.polyfrost.oneconfig.api.ui.v1.UIManager; import org.polyfrost.oneconfig.utils.v1.MHUtils; import org.polyfrost.polyui.renderer.Renderer; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import org.polyfrost.polyui.utils.IOUtils; import java.io.IOException; @@ -65,6 +67,7 @@ import java.util.Set; @SuppressWarnings("unused") +@ClassHasOverwrites("1.16.5-forge") public class UIManagerImpl extends URLClassLoader implements UIManager { @@ -242,13 +245,8 @@ public String map(String desc) { }; ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_MAXS); @SuppressWarnings({"deprecation", "RedundantSuppression"}) - ClassVisitor classRemapper = - //#if FABRIC - //$$ new org.objectweb.asm.commons.ClassRemapper(classWriter, remapper); - //#else - new org.objectweb.asm.commons.RemappingClassAdapter(classWriter, remapper); - //#endif - classReader.accept(classRemapper, ClassReader.EXPAND_FRAMES); + ClassVisitor mapper = new RemappingClassAdapter(classWriter, remapper); + classReader.accept(mapper, ClassReader.EXPAND_FRAMES); b = classWriter.toByteArray(); if (name.equalsIgnoreCase("org.lwjgl.nanovg.NanoVGGLConfig")) { diff --git a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java b/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java deleted file mode 100644 index e139f5ef8..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/api/ui/v1/screen/PolyUIScreen.java +++ /dev/null @@ -1,300 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.api.ui.v1.screen; - -import net.minecraft.client.Minecraft; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.MustBeInvokedByOverriders; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.polyfrost.oneconfig.api.PlatformDeclaration; -import org.polyfrost.universal.UKeyboard; -import org.polyfrost.universal.UMatrixStack; -import org.polyfrost.universal.UMinecraft; -import org.polyfrost.universal.UMouse; -import org.polyfrost.universal.UResolution; -import org.polyfrost.universal.UScreen; -import org.polyfrost.oneconfig.api.ui.v1.UIManager; -import org.polyfrost.polyui.PolyUI; -import org.polyfrost.polyui.color.Colors; -import org.polyfrost.polyui.color.DarkTheme; -import org.polyfrost.polyui.color.PolyColor; -import org.polyfrost.polyui.component.Drawable; -import org.polyfrost.polyui.event.InputManager; -import org.polyfrost.polyui.input.Translator; -import org.polyfrost.polyui.property.Settings; -import org.polyfrost.polyui.renderer.data.Cursor; -import org.polyfrost.polyui.unit.Align; -import org.polyfrost.polyui.unit.Vec2; - -import static org.lwjgl.opengl.GL11.glViewport; -import static org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindManager.translateKey; - -@SuppressWarnings("unused") -@PlatformDeclaration -public class PolyUIScreen extends UScreen implements UIPause, BlurScreen { - @Nullable - public final PolyUI polyUI; - - @NotNull - public final InputManager inputManager; - - @Nullable - public final Vec2 desiredResolution; - - public boolean pauses, blurs; - - private final MCWindow window; - - private Runnable close; - - //#if MC<=11300 - private float mx, my; - //#endif - - @Contract("_, null, _, _, _, _, _, _, null -> fail") - public PolyUIScreen(@Nullable Settings settings, - @Nullable InputManager inputManager, - @Nullable Translator translator, - @Nullable Align alignment, - @Nullable Colors colors, - @Nullable PolyColor backgroundColor, - @Nullable Vec2 desiredResolution, - @Nullable Vec2 size, - Drawable... drawables) { - super(true); - - Settings s = settings == null ? new Settings() : settings; - s.enableInitCleanup(false); - s.enableForceSettingInitialSize(true); - if (drawables == null || drawables.length == 0) { - if (inputManager == null) throw new IllegalArgumentException("Must be created with an inputManager or drawables"); - this.inputManager = inputManager; - this.polyUI = null; - this.desiredResolution = null; - this.window = null; - } else { - Colors c = colors == null ? new DarkTheme() : colors; - Align a = alignment == null ? new Align(Align.Main.Start, Align.Cross.Start, Align.Mode.Horizontal, Vec2.ZERO, 50) : alignment; - this.polyUI = new PolyUI(drawables, UIManager.INSTANCE.getRenderer(), s, inputManager, translator, backgroundColor, a, c, size); - this.window = new MCWindow(UMinecraft.getMinecraft()); - this.window.setPixelRatio(scale()); - this.polyUI.setWindow(window); - this.inputManager = this.polyUI.getInputManager(); - this.desiredResolution = desiredResolution; - adjustResolution(width(), height(), true); - } - } - - public PolyUIScreen(Drawable... drawables) { - this(null, null, null, null, null, null, null, null, drawables); - } - - public PolyUIScreen(@Nullable Align alignment, Vec2 size, Drawable... drawables) { - this(null, null, null, alignment, null, null, null, size, drawables); - } - - public PolyUIScreen(@NotNull InputManager inputManager) { - this(null, inputManager, null, null, null, null, null, null); - } - - @ApiStatus.Internal - public PolyUIScreen(@NotNull PolyUI polyUI) { - super(true); - this.polyUI = polyUI; - this.inputManager = polyUI.getInputManager(); - desiredResolution = null; - window = new MCWindow(UMinecraft.getMinecraft()); - window.setPixelRatio(scale()); - polyUI.setWindow(window); - } - - protected final void adjustResolution(float w, float h, boolean force) { - // asm: normally, a polyui instance is as big as its window and that is it. - // however, inside minecraft, the actual content is smaller than the window size, so resizing it directly would just fuck it up. - // so instead, the developer specifies a resolution that their UI was designed for, and we resize accordingly. - if (polyUI == null || desiredResolution == null) return; - float sx = w / desiredResolution.getX(); - float sy = h / desiredResolution.getY(); - if (sx == 1f && sy == 1f) return; - Vec2 size = polyUI.getMaster().getSize(); - polyUI.resize(size.getX() * sx, size.getY() * sy, force); - } - - - public boolean useMinecraftUIScaling() { - return false; - } - - public final org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreen closeCallback(Runnable r) { - close = r; - return this; - } - - - @Override - public void onDrawScreen(@NotNull UMatrixStack matrices, int mouseX, int mouseY, float delta) { - if (polyUI == null) return; - - Vec2 size = polyUI.getMaster().getSize(); - float scale = scale(); - float ox = (width() / 2f - size.getX() / 2f) * scale; - float oy = (height() / 2f - size.getY() / 2f) * scale; - glViewport((int) ox, (int) oy, (int) (size.getX() * scale), (int) (size.getY() * scale)); - - //#if MC<11300 - if (mouseX != mx || mouseY != my) { - mx = mouseX; - my = mouseY; - this.mouseMoved(mx, my); - } - //#endif - - matrices.runReplacingGlobalState(polyUI::render); - - glViewport(0, 0, UResolution.getViewportWidth(), UResolution.getViewportHeight()); - } - - @Override - @MustBeInvokedByOverriders - public final void onResize(Minecraft client, int width, int height) { - if (polyUI == null) return; - float w = (float) UResolution.getViewportWidth(); - float h = (float) UResolution.getViewportHeight(); - adjustResolution(w, h, false); - } - - @Override - @MustBeInvokedByOverriders - public boolean uKeyPressed(int keyCode, int scanCode, @Nullable UKeyboard.Modifiers modifiers) { - if (keyCode == UKeyboard.KEY_ESCAPE && shouldCloseOnEsc()) { - UScreen.displayScreen(null); - return true; - } - translateKey(inputManager, keyCode, (char) 0, true); - return true; - } - - @Override - @MustBeInvokedByOverriders - public boolean uKeyReleased(int keyCode, int scanCode, @Nullable UKeyboard.Modifiers modifiers) { - translateKey(inputManager, keyCode, (char) 0, false); - return true; - } - - @Override - @MustBeInvokedByOverriders - public boolean uCharTyped(char c, @Nullable UKeyboard.Modifiers modifiers) { - translateKey(inputManager, 0, c, true); - return true; - } - - @Override - @MustBeInvokedByOverriders - public boolean uMouseClicked(double mouseX, double mouseY, int mouseButton) { - inputManager.mousePressed(mouseButton); - return true; - } - - @Override - @MustBeInvokedByOverriders - public boolean uMouseReleased(double mouseX, double mouseY, int mouseButton) { - inputManager.mouseReleased(mouseButton); - return true; - } - - @Override - @MustBeInvokedByOverriders - public boolean uMouseScrolled(double delta) { - inputManager.mouseScrolled(0f, (float) delta); - return true; - } - - //#if MC>=11300 - //$$ @Override - //#endif - public boolean shouldCloseOnEsc() { - return true; - } - - //#if MC<=11300 - @Override - //#endif - public boolean doesGuiPauseGame() { - return doesUIPauseGame(); - } - - @Override - public boolean doesUIPauseGame() { - return pauses; - } - - @Override - public boolean hasBackgroundBlur() { - return blurs; - } - - - //#if MC>=11300 - //$$ @Override - //#endif - @MustBeInvokedByOverriders - public void mouseMoved(double mouseX, double mouseY) { - if (polyUI == null) return; - Vec2 size = polyUI.getMaster().getSize(); - float ox = (float) UResolution.getWindowWidth() / 2f - size.getX() / 2f; - float oy = (float) UResolution.getWindowHeight() / 2f - size.getY() / 2f; - inputManager.mouseMoved((float) UMouse.Raw.getX() - ox, (float) UMouse.Raw.getY() - oy); - } - - @Override - @MustBeInvokedByOverriders - public void onScreenClose() { - if (close != null) close.run(); - if (polyUI == null) return; - // noinspection DataFlowIssue - this.polyUI.getWindow().setCursor(Cursor.Pointer); - } - - public final Drawable getMaster() { - if (polyUI == null) throw new IllegalArgumentException("no drawables attached this way"); - return polyUI.getMaster(); - } - - public final float width() { - return useMinecraftUIScaling() ? UResolution.getScaledWidth() : UResolution.getWindowWidth(); - } - - public final float height() { - return useMinecraftUIScaling() ? UResolution.getScaledHeight() : UResolution.getWindowHeight(); - } - - public final float scale() { - return (float) UResolution.getViewportWidth() / UResolution.getWindowWidth(); - } -} \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java index 83df0f1c0..7347f86e2 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfig.java @@ -26,22 +26,22 @@ package org.polyfrost.oneconfig.internal; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.polyfrost.oneconfig.api.commands.v1.CommandManager; import org.polyfrost.oneconfig.api.commands.v1.factories.builder.CommandBuilder; import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.polyfrost.oneconfig.api.event.v1.events.InitializationEvent; import org.polyfrost.oneconfig.api.hud.v1.HudManager; +import org.polyfrost.oneconfig.api.platform.v1.Platform; import org.polyfrost.oneconfig.api.ui.v1.UIManager; import org.polyfrost.oneconfig.api.ui.v1.internal.BlurHandler; -import org.polyfrost.oneconfig.internal.ui.OneConfigUI; import org.polyfrost.oneconfig.api.ui.v1.keybind.KeybindHelper; -import org.polyfrost.oneconfig.utils.v1.GuiUtils; +import org.polyfrost.oneconfig.internal.ui.OneConfigUI; import org.polyfrost.polyui.PolyUI; import org.polyfrost.polyui.component.Drawable; import org.polyfrost.polyui.input.KeyModifiers; import org.polyfrost.polyui.input.Translator; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import static org.polyfrost.oneconfig.api.commands.v1.factories.builder.CommandBuilder.runs; @@ -86,10 +86,10 @@ private void init() { BlurHandler.init(); preload(); CommandBuilder b = CommandManager.builder("oneconfig", "ocfg", "ocfgv1").description("OneConfig main command"); - b.then(runs().does(() -> GuiUtils.displayScreen(OneConfigUI.INSTANCE.create())).description("Opens the OneConfig GUI")); - b.then(runs("hud").does(() -> GuiUtils.displayScreen(HudManager.INSTANCE.getWithEditor())).description("Opens the OneConfig HUD editor")); + b.then(runs().does(OneConfigUI.INSTANCE::open).description("Opens the OneConfig GUI")); + b.then(runs("hud").does(() -> Platform.screen().display(HudManager.INSTANCE.getWithEditor())).description("Opens the OneConfig HUD editor")); CommandManager.registerCommand(b); - KeybindHelper.builder().mods(KeyModifiers.RSHIFT).does(() -> GuiUtils.displayScreen(OneConfigUI.INSTANCE.create())).register(); + KeybindHelper.builder().mods(KeyModifiers.RSHIFT).does(OneConfigUI.INSTANCE::open).register(); EventManager.INSTANCE.post(InitializationEvent.INSTANCE); LOGGER.info("OneConfig initialized!"); } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfigMixinInit.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfigMixinInit.java index 7b49daba6..955eac830 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfigMixinInit.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/OneConfigMixinInit.java @@ -59,8 +59,8 @@ public void acceptTargets(Set myTargets, Set otherTargets) { @Override public List getMixins() { List mixins = new ArrayList<>(); - LoaderPlatform.Loaders loader = Platform.getLoaderPlatform().getLoader(); - int version = Platform.getLoaderPlatform().getMinecraftVersion(); + LoaderPlatform.Loaders loader = Platform.loader().getLoader(); + int version = Platform.loader().getMinecraftVersion(); // Loader-specific mixins if (loader == LoaderPlatform.Loaders.FORGE) { @@ -77,18 +77,18 @@ public List getMixins() { // legacy fabric mixins.add("commands.ChatScreenMixin"); } + if (version > 12000) { + mixins.add("hypixel.CustomPayloadS2CPacketMixin"); + } } // Inter-loader mixins if (version >= 11600) { mixins.add("KeyboardMixin"); mixins.add("MouseMixin"); - mixins.add("commands.ClientCommandSourceMixin"); mixins.add("commands.ClientPlayNetworkHandlerMixin"); mixins.add("commands.HelpCommandAccessor"); - if (version >= 12000) { - mixins.add("DebugHudAccessor"); - } else { + if (version < 12000) { // 1.16, 1.17, 1.18, 1.19 mixins.add("SchemasMixin"); mixins.add("EntityPlayerSPMixin"); diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/legacy/OneConfigTweaker.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/legacy/OneConfigTweaker.java index 185a7fe78..ca613424c 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/legacy/OneConfigTweaker.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/legacy/OneConfigTweaker.java @@ -31,15 +31,15 @@ import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; import net.minecraftforge.fml.relauncher.CoreModManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.polyfrost.oneconfig.api.platform.v1.Platform; import org.polyfrost.oneconfig.utils.v1.MHUtils; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; import org.spongepowered.asm.launch.MixinBootstrap; import org.spongepowered.asm.mixin.Mixins; import java.io.File; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle; import java.net.URI; import java.net.URL; import java.nio.file.Files; @@ -49,6 +49,7 @@ import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.function.Consumer; import java.util.jar.Attributes; import java.util.jar.JarFile; @@ -60,38 +61,31 @@ public class OneConfigTweaker implements ITweaker { private static final Logger LOGGER = LogManager.getLogger("OneConfig/Tweaker"); private static final String MIXIN_TWEAKER = "org.spongepowered.asm.launch.MixinTweaker"; - private static final Method loadCoreMod; - - static { - try { - loadCoreMod = MHUtils.setAccessible(CoreModManager.class.getDeclaredMethod("loadCoreMod", LaunchClassLoader.class, String.class, File.class)); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } + private static MethodHandle loadCoreMod; + private static Consumer addContainer; public OneConfigTweaker() { final List sourceFiles = getSourceFiles(); if (sourceFiles.isEmpty()) { - if (!Platform.getLoaderPlatform().isDevelopmentEnvironment()) LOGGER.fatal("Not able to detect jar sources. mixin will NOT work!"); + if (!Platform.loader().isDevelopmentEnvironment()) LOGGER.fatal("Not able to detect jar sources. mixin will NOT work!"); return; } - for (SourceFile sourceFile : sourceFiles) { - try { - setupSourceFile(sourceFile); - } catch (Exception e) { - LOGGER.error("failed to setup mixin initialization for {}", sourceFile.path.toString(), e); - } - } try { injectMixinTweaker(); } catch (Exception e) { LOGGER.error("failed to inject mixin tweaker", e); } + for (SourceFile sourceFile : sourceFiles) { + try { + setupSourceFile(sourceFile); + } catch (Throwable t) { + LOGGER.error("failed to setup mixin for {}", sourceFile.path.toString(), t); + } + } } @SuppressWarnings("unchecked") - private static void setupSourceFile(SourceFile sourceFile) throws Exception { + private static void setupSourceFile(SourceFile sourceFile) throws Throwable { String path = sourceFile.path.toString(); // Forge will by default ignore a mod file if it contains a tweaker // So we need to remove ourselves from that exclusion list @@ -106,40 +100,49 @@ private static void setupSourceFile(SourceFile sourceFile) throws Exception { // Mixin takes care of this as well, so we mustn't if it will. String coreMod = sourceFile.coreMod; if (coreMod != null && !sourceFile.mixin) { - ITweaker tweaker = (ITweaker) loadCoreMod.invoke(null, Launch.classLoader, coreMod, sourceFile.path.toFile()); + ITweaker tweaker = loadCoreMod(Launch.classLoader, coreMod, sourceFile.path.toFile()); ((List) Launch.blackboard.get("Tweaks")).add(tweaker); } - // If they declared our tweaker but also want to use mixin, then we'll inject the mixin tweaker - // for them. - if (sourceFile.mixin) { - // Mixin will only look at jar files which declare the MixinTweaker as their tweaker class, so we need - // to manually add our source files for inspection. - try { - injectMixinTweaker(); + // Mixin will only look at jar files which declare the MixinTweaker as their tweaker class, so we need + // to manually add our source files for inspection. + if (sourceFile.mixin) addContainer(sourceFile.path.toUri()); + } - Class MixinBootstrap = Class.forName("org.spongepowered.asm.launch.MixinBootstrap"); - Class MixinPlatformManager = Class.forName("org.spongepowered.asm.launch.platform.MixinPlatformManager"); - Object platformManager = MixinBootstrap.getDeclaredMethod("getPlatform").invoke(null); - Method addContainer; - Object arg; - URI uri = sourceFile.path.toUri(); - try { - // Mixin 0.7 - addContainer = MixinPlatformManager.getDeclaredMethod("addContainer", URI.class); - arg = uri; - } catch (NoSuchMethodException ignored) { - // Mixin 0.8 - Class IContainerHandle = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle"); - Class ContainerHandleURI = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI"); - //noinspection JavaReflectionMemberAccess - addContainer = MixinPlatformManager.getDeclaredMethod("addContainer", IContainerHandle); - arg = ContainerHandleURI.getDeclaredConstructor(URI.class).newInstance(uri); - } - addContainer.invoke(platformManager, arg); - } catch (Exception e) { - LOGGER.error("failed to add mixin container for {}", path, e); + private static ITweaker loadCoreMod(LaunchClassLoader loader, String cls, File src) throws Throwable { + MethodHandle mh = loadCoreMod == null ? loadCoreMod = createLoadCoreMod() : loadCoreMod; + return (ITweaker) mh.invoke(loader, src, src); + } + + private static MethodHandle createLoadCoreMod() { + return MHUtils.getStaticMethodHandle(CoreModManager.class, "loadCoreMod", ITweaker.class, LaunchClassLoader.class, String.class, File.class).getOrThrow(); + } + + private static void addContainer(URI uri) { + Consumer c = addContainer == null ? addContainer = createAddContainer() : addContainer; + c.accept(uri); + } + + private static Consumer createAddContainer() { + try { + Class MixinBootstrap = Class.forName("org.spongepowered.asm.launch.MixinBootstrap"); + Class MixinPlatformManager = Class.forName("org.spongepowered.asm.launch.platform.MixinPlatformManager"); + Object platformManager = MHUtils.invokeStatic(MixinBootstrap, "getPlatform"); + try { + // Mixin 0.7 + return MHUtils.getConsumerFunctionHandle(platformManager, "addContainer", URI.class).getOrThrow(); + } catch (Throwable ignored) { + // Mixin 0.8 + Class IContainerHandle = Class.forName("org.spongepowered.asm.launch.platform.container.IContainerHandle"); + Class ContainerHandleURI = Class.forName("org.spongepowered.asm.launch.platform.container.ContainerHandleURI"); + // as we can't refer to IContainerHandle, we have to use unchecked casts here. + // noinspection unchecked + Consumer addWrappedContainer = (Consumer) MHUtils.getConsumerFunctionHandle(MixinPlatformManager, "addContainer", IContainerHandle).getOrThrow(); + MethodHandle wrapper = MHUtils.getConstructorHandle(ContainerHandleURI, URI.class).getOrThrow(); + return it -> addWrappedContainer.accept(MHUtils.invokeCatching(wrapper, it).getOrThrow()); } + } catch (Throwable t) { + throw new RuntimeException("Failed to crack addContainer method. mixin will not work!", t); } } @@ -152,7 +155,7 @@ private static List getSourceFiles() { continue; } Path file = Paths.get(uri); - if(!Files.exists(file) || !Files.isRegularFile(file)) { + if (!Files.exists(file) || !Files.isRegularFile(file)) { continue; } String tweakClass = null; @@ -170,17 +173,17 @@ private static List getSourceFiles() { sourceFiles.add(new SourceFile(file, coreMod, mixin)); } } catch (Exception e) { - LOGGER.error("failed to inspect jar file {}", url, e); + LOGGER.error("failed to inspect jar file {}, ignoring", url, e); } } return sourceFiles; } - private static void injectMixinTweaker() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + private static void injectMixinTweaker() throws ClassNotFoundException { @SuppressWarnings("unchecked") List tweakClasses = (List) Launch.blackboard.get("TweakClasses"); - // If the MixinTweaker is already queued (because of another mod), then there's nothing we need to to + // If the MixinTweaker is already queued (because of another mod), then there's nothing we need to do if (tweakClasses.contains(MIXIN_TWEAKER)) { // Except we do need to initialize the MixinTweaker immediately so we can add containers // for our mods. @@ -205,9 +208,9 @@ private static void injectMixinTweaker() throws ClassNotFoundException, IllegalA tweaks.add(initMixinTweaker()); } - private static ITweaker initMixinTweaker() throws ClassNotFoundException, IllegalAccessException, InstantiationException { + private static ITweaker initMixinTweaker() throws ClassNotFoundException { Launch.classLoader.addClassLoaderExclusion(MIXIN_TWEAKER.substring(0, MIXIN_TWEAKER.lastIndexOf('.'))); - return (ITweaker) Class.forName(MIXIN_TWEAKER, true, Launch.classLoader).newInstance(); + return (ITweaker) MHUtils.instantiate(Class.forName(MIXIN_TWEAKER, true, Launch.classLoader), false).getOrThrow(); } private static class SourceFile { @@ -222,10 +225,6 @@ private SourceFile(Path path, String coreMod, boolean mixin) { } } - @Override - public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { - } - @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { MixinBootstrap.init(); @@ -255,6 +254,10 @@ private static void removeLWJGLException() { } } + @Override + public void acceptOptions(List args, File gameDir, File assetsDir, String profile) { + } + @Override public String getLaunchTarget() { return null; diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/EntityPlayerSPMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/EntityPlayerSPMixin.java index 970f965fa..5e7503113 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/EntityPlayerSPMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/EntityPlayerSPMixin.java @@ -44,7 +44,7 @@ public abstract class EntityPlayerSPMixin { @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) public void ocfg$chatCallback(String message, CallbackInfo ci) { - //#if MC>=11600 && FABRIC + //#if MC>=11600 //$$ if (org.polyfrost.oneconfig.internal.libs.fabric.ClientCommandInternals.executeCommand(message)) { //$$ ci.cancel(); //$$ } diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java index 193d401e2..6644b415c 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/GuiIngameMixin.java @@ -29,7 +29,7 @@ import net.minecraftforge.client.GuiIngameForge; import org.polyfrost.oneconfig.api.event.v1.EventManager; import org.polyfrost.oneconfig.api.event.v1.events.HudRenderEvent; -import org.polyfrost.oneconfig.internal.ClassHasOverwrites; +import org.polyfrost.oneconfig.api.ClassHasOverwrites; import org.polyfrost.universal.UMatrixStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -37,15 +37,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(value = GuiIngameForge.class, remap = false) -@ClassHasOverwrites({"1.8.9-fabric", "1.16.5-fabric"}) +@ClassHasOverwrites({"1.8.9-fabric", "1.16.5-fabric", "1.16.5-forge"}) public abstract class GuiIngameMixin { - //#if MC>=11600 - //$$ @Inject(method = "renderIngameGui", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/gui/ForgeIngameGui;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;Lcom/mojang/blaze3d/matrix/MatrixStack;)V", shift = At.Shift.AFTER, remap = false), remap = true) - //$$ private void ocfg$postRenderHudEvent(com.mojang.blaze3d.matrix.MatrixStack matrices, float partialTicks, CallbackInfo ci) { - //#else @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/GuiIngameForge;post(Lnet/minecraftforge/client/event/RenderGameOverlayEvent$ElementType;)V", shift = At.Shift.AFTER, remap = false), remap = true) private void ocfg$renderHudCallback(float partialTicks, CallbackInfo ci) { - //#endif EventManager.INSTANCE.post(new HudRenderEvent(UMatrixStack.Compat.INSTANCE.get(), partialTicks)); } } \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java index c96de413f..765575e11 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/MinecraftMixin.java @@ -44,17 +44,8 @@ import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -//#if MC<=11202 -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -//#endif - //#if FORGE -//#if MC<11900 import net.minecraftforge.client.event.GuiOpenEvent; -//#else -//$$ import net.minecraftforge.client.event.ScreenEvent.Opening; -//#endif import net.minecraftforge.fml.common.eventhandler.Event; //#else //$$ import org.polyfrost.oneconfig.api.event.v1.events.ScreenOpenEvent; @@ -131,37 +122,17 @@ public abstract class MinecraftMixin { } //#if FORGE - @ModifyArg(method = - //#if MC>11700 - //$$ "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/eventbus/api/IEventBus;post(Lnet/minecraftforge/eventbus/api/Event;)Z" - //#else - "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z" - //#endif - , remap = false)) + @ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false)) private Event ocfg$screenOpenCallback(Event a) { - if (a instanceof - //#if MC<11900 - GuiOpenEvent - //#else - //$$ Opening - //#endif - ) { + if (a instanceof GuiOpenEvent) { // w: not imported because 1.18+ they renamed it to be the same (breh) - //#if MC<11900 GuiOpenEvent forgeEvent = (GuiOpenEvent) a; - //#else - //$$ Opening forgeEvent = (Opening) a; - //#endif org.polyfrost.oneconfig.api.event.v1.events.ScreenOpenEvent event = new org.polyfrost.oneconfig.api.event.v1.events.ScreenOpenEvent(forgeEvent. //#if MC<=10809 gui //#else - //#if MC<11900 //$$ getGui() - //#else - //$$ getNewScreen() - //#endif //#endif ); EventManager.INSTANCE.post(event); @@ -193,87 +164,41 @@ public abstract class MinecraftMixin { //#if MC<=11202 - //#if FORGE + //#if MC<=10809 @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/settings/KeyBinding;setKeyBindState(IZ)V", ordinal = 1)) + //#else + //#if FORGE + //$$ @Inject(method = "runTickKeyboard", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;debugCrashKeyPressTime:J", opcode = org.objectweb.asm.Opcodes.PUTFIELD)) + //#else + //$$ @Inject(method = "method_12145", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;f3CTime:J", opcode = org.objectweb.asm.Opcodes.PUTFIELD)) + //#endif + //#endif private void ocfg$keyCallback(CallbackInfo ci) { int state = 0; - if (Keyboard.getEventKeyState()) { - if (Keyboard.isRepeatEvent()) { + if (org.lwjgl.input.Keyboard.getEventKeyState()) { + if (org.lwjgl.input.Keyboard.isRepeatEvent()) { state = 2; } else { state = 1; } } - EventManager.INSTANCE.post(new KeyInputEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), state)); + EventManager.INSTANCE.post(new KeyInputEvent(org.lwjgl.input.Keyboard.getEventKey(), org.lwjgl.input.Keyboard.getEventCharacter(), state)); } + //#if FORGE @Inject(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;postMouseEvent()Z", remap = false)) + //#else + //#if MC==10809 + //$$ @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButton()I", remap = false)) + //#else + //$$ @Inject(method = "method_12141", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/options/KeyBinding;setKeyPressed(IZ)V")) + //#endif + //#endif private void ocfg$mouseCallback(CallbackInfo ci) { - EventManager.INSTANCE.post(new MouseInputEvent(Mouse.getEventButton(), Mouse.getEventButtonState() ? 1 : 0)); + EventManager.INSTANCE.post(new MouseInputEvent(org.lwjgl.input.Mouse.getEventButton(), org.lwjgl.input.Mouse.getEventButtonState() ? 1 : 0)); } - //#else - //$$ @Inject(method = "runTickKeyboard", at = @At(value = "FIELD", target = "Lnet/minecraft/client/Minecraft;debugCrashKeyPressTime:J", opcode = org.objectweb.asm.Opcodes.PUTFIELD)) - //$$ private void ocfg$keyCallback(CallbackInfo ci) { - //$$ int state = 0; - //$$ if (Keyboard.getEventKeyState()) { - //$$ if (Keyboard.isRepeatEvent()) { - //$$ state = 2; - //$$ } else { - //$$ state = 1; - //$$ } - //$$ } - //$$ EventManager.INSTANCE.post(new KeyInputEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), state)); - //$$ } - //$$ - //$$ @Inject(method = "runTickMouse", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/ForgeHooksClient;postMouseEvent()Z", remap = false), remap = true) - //$$ private void ocfg$mouseCallback(CallbackInfo ci) { - //$$ EventManager.INSTANCE.post(new MouseInputEvent(Mouse.getEventButton(), Mouse.getEventButtonState() ? 1 : 0)); - //$$ } - //$$ - //#endif - //#else - //#if MC<=10809 - //$$ @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/options/KeyBinding;setKeyPressed(IZ)V", ordinal = 1)) - //$$ private void ocfg$keyCallback(CallbackInfo ci) { - //$$ int state = 0; - //$$ if (Keyboard.getEventKeyState()) { - //$$ if (Keyboard.isRepeatEvent()) { - //$$ state = 2; - //$$ } else { - //$$ state = 1; - //$$ } - //$$ } - //$$ EventManager.INSTANCE.post(new KeyInputEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), state)); - //$$ } - //$$ - //$$ @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lorg/lwjgl/input/Mouse;getEventButton()I", remap = false)) - //$$ private void ocfg$mouseCallback(CallbackInfo ci) { - //$$ EventManager.INSTANCE.post(new MouseInputEvent(Mouse.getEventButton(), Mouse.getEventButtonState() ? 1 : 0)); - //$$ } - //$$ - //#else - //$$ @Inject(method = "method_12145", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;f3CTime:J", opcode = org.objectweb.asm.Opcodes.PUTFIELD)) - //$$ private void ocfg$keyCallback(CallbackInfo ci) { - //$$ int state = 0; - //$$ if (Keyboard.getEventKeyState()) { - //$$ if (Keyboard.isRepeatEvent()) { - //$$ state = 2; - //$$ } else { - //$$ state = 1; - //$$ } - //$$ } - //$$ EventManager.INSTANCE.post(new KeyInputEvent(Keyboard.getEventKey(), Keyboard.getEventCharacter(), state)); - //$$ } - //$$ - //$$ @Inject(method = "method_12141", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/options/KeyBinding;setKeyPressed(IZ)V")) - //$$ private void ocfg$mouseCallback(CallbackInfo ci) { - //$$ EventManager.INSTANCE.post(new MouseInputEvent(Mouse.getEventButton(), Mouse.getEventButtonState() ? 1 : 0)); - //$$ } - //$$ - //#endif - //#endif //#endif } \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java index 87cfd9203..da93bc5c9 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/NetworkManagerMixin.java @@ -46,10 +46,10 @@ public abstract class NetworkManagerMixin { //#if MC<=11202 @Inject(method = "sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;[Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true) private void ocfg$packetSendCallbackGeneric(Packet packetIn, GenericFutureListener> listener, GenericFutureListener>[] listeners, CallbackInfo ci) { - //#else - //$$ @Inject(method = "sendPacket(Lnet/minecraft/network/IPacket;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true) - //$$ private void ocfg$packetCallback(IPacket packetIn, GenericFutureListener> genericFutureListener, CallbackInfo ci) { - //#endif + //#else + //$$ @Inject(method = "sendPacket(Lnet/minecraft/network/IPacket;Lio/netty/util/concurrent/GenericFutureListener;)V", at = @At("HEAD"), cancellable = true) + //$$ private void ocfg$packetCallback(IPacket packetIn, GenericFutureListener> genericFutureListener, CallbackInfo ci) { + //#endif ocfg$packetSendCallback(packetIn, ci); } //#endif diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java index de2385c61..28e7842c3 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/WorldClientMixin.java @@ -38,6 +38,7 @@ public abstract class WorldClientMixin { @Inject(method = "", at = @At("RETURN")) private void ocfg$worldLoadCallback(CallbackInfo ci) { - EventManager.INSTANCE.post(WorldLoadEvent.INSTANCE); + //noinspection DataFlowIssue + EventManager.INSTANCE.post(new WorldLoadEvent((WorldClient) ((Object) this))); } } \ No newline at end of file diff --git a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/forge/EventBusMixin.java b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/forge/EventBusMixin.java index d2245121d..c06f31e1f 100644 --- a/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/forge/EventBusMixin.java +++ b/versions/src/main/java/org/polyfrost/oneconfig/internal/mixin/forge/EventBusMixin.java @@ -36,13 +36,7 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -//#if MC>=10809 -//#if FORGE && MC>11700 -//$$ import net.minecraft.network.chat.ChatType; -//#else -//$$ import net.minecraft.util.text.ChatType; -//#endif -//#endif + @Mixin(EventBus.class) @@ -56,17 +50,17 @@ public abstract class EventBusMixin { if (event.type != 0) return; ChatReceiveEvent ev = new ChatReceiveEvent(event.message); //#else - //#if MC<11900 - //$$ if(event.getType() != ChatType.CHAT) return; - //#endif + //#if MC<11900 + //$$ if(event.getType() != net.minecraft.util.text.ChatType.CHAT) return; + //#endif //$$ ChatReceiveEvent ev = new ChatReceiveEvent(event.getMessage()); //#endif EventManager.INSTANCE.post(ev); //#if MC==10809 - event.message = ev.message; + event.message = ev.getMessage(); //#else - //$$ event.setMessage(ev.message); + //$$ event.setMessage(ev.getMessage()); //#endif if (ev.cancelled) { event.setCanceled(true); diff --git a/versions/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java b/versions/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java deleted file mode 100644 index 750bd3c9d..000000000 --- a/versions/src/main/java/org/polyfrost/oneconfig/utils/v1/GuiUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of OneConfig. - * OneConfig - Next Generation Config Library for Minecraft: Java Edition - * Copyright (C) 2021~2024 Polyfrost. - * - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * OneConfig is licensed under the terms of version 3 of the GNU Lesser - * General Public License as published by the Free Software Foundation, AND - * under the Additional Terms Applicable to OneConfig, as published by Polyfrost, - * either version 1.0 of the Additional Terms, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License. If not, see . You should - * have also received a copy of the Additional Terms Applicable - * to OneConfig, as published by Polyfrost. If not, see - * - */ - -package org.polyfrost.oneconfig.utils.v1; - -import net.minecraft.client.gui.GuiScreen; -import org.jetbrains.annotations.ApiStatus; -import org.polyfrost.oneconfig.api.PlatformDeclaration; -import org.polyfrost.oneconfig.api.event.v1.EventDelay; -import org.polyfrost.universal.UScreen; - -/** - * A class containing utility methods for working with GuiScreens. - */ -@PlatformDeclaration -public final class GuiUtils { - - // correct signature for platform compatibility - @ApiStatus.Internal - public static void displayScreen(Object o) { - displayScreen((GuiScreen) o); - } - - /** - * Displays a screen after a tick, preventing mouse sync issues. - * - * @param screen the screen to display. - */ - public static void displayScreen(GuiScreen screen) { - displayScreen(screen, 1); - } - - /** - * Displays a screen after the specified amount of ticks. - * - * @param screen the screen to display. - * @param ticks the amount of ticks to wait for before displaying the screen. - */ - public static void displayScreen(GuiScreen screen, int ticks) { - if (ticks < 1) UScreen.displayScreen(screen); - else EventDelay.tick(ticks, () -> UScreen.displayScreen(screen)); - } - - - /** - * Close the current open GUI screen. - */ - public static void closeScreen() { - displayScreen(null, 0); - } -} diff --git a/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternals b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternals new file mode 100644 index 000000000..23cd39f2c --- /dev/null +++ b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternals @@ -0,0 +1 @@ +org.polyfrost.oneconfig.api.hypixel.v0.internal.HypixelApiInternalsImpl \ No newline at end of file diff --git a/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.GuiPlatform b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.GuiPlatform deleted file mode 100644 index eb9d7d7d5..000000000 --- a/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.GuiPlatform +++ /dev/null @@ -1 +0,0 @@ -org.polyfrost.oneconfig.api.platform.v1.internal.GuiPlatformImpl \ No newline at end of file diff --git a/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.ScreenPlatform b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.ScreenPlatform new file mode 100644 index 000000000..2b3b4085d --- /dev/null +++ b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.platform.v1.ScreenPlatform @@ -0,0 +1 @@ +org.polyfrost.oneconfig.api.platform.v1.internal.ScreenPlatformImpl \ No newline at end of file diff --git a/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreenProvider b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreenProvider new file mode 100644 index 000000000..717503acf --- /dev/null +++ b/versions/src/main/resources/META-INF/services/org.polyfrost.oneconfig.api.ui.v1.screen.PolyUIScreenProvider @@ -0,0 +1 @@ +org.polyfrost.oneconfig.api.ui.v1.internal.PolyUIScreenProviderImpl \ No newline at end of file diff --git a/versions/src/main/resources/assets/minecraft/shaders/post/fade_in_blur.json b/versions/src/main/resources/assets/oneconfig/shaders/post/fade_in_blur.json similarity index 100% rename from versions/src/main/resources/assets/minecraft/shaders/post/fade_in_blur.json rename to versions/src/main/resources/assets/oneconfig/shaders/post/fade_in_blur.json diff --git a/versions/src/main/resources/assets/minecraft/shaders/program/fade_in_blur.fsh b/versions/src/main/resources/assets/oneconfig/shaders/program/fade_in_blur.fsh similarity index 100% rename from versions/src/main/resources/assets/minecraft/shaders/program/fade_in_blur.fsh rename to versions/src/main/resources/assets/oneconfig/shaders/program/fade_in_blur.fsh diff --git a/versions/src/main/resources/assets/minecraft/shaders/program/fade_in_blur.json b/versions/src/main/resources/assets/oneconfig/shaders/program/fade_in_blur.json similarity index 100% rename from versions/src/main/resources/assets/minecraft/shaders/program/fade_in_blur.json rename to versions/src/main/resources/assets/oneconfig/shaders/program/fade_in_blur.json