commit 7cd30d3d54b16e9facef1f5f05b6b79c75bea04e Author: cattyngmd Date: Sun Nov 5 21:10:54 2023 +0300 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b740e72 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Project exclude paths +/.gradle/ +/build/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..37c5cf1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 3arthqu4ke, alpha432, cattyn + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..4863beb --- /dev/null +++ b/build.gradle @@ -0,0 +1,89 @@ +plugins { + id 'fabric-loom' version '1.2-SNAPSHOT' + id 'maven-publish' +} + +version = project.mod_version +group = project.maven_group + +repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. +} + +loom { + accessWidenerPath = file("src/main/resources/oyvey.accesswidener") +} + +dependencies { + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + + // Fabric API. This is technically optional, but you probably want it anyway. + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + } + +processResources { + inputs.property "version", project.version + inputs.property "minecraft_version", project.minecraft_version + inputs.property "loader_version", project.loader_version + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version, + "minecraft_version": project.minecraft_version, + "loader_version": project.loader_version + } +} + +def targetJavaVersion = 17 +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + it.options.release = targetJavaVersion + } +} + +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } + archivesBaseName = project.archives_base_name + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..3c2bf93 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,17 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G + +# Fabric Properties + # check these on https://modmuss50.me/fabric.html + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.10 + loader_version=0.14.24 + +# Mod Properties + mod_version = 1.0-SNAPSHOT + maven_group = me.alpha432 + archives_base_name = oyvey + +# Dependencies + # check this on https://modmuss50.me/fabric.html + fabric_version=0.90.7+1.20.1 diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..aeb74cb --- /dev/null +++ b/gradlew @@ -0,0 +1,245 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +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 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +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. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +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. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..f91a4fe --- /dev/null +++ b/settings.gradle @@ -0,0 +1,9 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() + } +} diff --git a/src/main/java/me/alpha432/oyvey/OyVey.java b/src/main/java/me/alpha432/oyvey/OyVey.java new file mode 100644 index 0000000..750c36b --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/OyVey.java @@ -0,0 +1,51 @@ +package me.alpha432.oyvey; + +import me.alpha432.oyvey.manager.*; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.ModInitializer; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class OyVey implements ModInitializer, ClientModInitializer { + public static final String NAME = "OyVey"; + public static final String VERSION = "0.0.3 - 1.20.1"; + + public static float TIMER = 1f; + + public static final Logger LOGGER = LogManager.getLogger("OyVey"); + public static ServerManager serverManager; + public static ColorManager colorManager; + public static RotationManager rotationManager; + public static PositionManager positionManager; + public static HoleManager holeManager; + public static EventManager eventManager; + public static SpeedManager speedManager; + public static CommandManager commandManager; + public static FriendManager friendManager; + public static ModuleManager moduleManager; + public static ConfigManager configManager; + + + @Override public void onInitialize() { + eventManager = new EventManager(); + serverManager = new ServerManager(); + rotationManager = new RotationManager(); + positionManager = new PositionManager(); + friendManager = new FriendManager(); + colorManager = new ColorManager(); + commandManager = new CommandManager(); + moduleManager = new ModuleManager(); + speedManager = new SpeedManager(); + holeManager = new HoleManager(); + } + + + @Override public void onInitializeClient() { + eventManager.init(); + moduleManager.init(); + + configManager = new ConfigManager(); + configManager.load(); + Runtime.getRuntime().addShutdownHook(new Thread(() -> configManager.save())); + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/Event.java b/src/main/java/me/alpha432/oyvey/event/Event.java new file mode 100644 index 0000000..68fac19 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/Event.java @@ -0,0 +1,13 @@ +package me.alpha432.oyvey.event; + +public class Event { + private boolean cancelled; + + public boolean isCancelled() { + return cancelled; + } + + public void cancel() { + cancelled = true; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/Stage.java b/src/main/java/me/alpha432/oyvey/event/Stage.java new file mode 100644 index 0000000..ec6734c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/Stage.java @@ -0,0 +1,6 @@ +package me.alpha432.oyvey.event; + +public enum Stage { + PRE, + POST; +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/ChatEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/ChatEvent.java new file mode 100644 index 0000000..57862bd --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/ChatEvent.java @@ -0,0 +1,15 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; + +public class ChatEvent extends Event { + private final String content; + + public ChatEvent(String content) { + this.content = content; + } + + public String getMessage() { + return content; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/ClientEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/ClientEvent.java new file mode 100644 index 0000000..71338d2 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/ClientEvent.java @@ -0,0 +1,33 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.settings.Setting; + +public class ClientEvent extends Event { + private Feature feature; + private Setting setting; + private int stage; + + public ClientEvent(int stage, Feature feature) { + this.stage = stage; + this.feature = feature; + } + + public ClientEvent(Setting setting) { + this.stage = 2; + this.setting = setting; + } + + public Feature getFeature() { + return this.feature; + } + + public Setting getSetting() { + return this.setting; + } + + public int getStage() { + return stage; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/DeathEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/DeathEvent.java new file mode 100644 index 0000000..8a475bf --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/DeathEvent.java @@ -0,0 +1,16 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import net.minecraft.entity.LivingEntity; + +public class DeathEvent extends Event { + private final LivingEntity entity; + + public DeathEvent(LivingEntity entity) { + this.entity = entity; + } + + public LivingEntity getEntity() { + return entity; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/KeyEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/KeyEvent.java new file mode 100644 index 0000000..5f9a158 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/KeyEvent.java @@ -0,0 +1,15 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; + +public class KeyEvent extends Event { + private final int key; + + public KeyEvent(int key) { + this.key = key; + } + + public int getKey() { + return key; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/PacketEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/PacketEvent.java new file mode 100644 index 0000000..68992d1 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/PacketEvent.java @@ -0,0 +1,30 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import net.minecraft.network.packet.Packet; + +public abstract class PacketEvent extends Event { + + private final Packet packet; + + public PacketEvent(Packet packet) { + this.packet = packet; + } + + public Packet getPacket() { + return packet; + } + + public static class Receive extends PacketEvent { + public Receive(Packet packet) { + super(packet); + } + } + + public static class Send extends PacketEvent { + public Send(Packet packet) { + super(packet); + } + } + +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/event/impl/Render2DEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/Render2DEvent.java new file mode 100644 index 0000000..8dc478e --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/Render2DEvent.java @@ -0,0 +1,22 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import net.minecraft.client.gui.DrawContext; + +public class Render2DEvent extends Event { + private final DrawContext context; + private final float delta; + + public Render2DEvent(DrawContext context, float delta) { + this.context = context; + this.delta = delta; + } + + public DrawContext getContext() { + return context; + } + + public float getDelta() { + return delta; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/Render3DEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/Render3DEvent.java new file mode 100644 index 0000000..33a90ee --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/Render3DEvent.java @@ -0,0 +1,22 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import net.minecraft.client.util.math.MatrixStack; + +public class Render3DEvent extends Event { + private final MatrixStack matrix; + private final float delta; + + public Render3DEvent(MatrixStack matrix, float delta) { + this.matrix = matrix; + this.delta = delta; + } + + public MatrixStack getMatrix() { + return matrix; + } + + public float getDelta() { + return delta; + } +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/UpdateEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/UpdateEvent.java new file mode 100644 index 0000000..da162d2 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/UpdateEvent.java @@ -0,0 +1,6 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; + +public class UpdateEvent extends Event { +} diff --git a/src/main/java/me/alpha432/oyvey/event/impl/UpdateWalkingPlayerEvent.java b/src/main/java/me/alpha432/oyvey/event/impl/UpdateWalkingPlayerEvent.java new file mode 100644 index 0000000..9d6ff7a --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/event/impl/UpdateWalkingPlayerEvent.java @@ -0,0 +1,16 @@ +package me.alpha432.oyvey.event.impl; + +import me.alpha432.oyvey.event.Event; +import me.alpha432.oyvey.event.Stage; + +public class UpdateWalkingPlayerEvent extends Event { + private final Stage stage; + + public UpdateWalkingPlayerEvent(Stage stage) { + this.stage = stage; + } + + public Stage getStage() { + return stage; + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/Feature.java b/src/main/java/me/alpha432/oyvey/features/Feature.java new file mode 100644 index 0000000..99665bf --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/Feature.java @@ -0,0 +1,89 @@ +package me.alpha432.oyvey.features; + +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.traits.Util; + +import java.util.ArrayList; +import java.util.List; + +public class Feature + implements Util { + public List> settings = new ArrayList<>(); + private String name; + + public Feature() { + } + + public Feature(String name) { + this.name = name; + } + + public static boolean nullCheck() { + return Feature.mc.player == null; + } + + public static boolean fullNullCheck() { + return Feature.mc.player == null || Feature.mc.world == null; + } + + public String getName() { + return this.name; + } + + public List> getSettings() { + return this.settings; + } + + public boolean hasSettings() { + return !this.settings.isEmpty(); + } + + public boolean isEnabled() { + return false; + } + + public boolean isDisabled() { + return !this.isEnabled(); + } + + public Setting register(Setting setting) { + setting.setFeature(this); + this.settings.add(setting); +// if (this instanceof Module && Feature.mc.currentScreen instanceof OyVeyGui) { +// OyVeyGui.getInstance().updateModule((Module) this); +// } + return setting; + } + + public void unregister(Setting settingIn) { + ArrayList> removeList = new ArrayList<>(); + for (Setting setting : this.settings) { + if (!setting.equals(settingIn)) continue; + removeList.add(setting); + } + if (!removeList.isEmpty()) { + this.settings.removeAll(removeList); + } +// if (this instanceof Module && Feature.mc.currentScreen instanceof OyVeyGui) { +// OyVeyGui.getInstance().updateModule((Module) this); +// } + } + + public Setting getSettingByName(String name) { + for (Setting setting : this.settings) { + if (!setting.getName().equalsIgnoreCase(name)) continue; + return setting; + } + return null; + } + + public void reset() { + for (Setting setting : this.settings) { + setting.reset(); + } + } + + public void clearSettings() { + this.settings = new ArrayList<>(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/Command.java b/src/main/java/me/alpha432/oyvey/features/commands/Command.java new file mode 100644 index 0000000..4828f63 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/Command.java @@ -0,0 +1,52 @@ +package me.alpha432.oyvey.features.commands; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.Feature; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + + +public abstract class Command + extends Feature { + protected String name; + protected String[] commands; + + public Command(String name) { + super(name); + this.name = name; + this.commands = new String[]{""}; + } + + public Command(String name, String[] commands) { + super(name); + this.name = name; + this.commands = commands; + } + + public static void sendMessage(String message) { + Command.sendSilentMessage(OyVey.commandManager.getClientMessage() + " " + Formatting.GRAY + message); + } + + public static void sendSilentMessage(String message) { + if (Command.nullCheck()) { + return; + } + // TODO add silent support ig + mc.inGameHud.getChatHud().addMessage(Text.literal(message)); + } + + public static String getCommandPrefix() { + return OyVey.commandManager.getPrefix(); + } + + public abstract void execute(String[] var1); + + @Override + public String getName() { + return this.name; + } + + public String[] getCommands() { + return this.commands; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/BindCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/BindCommand.java new file mode 100644 index 0000000..e45584a --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/BindCommand.java @@ -0,0 +1,55 @@ +package me.alpha432.oyvey.features.commands.impl; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.KeyEvent; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Bind; +import me.alpha432.oyvey.util.KeyboardUtil; +import net.minecraft.util.Formatting; +import org.lwjgl.glfw.GLFW; + +import java.security.Key; + +public class BindCommand + extends Command { + private boolean listening; + private Module module; + + public BindCommand() { + super("bind", new String[]{""}); + EVENT_BUS.register(this); + } + + @Override + public void execute(String[] commands) { + if (commands.length == 1) { + sendMessage("Please specify a module."); + return; + } + String moduleName = commands[0]; + Module module = OyVey.moduleManager.getModuleByName(moduleName); + if (module == null) { + sendMessage("Unknown module '" + module + "'!"); + return; + } + + sendMessage(Formatting.GRAY + "Press a key."); + listening = true; + this.module = module; + } + + @Subscribe private void onKey(KeyEvent event) { + if (nullCheck() || !listening) return; + listening = false; + if (event.getKey() == GLFW.GLFW_KEY_ESCAPE) { + sendMessage(Formatting.GRAY + "Operation cancelled."); + return; + } + + sendMessage("Bind for " + Formatting.GREEN + module.getName() + Formatting.WHITE + " set to " + Formatting.GRAY + KeyboardUtil.getKeyName(event.getKey())); + module.bind.setValue(new Bind(event.getKey())); + } + +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/FriendCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/FriendCommand.java new file mode 100644 index 0000000..fb24097 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/FriendCommand.java @@ -0,0 +1,55 @@ +package me.alpha432.oyvey.features.commands.impl; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import net.minecraft.util.Formatting; + +public class FriendCommand + extends Command { + public FriendCommand() { + super("friend", new String[]{"", ""}); + } + + @Override + public void execute(String[] commands) { + if (commands.length == 1) { + if (OyVey.friendManager.getFriends().isEmpty()) { + FriendCommand.sendMessage("Friend list empty D:."); + } else { + StringBuilder f = new StringBuilder("Friends: "); + for (String friend : OyVey.friendManager.getFriends()) { + try { + f.append(friend).append(", "); + } catch (Exception exception) { + } + } + FriendCommand.sendMessage(f.toString()); + } + return; + } + if (commands.length == 2) { + if (commands[0].equals("reset")) { + OyVey.friendManager.getFriends().clear(); + FriendCommand.sendMessage("Friends got reset."); + return; + } + FriendCommand.sendMessage(commands[0] + (OyVey.friendManager.isFriend(commands[0]) ? " is friended." : " isn't friended.")); + return; + } + if (commands.length >= 2) { + switch (commands[0]) { + case "add" -> { + OyVey.friendManager.addFriend(commands[1]); + FriendCommand.sendMessage(Formatting.GREEN + commands[1] + " has been friended"); + return; + } + case "del", "remove" -> { + OyVey.friendManager.removeFriend(commands[1]); + FriendCommand.sendMessage(Formatting.RED + commands[1] + " has been unfriended"); + return; + } + } + FriendCommand.sendMessage("Unknown Command, try friend add/del (name)"); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/HelpCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/HelpCommand.java new file mode 100644 index 0000000..b01dfab --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/HelpCommand.java @@ -0,0 +1,28 @@ +package me.alpha432.oyvey.features.commands.impl; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import net.minecraft.util.Formatting; + +public class HelpCommand + extends Command { + public HelpCommand() { + super("help"); + } + + @Override + public void execute(String[] commands) { + HelpCommand.sendMessage("Commands: "); + for (Command command : OyVey.commandManager.getCommands()) { + StringBuilder builder = new StringBuilder(Formatting.GRAY.toString()); + builder.append(OyVey.commandManager.getPrefix()); + builder.append(command.getName()); + builder.append(" "); + for (String cmd : command.getCommands()) { + builder.append(cmd); + builder.append(" "); + } + HelpCommand.sendMessage(builder.toString()); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/ModuleCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/ModuleCommand.java new file mode 100644 index 0000000..61801aa --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/ModuleCommand.java @@ -0,0 +1,88 @@ +package me.alpha432.oyvey.features.commands.impl; + +import com.google.gson.JsonParser; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.manager.ConfigManager; +import net.minecraft.util.Formatting; + +public class ModuleCommand + extends Command { + public ModuleCommand() { + super("module", new String[]{"", "", "", ""}); + } + + @Override + public void execute(String[] commands) { + Setting setting; + if (commands.length == 1) { + ModuleCommand.sendMessage("Modules: "); + for (Module.Category category : OyVey.moduleManager.getCategories()) { + String modules = category.getName() + ": "; + for (Module module1 : OyVey.moduleManager.getModulesByCategory(category)) { + modules = modules + (module1.isEnabled() ? Formatting.GREEN : Formatting.RED) + module1.getName() + Formatting.WHITE + ", "; + } + ModuleCommand.sendMessage(modules); + } + return; + } + Module module = OyVey.moduleManager.getModuleByDisplayName(commands[0]); + if (module == null) { + module = OyVey.moduleManager.getModuleByName(commands[0]); + if (module == null) { + ModuleCommand.sendMessage("This module doesnt exist."); + return; + } + ModuleCommand.sendMessage(" This is the original name of the module. Its current name is: " + module.getDisplayName()); + return; + } + if (commands.length == 2) { + ModuleCommand.sendMessage(module.getDisplayName() + " : " + module.getDescription()); + for (Setting setting2 : module.getSettings()) { + ModuleCommand.sendMessage(setting2.getName() + " : " + setting2.getValue() + ", " + setting2.getDescription()); + } + return; + } + if (commands.length == 3) { + if (commands[1].equalsIgnoreCase("set")) { + ModuleCommand.sendMessage("Please specify a setting."); + } else if (commands[1].equalsIgnoreCase("reset")) { + for (Setting setting3 : module.getSettings()) { + setting3.setValue(setting3.getDefaultValue()); + } + } else { + ModuleCommand.sendMessage("This command doesnt exist."); + } + return; + } + if (commands.length == 4) { + ModuleCommand.sendMessage("Please specify a value."); + return; + } + if (commands.length == 5 && (setting = module.getSettingByName(commands[2])) != null) { + JsonParser jp = new JsonParser(); + if (setting.getType().equalsIgnoreCase("String")) { + setting.setValue(commands[3]); + ModuleCommand.sendMessage(Formatting.DARK_GRAY + module.getName() + " " + setting.getName() + " has been set to " + commands[3] + "."); + return; + } + try { + if (setting.getName().equalsIgnoreCase("Enabled")) { + if (commands[3].equalsIgnoreCase("true")) { + module.enable(); + } + if (commands[3].equalsIgnoreCase("false")) { + module.disable(); + } + } + ConfigManager.setValueFromJson(module, setting, jp.parse(commands[3])); + } catch (Exception e) { + ModuleCommand.sendMessage("Bad Value! This setting requires a: " + setting.getType() + " value."); + return; + } + ModuleCommand.sendMessage(Formatting.GRAY + module.getName() + " " + setting.getName() + " has been set to " + commands[3] + "."); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/PrefixCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/PrefixCommand.java new file mode 100644 index 0000000..8eb382c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/PrefixCommand.java @@ -0,0 +1,22 @@ +package me.alpha432.oyvey.features.commands.impl; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import net.minecraft.util.Formatting; + +public class PrefixCommand + extends Command { + public PrefixCommand() { + super("prefix", new String[]{""}); + } + + @Override + public void execute(String[] commands) { + if (commands.length == 1) { + Command.sendMessage(Formatting.GREEN + "Current prefix is " + OyVey.commandManager.getPrefix()); + return; + } + OyVey.commandManager.setPrefix(commands[0]); + Command.sendMessage("Prefix changed to " + Formatting.GRAY + commands[0]); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/commands/impl/ToggleCommand.java b/src/main/java/me/alpha432/oyvey/features/commands/impl/ToggleCommand.java new file mode 100644 index 0000000..925f75a --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/commands/impl/ToggleCommand.java @@ -0,0 +1,28 @@ +package me.alpha432.oyvey.features.commands.impl; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.modules.Module; + +public class ToggleCommand extends Command { + public ToggleCommand() { + super("toggle", new String[] {""}); + } + + @Override public void execute(String[] var1) { + if (var1.length < 1 || var1[0] == null) { + notFound(); + return; + } + Module mod = OyVey.moduleManager.getModuleByName(var1[0]); + if (mod == null) { + notFound(); + return; + } + mod.toggle(); + } + + private void notFound() { + sendMessage("Module is not found."); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/gui/Component.java b/src/main/java/me/alpha432/oyvey/features/gui/Component.java new file mode 100644 index 0000000..4058a4e --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/Component.java @@ -0,0 +1,194 @@ +package me.alpha432.oyvey.features.gui; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.gui.items.Item; +import me.alpha432.oyvey.features.gui.items.buttons.Button; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.util.ColorUtil; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; + +import java.awt.*; +import java.util.ArrayList; +import java.util.List; + +public class Component + extends Feature { + public static int[] counter1 = new int[]{1}; + protected DrawContext context; + private final List items = new ArrayList<>(); + public boolean drag; + private int x; + private int y; + private int x2; + private int y2; + private int width; + private int height; + private boolean open; + private boolean hidden = false; + + public Component(String name, int x, int y, boolean open) { + super(name); + this.x = x; + this.y = y; + this.width = 88; + this.height = 18; + this.open = open; + this.setupItems(); + } + + public void setupItems() { + } + + private void drag(int mouseX, int mouseY) { + if (!this.drag) { + return; + } + this.x = this.x2 + mouseX; + this.y = this.y2 + mouseY; + } + + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + this.context = context; + this.drag(mouseX, mouseY); + counter1 = new int[]{1}; + float totalItemHeight = this.open ? this.getTotalItemHeight() - 2.0f : 0.0f; + int color = ColorUtil.toARGB(ClickGui.getInstance().topRed.getValue(), ClickGui.getInstance().topGreen.getValue(), ClickGui.getInstance().topBlue.getValue(), 255); + context.fill(this.x, this.y - 1, this.x + this.width, this.y + this.height - 6, ClickGui.getInstance().rainbow.getValue() ? ColorUtil.rainbow(ClickGui.getInstance().rainbowHue.getValue()).getRGB() : color); + if (this.open) { + RenderUtil.rect(context.getMatrices(), this.x, (float) this.y + 12.5f, this.x + this.width, (float) (this.y + this.height) + totalItemHeight, 0x77000000); + } + drawString(this.getName(), (float) this.x + 3.0f, (float) this.y - 4.0f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); + if (this.open) { + float y = (float) (this.getY() + this.getHeight()) - 3.0f; + for (Item item : this.getItems()) { + Component.counter1[0] = counter1[0] + 1; + if (item.isHidden()) continue; + item.setLocation((float) this.x + 2.0f, y); + item.setWidth(this.getWidth() - 4); + item.drawScreen(context, mouseX, mouseY, partialTicks); + y += (float) item.getHeight() + 1.5f; + } + } + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0 && this.isHovering(mouseX, mouseY)) { + this.x2 = this.x - mouseX; + this.y2 = this.y - mouseY; + OyVeyGui.getClickGui().getComponents().forEach(component -> { + if (component.drag) { + component.drag = false; + } + }); + this.drag = true; + return; + } + if (mouseButton == 1 && this.isHovering(mouseX, mouseY)) { + this.open = !this.open; + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + return; + } + if (!this.open) { + return; + } + this.getItems().forEach(item -> item.mouseClicked(mouseX, mouseY, mouseButton)); + } + + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + if (releaseButton == 0) { + this.drag = false; + } + if (!this.open) { + return; + } + this.getItems().forEach(item -> item.mouseReleased(mouseX, mouseY, releaseButton)); + } + + public void onKeyTyped(char typedChar, int keyCode) { + if (!this.open) { + return; + } + this.getItems().forEach(item -> item.onKeyTyped(typedChar, keyCode)); + } + + public void onKeyPressed(int key) { + if (!open) return; + this.getItems().forEach(item -> item.onKeyPressed(key)); + } + + public void addButton(Button button) { + this.items.add(button); + } + + public int getX() { + return this.x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return this.y; + } + + public void setY(int y) { + this.y = y; + } + + public int getWidth() { + return this.width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return this.height; + } + + public void setHeight(int height) { + this.height = height; + } + + public boolean isHidden() { + return this.hidden; + } + + public void setHidden(boolean hidden) { + this.hidden = hidden; + } + + public boolean isOpen() { + return this.open; + } + + public final List getItems() { + return this.items; + } + + private boolean isHovering(int mouseX, int mouseY) { + return mouseX >= this.getX() && mouseX <= this.getX() + this.getWidth() && mouseY >= this.getY() && mouseY <= this.getY() + this.getHeight() - (this.open ? 2 : 0); + } + + private float getTotalItemHeight() { + float height = 0.0f; + for (Item item : this.getItems()) { + height += (float) item.getHeight() + 1.5f; + } + return height; + } + + protected void drawString(String text, double x, double y, Color color) { + drawString(text, x, y, color.hashCode()); + } + + protected void drawString(String text, double x, double y, int color) { + context.drawTextWithShadow(mc.textRenderer, text, (int) x, (int) y, color); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java b/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java new file mode 100644 index 0000000..29026a8 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/OyVeyGui.java @@ -0,0 +1,132 @@ +package me.alpha432.oyvey.features.gui; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.gui.items.Item; +import me.alpha432.oyvey.features.gui.items.buttons.ModuleButton; +import me.alpha432.oyvey.features.modules.Module; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Comparator; + +public class OyVeyGui extends Screen { + private static OyVeyGui oyveyGui; + private static OyVeyGui INSTANCE; + + static { + INSTANCE = new OyVeyGui(); + } + + private final ArrayList components = new ArrayList(); + + public OyVeyGui() { + super(Text.literal("OyVey")); + setInstance(); + load(); + } + + public static OyVeyGui getInstance() { + if (INSTANCE == null) { + INSTANCE = new OyVeyGui(); + } + return INSTANCE; + } + + public static OyVeyGui getClickGui() { + return OyVeyGui.getInstance(); + } + + private void setInstance() { + INSTANCE = this; + } + + private void load() { + int x = -84; + for (final Module.Category category : OyVey.moduleManager.getCategories()) { + this.components.add(new Component(category.getName(), x += 90, 4, true) { + + @Override + public void setupItems() { + counter1 = new int[]{1}; + OyVey.moduleManager.getModulesByCategory(category).forEach(module -> { + if (!module.hidden) { + this.addButton(new ModuleButton(module)); + } + }); + } + }); + } + this.components.forEach(components -> components.getItems().sort(Comparator.comparing(Feature::getName))); + } + + public void updateModule(Module module) { + for (Component component : this.components) { + for (Item item : component.getItems()) { + if (!(item instanceof ModuleButton)) continue; + ModuleButton button = (ModuleButton) item; + Module mod = button.getModule(); + if (module == null || !module.equals(mod)) continue; + button.initSettings(); + } + } + } + + @Override public void render(DrawContext context, int mouseX, int mouseY, float delta) { + Item.context = context; + context.fill(0, 0, context.getScaledWindowWidth(), context.getScaledWindowHeight(), new Color(0, 0, 0, 120).hashCode()); + this.components.forEach(components -> components.drawScreen(context, mouseX, mouseY, delta)); + } + + @Override public boolean mouseClicked(double mouseX, double mouseY, int clickedButton) { + this.components.forEach(components -> components.mouseClicked((int) mouseX, (int) mouseY, clickedButton)); + return super.mouseClicked(mouseX, mouseY, clickedButton); + } + + @Override public boolean mouseReleased(double mouseX, double mouseY, int releaseButton) { + this.components.forEach(components -> components.mouseReleased((int) mouseX, (int) mouseY, releaseButton)); + return super.mouseReleased(mouseX, mouseY, releaseButton); + } + + @Override public boolean mouseScrolled(double mouseX, double mouseY, double dWheel) { + if (dWheel < 0) { + this.components.forEach(component -> component.setY(component.getY() - 10)); + } else if (dWheel > 0) { + this.components.forEach(component -> component.setY(component.getY() + 10)); + } + return super.mouseScrolled(mouseX, mouseY, dWheel); + } + + @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + this.components.forEach(component -> component.onKeyPressed(keyCode)); + return super.keyPressed(keyCode, scanCode, modifiers); + } + + @Override public boolean charTyped(char chr, int modifiers) { + this.components.forEach(component -> component.onKeyTyped(chr, modifiers)); + return super.charTyped(chr, modifiers); + } + + @Override public boolean shouldPause() { + return false; + } + + public final ArrayList getComponents() { + return this.components; + } + + public int getTextOffset() { + return -6; + } + + public Component getComponentByName(String name) { + for (Component component : this.components) { + if (!component.getName().equalsIgnoreCase(name)) continue; + return component; + } + return null; + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/Item.java b/src/main/java/me/alpha432/oyvey/features/gui/items/Item.java new file mode 100644 index 0000000..c328411 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/Item.java @@ -0,0 +1,84 @@ +package me.alpha432.oyvey.features.gui.items; + +import me.alpha432.oyvey.features.Feature; +import net.minecraft.client.gui.DrawContext; + +import java.awt.*; + +public class Item + extends Feature { + public static DrawContext context; + protected float x; + protected float y; + protected int width; + protected int height; + private boolean hidden; + + public Item(String name) { + super(name); + } + + public void setLocation(float x, float y) { + this.x = x; + this.y = y; + } + + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + } + + public void mouseReleased(int mouseX, int mouseY, int releaseButton) { + } + + public void update() { + } + + public void onKeyTyped(char typedChar, int keyCode) { + } + + public void onKeyPressed(int key) { + } + + public float getX() { + return this.x; + } + + public float getY() { + return this.y; + } + + public int getWidth() { + return this.width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return this.height; + } + + public void setHeight(int height) { + this.height = height; + } + + public boolean isHidden() { + return this.hidden; + } + + public boolean setHidden(boolean hidden) { + this.hidden = hidden; + return this.hidden; + } + + protected void drawString(String text, double x, double y, Color color) { + drawString(text, x, y, color.hashCode()); + } + + protected void drawString(String text, double x, double y, int color) { + context.drawTextWithShadow(mc.textRenderer, text, (int) x, (int) y, color); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java new file mode 100644 index 0000000..13802f3 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BindButton.java @@ -0,0 +1,80 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Bind; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.ColorUtil; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Formatting; +import org.lwjgl.glfw.GLFW; + +public class BindButton + extends Button { + private final Setting setting; + public boolean isListening; + + public BindButton(Setting setting) { + super(setting.getName()); + this.setting = setting; + this.width = 15; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + int color = ColorUtil.toARGB(ClickGui.getInstance().red.getValue(), ClickGui.getInstance().green.getValue(), ClickGui.getInstance().blue.getValue(), 255); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515) : (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue()))); + if (this.isListening) { + drawString("Press a Key...", this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); + } else { + String str = this.setting.getValue().toString().toUpperCase(); + str = str.replace("KEY.KEYBOARD", "").replace(".", " "); + drawString(this.setting.getName() + " " + Formatting.GRAY + str, this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (this.isHovering(mouseX, mouseY)) { + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + } + + @Override public void onKeyPressed(int key) { + if (this.isListening) { + Bind bind = new Bind(key); + if (key == GLFW.GLFW_KEY_DELETE + || key == GLFW.GLFW_KEY_BACKSPACE + || key == GLFW.GLFW_KEY_ESCAPE) { + bind = new Bind(-1); + } + this.setting.setValue(bind); + this.onMouseClick(); + } + } + + @Override + public int getHeight() { + return 14; + } + + @Override + public void toggle() { + this.isListening = !this.isListening; + } + + @Override + public boolean getState() { + return !this.isListening; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java new file mode 100644 index 0000000..9bba0ba --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/BooleanButton.java @@ -0,0 +1,56 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; + +public class BooleanButton + extends Button { + private final Setting setting; + + public BooleanButton(Setting setting) { + super(setting.getName()); + this.setting = setting; + this.width = 15; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + drawString(this.getName(), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (this.isHovering(mouseX, mouseY)) { + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + } + + @Override + public int getHeight() { + return 14; + } + + @Override + public void toggle() { + this.setting.setValue(!this.setting.getValue()); + } + + @Override + public boolean getState() { + return this.setting.getValue(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java new file mode 100644 index 0000000..d0868ac --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Button.java @@ -0,0 +1,60 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.Component; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.gui.items.Item; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; + +public class Button + extends Item { + private boolean state; + + public Button(String name) { + super(name); + this.height = 15; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + drawString(this.getName(), this.x + 2.3f, this.y - 2.0f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0 && this.isHovering(mouseX, mouseY)) { + this.onMouseClick(); + } + } + + public void onMouseClick() { + this.state = !this.state; + this.toggle(); + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + + public void toggle() { + } + + public boolean getState() { + return this.state; + } + + @Override + public int getHeight() { + return 14; + } + + public boolean isHovering(int mouseX, int mouseY) { + for (Component component : OyVeyGui.getClickGui().getComponents()) { + if (!component.drag) continue; + return false; + } + return (float) mouseX >= this.getX() && (float) mouseX <= this.getX() + (float) this.getWidth() && (float) mouseY >= this.getY() && (float) mouseY <= this.getY() + (float) this.height; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java new file mode 100644 index 0000000..1e483f9 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/EnumButton.java @@ -0,0 +1,57 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Formatting; + +public class EnumButton + extends Button { + public Setting> setting; + + public EnumButton(Setting> setting) { + super(setting.getName()); + this.setting = setting; + this.width = 15; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + drawString(this.setting.getName() + " " + Formatting.GRAY + (this.setting.currentEnumName().equalsIgnoreCase("ABC") ? "ABC" : this.setting.currentEnumName()), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (this.isHovering(mouseX, mouseY)) { + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + } + + @Override + public int getHeight() { + return 14; + } + + @Override + public void toggle() { + this.setting.increaseEnum(); + } + + @Override + public boolean getState() { + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java new file mode 100644 index 0000000..f9a8951 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/ModuleButton.java @@ -0,0 +1,137 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.features.gui.Component; +import me.alpha432.oyvey.features.gui.items.Item; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Bind; +import me.alpha432.oyvey.features.settings.Setting; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; +import java.util.List; + +public class ModuleButton + extends Button { + private final Module module; + private List items = new ArrayList<>(); + private boolean subOpen; + + public ModuleButton(Module module) { + super(module.getName()); + this.module = module; + this.initSettings(); + } + + public void initSettings() { + ArrayList newItems = new ArrayList<>(); + if (!this.module.getSettings().isEmpty()) { + for (Setting setting : this.module.getSettings()) { + if (setting.getValue() instanceof Boolean && !setting.getName().equals("Enabled")) { + newItems.add(new BooleanButton((Setting) setting)); + } + if (setting.getValue() instanceof Bind && !setting.getName().equalsIgnoreCase("Keybind") && !this.module.getName().equalsIgnoreCase("Hud")) { + newItems.add(new BindButton((Setting) setting)); + } + if ((setting.getValue() instanceof String || setting.getValue() instanceof Character) && !setting.getName().equalsIgnoreCase("displayName")) { + newItems.add(new StringButton((Setting) setting)); + } + if (setting.isNumberSetting() && setting.hasRestriction()) { + newItems.add(new Slider((Setting) setting)); + continue; + } + if (!setting.isEnumSetting()) continue; + newItems.add(new EnumButton((Setting>) setting)); + } + } + newItems.add(new BindButton((Setting) this.module.getSettingByName("Keybind"))); + this.items = newItems; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + super.drawScreen(context, mouseX, mouseY, partialTicks); + if (!this.items.isEmpty()) { + if (this.subOpen) { + float height = 1.0f; + for (Item item : this.items) { + Component.counter1[0] = Component.counter1[0] + 1; + if (!item.isHidden()) { + item.setLocation(this.x + 1.0f, this.y + (height += 15.0f)); + item.setHeight(15); + item.setWidth(this.width - 9); + item.drawScreen(context, mouseX, mouseY, partialTicks); + } + item.update(); + } + } + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (!this.items.isEmpty()) { + if (mouseButton == 1 && this.isHovering(mouseX, mouseY)) { + this.subOpen = !this.subOpen; + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + if (this.subOpen) { + for (Item item : this.items) { + if (item.isHidden()) continue; + item.mouseClicked(mouseX, mouseY, mouseButton); + } + } + } + } + + @Override + public void onKeyTyped(char typedChar, int keyCode) { + super.onKeyTyped(typedChar, keyCode); + if (!this.items.isEmpty() && this.subOpen) { + for (Item item : this.items) { + if (item.isHidden()) continue; + item.onKeyTyped(typedChar, keyCode); + } + } + } + + @Override public void onKeyPressed(int key) { + super.onKeyPressed(key); + if (!this.items.isEmpty() && this.subOpen) { + for (Item item : this.items) { + if (item.isHidden()) continue; + item.onKeyPressed(key); + } + } + } + + @Override + public int getHeight() { + if (this.subOpen) { + int height = 14; + for (Item item : this.items) { + if (item.isHidden()) continue; + height += item.getHeight() + 1; + } + return height + 2; + } + return 14; + } + + public Module getModule() { + return this.module; + } + + @Override + public void toggle() { + this.module.toggle(); + } + + @Override + public boolean getState() { + return this.module.isEnabled(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java new file mode 100644 index 0000000..31616de --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/Slider.java @@ -0,0 +1,94 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.Component; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.RenderUtil; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.util.Formatting; +import org.lwjgl.glfw.GLFW; + +public class Slider + extends Button { + private final Number min; + private final Number max; + private final int difference; + public Setting setting; + + public Slider(Setting setting) { + super(setting.getName()); + this.setting = setting; + this.min = setting.getMin(); + this.max = setting.getMax(); + this.difference = this.max.intValue() - this.min.intValue(); + this.width = 15; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + this.dragSetting(mouseX, mouseY); + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, !this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515); + RenderUtil.rect(context.getMatrices(), this.x, this.y, (this.setting.getValue()).floatValue() <= this.min.floatValue() ? this.x : this.x + ((float) this.width + 7.4f) * this.partialMultiplier(), this.y + (float) this.height - 0.5f, !this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())); + drawString(this.getName() + " " + Formatting.GRAY + (this.setting.getValue() instanceof Float ? this.setting.getValue() : Double.valueOf((this.setting.getValue()).doubleValue())), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), -1); + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (this.isHovering(mouseX, mouseY)) { + this.setSettingFromX(mouseX); + } + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + for (Component component : OyVeyGui.getClickGui().getComponents()) { + if (!component.drag) continue; + return false; + } + return (float) mouseX >= this.getX() && (float) mouseX <= this.getX() + (float) this.getWidth() + 8.0f && (float) mouseY >= this.getY() && (float) mouseY <= this.getY() + (float) this.height; + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + private void dragSetting(int mouseX, int mouseY) { + if (this.isHovering(mouseX, mouseY) && GLFW.glfwGetMouseButton(mc.getWindow().getHandle(), 0) == 1) { + this.setSettingFromX(mouseX); + } + } + + @Override + public int getHeight() { + return 14; + } + + private void setSettingFromX(int mouseX) { + float percent = ((float) mouseX - this.x) / ((float) this.width + 7.4f); + if (this.setting.getValue() instanceof Double) { + double result = (Double) this.setting.getMin() + (double) ((float) this.difference * percent); + this.setting.setValue((double) Math.round(10.0 * result) / 10.0); + } else if (this.setting.getValue() instanceof Float) { + float result = ((Float) this.setting.getMin()).floatValue() + (float) this.difference * percent; + this.setting.setValue(Float.valueOf((float) Math.round(10.0f * result) / 10.0f)); + } else if (this.setting.getValue() instanceof Integer) { + this.setting.setValue((Integer) this.setting.getMin() + (int) ((float) this.difference * percent)); + } + } + + private float middle() { + return this.max.floatValue() - this.min.floatValue(); + } + + private float part() { + return (this.setting.getValue()).floatValue() - this.min.floatValue(); + } + + private float partialMultiplier() { + return this.part() / this.middle(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java new file mode 100644 index 0000000..06395df --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/gui/items/buttons/StringButton.java @@ -0,0 +1,125 @@ +package me.alpha432.oyvey.features.gui.items.buttons; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.RenderUtil; +import me.alpha432.oyvey.util.models.Timer; +import net.minecraft.SharedConstants; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.Formatting; + +public class StringButton + extends Button { + private static final Timer idleTimer = new Timer(); + private static boolean idle; + private final Setting setting; + public boolean isListening; + private CurrentString currentString = new CurrentString(""); + + public StringButton(Setting setting) { + super(setting.getName()); + this.setting = setting; + this.width = 15; + } + + public static String removeLastChar(String str) { + String output = ""; + if (str != null && str.length() > 0) { + output = str.substring(0, str.length() - 1); + } + return output; + } + + @Override + public void drawScreen(DrawContext context, int mouseX, int mouseY, float partialTicks) { + RenderUtil.rect(context.getMatrices(), this.x, this.y, this.x + (float) this.width + 7.4f, this.y + (float) this.height - 0.5f, this.getState() ? (!this.isHovering(mouseX, mouseY) ? OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).hoverAlpha.getValue()) : OyVey.colorManager.getColorWithAlpha(OyVey.moduleManager.getModuleByClass(ClickGui.class).alpha.getValue())) : (!this.isHovering(mouseX, mouseY) ? 0x11555555 : -2007673515)); + if (this.isListening) { + drawString(this.currentString.string() + "_", this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } else { + drawString((this.setting.getName().equals("Buttons") ? "Buttons " : (this.setting.getName().equals("Prefix") ? "Prefix " + Formatting.GRAY : "")) + this.setting.getValue(), this.x + 2.3f, this.y - 1.7f - (float) OyVeyGui.getClickGui().getTextOffset(), this.getState() ? -1 : -5592406); + } + } + + @Override + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + if (this.isHovering(mouseX, mouseY)) { + mc.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1f)); + } + } + + @Override + public void onKeyTyped(char typedChar, int keyCode) { + if (this.isListening) { + if (SharedConstants.isValidChar(typedChar)) { + this.setString(this.currentString.string() + typedChar); + } + } + } + + @Override public void onKeyPressed(int key) { + if (isListening) { + switch (key) { + case 1: { + return; + } + case 28: { + this.enterString(); + } + case 14: { + this.setString(StringButton.removeLastChar(this.currentString.string())); + } + } + } + } + + @Override + public void update() { + this.setHidden(!this.setting.isVisible()); + } + + private void enterString() { + if (this.currentString.string().isEmpty()) { + this.setting.setValue(this.setting.getDefaultValue()); + } else { + this.setting.setValue(this.currentString.string()); + } + this.setString(""); + this.onMouseClick(); + } + + @Override + public int getHeight() { + return 14; + } + + @Override + public void toggle() { + this.isListening = !this.isListening; + } + + @Override + public boolean getState() { + return !this.isListening; + } + + public void setString(String newString) { + this.currentString = new CurrentString(newString); + } + + public static String getIdleSign() { + if (idleTimer.passedMs(500)) { + idle = !idle; + idleTimer.reset(); + } + if (idle) return "_"; + return ""; + } + + public record CurrentString(String string) { + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/modules/Module.java b/src/main/java/me/alpha432/oyvey/features/modules/Module.java new file mode 100644 index 0000000..6c91a1c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/Module.java @@ -0,0 +1,211 @@ +package me.alpha432.oyvey.features.modules; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.ClientEvent; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.event.impl.Render3DEvent; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.settings.Bind; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.manager.ConfigManager; +import me.alpha432.oyvey.util.traits.Jsonable; +import net.minecraft.util.Formatting; + +public class Module extends Feature implements Jsonable { + private final String description; + private final Category category; + public Setting enabled = this.register(new Setting<>("Enabled", false)); + public Setting drawn = this.register(new Setting<>("Drawn", true)); + public Setting bind = this.register(new Setting<>("Keybind", new Bind(-1))); + public Setting displayName; + public boolean hasListener; + public boolean alwaysListening; + public boolean hidden; + + public Module(String name, String description, Category category, boolean hasListener, boolean hidden, boolean alwaysListening) { + super(name); + this.displayName = this.register(new Setting<>("DisplayName", name)); + this.description = description; + this.category = category; + this.hasListener = hasListener; + this.hidden = hidden; + this.alwaysListening = alwaysListening; + } + + public void onEnable() { + } + + public void onDisable() { + } + + public void onToggle() { + } + + public void onLoad() { + } + + public void onTick() { + } + + public void onUpdate() { + } + + public void onRender2D(Render2DEvent event) { + } + + public void onRender3D(Render3DEvent event) { + } + + public void onUnload() { + } + + public String getDisplayInfo() { + return null; + } + + public boolean isOn() { + return this.enabled.getValue(); + } + + public boolean isOff() { + return !this.enabled.getValue(); + } + + public void setEnabled(boolean enabled) { + if (enabled) { + this.enable(); + } else { + this.disable(); + } + } + + public void enable() { + this.enabled.setValue(true); + this.onToggle(); + this.onEnable(); + if (this.isOn() && this.hasListener && !this.alwaysListening) { + EVENT_BUS.register(this); + } + } + + public void disable() { + if (this.hasListener && !this.alwaysListening) { + EVENT_BUS.unregister(this); + } + this.enabled.setValue(false); + this.onToggle(); + this.onDisable(); + } + + public void toggle() { + ClientEvent event = new ClientEvent(!this.isEnabled() ? 1 : 0, this); + EVENT_BUS.post(event); + if (!event.isCancelled()) { + this.setEnabled(!this.isEnabled()); + } + } + + public String getDisplayName() { + return this.displayName.getValue(); + } + + public void setDisplayName(String name) { + Module module = OyVey.moduleManager.getModuleByDisplayName(name); + Module originalModule = OyVey.moduleManager.getModuleByName(name); + if (module == null && originalModule == null) { + Command.sendMessage(this.getDisplayName() + ", name: " + this.getName() + ", has been renamed to: " + name); + this.displayName.setValue(name); + return; + } + Command.sendMessage(Formatting.RED + "A module of this name already exists."); + } + + @Override public boolean isEnabled() { + return isOn(); + } + + public String getDescription() { + return this.description; + } + + public boolean isDrawn() { + return this.drawn.getValue(); + } + + public void setDrawn(boolean drawn) { + this.drawn.setValue(drawn); + } + + public Category getCategory() { + return this.category; + } + + public String getInfo() { + return null; + } + + public Bind getBind() { + return this.bind.getValue(); + } + + public void setBind(int key) { + this.bind.setValue(new Bind(key)); + } + + public boolean listening() { + return this.hasListener && this.isOn() || this.alwaysListening; + } + + public String getFullArrayString() { + return this.getDisplayName() + Formatting.GRAY + (this.getDisplayInfo() != null ? " [" + Formatting.WHITE + this.getDisplayInfo() + Formatting.GRAY + "]" : ""); + } + + @Override public JsonElement toJson() { + JsonObject object = new JsonObject(); + for (Setting setting : getSettings()) { + try { + if (setting.getValue() instanceof Bind bind) { + object.addProperty(setting.getName(), bind.getKey()); + } else { + object.addProperty(setting.getName(), setting.getValueAsString()); + } + } catch (Throwable e) { + } + } + return object; + } + + @Override public void fromJson(JsonElement element) { + JsonObject object = element.getAsJsonObject(); + String enabled = object.get("Enabled").getAsString(); + if (Boolean.parseBoolean(enabled)) toggle(); + for (Setting setting : getSettings()) { + try { + ConfigManager.setValueFromJson(this, setting, object.get(setting.getName())); + } catch (Throwable throwable) { + } + } + } + + public enum Category { + COMBAT("Combat"), + MISC("Misc"), + RENDER("Render"), + MOVEMENT("Movement"), + PLAYER("Player"), + CLIENT("Client"); + + private final String name; + + Category(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java b/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java new file mode 100644 index 0000000..f55fcad --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/ClickGui.java @@ -0,0 +1,99 @@ +package me.alpha432.oyvey.features.modules.client; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.ClientEvent; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.gui.OyVeyGui; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Setting; +import net.minecraft.util.Formatting; +import org.lwjgl.glfw.GLFW; + +public class ClickGui + extends Module { + private static ClickGui INSTANCE = new ClickGui(); + public Setting prefix = this.register(new Setting<>("Prefix", ".")); + public Setting customFov = this.register(new Setting<>("CustomFov", false)); + public Setting fov = this.register(new Setting<>("Fov", 150f, -180f, 180f)); + public Setting red = this.register(new Setting<>("Red", 0, 0, 255)); + public Setting green = this.register(new Setting<>("Green", 0, 0, 255)); + public Setting blue = this.register(new Setting<>("Blue", 255, 0, 255)); + public Setting hoverAlpha = this.register(new Setting<>("Alpha", 180, 0, 255)); + public Setting topRed = this.register(new Setting<>("SecondRed", 0, 0, 255)); + public Setting topGreen = this.register(new Setting<>("SecondGreen", 0, 0, 255)); + public Setting topBlue = this.register(new Setting<>("SecondBlue", 150, 0, 255)); + public Setting alpha = this.register(new Setting<>("HoverAlpha", 240, 0, 255)); + public Setting rainbow = this.register(new Setting<>("Rainbow", false)); + public Setting rainbowModeHud = this.register(new Setting<>("HRainbowMode", rainbowMode.Static, v -> this.rainbow.getValue())); + public Setting rainbowModeA = this.register(new Setting<>("ARainbowMode", rainbowModeArray.Static, v -> this.rainbow.getValue())); + public Setting rainbowHue = this.register(new Setting<>("Delay", 240, 0, 600, v -> this.rainbow.getValue())); + public Setting rainbowBrightness = this.register(new Setting<>("Brightness ", 150.0f, 1.0f, 255.0f, v -> this.rainbow.getValue())); + public Setting rainbowSaturation = this.register(new Setting<>("Saturation", 150.0f, 1.0f, 255.0f, v -> this.rainbow.getValue())); + private OyVeyGui click; + + public ClickGui() { + super("ClickGui", "Opens the ClickGui", Module.Category.CLIENT, true, false, false); + setBind(GLFW.GLFW_KEY_RIGHT_SHIFT); + this.setInstance(); + } + + public static ClickGui getInstance() { + if (INSTANCE == null) { + INSTANCE = new ClickGui(); + } + return INSTANCE; + } + + private void setInstance() { + INSTANCE = this; + } + + @Override + public void onUpdate() { + if (this.customFov.getValue().booleanValue()) { + mc.options.getFov().setValue(this.fov.getValue().intValue()); + } + } + + @Subscribe + public void onSettingChange(ClientEvent event) { + if (event.getStage() == 2 && event.getSetting().getFeature().equals(this)) { + if (event.getSetting().equals(this.prefix)) { + OyVey.commandManager.setPrefix(this.prefix.getPlannedValue()); + Command.sendMessage("Prefix set to " + Formatting.DARK_GRAY + OyVey.commandManager.getPrefix()); + } + OyVey.colorManager.setColor(this.red.getPlannedValue(), this.green.getPlannedValue(), this.blue.getPlannedValue(), this.hoverAlpha.getPlannedValue()); + } + } + + @Override + public void onEnable() { + mc.setScreen(OyVeyGui.getClickGui()); + } + + @Override + public void onLoad() { + OyVey.colorManager.setColor(this.red.getValue(), this.green.getValue(), this.blue.getValue(), this.hoverAlpha.getValue()); + OyVey.commandManager.setPrefix(this.prefix.getValue()); + } + + @Override + public void onTick() { + if (!(ClickGui.mc.currentScreen instanceof OyVeyGui)) { + this.disable(); + } + } + + public enum rainbowModeArray { + Static, + Up + + } + + public enum rainbowMode { + Static, + Sideway + + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java new file mode 100644 index 0000000..6694ebc --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/client/HudModule.java @@ -0,0 +1,20 @@ +package me.alpha432.oyvey.features.modules.client; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.features.modules.Module; + +public class HudModule extends Module { + public HudModule() { + super("Hud", "hud", Category.CLIENT, true, false, false); + } + + @Override public void onRender2D(Render2DEvent event) { + event.getContext().drawTextWithShadow( + mc.textRenderer, + OyVey.NAME + " " + OyVey.VERSION, + 2, 2, + -1 + ); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/combat/Criticals.java b/src/main/java/me/alpha432/oyvey/features/modules/combat/Criticals.java new file mode 100644 index 0000000..07dfe69 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/combat/Criticals.java @@ -0,0 +1,37 @@ +package me.alpha432.oyvey.features.modules.combat; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.event.impl.PacketEvent; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.util.models.Timer; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.decoration.EndCrystalEntity; +import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; + +public class Criticals extends Module { + private final Timer timer = new Timer(); + public Criticals() { + super("Criticals", "", Category.COMBAT, true, false, false); + } + @Subscribe private void onPacketSend(PacketEvent.Send event) { + if (event.getPacket() instanceof PlayerInteractEntityC2SPacket packet && packet.type.getType() == PlayerInteractEntityC2SPacket.InteractType.ATTACK) { + Entity entity = mc.world.getEntityById(packet.entityId); + if (entity == null + || entity instanceof EndCrystalEntity + || !mc.player.isOnGround() + || !(entity instanceof LivingEntity) + || !timer.passedMs(0)) return; + + mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(mc.player.getX(), mc.player.getY() + (double) 0.1f, mc.player.getZ(), false)); + mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(mc.player.getX(), mc.player.getY(), mc.player.getZ(), false)); + mc.player.addCritParticles(entity); + timer.reset(); + } + } + + @Override public String getDisplayInfo() { + return "Packet"; + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/misc/MCF.java b/src/main/java/me/alpha432/oyvey/features/modules/misc/MCF.java new file mode 100644 index 0000000..7b82370 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/misc/MCF.java @@ -0,0 +1,38 @@ +package me.alpha432.oyvey.features.modules.misc; + +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.modules.Module; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.Formatting; +import org.lwjgl.glfw.GLFW; + +public class MCF extends Module { + private boolean pressed; + public MCF() { + super("MCF", "", Category.MISC, true, false, false); + } + + @Override public void onTick() { + if (GLFW.glfwGetMouseButton(mc.getWindow().getHandle(), 2) == 1) { + if (!pressed) { + Entity targetedEntity = mc.targetedEntity; + if (!(targetedEntity instanceof PlayerEntity)) return; + String name = ((PlayerEntity) targetedEntity).getGameProfile().getName(); + + if (OyVey.friendManager.isFriend(name)) { + OyVey.friendManager.removeFriend(name); + Command.sendMessage(Formatting.RED + name + Formatting.RED + " has been unfriended."); + } else { + OyVey.friendManager.addFriend(name); + Command.sendMessage(Formatting.AQUA + name + Formatting.AQUA + " has been friended."); + } + + pressed = true; + } + } else { + pressed = false; + } + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/movement/ReverseStep.java b/src/main/java/me/alpha432/oyvey/features/modules/movement/ReverseStep.java new file mode 100644 index 0000000..98cca89 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/movement/ReverseStep.java @@ -0,0 +1,15 @@ +package me.alpha432.oyvey.features.modules.movement; + +import me.alpha432.oyvey.features.modules.Module; + +public class ReverseStep extends Module { + public ReverseStep() { + super("ReverseStep", "step but reversed..", Category.MOVEMENT, true, false, false); + } + + @Override public void onUpdate() { + if (nullCheck()) return; + if (mc.player.isInLava() || mc.player.isTouchingWater() || !mc.player.isOnGround()) return; + mc.player.addVelocity(0, -1, 0); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/movement/Step.java b/src/main/java/me/alpha432/oyvey/features/modules/movement/Step.java new file mode 100644 index 0000000..34697d8 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/movement/Step.java @@ -0,0 +1,21 @@ +package me.alpha432.oyvey.features.modules.movement; + +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.settings.Setting; + +public class Step extends Module { + private final Setting height = register(new Setting<>("Height", 2f, 1f, 3f, v -> true)); + public Step() { + super("Step", "step..", Category.MOVEMENT, true, false, false); + } + + @Override public void onDisable() { + if (nullCheck()) return; + mc.player.setStepHeight(0.6f); + } + + @Override public void onUpdate() { + if (nullCheck()) return; + mc.player.setStepHeight(height.getValue()); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/player/FastPlace.java b/src/main/java/me/alpha432/oyvey/features/modules/player/FastPlace.java new file mode 100644 index 0000000..84111a2 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/player/FastPlace.java @@ -0,0 +1,18 @@ +package me.alpha432.oyvey.features.modules.player; + +import me.alpha432.oyvey.features.modules.Module; +import net.minecraft.item.Items; + +public class FastPlace extends Module { + public FastPlace() { + super("FastPlace", "", Category.PLAYER, true, false, false); + } + + @Override public void onUpdate() { + if (nullCheck()) return; + + if (mc.player.isHolding(Items.EXPERIENCE_BOTTLE)) { + mc.itemUseCooldown = 0; + } + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/modules/player/Velocity.java b/src/main/java/me/alpha432/oyvey/features/modules/player/Velocity.java new file mode 100644 index 0000000..0155376 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/modules/player/Velocity.java @@ -0,0 +1,17 @@ +package me.alpha432.oyvey.features.modules.player; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.event.impl.PacketEvent; +import me.alpha432.oyvey.features.modules.Module; +import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket; +import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket; + +public class Velocity extends Module { + public Velocity() { + super("Velocity", "", Category.PLAYER, true, false, false); + } + + @Subscribe private void onPacketReceive(PacketEvent.Receive event) { + if (event.getPacket() instanceof EntityVelocityUpdateS2CPacket || event.getPacket() instanceof ExplosionS2CPacket) event.cancel(); + } +} diff --git a/src/main/java/me/alpha432/oyvey/features/settings/Bind.java b/src/main/java/me/alpha432/oyvey/features/settings/Bind.java new file mode 100644 index 0000000..d8c4320 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/settings/Bind.java @@ -0,0 +1,73 @@ +package me.alpha432.oyvey.features.settings; + +import com.google.common.base.Converter; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import me.alpha432.oyvey.util.traits.Util; +import net.minecraft.client.util.InputUtil; +import org.lwjgl.glfw.GLFW; + +public class Bind implements Util { + private int key; + + public Bind(int key) { + this.key = key; + } + + public static Bind none() { + return new Bind(-1); + } + + public int getKey() { + return this.key; + } + + public void setKey(int key) { + this.key = key; + } + + public boolean isEmpty() { + return this.key < 0; + } + + public String toString() { + return this.isEmpty() ? "None" : (this.key < 0 + ? "None" + : this.capitalise(InputUtil.fromKeyCode(this.key, 0).getTranslationKey())); + } + + public boolean isDown() { + return !this.isEmpty() && GLFW.glfwGetKey(mc.getWindow().getHandle(), this.getKey()) == 1; + } + + private String capitalise(String str) { + if (str.isEmpty()) { + return ""; + } + return Character.toUpperCase(str.charAt(0)) + (str.length() != 1 ? str.substring(1).toLowerCase() : ""); + } + + public static class BindConverter + extends Converter { + public JsonElement doForward(Bind bind) { + return new JsonPrimitive(bind.toString()); + } + + public Bind doBackward(JsonElement jsonElement) { + String s = jsonElement.getAsString(); + if (s.equalsIgnoreCase("None")) { + return Bind.none(); + } + int key = -1; + try { + key = InputUtil.fromTranslationKey(s.toUpperCase()).getCode(); + } catch (Exception exception) { + // empty catch block + } + if (key == 0) { + return Bind.none(); + } + return new Bind(key); + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/settings/EnumConverter.java b/src/main/java/me/alpha432/oyvey/features/settings/EnumConverter.java new file mode 100644 index 0000000..21ce799 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/settings/EnumConverter.java @@ -0,0 +1,49 @@ +package me.alpha432.oyvey.features.settings; + +import com.google.common.base.Converter; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; + +public class EnumConverter + extends Converter { + private final Class clazz; + + public EnumConverter(Class clazz) { + this.clazz = clazz; + } + + public static int currentEnum(Enum clazz) { + for (int i = 0; i < clazz.getClass().getEnumConstants().length; ++i) { + Enum e = clazz.getClass().getEnumConstants()[i]; + if (!e.name().equalsIgnoreCase(clazz.name())) continue; + return i; + } + return -1; + } + + public static Enum increaseEnum(Enum clazz) { + int index = EnumConverter.currentEnum(clazz); + for (int i = 0; i < clazz.getClass().getEnumConstants().length; ++i) { + Enum e = clazz.getClass().getEnumConstants()[i]; + if (i != index + 1) continue; + return e; + } + return clazz.getClass().getEnumConstants()[0]; + } + + public static String getProperName(Enum clazz) { + return Character.toUpperCase(clazz.name().charAt(0)) + clazz.name().toLowerCase().substring(1); + } + + public JsonElement doForward(Enum anEnum) { + return new JsonPrimitive(anEnum.toString()); + } + + public Enum doBackward(JsonElement jsonElement) { + try { + return Enum.valueOf(this.clazz, jsonElement.getAsString()); + } catch (IllegalArgumentException e) { + return null; + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/features/settings/Setting.java b/src/main/java/me/alpha432/oyvey/features/settings/Setting.java new file mode 100644 index 0000000..ce60cf9 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/features/settings/Setting.java @@ -0,0 +1,259 @@ +package me.alpha432.oyvey.features.settings; + +import me.alpha432.oyvey.event.impl.ClientEvent; +import me.alpha432.oyvey.features.Feature; + +import java.util.function.Predicate; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +public class Setting { + private final String name; + private final T defaultValue; + private T value; + private T plannedValue; + private T min; + private T max; + private boolean hasRestriction; + private Predicate visibility; + private String description; + private Feature feature; + + public Setting(String name, T defaultValue) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.plannedValue = defaultValue; + this.description = ""; + } + + public Setting(String name, T defaultValue, String description) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.plannedValue = defaultValue; + this.description = description; + } + + public Setting(String name, T defaultValue, T min, T max, String description) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.min = min; + this.max = max; + this.plannedValue = defaultValue; + this.description = description; + this.hasRestriction = true; + } + + public Setting(String name, T defaultValue, T min, T max) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.min = min; + this.max = max; + this.plannedValue = defaultValue; + this.description = ""; + this.hasRestriction = true; + } + + public Setting(String name, T defaultValue, T min, T max, Predicate visibility, String description) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.min = min; + this.max = max; + this.plannedValue = defaultValue; + this.visibility = visibility; + this.description = description; + this.hasRestriction = true; + } + + public Setting(String name, T defaultValue, T min, T max, Predicate visibility) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.min = min; + this.max = max; + this.plannedValue = defaultValue; + this.visibility = visibility; + this.description = ""; + this.hasRestriction = true; + } + + public Setting(String name, T defaultValue, Predicate visibility) { + this.name = name; + this.defaultValue = defaultValue; + this.value = defaultValue; + this.visibility = visibility; + this.plannedValue = defaultValue; + } + + public String getName() { + return this.name; + } + + public T getValue() { + return this.value; + } + + public void setValue(T value) { + this.setPlannedValue(value); + if (this.hasRestriction) { + if (((Number) this.min).floatValue() > ((Number) value).floatValue()) { + this.setPlannedValue(this.min); + } + if (((Number) this.max).floatValue() < ((Number) value).floatValue()) { + this.setPlannedValue(this.max); + } + } + ClientEvent event = new ClientEvent(this); + EVENT_BUS.post(event); + if (!event.isCancelled()) { + this.value = this.plannedValue; + } else { + this.plannedValue = this.value; + } + } + + public void reset() { + setValue(getDefaultValue()); + } + + public T getPlannedValue() { + return this.plannedValue; + } + + public void setPlannedValue(T value) { + this.plannedValue = value; + } + + public T getMin() { + return this.min; + } + + public void setMin(T min) { + this.min = min; + } + + public T getMax() { + return this.max; + } + + public void setMax(T max) { + this.max = max; + } + + public void setValueNoEvent(T value) { + this.setPlannedValue(value); + if (this.hasRestriction) { + if (((Number) this.min).floatValue() > ((Number) value).floatValue()) { + this.setPlannedValue(this.min); + } + if (((Number) this.max).floatValue() < ((Number) value).floatValue()) { + this.setPlannedValue(this.max); + } + } + this.value = this.plannedValue; + } + + public Feature getFeature() { + return this.feature; + } + + public void setFeature(Feature feature) { + this.feature = feature; + } + + public int getEnum(String input) { + for (int i = 0; i < this.value.getClass().getEnumConstants().length; ++i) { + Enum e = (Enum) this.value.getClass().getEnumConstants()[i]; + if (!e.name().equalsIgnoreCase(input)) continue; + return i; + } + return -1; + } + + public void setEnumValue(String value) { + for (Enum e : (Enum[]) ((Enum) this.value).getClass().getEnumConstants()) { + if (!e.name().equalsIgnoreCase(value)) continue; + this.value = (T) e; + } + } + + public String currentEnumName() { + return EnumConverter.getProperName((Enum) this.value); + } + + public int currentEnum() { + return EnumConverter.currentEnum((Enum) this.value); + } + + public void increaseEnum() { + this.plannedValue = (T) EnumConverter.increaseEnum((Enum) this.value); + ClientEvent event = new ClientEvent(this); + EVENT_BUS.post(event); + if (!event.isCancelled()) { + this.value = this.plannedValue; + } else { + this.plannedValue = this.value; + } + } + + public void increaseEnumNoEvent() { + this.value = (T) EnumConverter.increaseEnum((Enum) this.value); + } + + public String getType() { + if (this.isEnumSetting()) { + return "Enum"; + } + return this.getClassName(this.defaultValue); + } + + public String getClassName(T value) { + return value.getClass().getSimpleName(); + } + + public String getDescription() { + if (this.description == null) { + return ""; + } + return this.description; + } + + public boolean isNumberSetting() { + return this.value instanceof Double || this.value instanceof Integer || this.value instanceof Short || this.value instanceof Long || this.value instanceof Float; + } + + public boolean isEnumSetting() { + return !this.isNumberSetting() && !(this.value instanceof String) && !(this.value instanceof Bind) && !(this.value instanceof Character) && !(this.value instanceof Boolean); + } + + public boolean isStringSetting() { + return this.value instanceof String; + } + + public T getDefaultValue() { + return this.defaultValue; + } + + public String getValueAsString() { + return this.value.toString(); + } + + public boolean hasRestriction() { + return this.hasRestriction; + } + + public void setVisibility(Predicate visibility) { + this.visibility = visibility; + } + + public boolean isVisible() { + if (this.visibility == null) { + return true; + } + return this.visibility.test(this.getValue()); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/ColorManager.java b/src/main/java/me/alpha432/oyvey/manager/ColorManager.java new file mode 100644 index 0000000..25c289e --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/ColorManager.java @@ -0,0 +1,78 @@ +package me.alpha432.oyvey.manager; + +import me.alpha432.oyvey.features.gui.Component; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.util.ColorUtil; + +import java.awt.*; + +public class ColorManager { + private float red = 1.0f; + private float green = 1.0f; + private float blue = 1.0f; + private float alpha = 1.0f; + private Color color = new Color(this.red, this.green, this.blue, this.alpha); + + public Color getColor() { + return this.color; + } + + public void setColor(Color color) { + this.color = color; + } + + public int getColorAsInt() { + return ColorUtil.toRGBA(this.color); + } + + public int getColorAsIntFullAlpha() { + return ColorUtil.toRGBA(new Color(this.color.getRed(), this.color.getGreen(), this.color.getBlue(), 255)); + } + + public int getColorWithAlpha(int alpha) { + if (ClickGui.getInstance().rainbow.getValue()) { + return ColorUtil.rainbow(Component.counter1[0] * ClickGui.getInstance().rainbowHue.getValue()).getRGB(); + } + return ColorUtil.toRGBA(new Color(this.red, this.green, this.blue, (float) alpha / 255.0f)); + } + + public void setColor(float red, float green, float blue, float alpha) { + this.red = red; + this.green = green; + this.blue = blue; + this.alpha = alpha; + this.updateColor(); + } + + public void updateColor() { + this.setColor(new Color(this.red, this.green, this.blue, this.alpha)); + } + + public void setColor(int red, int green, int blue, int alpha) { + this.red = (float) red / 255.0f; + this.green = (float) green / 255.0f; + this.blue = (float) blue / 255.0f; + this.alpha = (float) alpha / 255.0f; + this.updateColor(); + } + + public void setRed(float red) { + this.red = red; + this.updateColor(); + } + + public void setGreen(float green) { + this.green = green; + this.updateColor(); + } + + public void setBlue(float blue) { + this.blue = blue; + this.updateColor(); + } + + public void setAlpha(float alpha) { + this.alpha = alpha; + this.updateColor(); + } +} diff --git a/src/main/java/me/alpha432/oyvey/manager/CommandManager.java b/src/main/java/me/alpha432/oyvey/manager/CommandManager.java new file mode 100644 index 0000000..6f3f026 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/CommandManager.java @@ -0,0 +1,105 @@ +package me.alpha432.oyvey.manager; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.features.commands.impl.*; +import me.alpha432.oyvey.util.traits.Jsonable; +import net.minecraft.util.Formatting; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +public class CommandManager + extends Feature implements Jsonable { + private final List commands = new ArrayList<>(); + private String clientMessage = ""; + private String prefix = "."; + + public CommandManager() { + super("Command"); + commands.add(new ToggleCommand()); + commands.add(new BindCommand()); + commands.add(new FriendCommand()); + commands.add(new ModuleCommand()); + commands.add(new PrefixCommand()); + + commands.add(new HelpCommand()); + } + + public static String[] removeElement(String[] input, int indexToDelete) { + LinkedList result = new LinkedList<>(); + for (int i = 0; i < input.length; ++i) { + if (i == indexToDelete) continue; + result.add(input[i]); + } + return result.toArray(input); + } + + private static String strip(String str, String key) { + if (str.startsWith(key) && str.endsWith(key)) { + return str.substring(key.length(), str.length() - key.length()); + } + return str; + } + + public void executeCommand(String command) { + String[] parts = command.split(" (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"); + String name = parts[0].substring(1); + String[] args = CommandManager.removeElement(parts, 0); + for (int i = 0; i < args.length; ++i) { + if (args[i] == null) continue; + args[i] = CommandManager.strip(args[i], "\""); + } + for (Command c : this.commands) { + if (!c.getName().equalsIgnoreCase(name)) continue; + c.execute(parts); + return; + } + Command.sendMessage(Formatting.GRAY + "Command not found, type 'help' for the commands list."); + } + + public Command getCommandByName(String name) { + for (Command command : this.commands) { + if (!command.getName().equals(name)) continue; + return command; + } + return null; + } + + public List getCommands() { + return this.commands; + } + + public String getClientMessage() { + return this.clientMessage; + } + + public void setClientMessage(String clientMessage) { + this.clientMessage = clientMessage; + } + + public String getPrefix() { + return this.prefix; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + @Override public JsonElement toJson() { + JsonObject object = new JsonObject(); + object.addProperty("prefix", prefix); + return object; + } + + @Override public void fromJson(JsonElement element) { + setPrefix(element.getAsJsonObject().get("prefix").getAsString()); + } + + @Override public String getFileName() { + return "commands.json"; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java b/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java new file mode 100644 index 0000000..7ff7a6e --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/ConfigManager.java @@ -0,0 +1,83 @@ +package me.alpha432.oyvey.manager; + +import com.google.gson.*; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.settings.Bind; +import me.alpha432.oyvey.features.settings.EnumConverter; +import me.alpha432.oyvey.features.settings.Setting; +import me.alpha432.oyvey.util.traits.Jsonable; +import net.fabricmc.loader.api.FabricLoader; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +public class ConfigManager { + private static final Path OYVEY_PATH = FabricLoader.getInstance().getGameDir().resolve("oyvey"); + private static final Gson gson = new GsonBuilder() + .setLenient() + .setPrettyPrinting() + .create(); + private final List jsonables = List.of(OyVey.friendManager, OyVey.moduleManager, OyVey.commandManager); + + @SuppressWarnings({"rawtypes", "unchecked"}) + public static void setValueFromJson(Feature feature, Setting setting, JsonElement element) { + String str; + switch (setting.getType()) { + case "Boolean" -> { + setting.setValue(element.getAsBoolean()); + } + case "Double" -> { + setting.setValue(element.getAsDouble()); + } + case "Float" -> { + setting.setValue(element.getAsFloat()); + } + case "Integer" -> { + setting.setValue(element.getAsInt()); + } + case "String" -> { + str = element.getAsString(); + setting.setValue(str.replace("_", " ")); + } + case "Bind" -> { + setting.setValue(new Bind(element.getAsInt())); + } + case "Enum" -> { + try { + EnumConverter converter = new EnumConverter(((Enum) setting.getValue()).getClass()); + Enum value = converter.doBackward(element); + setting.setValue((value == null) ? setting.getDefaultValue() : value); + } catch (Exception exception) { + } + } + default -> { + OyVey.LOGGER.error("Unknown Setting type for: " + feature.getName() + " : " + setting.getName()); + } + } + } + + public void load() { + if (!OYVEY_PATH.toFile().exists()) OYVEY_PATH.toFile().mkdirs(); + for (Jsonable jsonable : jsonables) { + try { + String read = Files.readString(OYVEY_PATH.resolve(jsonable.getFileName())); + jsonable.fromJson(JsonParser.parseString(read)); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + + public void save() { + if (!OYVEY_PATH.toFile().exists()) OYVEY_PATH.toFile().mkdirs(); + for (Jsonable jsonable : jsonables) { + try { + JsonElement json = jsonable.toJson(); + Files.writeString(OYVEY_PATH.resolve(jsonable.getFileName()), gson.toJson(json)); + } catch (Throwable e) { + } + } + } +} diff --git a/src/main/java/me/alpha432/oyvey/manager/EventManager.java b/src/main/java/me/alpha432/oyvey/manager/EventManager.java new file mode 100644 index 0000000..0cb0798 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/EventManager.java @@ -0,0 +1,103 @@ +package me.alpha432.oyvey.manager; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.OyVey; +import me.alpha432.oyvey.event.Stage; +import me.alpha432.oyvey.event.impl.*; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.commands.Command; +import me.alpha432.oyvey.util.models.Timer; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.s2c.play.WorldTimeUpdateS2CPacket; +import net.minecraft.util.Formatting; + +public class EventManager extends Feature { + private final Timer logoutTimer = new Timer(); + + public void init() { + EVENT_BUS.register(this); + } + + public void onUnload() { + EVENT_BUS.unregister(this); + } + + @Subscribe + public void onUpdate(UpdateEvent event) { + mc.getWindow().setTitle("OyVey 0.0.3"); + if (!fullNullCheck()) { +// OyVey.inventoryManager.update(); + OyVey.moduleManager.onUpdate(); + OyVey.moduleManager.sortModules(true); + onTick(); +// if ((HUD.getInstance()).renderingMode.getValue() == HUD.RenderingMode.Length) { +// OyVey.moduleManager.sortModules(true); +// } else { +// OyVey.moduleManager.sortModulesABC(); +// } + } + } + + public void onTick() { + if (fullNullCheck()) + return; + OyVey.moduleManager.onTick(); + for (PlayerEntity player : mc.world.getPlayers()) { + if (player == null || player.getHealth() > 0.0F) + continue; + EVENT_BUS.post(new DeathEvent(player)); +// PopCounter.getInstance().onDeath(player); + } + } + + @Subscribe + public void onUpdateWalkingPlayer(UpdateWalkingPlayerEvent event) { + if (fullNullCheck()) + return; + if (event.getStage() == Stage.PRE) { + OyVey.speedManager.updateValues(); + OyVey.rotationManager.updateRotations(); + OyVey.positionManager.updatePosition(); + } + if (event.getStage() == Stage.POST) { + OyVey.rotationManager.restoreRotations(); + OyVey.positionManager.restorePosition(); + } + } + + @Subscribe + public void onPacketReceive(PacketEvent.Receive event) { + OyVey.serverManager.onPacketReceived(); + if (event.getPacket() instanceof WorldTimeUpdateS2CPacket) + OyVey.serverManager.update(); + } + + @Subscribe + public void onWorldRender(Render3DEvent event) { + OyVey.moduleManager.onRender3D(event); + } + + @Subscribe public void onRenderGameOverlayEvent(Render2DEvent event) { + OyVey.moduleManager.onRender2D(event); + } + + @Subscribe public void onKeyInput(KeyEvent event) { + OyVey.moduleManager.onKeyPressed(event.getKey()); + } + + @Subscribe public void onChatSent(ChatEvent event) { + if (event.getMessage().startsWith(Command.getCommandPrefix())) { + event.cancel(); + try { + if (event.getMessage().length() > 1) { + OyVey.commandManager.executeCommand(event.getMessage().substring(Command.getCommandPrefix().length() - 1)); + } else { + Command.sendMessage("Please enter a command."); + } + } catch (Exception e) { + e.printStackTrace(); + Command.sendMessage(Formatting.RED + "An error occurred while running this command. Check the log!"); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/FriendManager.java b/src/main/java/me/alpha432/oyvey/manager/FriendManager.java new file mode 100644 index 0000000..a302d2e --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/FriendManager.java @@ -0,0 +1,54 @@ +package me.alpha432.oyvey.manager; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import me.alpha432.oyvey.util.traits.Jsonable; +import net.minecraft.entity.player.PlayerEntity; + +import java.util.ArrayList; +import java.util.List; + +public class FriendManager implements Jsonable { + private final List friends = new ArrayList<>(); + + public boolean isFriend(String name) { + return this.friends.stream().anyMatch(friend -> friend.equalsIgnoreCase(name)); + } + + public boolean isFriend(PlayerEntity player) { + return this.isFriend(player.getGameProfile().getName()); + } + + public void addFriend(String name) { + this.friends.add(name); + } + + public void removeFriend(String name) { + friends.removeIf(s -> s.equalsIgnoreCase(name)); + } + + public List getFriends() { + return this.friends; + } + + @Override public JsonElement toJson() { + JsonObject object = new JsonObject(); + JsonArray array = new JsonArray(); + for (String friend : friends) { + array.add(friend); + } + object.add("friends", array); + return object; + } + + @Override public void fromJson(JsonElement element) { + for (JsonElement e : element.getAsJsonObject().get("friends").getAsJsonArray()) { + friends.add(e.getAsString()); + } + } + + @Override public String getFileName() { + return "friends.json"; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/HoleManager.java b/src/main/java/me/alpha432/oyvey/manager/HoleManager.java new file mode 100644 index 0000000..a8e3eb5 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/HoleManager.java @@ -0,0 +1,57 @@ +package me.alpha432.oyvey.manager; + +import com.google.common.eventbus.Subscribe; +import me.alpha432.oyvey.event.impl.UpdateEvent; +import me.alpha432.oyvey.features.Feature; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +public class HoleManager extends Feature { + private final int range = 8; + private final List holes = new ArrayList<>(); + private final BlockPos.Mutable pos = new BlockPos.Mutable(); + + public HoleManager() { + EVENT_BUS.register(this); + } + + @Subscribe private void onTick(UpdateEvent event) { + holes.clear(); + for (int x = -range; x < range; x++) { + for (int y = -range; y < range; y++) { + for (int z = -range; z < range; z++) { + pos.set(mc.player.getX() + x, mc.player.getY() + y, mc.player.getZ() + z); + Hole hole = getHole(pos); + if (hole == null) continue; + holes.add(hole); + } + } + } + } + + @Nullable public Hole getHole(BlockPos pos) { + if (mc.world.getBlockState(pos).getBlock() != Blocks.AIR) + return null; + HoleType type = HoleType.BEDROCK; + for (Direction direction : Direction.Type.HORIZONTAL) { + Block block = mc.world.getBlockState(pos.offset(direction)).getBlock(); + if (block == Blocks.OBSIDIAN) type = HoleType.UNSAFE; + else if (block != Blocks.BEDROCK) return null; + } + return new Hole(pos, type); + } + + private record Hole(BlockPos pos, HoleType holeType) { + } + + private enum HoleType { + BEDROCK, + UNSAFE; + } +} diff --git a/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java new file mode 100644 index 0000000..3c896eb --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/ModuleManager.java @@ -0,0 +1,205 @@ +package me.alpha432.oyvey.manager; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import me.alpha432.oyvey.event.impl.Render3DEvent; +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.features.modules.Module; +import me.alpha432.oyvey.features.modules.client.ClickGui; +import me.alpha432.oyvey.features.modules.client.HudModule; +import me.alpha432.oyvey.features.modules.combat.Criticals; +import me.alpha432.oyvey.features.modules.misc.MCF; +import me.alpha432.oyvey.features.modules.movement.ReverseStep; +import me.alpha432.oyvey.features.modules.movement.Step; +import me.alpha432.oyvey.features.modules.player.FastPlace; +import me.alpha432.oyvey.features.modules.player.Velocity; +import me.alpha432.oyvey.util.traits.Jsonable; +import me.alpha432.oyvey.util.traits.Util; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class ModuleManager implements Jsonable, Util { + public List modules = new ArrayList<>(); + public List sortedModules = new ArrayList<>(); + public List sortedModulesABC = new ArrayList<>(); + + public void init() { + modules.add(new HudModule()); + modules.add(new ClickGui()); + modules.add(new Criticals()); + modules.add(new MCF()); + modules.add(new Step()); + modules.add(new ReverseStep()); + modules.add(new FastPlace()); + modules.add(new Velocity()); + } + + public Module getModuleByName(String name) { + for (Module module : this.modules) { + if (!module.getName().equalsIgnoreCase(name)) continue; + return module; + } + return null; + } + + public T getModuleByClass(Class clazz) { + for (Module module : this.modules) { + if (!clazz.isInstance(module)) continue; + return (T) module; + } + return null; + } + + public void enableModule(Class clazz) { + Module module = this.getModuleByClass(clazz); + if (module != null) { + module.enable(); + } + } + + public void disableModule(Class clazz) { + Module module = this.getModuleByClass(clazz); + if (module != null) { + module.disable(); + } + } + + public void enableModule(String name) { + Module module = this.getModuleByName(name); + if (module != null) { + module.enable(); + } + } + + public void disableModule(String name) { + Module module = this.getModuleByName(name); + if (module != null) { + module.disable(); + } + } + + public boolean isModuleEnabled(String name) { + Module module = this.getModuleByName(name); + return module != null && module.isOn(); + } + + public boolean isModuleEnabled(Class clazz) { + Module module = this.getModuleByClass(clazz); + return module != null && module.isOn(); + } + + public Module getModuleByDisplayName(String displayName) { + for (Module module : this.modules) { + if (!module.getDisplayName().equalsIgnoreCase(displayName)) continue; + return module; + } + return null; + } + + public ArrayList getEnabledModules() { + ArrayList enabledModules = new ArrayList<>(); + for (Module module : this.modules) { + if (!module.isEnabled()) continue; + enabledModules.add(module); + } + return enabledModules; + } + + public ArrayList getEnabledModulesName() { + ArrayList enabledModules = new ArrayList<>(); + for (Module module : this.modules) { + if (!module.isEnabled() || !module.isDrawn()) continue; + enabledModules.add(module.getFullArrayString()); + } + return enabledModules; + } + + public ArrayList getModulesByCategory(Module.Category category) { + ArrayList modulesCategory = new ArrayList(); + this.modules.forEach(module -> { + if (module.getCategory() == category) { + modulesCategory.add(module); + } + }); + return modulesCategory; + } + + public List getCategories() { + return Arrays.asList(Module.Category.values()); + } + + public void onLoad() { + this.modules.stream().filter(Module::listening).forEach(EVENT_BUS::register); + this.modules.forEach(Module::onLoad); + } + + public void onUpdate() { + this.modules.stream().filter(Feature::isEnabled).forEach(Module::onUpdate); + } + + public void onTick() { + this.modules.stream().filter(Feature::isEnabled).forEach(Module::onTick); + } + + public void onRender2D(Render2DEvent event) { + this.modules.stream().filter(Feature::isEnabled).forEach(module -> module.onRender2D(event)); + } + + public void onRender3D(Render3DEvent event) { + this.modules.stream().filter(Feature::isEnabled).forEach(module -> module.onRender3D(event)); + } + + public void sortModules(boolean reverse) { + this.sortedModules = this.getEnabledModules().stream().filter(Module::isDrawn) + .sorted(Comparator.comparing(module -> mc.textRenderer.getWidth(module.getFullArrayString()) * (reverse ? -1 : 1))) + .collect(Collectors.toList()); + } + + public void sortModulesABC() { + this.sortedModulesABC = new ArrayList<>(this.getEnabledModulesName()); + this.sortedModulesABC.sort(String.CASE_INSENSITIVE_ORDER); + } + + public void onUnload() { + this.modules.forEach(EVENT_BUS::unregister); + this.modules.forEach(Module::onUnload); + } + + public void onUnloadPost() { + for (Module module : this.modules) { + module.enabled.setValue(false); + } + } + + public void onKeyPressed(int eventKey) { + if (eventKey <= 0) return; + this.modules.forEach(module -> { + if (module.getBind().getKey() == eventKey) { + module.toggle(); + } + }); + } + + @Override public JsonElement toJson() { + JsonObject object = new JsonObject(); + for (Module module : modules) { + object.add(module.getName(), module.toJson()); + } + return object; + } + + @Override public void fromJson(JsonElement element) { + for (Module module : modules) { + module.fromJson(element.getAsJsonObject().get(module.getName())); + } + } + + @Override public String getFileName() { + return "modules.json"; + } +} diff --git a/src/main/java/me/alpha432/oyvey/manager/PositionManager.java b/src/main/java/me/alpha432/oyvey/manager/PositionManager.java new file mode 100644 index 0000000..0f7c379 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/PositionManager.java @@ -0,0 +1,67 @@ +package me.alpha432.oyvey.manager; + +import me.alpha432.oyvey.features.Feature; +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; + +public class PositionManager + extends Feature { + private double x; + private double y; + private double z; + private boolean onground; + + public void updatePosition() { + this.x = mc.player.getX(); + this.y = mc.player.getY(); + this.z = mc.player.getZ(); + this.onground = mc.player.isOnGround(); + } + + public void restorePosition() { + mc.player.setPosition(x, y, z); + mc.player.setOnGround(onground); + } + + public void setPlayerPosition(double x, double y, double z) { + mc.player.setPosition(x, y, z); + } + + public void setPlayerPosition(double x, double y, double z, boolean onground) { + mc.player.setPosition(x, y, z); + mc.player.setOnGround(onground); + } + + public void setPositionPacket(double x, double y, double z, boolean onGround, boolean setPos, boolean noLagBack) { + mc.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.PositionAndOnGround(x, y, z, onGround)); + if (setPos) { + mc.player.setPosition(x, y, z); + if (noLagBack) { + this.updatePosition(); + } + } + } + + public double getX() { + return this.x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return this.y; + } + + public void setY(double y) { + this.y = y; + } + + public double getZ() { + return this.z; + } + + public void setZ(double z) { + this.z = z; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/RotationManager.java b/src/main/java/me/alpha432/oyvey/manager/RotationManager.java new file mode 100644 index 0000000..118b916 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/RotationManager.java @@ -0,0 +1,75 @@ +package me.alpha432.oyvey.manager; + +import me.alpha432.oyvey.util.MathUtil; +import me.alpha432.oyvey.util.traits.Util; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; +import net.minecraft.entity.Entity; + +public class RotationManager implements Util { + private float yaw; + private float pitch; + + public void updateRotations() { + this.yaw = mc.player.getYaw(); + this.pitch = mc.player.getPitch(); + } + + public void restoreRotations() { + mc.player.setYaw(yaw); + mc.player.headYaw = yaw; + mc.player.setPitch(pitch); + } + + public void setPlayerRotations(float yaw, float pitch) { + mc.player.setYaw(yaw); + mc.player.headYaw = yaw; + mc.player.setPitch(pitch); + } + + public void setPlayerYaw(float yaw) { + mc.player.setYaw(yaw); + mc.player.headYaw = yaw; + } + + public void lookAtPos(BlockPos pos) { + float[] angle = MathUtil.calcAngle(mc.player.getEyePos(), new Vec3d((float) pos.getX() + 0.5f, (float) pos.getY() + 0.5f, (float) pos.getZ() + 0.5f)); + this.setPlayerRotations(angle[0], angle[1]); + } + + public void lookAtVec3d(Vec3d vec3d) { + float[] angle = MathUtil.calcAngle(mc.player.getEyePos(), new Vec3d(vec3d.x, vec3d.y, vec3d.z)); + this.setPlayerRotations(angle[0], angle[1]); + } + + public void lookAtVec3d(double x, double y, double z) { + Vec3d vec3d = new Vec3d(x, y, z); + this.lookAtVec3d(vec3d); + } + + public void lookAtEntity(Entity entity) { + float[] angle = MathUtil.calcAngle(mc.player.getEyePos(), entity.getEyePos()); + this.setPlayerRotations(angle[0], angle[1]); + } + + public void setPlayerPitch(float pitch) { + mc.player.setPitch(pitch); + } + + public float getYaw() { + return this.yaw; + } + + public void setYaw(float yaw) { + this.yaw = yaw; + } + + public float getPitch() { + return this.pitch; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + +} diff --git a/src/main/java/me/alpha432/oyvey/manager/ServerManager.java b/src/main/java/me/alpha432/oyvey/manager/ServerManager.java new file mode 100644 index 0000000..1fac081 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/ServerManager.java @@ -0,0 +1,90 @@ +package me.alpha432.oyvey.manager; + +import me.alpha432.oyvey.features.Feature; +import me.alpha432.oyvey.util.models.Timer; + +import java.text.DecimalFormat; +import java.util.Arrays; + +public class ServerManager + extends Feature { + private final float[] tpsCounts = new float[10]; + private final DecimalFormat format = new DecimalFormat("##.00#"); + private final Timer timer = new Timer(); + private float TPS = 20.0f; + private long lastUpdate = -1L; + private String serverBrand = ""; + + public void onPacketReceived() { + this.timer.reset(); + } + + public boolean isServerNotResponding() { + return this.timer.passedMs(2000); + } + + public long serverRespondingTime() { + return this.timer.getPassedTimeMs(); + } + + public void update() { + float tps; + long currentTime = System.currentTimeMillis(); + if (this.lastUpdate == -1L) { + this.lastUpdate = currentTime; + return; + } + long timeDiff = currentTime - this.lastUpdate; + float tickTime = (float) timeDiff / 20.0f; + if (tickTime == 0.0f) { + tickTime = 50.0f; + } + if ((tps = 1000.0f / tickTime) > 20.0f) { + tps = 20.0f; + } + System.arraycopy(this.tpsCounts, 0, this.tpsCounts, 1, this.tpsCounts.length - 1); + this.tpsCounts[0] = tps; + double total = 0.0; + for (float f : this.tpsCounts) { + total += f; + } + if ((total /= this.tpsCounts.length) > 20.0) { + total = 20.0; + } + this.TPS = Float.parseFloat(this.format.format(total).replace(",", ".")); + this.lastUpdate = currentTime; + } + + @Override + public void reset() { + Arrays.fill(this.tpsCounts, 20.0f); + this.TPS = 20.0f; + } + + public float getTpsFactor() { + return 20.0f / this.TPS; + } + + public float getTPS() { + return this.TPS; + } + + public String getServerBrand() { + return this.serverBrand; + } + + public void setServerBrand(String brand) { + this.serverBrand = brand; + } + + public int getPing() { + if (ServerManager.fullNullCheck()) { + return 0; + } + try { + return mc.getNetworkHandler().getPlayerListEntry(mc.player.getGameProfile().getName()).getLatency(); + } catch (Throwable e) { + return 0; + } + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/manager/SpeedManager.java b/src/main/java/me/alpha432/oyvey/manager/SpeedManager.java new file mode 100644 index 0000000..3c14607 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/manager/SpeedManager.java @@ -0,0 +1,91 @@ +package me.alpha432.oyvey.manager; +import me.alpha432.oyvey.features.Feature; +import net.minecraft.client.MinecraftClient; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.MathHelper; + +import java.util.HashMap; + +public class SpeedManager + extends Feature { + public static final double LAST_JUMP_INFO_DURATION_DEFAULT = 3.0; + public static boolean didJumpThisTick = false; + public static boolean isJumping = false; + private final int distancer = 20; + public double firstJumpSpeed = 0.0; + public double lastJumpSpeed = 0.0; + public double percentJumpSpeedChanged = 0.0; + public double jumpSpeedChanged = 0.0; + public boolean didJumpLastTick = false; + public long jumpInfoStartTime = 0L; + public boolean wasFirstJump = true; + public double speedometerCurrentSpeed = 0.0; + public HashMap playerSpeeds = new HashMap(); + + public static void setDidJumpThisTick(boolean val) { + didJumpThisTick = val; + } + + public static void setIsJumping(boolean val) { + isJumping = val; + } + + public float lastJumpInfoTimeRemaining() { + return (float) (System.currentTimeMillis() - this.jumpInfoStartTime) / 1000.0f; + } + + public void updateValues() { + double distTraveledLastTickX = mc.player.getX() - mc.player.prevX; + double distTraveledLastTickZ = mc.player.getZ() - mc.player.prevZ; + this.speedometerCurrentSpeed = distTraveledLastTickX * distTraveledLastTickX + distTraveledLastTickZ * distTraveledLastTickZ; + if (didJumpThisTick && (!mc.player.isOnGround() || isJumping)) { + if (didJumpThisTick && !this.didJumpLastTick) { + this.wasFirstJump = this.lastJumpSpeed == 0.0; + this.percentJumpSpeedChanged = this.speedometerCurrentSpeed != 0.0 ? this.speedometerCurrentSpeed / this.lastJumpSpeed - 1.0 : -1.0; + this.jumpSpeedChanged = this.speedometerCurrentSpeed - this.lastJumpSpeed; + this.jumpInfoStartTime = System.currentTimeMillis(); + this.lastJumpSpeed = this.speedometerCurrentSpeed; + this.firstJumpSpeed = this.wasFirstJump ? this.lastJumpSpeed : 0.0; + } + this.didJumpLastTick = didJumpThisTick; + } else { + this.didJumpLastTick = false; + this.lastJumpSpeed = 0.0; + } + this.updatePlayers(); + } + + public void updatePlayers() { + for (PlayerEntity player : mc.world.getPlayers()) { + if (!(mc.player.distanceTo(player) < distancer)) + continue; + double distTraveledLastTickX = player.getX() - player.prevX; + double distTraveledLastTickZ = player.getZ() - player.prevZ; + double playerSpeed = distTraveledLastTickX * distTraveledLastTickX + distTraveledLastTickZ * distTraveledLastTickZ; + this.playerSpeeds.put(player, playerSpeed); + } + } + + public double getPlayerSpeed(PlayerEntity player) { + if (this.playerSpeeds.get(player) == null) { + return 0.0; + } + return this.turnIntoKpH(this.playerSpeeds.get(player)); + } + + public double turnIntoKpH(double input) { + return Math.sqrt(input) * 71.2729367892; + } + + public double getSpeedKpH() { + double speedometerkphdouble = this.turnIntoKpH(this.speedometerCurrentSpeed); + speedometerkphdouble = (double) Math.round(10.0 * speedometerkphdouble) / 10.0; + return speedometerkphdouble; + } + + public double getSpeedMpS() { + double speedometerMpsdouble = this.turnIntoKpH(this.speedometerCurrentSpeed) / 3.6; + speedometerMpsdouble = (double) Math.round(10.0 * speedometerMpsdouble) / 10.0; + return speedometerMpsdouble; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinClientConnection.java b/src/main/java/me/alpha432/oyvey/mixin/MixinClientConnection.java new file mode 100644 index 0000000..ecb21c7 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinClientConnection.java @@ -0,0 +1,50 @@ +package me.alpha432.oyvey.mixin; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import me.alpha432.oyvey.event.impl.PacketEvent; +import net.minecraft.network.ClientConnection; +import net.minecraft.network.NetworkSide; +import net.minecraft.network.PacketCallbacks; +import net.minecraft.network.packet.Packet; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin( ClientConnection.class ) +public class MixinClientConnection { + + @Shadow private Channel channel; + @Shadow @Final private NetworkSide side; + + @Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true) + public void channelRead0(ChannelHandlerContext chc, Packet packet, CallbackInfo ci) { + if (this.channel.isOpen() && packet != null) { + try { + PacketEvent.Receive event = new PacketEvent.Receive(packet); + EVENT_BUS.post(event); + if (event.isCancelled()) + ci.cancel(); + } catch (Exception e) { + } + } + } + + @Inject(method = "sendImmediately", at = @At("HEAD"), cancellable = true) + private void sendImmediately(Packet packet, PacketCallbacks callbacks, CallbackInfo ci) { + if (this.side != NetworkSide.CLIENTBOUND) return; + try { + PacketEvent.Send event = new PacketEvent.Send(packet); + EVENT_BUS.post(event); + if (event.isCancelled()) ci.cancel(); + } catch (Exception e) { + } + } + + +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayNetworkHandler.java b/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayNetworkHandler.java new file mode 100644 index 0000000..8af7456 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayNetworkHandler.java @@ -0,0 +1,20 @@ +package me.alpha432.oyvey.mixin; + +import me.alpha432.oyvey.event.impl.ChatEvent; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin(ClientPlayNetworkHandler.class) +public class MixinClientPlayNetworkHandler { + @Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true) + private void sendChatMessageHook(String content, CallbackInfo ci) { + ChatEvent event = new ChatEvent(content); + EVENT_BUS.post(event); + if (event.isCancelled()) ci.cancel(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayerEntity.java b/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayerEntity.java new file mode 100644 index 0000000..2684ac3 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinClientPlayerEntity.java @@ -0,0 +1,30 @@ +package me.alpha432.oyvey.mixin; + +import me.alpha432.oyvey.event.Stage; +import me.alpha432.oyvey.event.impl.UpdateEvent; +import me.alpha432.oyvey.event.impl.UpdateWalkingPlayerEvent; +import net.minecraft.client.network.ClientPlayerEntity; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin(ClientPlayerEntity.class) +public class MixinClientPlayerEntity { + @Inject(method = "tick", at = @At("TAIL")) + private void tickHook(CallbackInfo ci) { + EVENT_BUS.post(new UpdateEvent()); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;tick()V", shift = At.Shift.AFTER)) + private void tickHook2(CallbackInfo ci) { + EVENT_BUS.post(new UpdateWalkingPlayerEvent(Stage.PRE)); + } + + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendMovementPackets()V", shift = At.Shift.AFTER)) + private void tickHook3(CallbackInfo ci) { + EVENT_BUS.post(new UpdateWalkingPlayerEvent(Stage.POST)); + } +} diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinInGameHud.java b/src/main/java/me/alpha432/oyvey/mixin/MixinInGameHud.java new file mode 100644 index 0000000..cc89898 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinInGameHud.java @@ -0,0 +1,40 @@ +package me.alpha432.oyvey.mixin; + +import com.mojang.blaze3d.systems.RenderSystem; +import me.alpha432.oyvey.event.impl.Render2DEvent; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.hud.InGameHud; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin( InGameHud.class ) +public class MixinInGameHud { + + @Inject(method = "render", at = @At("RETURN")) + public void render(DrawContext context, float tickDelta, CallbackInfo ci) { + if(MinecraftClient.getInstance().options.debugEnabled) return; + RenderSystem.setShaderColor(1, 1, 1, 1); + + RenderSystem.disableDepthTest(); + RenderSystem.enableBlend(); + RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + RenderSystem.disableCull(); + GL11.glEnable(GL11.GL_LINE_SMOOTH); + + + Render2DEvent event = new Render2DEvent(context, tickDelta); + EVENT_BUS.post(event); + + RenderSystem.enableDepthTest(); + GL11.glDisable(GL11.GL_LINE_SMOOTH); + + } + +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinKeyboard.java b/src/main/java/me/alpha432/oyvey/mixin/MixinKeyboard.java new file mode 100644 index 0000000..89f23f1 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinKeyboard.java @@ -0,0 +1,20 @@ +package me.alpha432.oyvey.mixin; + +import me.alpha432.oyvey.event.impl.KeyEvent; +import net.minecraft.client.Keyboard; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin(Keyboard.class) +public class MixinKeyboard { + @Inject(method = "onKey", at = @At(value = "INVOKE", target = "net/minecraft/client/util/InputUtil.isKeyPressed(JI)Z", ordinal = 5), cancellable = true) + private void onKey(long windowPointer, int key, int scanCode, int action, int modifiers, CallbackInfo ci) { + KeyEvent event = new KeyEvent(key); + EVENT_BUS.post(event); + if (event.isCancelled()) ci.cancel(); + } +} diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinRenderTickCounter.java b/src/main/java/me/alpha432/oyvey/mixin/MixinRenderTickCounter.java new file mode 100644 index 0000000..8beee4d --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinRenderTickCounter.java @@ -0,0 +1,19 @@ +package me.alpha432.oyvey.mixin; + +import me.alpha432.oyvey.OyVey; +import net.minecraft.client.render.RenderTickCounter; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin( RenderTickCounter.class ) +public class MixinRenderTickCounter { + @Shadow public float lastFrameDuration; + + @Inject(method = "beginRenderTick", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/RenderTickCounter;prevTimeMillis:J")) + public void beginRenderTick(long timeMillis, CallbackInfoReturnable cir) { + this.lastFrameDuration *= OyVey.TIMER; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/mixin/MixinWorldRenderer.java b/src/main/java/me/alpha432/oyvey/mixin/MixinWorldRenderer.java new file mode 100644 index 0000000..b815ce3 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/mixin/MixinWorldRenderer.java @@ -0,0 +1,29 @@ +package me.alpha432.oyvey.mixin; +import com.mojang.blaze3d.systems.RenderSystem; +import me.alpha432.oyvey.event.impl.Render3DEvent; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.Camera; +import net.minecraft.client.render.GameRenderer; +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.WorldRenderer; +import net.minecraft.client.util.math.MatrixStack; +import org.joml.Matrix4f; +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import static me.alpha432.oyvey.util.traits.Util.EVENT_BUS; + +@Mixin( WorldRenderer.class ) +public class MixinWorldRenderer { + @Inject(method = "render", at = @At("RETURN")) + private void render(MatrixStack matrices, float tickDelta, long limitTime, boolean renderBlockOutline, Camera camera, GameRenderer gameRenderer, LightmapTextureManager lightmapTextureManager, Matrix4f positionMatrix, CallbackInfo ci) { + MinecraftClient.getInstance().getProfiler().push("oyvey-render-3d"); + RenderSystem.clear(GL11.GL_DEPTH_BUFFER_BIT, MinecraftClient.IS_SYSTEM_MAC); + Render3DEvent event = new Render3DEvent(matrices, tickDelta); + EVENT_BUS.post(event); + MinecraftClient.getInstance().getProfiler().pop(); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/util/ColorUtil.java b/src/main/java/me/alpha432/oyvey/util/ColorUtil.java new file mode 100644 index 0000000..10f7575 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/ColorUtil.java @@ -0,0 +1,46 @@ +package me.alpha432.oyvey.util; + +import me.alpha432.oyvey.features.modules.client.ClickGui; + +import java.awt.*; + +public class ColorUtil { + public static int toARGB(int r, int g, int b, int a) { + return new Color(r, g, b, a).getRGB(); + } + + public static int toRGBA(int r, int g, int b) { + return ColorUtil.toRGBA(r, g, b, 255); + } + + public static int toRGBA(int r, int g, int b, int a) { + return (r << 16) + (g << 8) + b + (a << 24); + } + + public static int toRGBA(float r, float g, float b, float a) { + return ColorUtil.toRGBA((int) (r * 255.0f), (int) (g * 255.0f), (int) (b * 255.0f), (int) (a * 255.0f)); + } + + public static Color rainbow(int delay) { + double rainbowState = Math.ceil((double) (System.currentTimeMillis() + (long) delay) / 20.0); + return Color.getHSBColor((float) ((rainbowState %= 360.0) / 360.0), ClickGui.getInstance().rainbowSaturation.getValue().floatValue() / 255.0f, ClickGui.getInstance().rainbowBrightness.getValue().floatValue() / 255.0f); + } + + public static int toRGBA(float[] colors) { + if (colors.length != 4) { + throw new IllegalArgumentException("colors[] must have a length of 4!"); + } + return ColorUtil.toRGBA(colors[0], colors[1], colors[2], colors[3]); + } + + public static int toRGBA(double[] colors) { + if (colors.length != 4) { + throw new IllegalArgumentException("colors[] must have a length of 4!"); + } + return ColorUtil.toRGBA((float) colors[0], (float) colors[1], (float) colors[2], (float) colors[3]); + } + + public static int toRGBA(Color color) { + return ColorUtil.toRGBA(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/util/InteractionUtil.java b/src/main/java/me/alpha432/oyvey/util/InteractionUtil.java new file mode 100644 index 0000000..4cb3e6c --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/InteractionUtil.java @@ -0,0 +1,166 @@ +package me.alpha432.oyvey.util; + +import me.alpha432.oyvey.util.traits.Util; +import net.minecraft.block.BlockState; +import net.minecraft.enchantment.EnchantmentHelper; +import net.minecraft.enchantment.Enchantments; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ExperienceOrbEntity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.effect.StatusEffectUtil; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.thrown.ExperienceBottleEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.c2s.play.HandSwingC2SPacket; +import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; +import net.minecraft.registry.tag.FluidTags; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.shape.VoxelShapes; + +public class InteractionUtil implements Util { + public static boolean canBreak(BlockPos blockPos, BlockState state) { + if (!mc.player.isCreative() && state.getHardness(mc.world, blockPos) < 0) return false; + return state.getOutlineShape(mc.world, blockPos) != VoxelShapes.empty(); + } + + public static boolean isPlaceable(BlockPos pos, boolean entityCheck) { + if (!mc.world.getBlockState(pos).isReplaceable()) return false; + for (Entity e : mc.world.getEntitiesByClass(Entity.class, new Box(pos), e -> !(e instanceof ExperienceBottleEntity || e instanceof ItemEntity || e instanceof ExperienceOrbEntity))) { + if (e instanceof PlayerEntity) return false; + return !entityCheck; + } + return true; + } + + public static boolean breakBlock(BlockPos pos) { + if (!canBreak(pos, mc.world.getBlockState(pos))) return false; + BlockPos bp = pos instanceof BlockPos.Mutable ? new BlockPos(pos) : pos; + + mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, bp, Direction.UP)); + mc.player.swingHand(Hand.MAIN_HAND); + mc.getNetworkHandler().sendPacket(new PlayerActionC2SPacket(PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, bp, Direction.UP)); + + mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND)); + + return true; + } + + public static void useItem(BlockPos pos) { + useItem(pos, Hand.MAIN_HAND); + } + + public static void useItem(BlockPos pos, Hand hand) { + if (mc.world == null || mc.player == null || mc.interactionManager == null) return; + Direction direction = mc.crosshairTarget != null ? (( BlockHitResult ) mc.crosshairTarget).getSide() : Direction.DOWN; + ActionResult result = mc.interactionManager.interactBlock(mc.player, hand, new BlockHitResult( + Vec3d.ofCenter(pos), direction, pos, false + )); + if (result.shouldSwingHand()) { + mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(hand)); + } + } + + public static boolean place(BlockPos pos, boolean airPlace) { + return place(pos, airPlace, Hand.MAIN_HAND); + } + + public static boolean place(BlockPos pos, boolean airPlace, Hand hand) { + if (mc.world == null || mc.player == null || mc.interactionManager == null) return false; + if (!isPlaceable(pos, false)) return false; + Direction direction = calcSide(pos); + if (direction == null) { + if (airPlace) direction = mc.crosshairTarget != null ? (( BlockHitResult ) mc.crosshairTarget).getSide() : Direction.DOWN; + else return false; + } + BlockPos bp = airPlace ? pos : pos.offset(direction); + ActionResult result = mc.interactionManager.interactBlock(mc.player, hand, new BlockHitResult( + airPlace ? Vec3d.ofCenter(pos) : Vec3d.ofCenter(pos).offset(direction.getOpposite(), 0.5), + airPlace ? direction : direction.getOpposite(), bp, false + )); + if (result.shouldSwingHand()) { + mc.player.networkHandler.sendPacket(new HandSwingC2SPacket(hand)); + } + return true; + } + + public static Direction calcSide(BlockPos pos) { + for (Direction d : Direction.values()) + if (!mc.world.getBlockState(pos.add(d.getVector())).isReplaceable()) return d; + return null; + } + + public static double getBlockBreakingSpeed(int slot, BlockPos pos) { + return getBlockBreakingSpeed(slot, mc.world.getBlockState(pos)); + } + + public static double getBlockBreakingSpeed(int slot, BlockState block) { + double speed = mc.player.getInventory().main.get(slot).getMiningSpeedMultiplier(block); + + if (speed > 1) { + ItemStack tool = mc.player.getInventory().getStack(slot); + + int efficiency = EnchantmentHelper.getLevel(Enchantments.EFFICIENCY, tool); + + if (efficiency > 0 && !tool.isEmpty()) speed += efficiency * efficiency + 1; + } + + if (StatusEffectUtil.hasHaste(mc.player)) { + speed *= 1 + (StatusEffectUtil.getHasteAmplifier(mc.player) + 1) * 0.2F; + } + + if (mc.player.hasStatusEffect(StatusEffects.MINING_FATIGUE)) { + float k = switch (mc.player.getStatusEffect(StatusEffects.MINING_FATIGUE).getAmplifier()) { + case 0 -> 0.3F; + case 1 -> 0.09F; + case 2 -> 0.0027F; + default -> 8.1E-4F; + }; + + speed *= k; + } + + if (mc.player.isSubmergedIn(FluidTags.WATER) && !EnchantmentHelper.hasAquaAffinity(mc.player)) { + speed /= 5.0F; + } + + if (!mc.player.isOnGround()) { + speed /= 5.0F; + } + + float hardness = block.getHardness(null, null); + if (hardness == -1) return 0; + + speed /= hardness / (!block.isToolRequired() || mc.player.getInventory().main.get(slot).isSuitableFor(block) ? 30 : 100); + + float ticks = ( float ) (Math.floor(1.0f / speed) + 1.0f); + + return ( long ) ((ticks / 20.0f) * 1000); + } + + public static Direction right(Direction direction) { + return switch (direction) { + case EAST -> Direction.SOUTH; + case SOUTH -> Direction.WEST; + case WEST -> Direction.NORTH; + case NORTH -> Direction.EAST; + default -> throw new IllegalStateException("Unexpected value: " + direction); + }; + } + + public static Direction left(Direction direction) { + return switch (direction) { + case EAST -> Direction.NORTH; + case NORTH -> Direction.WEST; + case WEST -> Direction.SOUTH; + case SOUTH -> Direction.EAST; + default -> throw new IllegalStateException("Unexpected value: " + direction); + }; + } +} diff --git a/src/main/java/me/alpha432/oyvey/util/KeyboardUtil.java b/src/main/java/me/alpha432/oyvey/util/KeyboardUtil.java new file mode 100644 index 0000000..3669a64 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/KeyboardUtil.java @@ -0,0 +1,11 @@ +package me.alpha432.oyvey.util; + +import me.alpha432.oyvey.features.settings.Bind; + +public class KeyboardUtil { + public static String getKeyName(int key) { + String str = new Bind(key).toString().toUpperCase(); + str = str.replace("KEY.KEYBOARD", "").replace(".", " "); + return str; + } +} diff --git a/src/main/java/me/alpha432/oyvey/util/MathUtil.java b/src/main/java/me/alpha432/oyvey/util/MathUtil.java new file mode 100644 index 0000000..662f3a2 --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/MathUtil.java @@ -0,0 +1,207 @@ +package me.alpha432.oyvey.util; + +import me.alpha432.oyvey.util.traits.Util; +import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.*; + +public class MathUtil + implements Util { + private static final Random random = new Random(); + + public static int getRandom(int min, int max) { + return min + random.nextInt(max - min + 1); + } + + public static double getRandom(double min, double max) { + return MathHelper.clamp(min + random.nextDouble() * max, min, max); + } + + public static float getRandom(float min, float max) { + return MathHelper.clamp(min + random.nextFloat() * max, min, max); + } + + public static int clamp(int num, int min, int max) { + return num < min ? min : Math.min(num, max); + } + + public static float clamp(float num, float min, float max) { + return num < min ? min : Math.min(num, max); + } + + public static double clamp(double num, double min, double max) { + return num < min ? min : Math.min(num, max); + } + + public static float sin(float value) { + return MathHelper.sin(value); + } + + public static float cos(float value) { + return MathHelper.cos(value); + } + + public static float wrapDegrees(float value) { + return MathHelper.wrapDegrees(value); + } + + public static double wrapDegrees(double value) { + return MathHelper.wrapDegrees(value); + } + + public static Vec3d roundVec(Vec3d vec3d, int places) { + return new Vec3d(MathUtil.round(vec3d.x, places), MathUtil.round(vec3d.y, places), MathUtil.round(vec3d.z, places)); + } + + public static double square(double input) { + return input * input; + } + + public static double round(double value, int places) { + if (places < 0) { + throw new IllegalArgumentException(); + } + BigDecimal bd = BigDecimal.valueOf(value); + bd = bd.setScale(places, RoundingMode.FLOOR); + return bd.doubleValue(); + } + + public static float wrap(float valI) { + float val = valI % 360.0f; + if (val >= 180.0f) { + val -= 360.0f; + } + if (val < -180.0f) { + val += 360.0f; + } + return val; + } + + public static Vec3d direction(float yaw) { + return new Vec3d(Math.cos(MathUtil.degToRad(yaw + 90.0f)), 0.0, Math.sin(MathUtil.degToRad(yaw + 90.0f))); + } + + public static float round(float value, int places) { + if (places < 0) { + throw new IllegalArgumentException(); + } + BigDecimal bd = BigDecimal.valueOf(value); + bd = bd.setScale(places, RoundingMode.FLOOR); + return bd.floatValue(); + } + + public static > Map sortByValue(Map map, boolean descending) { + LinkedList> list = new LinkedList<>(map.entrySet()); + if (descending) { + list.sort(Map.Entry.comparingByValue(Comparator.reverseOrder())); + } else { + list.sort(Map.Entry.comparingByValue()); + } + LinkedHashMap result = new LinkedHashMap<>(); + for (Map.Entry entry : list) { + result.put(entry.getKey(), entry.getValue()); + } + return result; + } + + public static String getTimeOfDay() { + Calendar c = Calendar.getInstance(); + int timeOfDay = c.get(11); + if (timeOfDay < 12) { + return "Good Morning "; + } + if (timeOfDay < 16) { + return "Good Afternoon "; + } + if (timeOfDay < 21) { + return "Good Evening "; + } + return "Good Night "; + } + + public static double radToDeg(double rad) { + return rad * (double) 57.29578f; + } + + public static double degToRad(double deg) { + return deg * 0.01745329238474369; + } + + public static double getIncremental(double val, double inc) { + double one = 1.0 / inc; + return (double) Math.round(val * one) / one; + } + + public static double[] directionSpeed(double speed) { + float forward = MathUtil.mc.player.input.movementForward; + float side = MathUtil.mc.player.input.movementSideways; + float yaw = MathUtil.mc.player.prevYaw + (MathUtil.mc.player.getYaw() - MathUtil.mc.player.prevYaw) * mc.getTickDelta(); + if (forward != 0.0f) { + if (side > 0.0f) { + yaw += (float) (forward > 0.0f ? -45 : 45); + } else if (side < 0.0f) { + yaw += (float) (forward > 0.0f ? 45 : -45); + } + side = 0.0f; + if (forward > 0.0f) { + forward = 1.0f; + } else if (forward < 0.0f) { + forward = -1.0f; + } + } + double sin = Math.sin(Math.toRadians(yaw + 90.0f)); + double cos = Math.cos(Math.toRadians(yaw + 90.0f)); + double posX = (double) forward * speed * cos + (double) side * speed * sin; + double posZ = (double) forward * speed * sin - (double) side * speed * cos; + return new double[]{posX, posZ}; + } + + public static List getBlockBlocks(Entity entity) { + ArrayList vec3ds = new ArrayList<>(); + Box bb = entity.getBoundingBox(); + double y = entity.getY(); + double minX = MathUtil.round(bb.minX, 0); + double minZ = MathUtil.round(bb.minZ, 0); + double maxX = MathUtil.round(bb.maxX, 0); + double maxZ = MathUtil.round(bb.maxZ, 0); + if (minX != maxX) { + vec3ds.add(new Vec3d(minX, y, minZ)); + vec3ds.add(new Vec3d(maxX, y, minZ)); + if (minZ != maxZ) { + vec3ds.add(new Vec3d(minX, y, maxZ)); + vec3ds.add(new Vec3d(maxX, y, maxZ)); + return vec3ds; + } + } else if (minZ != maxZ) { + vec3ds.add(new Vec3d(minX, y, minZ)); + vec3ds.add(new Vec3d(minX, y, maxZ)); + return vec3ds; + } + vec3ds.add(entity.getPos()); + return vec3ds; + } + + public static boolean areVec3dsAligned(Vec3d vec3d1, Vec3d vec3d2) { + return MathUtil.areVec3dsAlignedRetarded(vec3d1, vec3d2); + } + + public static boolean areVec3dsAlignedRetarded(Vec3d vec3d1, Vec3d vec3d2) { + BlockPos pos1 = BlockPos.ofFloored(vec3d1); + BlockPos pos2 = BlockPos.ofFloored(vec3d2.x, vec3d1.y, vec3d2.z); + return pos1.equals(pos2); + } + + public static float[] calcAngle(Vec3d from, Vec3d to) { + double difX = to.x - from.x; + double difY = (to.y - from.y) * -1.0; + double difZ = to.z - from.z; + double dist = Math.sqrt(difX * difX + difZ * difZ); + return new float[]{(float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(difZ, difX)) - 90.0), (float) MathHelper.wrapDegrees(Math.toDegrees(Math.atan2(difY, dist)))}; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/util/RenderUtil.java b/src/main/java/me/alpha432/oyvey/util/RenderUtil.java new file mode 100644 index 0000000..055968d --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/RenderUtil.java @@ -0,0 +1,222 @@ +package me.alpha432.oyvey.util; + +import com.mojang.blaze3d.systems.RenderSystem; +import me.alpha432.oyvey.util.traits.Util; +import net.minecraft.client.render.*; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.RotationAxis; +import net.minecraft.util.math.Vec3d; + +import java.awt.*; + +public class RenderUtil implements Util { + + public static void rect(MatrixStack stack, float x1, float y1, float x2, float y2, int color) { + rectFilled(stack, x1, y1, x2, y2, color); + } + + public static void rect(MatrixStack stack, float x1, float y1, float x2, float y2, int color, float width) { + drawHorizontalLine(stack, x1, x2, y1, color, width); + drawVerticalLine(stack, x2, y1, y2, color, width); + drawHorizontalLine(stack, x1, x2, y2, color, width); + drawVerticalLine(stack, x1, y1, y2, color, width); + } + + protected static void drawHorizontalLine(MatrixStack matrices, float x1, float x2, float y, int color) { + if (x2 < x1) { + float i = x1; + x1 = x2; + x2 = i; + } + + rectFilled(matrices, x1, y, x2 + 1, y + 1, color); + } + + protected static void drawVerticalLine(MatrixStack matrices, float x, float y1, float y2, int color) { + if (y2 < y1) { + float i = y1; + y1 = y2; + y2 = i; + } + + rectFilled(matrices, x, y1 + 1, x + 1, y2, color); + } + + protected static void drawHorizontalLine(MatrixStack matrices, float x1, float x2, float y, int color, float width) { + if (x2 < x1) { + float i = x1; + x1 = x2; + x2 = i; + } + + rectFilled(matrices, x1, y, x2 + width, y + width, color); + } + + protected static void drawVerticalLine(MatrixStack matrices, float x, float y1, float y2, int color, float width) { + if (y2 < y1) { + float i = y1; + y1 = y2; + y2 = i; + } + + rectFilled(matrices, x, y1 + width, x + width, y2, color); + } + + public static void rectFilled(MatrixStack matrix, float x1, float y1, float x2, float y2, int color) { + float i; + if (x1 < x2) { + i = x1; + x1 = x2; + x2 = i; + } + + if (y1 < y2) { + i = y1; + y1 = y2; + y2 = i; + } + + float f = (float) (color >> 24 & 255) / 255.0F; + float g = (float) (color >> 16 & 255) / 255.0F; + float h = (float) (color >> 8 & 255) / 255.0F; + float j = (float) (color & 255) / 255.0F; + BufferBuilder bufferBuilder = Tessellator.getInstance().getBuffer(); + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + RenderSystem.setShader(GameRenderer::getPositionColorProgram); + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y2, 0.0F).color(g, h, j, f).next(); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y2, 0.0F).color(g, h, j, f).next(); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x2, y1, 0.0F).color(g, h, j, f).next(); + bufferBuilder.vertex(matrix.peek().getPositionMatrix(), x1, y1, 0.0F).color(g, h, j, f).next(); + BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()); + RenderSystem.disableBlend(); + } + + // 3d + + + public static void drawBoxFilled(MatrixStack stack, Box box, Color c) { + float minX = (float) (box.minX - mc.getEntityRenderDispatcher().camera.getPos().getX()); + float minY = (float) (box.minY - mc.getEntityRenderDispatcher().camera.getPos().getY()); + float minZ = (float) (box.minZ - mc.getEntityRenderDispatcher().camera.getPos().getZ()); + float maxX = (float) (box.maxX - mc.getEntityRenderDispatcher().camera.getPos().getX()); + float maxY = (float) (box.maxY - mc.getEntityRenderDispatcher().camera.getPos().getY()); + float maxZ = (float) (box.maxZ - mc.getEntityRenderDispatcher().camera.getPos().getZ()); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + + setup3D(); + RenderSystem.setShader(GameRenderer::getPositionColorProgram); + bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, maxZ).color(c.getRGB()).next(); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, minZ).color(c.getRGB()).next(); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, minZ).color(c.getRGB()).next(); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, maxZ).color(c.getRGB()).next(); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, minY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), maxX, maxY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, maxZ).color(c.getRGB()).next(); + + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, minZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, minY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, maxZ).color(c.getRGB()).next(); + bufferBuilder.vertex(stack.peek().getPositionMatrix(), minX, maxY, minZ).color(c.getRGB()).next(); + + tessellator.draw(); + clean3D(); + } + + public static void drawBoxFilled(MatrixStack stack, Vec3d vec, Color c) { + drawBoxFilled(stack, Box.from(vec), c); + } + + public static void drawBoxFilled(MatrixStack stack, BlockPos bp, Color c) { + drawBoxFilled(stack, new Box(bp), c); + } + + public static void drawBox(MatrixStack stack, Box box, Color c, double lineWidth) { + float minX = (float) (box.minX - mc.getEntityRenderDispatcher().camera.getPos().getX()); + float minY = (float) (box.minY - mc.getEntityRenderDispatcher().camera.getPos().getY()); + float minZ = (float) (box.minZ - mc.getEntityRenderDispatcher().camera.getPos().getZ()); + float maxX = (float) (box.maxX - mc.getEntityRenderDispatcher().camera.getPos().getX()); + float maxY = (float) (box.maxY - mc.getEntityRenderDispatcher().camera.getPos().getY()); + float maxZ = (float) (box.maxZ - mc.getEntityRenderDispatcher().camera.getPos().getZ()); + + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferBuilder = tessellator.getBuffer(); + setup3D(); + RenderSystem.lineWidth(( float ) lineWidth); + RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram); + + RenderSystem.defaultBlendFunc(); + + bufferBuilder.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES); + + WorldRenderer.drawBox(stack, bufferBuilder, minX, minY, minZ, maxX, maxY, maxZ, c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f); + + tessellator.draw(); + clean3D(); + } + + public static void drawBox(MatrixStack stack, Vec3d vec, Color c, double lineWidth) { + drawBox(stack, Box.from(vec), c, lineWidth); + } + + public static void drawBox(MatrixStack stack, BlockPos bp, Color c, double lineWidth) { + drawBox(stack, new Box(bp), c, lineWidth); + } + + public static MatrixStack matrixFrom(Vec3d pos) { + MatrixStack matrices = new MatrixStack(); + Camera camera = mc.gameRenderer.getCamera(); + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch())); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(camera.getYaw() + 180.0F)); + matrices.translate(pos.getX() - camera.getPos().x, pos.getY() - camera.getPos().y, pos.getZ() - camera.getPos().z); + return matrices; + } + + public static void setup() { + RenderSystem.enableBlend(); + RenderSystem.defaultBlendFunc(); + } + + public static void setup3D() { + setup(); + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.disableCull(); + } + + public static void clean() { + RenderSystem.disableBlend(); + } + + public static void clean3D() { + clean(); + RenderSystem.enableDepthTest(); + RenderSystem.depthMask(true); + RenderSystem.enableCull(); + } + +} diff --git a/src/main/java/me/alpha432/oyvey/util/models/Timer.java b/src/main/java/me/alpha432/oyvey/util/models/Timer.java new file mode 100644 index 0000000..75276ac --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/models/Timer.java @@ -0,0 +1,45 @@ +package me.alpha432.oyvey.util.models; + +public class Timer { + private long time = -1L; + + public boolean passedS(double s) { + return this.getMs(System.nanoTime() - this.time) >= (long) (s * 1000.0); + } + + public boolean passedM(double m) { + return this.getMs(System.nanoTime() - this.time) >= (long) (m * 1000.0 * 60.0); + } + + public boolean passedDms(double dms) { + return this.getMs(System.nanoTime() - this.time) >= (long) (dms * 10.0); + } + + public boolean passedDs(double ds) { + return this.getMs(System.nanoTime() - this.time) >= (long) (ds * 100.0); + } + + public boolean passedMs(long ms) { + return this.getMs(System.nanoTime() - this.time) >= ms; + } + + public boolean passedNS(long ns) { + return System.nanoTime() - this.time >= ns; + } + + public void setMs(long ms) { + this.time = System.nanoTime() - ms * 1000000L; + } + + public long getPassedTimeMs() { + return this.getMs(System.nanoTime() - this.time); + } + + public void reset() { + this.time = System.nanoTime(); + } + + public long getMs(long time) { + return time / 1000000L; + } +} \ No newline at end of file diff --git a/src/main/java/me/alpha432/oyvey/util/traits/Jsonable.java b/src/main/java/me/alpha432/oyvey/util/traits/Jsonable.java new file mode 100644 index 0000000..209754a --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/traits/Jsonable.java @@ -0,0 +1,13 @@ +package me.alpha432.oyvey.util.traits; + +import com.google.gson.JsonElement; + +public interface Jsonable { + JsonElement toJson(); + + void fromJson(JsonElement element); + + default String getFileName() { + return ""; + } +} diff --git a/src/main/java/me/alpha432/oyvey/util/traits/Util.java b/src/main/java/me/alpha432/oyvey/util/traits/Util.java new file mode 100644 index 0000000..6958fca --- /dev/null +++ b/src/main/java/me/alpha432/oyvey/util/traits/Util.java @@ -0,0 +1,9 @@ +package me.alpha432.oyvey.util.traits; + +import com.google.common.eventbus.EventBus; +import net.minecraft.client.MinecraftClient; + +public interface Util { + MinecraftClient mc = MinecraftClient.getInstance(); + EventBus EVENT_BUS = new EventBus(); +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..dd4da4a --- /dev/null +++ b/src/main/resources/fabric.mod.json @@ -0,0 +1,34 @@ +{ + "schemaVersion": 1, + "id": "oyvey", + "version": "${version}", + "name": "oyvey-ported", + "description": "free and opensource client base", + "authors": [ + "3arthqu4ke", + "alpha432", + "cattyn" + ], + "contact": { + "repo": "https://github.com/cattyngmd/oyvey-portedvey-ported" + }, + "license": "MIT", + "environment": "client", + "accessWidener": "oyvey.accesswidener", + "entrypoints": { + "client": [ + "me.alpha432.oyvey.OyVey" + ], + "main": [ + "me.alpha432.oyvey.OyVey" + ] + }, + "mixins": [ + "oyvey.mixins.json" + ], + "depends": { + "fabricloader": ">=${loader_version}", + "fabric": "*", + "minecraft": "${minecraft_version}" + } +} diff --git a/src/main/resources/oyvey.accesswidener b/src/main/resources/oyvey.accesswidener new file mode 100644 index 0000000..a3a276e --- /dev/null +++ b/src/main/resources/oyvey.accesswidener @@ -0,0 +1,7 @@ +accessWidener v2 named + +accessible field net/minecraft/client/MinecraftClient itemUseCooldown I +accessible field net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket entityId I +accessible method net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractTypeHandler getType ()Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractType; +accessible class net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractType +accessible field net/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket type Lnet/minecraft/network/packet/c2s/play/PlayerInteractEntityC2SPacket$InteractTypeHandler; \ No newline at end of file diff --git a/src/main/resources/oyvey.mixins.json b/src/main/resources/oyvey.mixins.json new file mode 100644 index 0000000..fd4434e --- /dev/null +++ b/src/main/resources/oyvey.mixins.json @@ -0,0 +1,20 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "me.alpha432.oyvey.mixin", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "MixinClientConnection" + ], + "client": [ + "MixinClientPlayerEntity", + "MixinClientPlayNetworkHandler", + "MixinInGameHud", + "MixinKeyboard", + "MixinRenderTickCounter", + "MixinWorldRenderer" + ], + "injectors": { + "defaultRequire": 1 + } +}