diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4900539 --- /dev/null +++ b/.gitignore @@ -0,0 +1,62 @@ +# Created by .ignore support plugin (hsz.mobi) +### Eclipse template +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +eclipse + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + + +### JetBrains template +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm +*.iml + +## Directory-based project format: +.idea/ + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + + +### Gradle template +.gradle +build/ +gradle/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +### Java template +*.class + +# Package Files # +*.jar +*.war +*.ear + +libs/ +run/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..9673ace --- /dev/null +++ b/README.md @@ -0,0 +1,118 @@ +ToggleSneak +================= +Shotbows ToggleSneak mod for Minecraft. + +### Technical Info + - [Setup Java](#setup-java) + - [Setup Gradle](#setup-gradle) + - [Setup Git](#setup-git) + - [Setup ToggleSneak](#setup-togglesneak) + - [Compile ToggleSneak](#compile-togglesneak) + - [Updating Your Repository](#updating-your-repository) + +#### Setup Java +The Java JDK is used to compile ToggleSneak. + +1. Download and install the Java JDK. + * [Windows/Mac download link](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). Scroll down, accept the `Oracle Binary Code License Agreement for Java SE`, and download it (if you have a 64-bit OS, please download the 64-bit version). + * Linux: Installation methods for certain popular flavors of Linux are listed below. If your distribution is not listed, follow the instructions specific to your package manager or install it manually [here](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). + * Gentoo: `emerge dev-java/oracle-jdk-bin` + * Archlinux: `pacman -S jdk8-openjdk` + * Ubuntu/Debian: `apt-get install openjdk-8-jdk` + * Fedora: `yum install java-1.8.0-openjdk` +2. Set up the environment. + * Windows: Set environment variables for the JDK. + 1. Go to `Control Panel\System and Security\System`, and click on `Advanced System Settings` on the left-hand side. + 2. Click on `Environment Variables`. + 3. Under `System Variables`, click `New`. + 4. For `Variable Name`, input `JAVA_HOME`. + 5. For `Variable Value`, input something similar to `C:\Program Files\Java\jdk1.8.0_91` exactly as shown (or wherever your Java JDK installation is), and click `Ok`. + 6. Scroll down to a variable named `Path`, and double-click on it. + 7. Append `;%JAVA_HOME%\bin` EXACTLY AS SHOWN and click `Ok`. Make sure the location is correct; double-check just to make sure. +3. Open up your command line and run `javac`. If it spews out a bunch of possible options and the usage, then you're good to go. If not try the steps again. + +#### Setup Gradle +Gradle is used to execute the various build tasks when compiling ToggleSneak. + +1. Download and install Gradle. + * [Windows/Mac download link](http://www.gradle.org/downloads). You only need the binaries, but choose whatever flavor you want. + * Unzip the package and put it wherever you want, eg `C:\Gradle`. + * Linux: Installation methods for certain popular flavors of Linux are listed below. If your distribution is not listed, follow the instructions specific to your package manager or install it manually [here](http://www.gradle.org/downloads). + * Gentoo: `emerge dev-java/gradle-bin` + * Archlinux: You'll have to install it from the [AUR](https://aur.archlinux.org/packages/gradle). + * Ubuntu/Debian: `apt-get install gradle` + * Fedora: Install Gradle manually from its website (see above), as Fedora ships a "broken" version of Gradle. Use `yum install gradle` only if you know what you're doing. +2. Set up the environment. + * Windows: Set environment variables for Gradle. + 1. Go back to `Environment Variables` and then create a new system variable. + 2. For `Variable Name`, input `GRADLE_HOME`. + 3. For `Variable Value`, input something similar to `C:\Gradle-1.10` exactly as shown (or wherever your Gradle installation is), and click `Ok`. + 4. Scroll down to `Path` again, and append `;%GRADLE_HOME%\bin` EXACTLY AS SHOWN and click `Ok`. Once again, double-check the location. +3. Open up your command line and run `gradle`. If it says "Welcome to Gradle [version].", then you're good to go. If not try the steps again. + +#### Setup Git +Git is used to clone ToggleSneak and update your local copy. + +1. Download and install Git [here](http://git-scm.com/download/). +2. *Optional* Download and install a Git GUI client, such as Github for Windows/Mac, SmartGitHg, TortoiseGit, etc. A nice list is available [here](http://git-scm.com/downloads/guis). + +#### Setup ToggleSneak +This section assumes that you're using the command-line version of Git. + +1. Open up your command line. +2. Navigate to a place where you want to download ToggleSneak's source (eg `C:\Development\Github\Minecraft\`) by executing `cd [folder location]`. This location is known as `mcdev` from now on. +3. Execute `git clone git@github.com:Shotbow/ToggleSneak.git`. This will download ToggleSneak's source into `mcdev`. +4. Right now, you should have a directory that looks something like: + +*** + mcdev + \-ToggleSneak + \-ToggleSneak's files (should have build.gradle) +*** + +#### Compile ToggleSneak +1. Execute `gradle setupDecompWorkspace`. This sets up Forge and downloads the necessary libraries to build ToggleSneak. This might take some time, be patient. + * You will generally only have to do this once until the Forge version in `build.properties` changes. +2. Execute `gradle build`. If you did everything right, `BUILD SUCCESSFUL` will be displayed after it finishes. This should be relatively quick. + * If you see `BUILD FAILED`, check the error output (it should be right around `BUILD FAILED`), fix everything (if possible), and try again. +3. Go to `mcdev\ToggleSneak\build\libs`. + * You should see a `.jar` file named `ToggleSneak--.jar`. +4. Copy the jar into your Minecraft mods folder, and you are done! + +#### Updating Your Repository +In order to get the most up-to-date builds, you'll have to periodically update your local repository. + +1. Open up your command line. +2. Navigate to `mcdev` in the console. +3. Make sure you have not made any changes to the local repository, or else there might be issues with Git. + * If you have, try reverting them to the status that they were when you last updated your repository. +4. Execute `git pull master`. This pulls all commits from the official repository that do not yet exist on your local repository and updates it. + +### Contributing +#### Submitting a Pull Request (PR) +So you found a bug in the code? Think you can make it more efficient? Want to help in general? Great! + +1. If you haven't already, create a [GitHub account](https://github.com/signup/free). +2. Click the `Fork` icon located at the top-right of this page (below your username). +3. Make the changes that you want to and commit them. + * If you're making changes locally, you'll have to do `git add -A`, `git commit` and `git push` in your command line. +4. Click `Pull Request` at the right-hand side of the gray bar directly below your fork's name. +5. Click `Click to create a pull request for this comparison`, enter your pull request title, and create a detailed description explaining what you changed. +6. Click `Send pull request`, and wait for feedback! + +#### Creating an Issue +Crashing? Have a suggestion? Found a bug? Create an issue now! + +1. Make sure your issue hasn't already been answered or fixed. Also think about whether your issue is a valid one before submitting it. +2. Go to the issues page. +3. Click `New Issue` right below `Star` and `Fork`. +4. Enter your issue title (something that summarizes your issue), and then add a detailed description ("Hey, could you add/change xxx?" or "Hey, found an exploit: stuff"). + * If you are reporting a bug, make sure you include the following: + * Version (can be found in the mcmod.info file or in the mod list) + * ForgeModLoader log (please use [gists](https://gist.github.com/) for large amounts of text!) + * Detailed description of the bug +5. Click `Submit new issue`, and wait for feedback! + +this README was based on [bspkrs'](https://github.com/bspkrs/bspkrsCore/blob/master/README.md) + +Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b29171b --- /dev/null +++ b/build.gradle @@ -0,0 +1,54 @@ +// For those who want the bleeding edge +buildscript { + repositories { + jcenter() + maven { + name = "forge" + url = "http://files.minecraftforge.net/maven" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' + } +} +apply plugin: 'net.minecraftforge.gradle.forge' + +version = "3.2.0" +group= "deez.togglesneak" +archivesBaseName = "ToggleSneak" + +minecraft { + version = "1.8.9-11.15.1.1722" + runDir = "run" + mappings = "stable_22" +} + +dependencies { + provided fileTree(dir: 'flat', includes: ['*.jar','*.zip']) +} + +jar { + manifest { + attributes 'ModSide':'CLIENT' + } +} + +processResources +{ + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + + // replace version and mcversion + expand 'version':project.version, 'mcversion':project.minecraft.version + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} diff --git a/flat/.gitignore b/flat/.gitignore new file mode 100644 index 0000000..952d7a6 --- /dev/null +++ b/flat/.gitignore @@ -0,0 +1,2 @@ +*.jar +*.zip \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e8c6bf7 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..17dfeef --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Apr 27 19:09:11 CEST 2016 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..97fac78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +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" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..aec9973 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@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 + +@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= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +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 init + +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 + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +: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 %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="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! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/deez/togglesneak/CustomMovementInput.java b/src/main/java/deez/togglesneak/CustomMovementInput.java index 552651b..4e1ae0d 100644 --- a/src/main/java/deez/togglesneak/CustomMovementInput.java +++ b/src/main/java/deez/togglesneak/CustomMovementInput.java @@ -1,57 +1,53 @@ package deez.togglesneak; -import java.text.DecimalFormat; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.settings.GameSettings; import net.minecraft.util.MovementInputFromOptions; +import net.minecraft.world.WorldSettings; + +import java.text.DecimalFormat; /* * ToggleSneak's replacement for MovementInputFromOptions */ -public class CustomMovementInput -{ +public class CustomMovementInput { public boolean isDisabled; public boolean canDoubleTap; - + public boolean sprint = false; public boolean sprintHeldAndReleased = false; public boolean sprintDoubleTapped = false; - + private long lastPressed; private long lastSprintPressed; private boolean handledSneakPress; private boolean handledSprintPress; - private boolean wasRiding; + private boolean wasRiding; /* * MovementInputFromOptions.updatePlayerMoveState() */ - public void update(Minecraft mc, MovementInputFromOptions options, EntityPlayerSP thisPlayer) - { + public void update(Minecraft mc, MovementInputFromOptions options, EntityPlayerSP thisPlayer) { options.moveStrafe = 0.0F; options.moveForward = 0.0F; GameSettings settings = mc.gameSettings; - if(settings.keyBindForward.isKeyDown()) - { + if (settings.keyBindForward.isKeyDown()) { ++options.moveForward; } - if(settings.keyBindBack.isKeyDown()) - { + if (settings.keyBindBack.isKeyDown()) { --options.moveForward; } - if(settings.keyBindLeft.isKeyDown()) - { + if (settings.keyBindLeft.isKeyDown()) { ++options.moveStrafe; } - if(settings.keyBindRight.isKeyDown()) - { + if (settings.keyBindRight.isKeyDown()) { --options.moveStrafe; } @@ -60,139 +56,120 @@ public void update(Minecraft mc, MovementInputFromOptions options, EntityPlayerS // // Sneak Toggle - Essentially the same as old ToggleSneak // - + // Check to see if Enabled - Added 6/17/14 to provide option to disable Sneak Toggle - if (ToggleSneakMod.optionToggleSneak) - { + if (ToggleSneakMod.optionToggleSneak) { // Key Pressed - if (settings.keyBindSneak.isKeyDown() && !this.handledSneakPress) - { + if (settings.keyBindSneak.isKeyDown() && !this.handledSneakPress) { // Descend if we are flying, note if we were riding (so we can unsneak once dismounted) - if(thisPlayer.isRiding() || thisPlayer.capabilities.isFlying) - { - options.sneak = true; - this.wasRiding = thisPlayer.isRiding(); - } - else - { - options.sneak = !options.sneak; - } - - this.lastPressed = System.currentTimeMillis(); - this.handledSneakPress = true; - } - + if (thisPlayer.isRiding() || thisPlayer.capabilities.isFlying) { + options.sneak = true; + this.wasRiding = thisPlayer.isRiding(); + } else { + options.sneak = !options.sneak; + } + + this.lastPressed = System.currentTimeMillis(); + this.handledSneakPress = true; + } + // Key Released - if (!settings.keyBindSneak.isKeyDown() && this.handledSneakPress) - { - // If we are flying or riding, stop sneaking after descent/dismount. - if(thisPlayer.capabilities.isFlying || this.wasRiding) - { - options.sneak = false; - this.wasRiding = false; - } - // If the key was held down for more than 300ms, stop sneaking upon release. - else if(System.currentTimeMillis() - this.lastPressed > 300L) - { - options.sneak = false; - } - - this.handledSneakPress = false; - } - } - else - { + if (!settings.keyBindSneak.isKeyDown() && this.handledSneakPress) { + // If we are flying or riding, stop sneaking after descent/dismount. + if (thisPlayer.capabilities.isFlying || this.wasRiding) { + options.sneak = false; + this.wasRiding = false; + } + // If the key was held down for more than 300ms, stop sneaking upon release. + else if (System.currentTimeMillis() - this.lastPressed > 300L) { + options.sneak = false; + } + + this.handledSneakPress = false; + } + } else { options.sneak = settings.keyBindSneak.isKeyDown(); } - if(options.sneak) - { - options.moveStrafe = (float)((double)options.moveStrafe * 0.3D); - options.moveForward = (float)((double)options.moveForward * 0.3D); + if (options.sneak) { + options.moveStrafe = (float) ((double) options.moveStrafe * 0.3D); + options.moveForward = (float) ((double) options.moveForward * 0.3D); } - + // // Sprint Toggle - Updated 6/18/2014 // - + // Establish conditions where we don't want to start a sprint - sneaking, riding, flying, hungry - boolean enoughHunger = (float)thisPlayer.getFoodStats().getFoodLevel() > 6.0F || thisPlayer.capabilities.isFlying; + boolean enoughHunger = (float) thisPlayer.getFoodStats().getFoodLevel() > 6.0F || thisPlayer.capabilities.isFlying; boolean canSprint = !options.sneak && !thisPlayer.isRiding() && !thisPlayer.capabilities.isFlying && enoughHunger; - + isDisabled = !ToggleSneakMod.optionToggleSprint; canDoubleTap = ToggleSneakMod.optionDoubleTap; - + // Key Pressed - if((canSprint || isDisabled) && settings.keyBindSprint.isKeyDown() && !this.handledSprintPress) - { - if(!isDisabled) - { + if ((canSprint || isDisabled) && settings.keyBindSprint.isKeyDown() && !this.handledSprintPress) { + if (!isDisabled) { this.sprint = !this.sprint; this.lastSprintPressed = System.currentTimeMillis(); this.handledSprintPress = true; this.sprintHeldAndReleased = false; } } - + // Key Released - if((canSprint || isDisabled) && !settings.keyBindSprint.isKeyDown() && this.handledSprintPress) - { + if ((canSprint || isDisabled) && !settings.keyBindSprint.isKeyDown() && this.handledSprintPress) { // Was key held for longer than 300ms? If so, mark it so we can resume vanilla behavior - if(System.currentTimeMillis() - this.lastSprintPressed > 300L) - { + if (System.currentTimeMillis() - this.lastSprintPressed > 300L) { this.sprintHeldAndReleased = true; } this.handledSprintPress = false; } - + UpdateStatus(options, thisPlayer, settings); } - - public void UpdateSprint(boolean newValue, boolean doubleTapped) - { + + public void UpdateSprint(boolean newValue, boolean doubleTapped) { this.sprint = newValue; this.sprintDoubleTapped = doubleTapped; } - + // // Detect any changes in movement state and update HUD - Added 4/14/2014 // - private void UpdateStatus(MovementInputFromOptions options, EntityPlayerSP thisPlayer, GameSettings settings) - { - if(ToggleSneakMod.optionShowHUDText) - { + private void UpdateStatus(MovementInputFromOptions options, EntityPlayerSP thisPlayer, GameSettings settings) { + if (ToggleSneakMod.optionShowHUDText) { String output = ""; - + boolean isFlying = thisPlayer.capabilities.isFlying; boolean isRiding = thisPlayer.isRiding(); boolean isHoldingSneak = settings.keyBindSneak.isKeyDown(); boolean isHoldingSprint = settings.keyBindSprint.isKeyDown(); - - if(isFlying) - { + + if (isFlying) { DecimalFormat numFormat = new DecimalFormat("#.00"); - if (ToggleSneakMod.optionEnableFlyBoost && isHoldingSprint) output += "[Flying (" + numFormat.format(ToggleSneakMod.optionFlyBoostAmount) + "x boost)] "; + + final PlayerControllerMP playerController = Minecraft.getMinecraft().playerController; + if (ToggleSneakMod.optionEnableFlyBoost && isHoldingSprint && (playerController.isInCreativeMode() + || playerController.getCurrentGameType().equals(WorldSettings.GameType.SPECTATOR))) + output += "[Flying (" + numFormat.format(ToggleSneakMod.optionFlyBoostAmount) + "x boost)] "; else output += "[Flying] "; } - if(isRiding) output += "[Riding] "; - - if (options.sneak) - { - if(isFlying) output += "[Descending] "; - else if(isRiding) output += "[Dismounting] "; - else if(isHoldingSneak) output += "[Sneaking (Key Held)] "; - else output += "[Sneaking (Toggled)] "; - } - else if (this.sprint) - { - if(!isFlying && !isRiding) - { + if (isRiding) output += "[Riding] "; + + if (options.sneak) { + if (isFlying) output += "[Descending] "; + else if (isRiding) output += "[Dismounting] "; + else if (isHoldingSneak) output += "[Sneaking (Key Held)] "; + else output += "[Sneaking (Toggled)] "; + } else if (this.sprint) { + if (!isFlying && !isRiding) { // Detect Vanilla conditions - ToggleSprint disabled, DoubleTapped and Hold & Release boolean isVanilla = this.sprintHeldAndReleased || isDisabled || this.sprintDoubleTapped; - - if(isHoldingSprint) output += "[Sprinting (Key Held)]"; - else if(isVanilla) output += "[Sprinting (Vanilla)]"; - else output += "[Sprinting (Toggled)]"; + + if (isHoldingSprint) output += "[Sprinting (Key Held)]"; + else if (isVanilla) output += "[Sprinting (Vanilla)]"; + else output += "[Sprinting (Toggled)]"; } } RenderTextToHUD.SetHUDText(output); diff --git a/src/main/java/deez/togglesneak/FlySpeedRegulator.java b/src/main/java/deez/togglesneak/FlySpeedRegulator.java new file mode 100644 index 0000000..6251be4 --- /dev/null +++ b/src/main/java/deez/togglesneak/FlySpeedRegulator.java @@ -0,0 +1,90 @@ +package deez.togglesneak; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.world.WorldSettings.GameType; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.relauncher.Side; + +/** + * Created by Douwe Koopmans on 27-4-16. + */ +public class FlySpeedRegulator { + private final Minecraft mc = Minecraft.getMinecraft(); + /** + * the default fly speed for any client + */ + private final float vanillaSpeed = 0.05F; + + private float lastClientFlySpeed = vanillaSpeed; + private float lastServerFlySpeed = vanillaSpeed; + private boolean speedModified = false; + private GameType oldGt = GameType.NOT_SET; + + /** + *

+ * checks if we are allowed to change our fly speed right now, if we are not allowed the provided speed will be saved + * and applied when we are allowed to change our fly speed. + *

+ * + *

+ * if we are allowed to change our fly speed, the provided speed will be set as the new fly speed. + * if the old speed was set by the server this value will be saved for when we go into a state where we are + * not allowed to have a modified speed + *

+ * @param speed the preferred fly speed + */ + public void updateFlySpeed(float speed){ + final EntityPlayerSP player = mc.thePlayer; + if (player.capabilities.getFlySpeed() != lastClientFlySpeed) { + lastServerFlySpeed = player.capabilities.getFlySpeed(); + } + + if (canSetFlySpeed()) { + lastClientFlySpeed = speed; + player.capabilities.setFlySpeed(speed); + speedModified = true; + } else { + lastClientFlySpeed = speed; + speedModified = false; + } + } + + // forge doesn't have an event for when your gamemode updates, so we'll have to check every tick if our gm has changed + @SubscribeEvent + public void ticker(TickEvent event) { + if (event.phase.equals(TickEvent.Phase.END) && event.side.equals(Side.CLIENT)) { + mc.mcProfiler.endStartSection(References.MOD_ID); + GameType currentGameType = mc.playerController.getCurrentGameType(); + if (!currentGameType.equals(this.oldGt)) { + onGameModeChange(this.oldGt, currentGameType); + oldGt = currentGameType; + } + mc.mcProfiler.endStartSection(References.MOD_ID); + } + } + + private void onGameModeChange(GameType oldGt, GameType newGt) { + final EntityPlayerSP player = mc.thePlayer; + + // has the fly speed been modified and is the new gamemode not creative or spectator + if (player.capabilities.getFlySpeed() == lastClientFlySpeed && speedModified && !canSetFlySpeed()) { + player.capabilities.setFlySpeed(lastServerFlySpeed); + speedModified = false; + // was the old gamemode not creative or spectator and can we modify our fly speed right now + } else if (!(oldGt.equals(GameType.CREATIVE) || oldGt.equals(GameType.SPECTATOR)) && canSetFlySpeed()) { + //modify the fly speed, this will first do some check to make sure we are allow to and will save the servers fly speed + updateFlySpeed(lastClientFlySpeed); + } + } + + /** + * are we currently allowed to have a modified fly speed + * @return if we are allowed to modify our fly speed + */ + public boolean canSetFlySpeed() { + GameType currentGameType = mc.playerController.getCurrentGameType(); + return currentGameType.equals(GameType.CREATIVE) || currentGameType.equals(GameType.SPECTATOR); + } +} diff --git a/src/main/java/deez/togglesneak/PlayerBase.java b/src/main/java/deez/togglesneak/PlayerBase.java index a7bac2e..599444e 100644 --- a/src/main/java/deez/togglesneak/PlayerBase.java +++ b/src/main/java/deez/togglesneak/PlayerBase.java @@ -1,50 +1,43 @@ package deez.togglesneak; +import api.player.client.ClientPlayerAPI; +import api.player.client.ClientPlayerBase; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.entity.EntityPlayerSP; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.GameSettings; - import net.minecraft.network.play.client.C0BPacketEntityAction; import net.minecraft.potion.Potion; import net.minecraft.util.MovementInputFromOptions; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.common.MinecraftForge; -import api.player.client.ClientPlayerAPI; -import api.player.client.ClientPlayerBase; +public class PlayerBase extends ClientPlayerBase { + private final Minecraft mc = Minecraft.getMinecraft(); + private final CustomMovementInput customMovementInput = new CustomMovementInput(); + private final GameSettings settings = mc.gameSettings; + private final FlySpeedRegulator flySpeedRegulator = new FlySpeedRegulator(); -public class PlayerBase extends ClientPlayerBase -{ - private Minecraft mc = Minecraft.getMinecraft(); - private CustomMovementInput customMovementInput = new CustomMovementInput(); - private GameSettings settings = mc.gameSettings; - // private boolean showDebug = true; // private boolean handledDebugPress = false; - - public PlayerBase(ClientPlayerAPI api) - { + + public PlayerBase(ClientPlayerAPI api) { super(api); + MinecraftForge.EVENT_BUS.register(flySpeedRegulator); } - + /* * EntityPlayerSP.onLivingUpdate() - Adapted to PlayerAPI */ @Override - public void onLivingUpdate() - { - if(this.player.sprintingTicksLeft > 0) - { + public void onLivingUpdate() { + if (this.player.sprintingTicksLeft > 0) { --this.player.sprintingTicksLeft; - if(this.player.sprintingTicksLeft == 0) - { + if (this.player.sprintingTicksLeft == 0) { this.player.setSprinting(false); } } - if(this.playerAPI.getSprintToggleTimerField() > 0) - { + if (this.playerAPI.getSprintToggleTimerField() > 0) { this.playerAPI.setSprintToggleTimerField(this.playerAPI.getSprintToggleTimerField() - 1); } @@ -61,170 +54,140 @@ public void onLivingUpdate() else { */ - this.player.prevTimeInPortal = this.player.timeInPortal; - if(this.playerAPI.getInPortalField()) - { - if(this.mc.currentScreen != null) - { - this.mc.displayGuiScreen((GuiScreen)null); - } + this.player.prevTimeInPortal = this.player.timeInPortal; + if (this.playerAPI.getInPortalField()) { + if (this.mc.currentScreen != null) { + this.mc.displayGuiScreen(null); + } - if(this.player.timeInPortal == 0.0F) - { - this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.player.getRNG().nextFloat() * 0.4F + 0.8F)); - } + if (this.player.timeInPortal == 0.0F) { + this.mc.getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("portal.trigger"), this.player.getRNG().nextFloat() * 0.4F + 0.8F)); + } - this.player.timeInPortal += 0.0125F; + this.player.timeInPortal += 0.0125F; - if(this.player.timeInPortal >= 1.0F) - { - this.player.timeInPortal = 1.0F; - } + if (this.player.timeInPortal >= 1.0F) { + this.player.timeInPortal = 1.0F; + } - this.playerAPI.setInPortalField(false); + this.playerAPI.setInPortalField(false); + } else if (this.player.isPotionActive(Potion.confusion) && this.player.getActivePotionEffect(Potion.confusion).getDuration() > 60) { + this.player.timeInPortal += 0.006666667F; + if (this.player.timeInPortal > 1.0F) { + this.player.timeInPortal = 1.0F; } - else if(this.player.isPotionActive(Potion.confusion) && this.player.getActivePotionEffect(Potion.confusion).getDuration() > 60) - { - this.player.timeInPortal += 0.006666667F; - if(this.player.timeInPortal > 1.0F) - { - this.player.timeInPortal = 1.0F; - } + } else { + if (this.player.timeInPortal > 0.0F) { + this.player.timeInPortal -= 0.05F; } - else - { - if(this.player.timeInPortal > 0.0F) - { - this.player.timeInPortal -= 0.05F; - } - if(this.player.timeInPortal < 0.0F) - { - this.player.timeInPortal = 0.0F; - } + if (this.player.timeInPortal < 0.0F) { + this.player.timeInPortal = 0.0F; } + } - if(this.player.timeUntilPortal > 0) - { - --this.player.timeUntilPortal; - } + if (this.player.timeUntilPortal > 0) { + --this.player.timeUntilPortal; + } - boolean isJumping = this.player.movementInput.jump; - - float minSpeed = 0.8F; - boolean isMovingForward = this.player.movementInput.moveForward >= minSpeed; - this.customMovementInput.update(this.mc, (MovementInputFromOptions)this.player.movementInput, this.player); + boolean isJumping = this.player.movementInput.jump; + + float minSpeed = 0.8F; + boolean isMovingForward = this.player.movementInput.moveForward >= minSpeed; + this.customMovementInput.update(this.mc, (MovementInputFromOptions) this.player.movementInput, this.player); + + if (this.player.isUsingItem() && !this.player.isRiding()) { + this.player.movementInput.moveStrafe *= 0.2F; + this.player.movementInput.moveForward *= 0.2F; + this.playerAPI.setSprintToggleTimerField(0); + } - if(this.player.isUsingItem() && !this.player.isRiding()) - { - this.player.movementInput.moveStrafe *= 0.2F; - this.player.movementInput.moveForward *= 0.2F; - this.playerAPI.setSprintToggleTimerField(0); - } - /* TODO: removed in vanilla 1.8 - investigate if(this.player.movementInput.sneak && this.player.ySize < 0.2F) { this.player.ySize = 0.2F; } - + */ - this.playerAPI.localPushOutOfBlocks(this.player.posX - (double)this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ + (double)this.player.width * 0.35D); - this.playerAPI.localPushOutOfBlocks(this.player.posX - (double)this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ - (double)this.player.width * 0.35D); - this.playerAPI.localPushOutOfBlocks(this.player.posX + (double)this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ - (double)this.player.width * 0.35D); - this.playerAPI.localPushOutOfBlocks(this.player.posX + (double)this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ + (double)this.player.width * 0.35D); - boolean enoughHunger = (float)this.player.getFoodStats().getFoodLevel() > 6.0F || this.player.capabilities.isFlying; - + this.playerAPI.localPushOutOfBlocks(this.player.posX - (double) this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ + (double) this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX - (double) this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ - (double) this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX + (double) this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ - (double) this.player.width * 0.35D); + this.playerAPI.localPushOutOfBlocks(this.player.posX + (double) this.player.width * 0.35D, this.player.getEntityBoundingBox().minY + 0.5D, this.player.posZ + (double) this.player.width * 0.35D); + boolean enoughHunger = (float) this.player.getFoodStats().getFoodLevel() > 6.0F || this.player.capabilities.isFlying; + /* * Begin ToggleSneak Changes - ToggleSprint */ - - boolean isSprintDisabled = !ToggleSneakMod.optionToggleSprint; - boolean canDoubleTap = ToggleSneakMod.optionDoubleTap; - - // Detect when ToggleSprint was disabled in the in-game options menu - if(ToggleSneakMod.wasSprintDisabled) - { - this.player.setSprinting(false); - customMovementInput.UpdateSprint(false, false); - ToggleSneakMod.wasSprintDisabled = false; + + boolean isSprintDisabled = !ToggleSneakMod.optionToggleSprint; + boolean canDoubleTap = ToggleSneakMod.optionDoubleTap; + + // Detect when ToggleSprint was disabled in the in-game options menu + if (ToggleSneakMod.wasSprintDisabled) { + this.player.setSprinting(false); + customMovementInput.UpdateSprint(false, false); + ToggleSneakMod.wasSprintDisabled = false; + } + + // Default Sprint routine converted to PlayerAPI, use if ToggleSprint is disabled + if (isSprintDisabled) { + if (ToggleSneakMod.optionDoubleTap && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) { + if (this.playerAPI.getSprintToggleTimerField() <= 0 && !this.settings.keyBindSprint.isKeyDown()) { + this.playerAPI.setSprintToggleTimerField(7); + } else { + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, false); + } } - - // Default Sprint routine converted to PlayerAPI, use if ToggleSprint is disabled - if(isSprintDisabled) - { - if(ToggleSneakMod.optionDoubleTap && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) - { - if(this.playerAPI.getSprintToggleTimerField() <= 0 && !this.settings.keyBindSprint.isKeyDown()) - { - this.playerAPI.setSprintToggleTimerField(7); - } - else - { - this.player.setSprinting(true); - customMovementInput.UpdateSprint(true, false); - } - } - - if(!this.player.isSprinting() && this.player.movementInput.moveForward >= minSpeed && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && this.settings.keyBindSprint.isKeyDown()) - { - this.player.setSprinting(true); - customMovementInput.UpdateSprint(true, false); - } + + if (!this.player.isSprinting() && this.player.movementInput.moveForward >= minSpeed && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && this.settings.keyBindSprint.isKeyDown()) { + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, false); } - else - { - boolean state = this.customMovementInput.sprint; - - // Only handle changes in state under the following conditions: - // On ground, not hungry, not eating/using item, not blind, and not Vanilla - // - // 5/6/14 - onGround check removed to match vanilla's 'start sprint while jumping' behavior. - //if(this.player.onGround && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) - - if(enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) - { - if(canDoubleTap && !this.player.isSprinting() || !canDoubleTap) - { - this.player.setSprinting(state); - } + } else { + boolean state = this.customMovementInput.sprint; + + // Only handle changes in state under the following conditions: + // On ground, not hungry, not eating/using item, not blind, and not Vanilla + // + // 5/6/14 - onGround check removed to match vanilla's 'start sprint while jumping' behavior. + //if(this.player.onGround && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) + + if (enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness) && !this.customMovementInput.sprintHeldAndReleased) { + if (!canDoubleTap || !this.player.isSprinting()) { + this.player.setSprinting(state); } - - if(canDoubleTap && !state && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) - { - if(this.playerAPI.getSprintToggleTimerField() == 0) - { - this.playerAPI.setSprintToggleTimerField(7); - } - else - { - this.player.setSprinting(true); - customMovementInput.UpdateSprint(true, true); - this.playerAPI.setSprintToggleTimerField(0); - } - } } - - // If sprinting, break the sprint in appropriate circumstances: - // Player stops moving forward, runs into something, or gets too hungry - if(this.player.isSprinting() && (this.player.movementInput.moveForward < minSpeed || this.player.isCollidedHorizontally || !enoughHunger)) - { - this.player.setSprinting(false); - - // Undo toggle if we resumed vanilla operation due to Hold&Release, DoubleTap, Fly, Ride - if (customMovementInput.sprintHeldAndReleased == true || isSprintDisabled || customMovementInput.sprintDoubleTapped || this.player.capabilities.isFlying || this.player.isRiding()) - { - customMovementInput.UpdateSprint(false, false); + + if (canDoubleTap && !state && this.player.onGround && !isMovingForward && this.player.movementInput.moveForward >= minSpeed && !this.player.isSprinting() && enoughHunger && !this.player.isUsingItem() && !this.player.isPotionActive(Potion.blindness)) { + if (this.playerAPI.getSprintToggleTimerField() == 0) { + this.playerAPI.setSprintToggleTimerField(7); + } else { + this.player.setSprinting(true); + customMovementInput.UpdateSprint(true, true); + this.playerAPI.setSprintToggleTimerField(0); } } - + } + + // If sprinting, break the sprint in appropriate circumstances: + // Player stops moving forward, runs into something, or gets too hungry + if (this.player.isSprinting() && (this.player.movementInput.moveForward < minSpeed || this.player.isCollidedHorizontally || !enoughHunger)) { + this.player.setSprinting(false); + + // Undo toggle if we resumed vanilla operation due to Hold&Release, DoubleTap, Fly, Ride + if (customMovementInput.sprintHeldAndReleased || isSprintDisabled || customMovementInput.sprintDoubleTapped || this.player.capabilities.isFlying || this.player.isRiding()) { + customMovementInput.UpdateSprint(false, false); + } + } + /* - * End ToggleSneak Changes - ToggleSprint + * End ToggleSneak Changes - ToggleSprint */ - + // // // // Debug Framework - Added 5/7/2014 // // @@ -244,103 +207,93 @@ else if(this.player.isPotionActive(Potion.confusion) && this.player.getActivePot // this.player.addChatMessage(new ChatComponentText("keybindJump - " + (this.settings.keyBindJump.isKeyDown() == true ? "True" : "False"))); // this.player.addChatMessage(new ChatComponentText(" ")); // this.player.addChatMessage(new ChatComponentText(" ")); -// +// // this.handledDebugPress = true; // } // else if (this.showDebug && !this.settings.keyBindPickBlock.isKeyDown() && this.handledDebugPress) // { // this.handledDebugPress = false; // } - - // - // Fly Speed Boosting - Added 5/7/2014 - // - if(ToggleSneakMod.optionEnableFlyBoost && this.player.capabilities.isFlying && this.settings.keyBindSprint.isKeyDown() && this.player.capabilities.isCreativeMode) - { - this.player.capabilities.setFlySpeed(0.05F * (float)ToggleSneakMod.optionFlyBoostAmount); - - if(this.player.movementInput.sneak) this.player.motionY -= 0.15D * (double)ToggleSneakMod.optionFlyBoostAmount; - if(this.player.movementInput.jump) this.player.motionY += 0.15D * (double)ToggleSneakMod.optionFlyBoostAmount; - - } - else if(this.player.capabilities.getFlySpeed() != 0.05F) - { - this.player.capabilities.setFlySpeed(0.05F); - } - - - if(this.player.capabilities.allowFlying && !isJumping && this.player.movementInput.jump) - { - if(this.playerAPI.getFlyToggleTimerField() == 0) - { - this.playerAPI.setFlyToggleTimerField(7); - } - else - { - this.player.capabilities.isFlying = !this.player.capabilities.isFlying; - this.player.sendPlayerAbilities(); - this.playerAPI.setFlyToggleTimerField(0); - } - } - if(this.player.capabilities.isFlying) - { - if(this.player.movementInput.sneak) - { - this.player.motionY -= 0.15D; - } - if(this.player.movementInput.jump) - { - this.player.motionY += 0.15D; - } + // + // Fly Speed Boosting - Added 5/7/2014 + // +// if (ToggleSneakMod.optionEnableFlyBoost && this.player.capabilities.isFlying && this.settings.keyBindSprint.isKeyDown() && this.player.capabilities.isCreativeMode) { +// this.player.capabilities.setFlySpeed(0.05F * (float) ToggleSneakMod.optionFlyBoostAmount); +// +// if (this.player.movementInput.sneak) this.player.motionY -= 0.15D * ToggleSneakMod.optionFlyBoostAmount; +// if (this.player.movementInput.jump) this.player.motionY += 0.15D * ToggleSneakMod.optionFlyBoostAmount; +// +// } else if (this.player.capabilities.getFlySpeed() != 0.05F) { +// this.player.capabilities.setFlySpeed(0.05F); +// } + if (ToggleSneakMod.optionEnableFlyBoost && this.player.capabilities.isFlying && this.settings.keyBindSprint.isKeyDown()) { + flySpeedRegulator.updateFlySpeed(0.05F * (float) ToggleSneakMod.optionFlyBoostAmount); + if (this.player.movementInput.sneak && flySpeedRegulator.canSetFlySpeed()) + this.player.motionY -= 0.15D * ToggleSneakMod.optionFlyBoostAmount; + if (this.player.movementInput.jump && flySpeedRegulator.canSetFlySpeed()) + this.player.motionY += 0.15D * ToggleSneakMod.optionFlyBoostAmount; + + } else if (player.capabilities.getFlySpeed() != 0.05F) { + flySpeedRegulator.updateFlySpeed(0.05F); + } + + + if (this.player.capabilities.allowFlying && !isJumping && this.player.movementInput.jump) { + if (this.playerAPI.getFlyToggleTimerField() == 0) { + this.playerAPI.setFlyToggleTimerField(7); + } else { + this.player.capabilities.isFlying = !this.player.capabilities.isFlying; + this.player.sendPlayerAbilities(); + this.playerAPI.setFlyToggleTimerField(0); } + } - if(this.player.isRidingHorse()) - { - if(this.playerAPI.getHorseJumpPowerCounterField() < 0) - { - this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); - if(this.playerAPI.getHorseJumpPowerCounterField() == 0) - { - this.playerAPI.setHorseJumpPowerField(0.0F); - } - } + if (this.player.capabilities.isFlying && mc.getRenderViewEntity() == this.player) + { + if (this.player.movementInput.sneak) + { + this.player.motionY -= (double)(this.player.capabilities.getFlySpeed() * 3.0F); + } - if(isJumping && !this.player.movementInput.jump) - { - this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() - 10); - this.playerAPI.setHorseJumpPowerCounterField(-10); - ((EntityPlayerSP)this.player).sendQueue.addToSendQueue(new C0BPacketEntityAction(this.player, C0BPacketEntityAction.Action.RIDING_JUMP, (int)(this.player.getHorseJumpPower() * 100.0F))); - } - else if(!isJumping && this.player.movementInput.jump) - { - this.playerAPI.setHorseJumpPowerCounterField(0); + if (this.player.movementInput.jump) + { + this.player.motionY += (double)(this.player.capabilities.getFlySpeed() * 3.0F); + } + } + + if (this.player.isRidingHorse()) { + if (this.playerAPI.getHorseJumpPowerCounterField() < 0) { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); + if (this.playerAPI.getHorseJumpPowerCounterField() == 0) { this.playerAPI.setHorseJumpPowerField(0.0F); } - else if(isJumping) - { - this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); - if(this.playerAPI.getHorseJumpPowerCounterField() < 10) - { - this.playerAPI.setHorseJumpPowerField((float)this.playerAPI.getHorseJumpPowerCounterField() * 0.1F); - } - else - { - this.playerAPI.setHorseJumpPowerField(0.8F + 2.0F / (float)(this.playerAPI.getHorseJumpPowerCounterField() - 9) * 0.1F); - } - } } - else - { + + if (isJumping && !this.player.movementInput.jump) { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() - 10); + this.playerAPI.setHorseJumpPowerCounterField(-10); + this.player.sendQueue.addToSendQueue(new C0BPacketEntityAction(this.player, C0BPacketEntityAction.Action.RIDING_JUMP, (int) (this.player.getHorseJumpPower() * 100.0F))); + } else if (!isJumping && this.player.movementInput.jump) { + this.playerAPI.setHorseJumpPowerCounterField(0); this.playerAPI.setHorseJumpPowerField(0.0F); + } else if (isJumping) { + this.playerAPI.setHorseJumpPowerCounterField(this.playerAPI.getHorseJumpPowerCounterField() + 1); + if (this.playerAPI.getHorseJumpPowerCounterField() < 10) { + this.playerAPI.setHorseJumpPowerField((float) this.playerAPI.getHorseJumpPowerCounterField() * 0.1F); + } else { + this.playerAPI.setHorseJumpPowerField(0.8F + 2.0F / (float) (this.playerAPI.getHorseJumpPowerCounterField() - 9) * 0.1F); + } } + } else { + this.playerAPI.setHorseJumpPowerField(0.0F); + } - this.playerAPI.superOnLivingUpdate(); - if(this.player.onGround && this.player.capabilities.isFlying) - { - this.player.capabilities.isFlying = false; - this.player.sendPlayerAbilities(); - } + this.playerAPI.superOnLivingUpdate(); + if (this.player.onGround && this.player.capabilities.isFlying) { + this.player.capabilities.isFlying = false; + this.player.sendPlayerAbilities(); + } //} } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/References.java b/src/main/java/deez/togglesneak/References.java new file mode 100644 index 0000000..f9ef750 --- /dev/null +++ b/src/main/java/deez/togglesneak/References.java @@ -0,0 +1,12 @@ +package deez.togglesneak; + +/** + * Created by Douwe Koopmans on 27-4-16. + */ +public class References { + // mod metadata + public static final String MOD_ID = "ToggleSneak"; + public static final String MOD_NAME = "ToggleSneak"; + public static final String MOD_VERSION = "3.2.0"; + public static final String GUI_FACTORY = "deez.togglesneak.gui.TSGuiFactoryHandler"; +} diff --git a/src/main/java/deez/togglesneak/RenderTextToHUD.java b/src/main/java/deez/togglesneak/RenderTextToHUD.java index 12de19f..3ff6b20 100644 --- a/src/main/java/deez/togglesneak/RenderTextToHUD.java +++ b/src/main/java/deez/togglesneak/RenderTextToHUD.java @@ -4,27 +4,22 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; -public class RenderTextToHUD -{ +public class RenderTextToHUD { public static RenderTextToHUD instance = new RenderTextToHUD(); private static Minecraft mc = Minecraft.getMinecraft(); private static String textForHUD = ""; @SubscribeEvent - public void RenderGameOverlayEvent(RenderGameOverlayEvent event) - { - if(event.type == RenderGameOverlayEvent.ElementType.TEXT) - { - if(ToggleSneakMod.optionShowHUDText) - { + public void RenderGameOverlayEvent(RenderGameOverlayEvent event) { + if(event.type == RenderGameOverlayEvent.ElementType.TEXT) { + if(ToggleSneakMod.optionShowHUDText) { mc.fontRendererObj.drawStringWithShadow(textForHUD, ToggleSneakMod.optionHUDTextPosX, ToggleSneakMod.optionHUDTextPosY, 0xffffff); } } } - public static void SetHUDText(String text) - { + public static void SetHUDText(String text) { textForHUD = text; } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/ToggleSneakEvents.java b/src/main/java/deez/togglesneak/ToggleSneakEvents.java index 2c4f2be..aeb97fa 100644 --- a/src/main/java/deez/togglesneak/ToggleSneakEvents.java +++ b/src/main/java/deez/togglesneak/ToggleSneakEvents.java @@ -1,25 +1,31 @@ package deez.togglesneak; +import deez.togglesneak.gui.GuiOptionsReplace; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiIngameMenu; import net.minecraft.client.gui.GuiOptions; import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.network.FMLNetworkEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; -import deez.togglesneak.gui.GuiOptionsReplace; - -public class ToggleSneakEvents -{ - public static ToggleSneakEvents instance = new ToggleSneakEvents(); +public class ToggleSneakEvents { + private static final Logger log = LogManager.getLogger(References.MOD_ID); + public static ToggleSneakEvents instance = new ToggleSneakEvents(); - protected static final Minecraft mc = Minecraft.getMinecraft(); + private static final Minecraft mc = Minecraft.getMinecraft(); @SubscribeEvent - public void GuiOpenEvent(GuiOpenEvent event) - { - if(event.gui instanceof GuiOptions && mc.theWorld != null) - { + public void GuiOpenEvent(GuiOpenEvent event) { + if(event.gui instanceof GuiOptions && mc.theWorld != null) { event.gui = new GuiOptionsReplace(new GuiIngameMenu(), mc.gameSettings); } } + + @Mod.EventHandler + public void connectToServer(FMLNetworkEvent.ClientConnectedToServerEvent event) { + log.info("connected to server, fly speed: " + mc.thePlayer.capabilities.getFlySpeed()); + } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/ToggleSneakMod.java b/src/main/java/deez/togglesneak/ToggleSneakMod.java index a3075ad..5dced4d 100644 --- a/src/main/java/deez/togglesneak/ToggleSneakMod.java +++ b/src/main/java/deez/togglesneak/ToggleSneakMod.java @@ -1,135 +1,113 @@ package deez.togglesneak; -import java.io.File; - +import api.player.client.ClientPlayerAPI; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import deez.togglesneak.proxy.CommonProxy; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -@Mod -( - modid = ToggleSneakMod.ModID, - name = ToggleSneakMod.ModName, - version = ToggleSneakMod.ModVersion, - guiFactory = "deez.togglesneak.gui.TSGuiFactoryHandler" -) - -public class ToggleSneakMod -{ - public static final String ModID = "ToggleSneak"; - public static final String ModName = "ToggleSneak"; - public static final String ModVersion = "3.1.1"; - - public static Configuration config = null; - public static File configFile = null; - - public static boolean optionToggleSprint = true; - public static boolean optionToggleSneak = true; - public static boolean optionShowHUDText = true; - public static int optionHUDTextPosX = 1; - public static int optionHUDTextPosY = 1; - public static boolean optionDoubleTap = false; - public static boolean optionEnableFlyBoost = false; - public static double optionFlyBoostAmount = 4.0; - public static int optionButtonPosition = 1; - - public static boolean wasSprintDisabled = false; - - @Instance("ToggleSneak") - public static ToggleSneakMod instance; - - @SidedProxy - ( - clientSide = "deez.togglesneak.proxy.ClientProxy", - serverSide = "deez.togglesneak.proxy.CommonProxy" - ) - public static CommonProxy proxy; - +import java.io.File; + +@Mod(modid = References.MOD_ID, name = References.MOD_NAME, version = References.MOD_VERSION, + guiFactory = References.GUI_FACTORY, clientSideOnly = true, acceptedMinecraftVersions = "[1.8,1.8.9]") +public class ToggleSneakMod { + + public static Configuration config = null; + public static File configFile = null; + + public static boolean optionToggleSprint = true; + public static boolean optionToggleSneak = true; + public static boolean optionShowHUDText = true; + public static int optionHUDTextPosX = 1; + public static int optionHUDTextPosY = 1; + public static boolean optionDoubleTap = false; + public static boolean optionEnableFlyBoost = false; + public static double optionFlyBoostAmount = 4.0; + public static int optionButtonPosition = 1; + + public static boolean wasSprintDisabled = false; + + // TODO: 28-4-16 delete me + @EventHandler - public void onPreInit(FMLPreInitializationEvent event) - { + public void onPreInit(FMLPreInitializationEvent event) { updateConfig(event.getSuggestedConfigurationFile(), true); - proxy.registerEvents(event); + + MinecraftForge.EVENT_BUS.register(RenderTextToHUD.instance); + MinecraftForge.EVENT_BUS.register(ToggleSneakEvents.instance); } - + @EventHandler - public void init(FMLInitializationEvent event) - { - proxy.initMod(); + public void init(FMLInitializationEvent event) { + RenderTextToHUD.SetHUDText(References.MOD_ID + " for Forge - version " + References.MOD_VERSION + " Beta!"); + ClientPlayerAPI.register(References.MOD_ID, PlayerBase.class); } - - public static void reloadConfig() - { + + public static void reloadConfig() { updateConfig(configFile, true); } - - public static void saveConfig() - { + + public static void saveConfig() { updateConfig(configFile, false); } - - public static void updateConfig(File cfgFile, boolean isLoading) - { + + public static void updateConfig(File cfgFile, boolean isLoading) { Property property; - - if(isLoading) - { + + if (isLoading) { config = new Configuration(cfgFile); config.load(); configFile = cfgFile; } - + property = config.get("ToggleSneak", "optionToggleSprint", optionToggleSprint); property.comment = "If true, use Sprint Toggling - If false, use vanilla sprinting"; - if(isLoading) optionToggleSprint = property.getBoolean(true); - else property.set(optionToggleSprint); - + if (isLoading) optionToggleSprint = property.getBoolean(true); + else property.set(optionToggleSprint); + property = config.get("ToggleSneak", "optionToggleSneak", optionToggleSneak); property.comment = "If true, use Sneak Toggling - If false, use vanilla sneaking"; - if(isLoading) optionToggleSneak = property.getBoolean(true); - else property.set(optionToggleSneak); - + if (isLoading) optionToggleSneak = property.getBoolean(true); + else property.set(optionToggleSneak); + property = config.get("ToggleSneak", "optionShowHUDText", optionShowHUDText); property.comment = "Show movement status (Sneaking, Sprinting, etc) on the HUD."; - if(isLoading) optionShowHUDText = property.getBoolean(true); - else property.set(optionShowHUDText); + if (isLoading) optionShowHUDText = property.getBoolean(true); + else property.set(optionShowHUDText); property = config.get("ToggleSneak", "optionHUDTextPosX", optionHUDTextPosX); property.comment = "Sets the horizontal position of the HUD Info. [Far Left = 1, Far Right = 400]"; - if(isLoading) optionHUDTextPosX = property.getInt(); - else property.set(optionHUDTextPosX); - + if (isLoading) optionHUDTextPosX = property.getInt(); + else property.set(optionHUDTextPosX); + property = config.get("ToggleSneak", "optionHUDTextPosY", optionHUDTextPosY); property.comment = "Sets the vertical position of the HUD Info. [Top Line = 1, Bottom Line = 200]"; - if(isLoading) optionHUDTextPosY = property.getInt(); - else property.set(optionHUDTextPosY); - + if (isLoading) optionHUDTextPosY = property.getInt(); + else property.set(optionHUDTextPosY); + property = config.get("ToggleSneak", "optionDoubleTap", optionDoubleTap); property.comment = "Allow double-tapping the forward key (W) to begin sprinting"; - if(isLoading) optionDoubleTap = property.getBoolean(false); - else property.set(optionDoubleTap); - + if (isLoading) optionDoubleTap = property.getBoolean(false); + else property.set(optionDoubleTap); + property = config.get("ToggleSneak", "optionEnableFlyBoost", optionEnableFlyBoost); property.comment = "Enable speed boost when flying in creative mode"; - if(isLoading) optionEnableFlyBoost = property.getBoolean(false); - else property.set(optionEnableFlyBoost); - + if (isLoading) optionEnableFlyBoost = property.getBoolean(false); + else property.set(optionEnableFlyBoost); + property = config.get("ToggleSneak", "optionFlyBoostAmount", optionFlyBoostAmount); property.comment = "The multiplier to use when boosting fly speed"; - if(isLoading) optionFlyBoostAmount = property.getDouble(4.0); - else property.set(optionFlyBoostAmount); - + if (isLoading) optionFlyBoostAmount = property.getDouble(4.0); + else property.set(optionFlyBoostAmount); + property = config.get("ToggleSneak", "optionButtonPosition", optionButtonPosition); property.comment = "The position of the options button on the options screen [Left Column = 1, Right Column = 2]"; - if(isLoading) optionButtonPosition = property.getInt(); - else property.set(optionButtonPosition); - + if (isLoading) optionButtonPosition = property.getInt(); + else property.set(optionButtonPosition); + config.save(); } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/gui/GuiOptionsReplace.java b/src/main/java/deez/togglesneak/gui/GuiOptionsReplace.java index ffee9cd..b8eda2f 100644 --- a/src/main/java/deez/togglesneak/gui/GuiOptionsReplace.java +++ b/src/main/java/deez/togglesneak/gui/GuiOptionsReplace.java @@ -1,26 +1,22 @@ package deez.togglesneak.gui; -import java.io.IOException; - import deez.togglesneak.ToggleSneakMod; - import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiOptions; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.GameSettings; -public class GuiOptionsReplace extends GuiOptions -{ +import java.io.IOException; + +public class GuiOptionsReplace extends GuiOptions { private GuiButton btnToggleSneakOptions; - public GuiOptionsReplace(GuiScreen parentScreen, GameSettings settings) - { + public GuiOptionsReplace(GuiScreen parentScreen, GameSettings settings) { super(parentScreen, settings); } @Override - public void initGui() - { + public void initGui() { super.initGui(); int yPos; @@ -31,23 +27,17 @@ public void initGui() btnToggleSneakOptions = new GuiButton(9999, this.width /2 + yPos, this.height / 6 + 24 - 6, 150, 20, "ToggleSneak Options"); this.buttonList.add(btnToggleSneakOptions); } - + @Override - protected void actionPerformed(GuiButton buttonPressed) - { - try - { + protected void actionPerformed(GuiButton buttonPressed) { + try { super.actionPerformed(buttonPressed); - - if(buttonPressed.id == 9999) - { + + if (buttonPressed.id == 9999) { this.mc.gameSettings.saveOptions(); this.mc.displayGuiScreen(new GuiTSConfig(this)); } - } - catch (IOException ex) - { - ; + } catch (IOException ignored) { } } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/gui/GuiSlideControl.java b/src/main/java/deez/togglesneak/gui/GuiSlideControl.java index cf8132b..520e692 100644 --- a/src/main/java/deez/togglesneak/gui/GuiSlideControl.java +++ b/src/main/java/deez/togglesneak/gui/GuiSlideControl.java @@ -1,123 +1,102 @@ package deez.togglesneak.gui; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import org.lwjgl.opengl.GL11; + import java.text.DecimalFormat; -import org.lwjgl.opengl.GL11; +public class GuiSlideControl extends GuiButton { + public String label; // Text displayed next to value + public float curValue; // Current Slider position, from 0 to 1 + public float minValue; // Smallest value represented by the Slider + public float maxValue; // Largest value represented by the Slider + public boolean isSliding; // Is Control currently being manipulated? + public boolean useIntegers; // Use Integers to display values -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; + private static DecimalFormat numFormat = new DecimalFormat("#.00"); + + public GuiSlideControl(int id, int x, int y, int width, int height, String displayString, float minVal, float maxVal, float curVal, boolean useInts) { + super(id, x, y, width, height, (useInts ? displayString + ((int) curVal) : displayString + numFormat.format(curVal))); -public class GuiSlideControl extends GuiButton -{ - public String label; // Text displayed next to value - public float curValue; // Current Slider position, from 0 to 1 - public float minValue; // Smallest value represented by the Slider - public float maxValue; // Largest value represented by the Slider - public boolean isSliding; // Is Control currently being manipulated? - public boolean useIntegers; // Use Integers to display values - - private static DecimalFormat numFormat = new DecimalFormat("#.00"); - - public GuiSlideControl(int id, int x, int y, int width, int height, String displayString, float minVal, float maxVal, float curVal, boolean useInts) - { - super(id, x, y, width, height, (useInts ? displayString + ((int)curVal) : displayString + numFormat.format(curVal))); - - this.label = displayString; - this.minValue = minVal; - this.maxValue = maxVal; - this.curValue = (curVal - minVal) / (maxVal - minVal); - this.useIntegers = useInts; - } - - public float GetValueAsFloat() - { - return (maxValue - minValue) * curValue + minValue; - } - - public int GetValueAsInt() - { - return (int)((maxValue - minValue) * curValue + minValue); - } - - protected float roundValue(float value) - { - value = 0.01F * (float)Math.round(value / 0.01F); + this.label = displayString; + this.minValue = minVal; + this.maxValue = maxVal; + this.curValue = (curVal - minVal) / (maxVal - minVal); + this.useIntegers = useInts; + } + + public float GetValueAsFloat() { + return (maxValue - minValue) * curValue + minValue; + } + + public int GetValueAsInt() { + return (int) ((maxValue - minValue) * curValue + minValue); + } + + protected float roundValue(float value) { + value = 0.01F * (float) Math.round(value / 0.01F); return value; } - - public String GetLabel() - { - if(useIntegers) return label + GetValueAsInt(); - else return label + numFormat.format(GetValueAsFloat()); - } - - protected void SetLabel() - { - displayString = GetLabel(); - } - - @Override - protected int getHoverState(boolean isMouseOver) - { - return 0; - } - - @Override - protected void mouseDragged(Minecraft mc, int mousePosX, int mousePosY) - { - if(visible) - { - if(this.isSliding) - { - curValue = roundValue((float)(mousePosX - (xPosition + 4)) / (float)(width - 8)); - - if(curValue < 0.0F) - { - curValue = 0.0F; - } - if(curValue > 1.0F) - { - curValue = 1.0F; - } - - SetLabel(); - } - - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - this.drawTexturedModalRect(xPosition + (int)(curValue * (float)(width - 8)), yPosition, 0, 66, 4, 20); - this.drawTexturedModalRect(xPosition + (int)(curValue * (float)(width - 8)) + 4, yPosition, 196, 66, 4, 20); - } - } - - @Override - public boolean mousePressed(Minecraft mc, int mousePosX, int mousePosY) - { - if(super.mousePressed(mc, mousePosX, mousePosY)) - { - curValue = roundValue((float)(mousePosX - (xPosition + 4)) / (float)(width - 8)); - - if(curValue < 0.0F) - { - curValue = 0.0F; - } - if(curValue > 1.0F) - { - curValue = 1.0F; - } - - SetLabel(); - this.isSliding = true; - return true; - } - else - { - return false; - } - } - - @Override - public void mouseReleased(int mousePosX, int mousePosY) - { - this.isSliding = false; - } + + public String GetLabel() { + if (useIntegers) return label + GetValueAsInt(); + else return label + numFormat.format(GetValueAsFloat()); + } + + protected void SetLabel() { + displayString = GetLabel(); + } + + @Override + protected int getHoverState(boolean isMouseOver) { + return 0; + } + + @Override + protected void mouseDragged(Minecraft mc, int mousePosX, int mousePosY) { + if (visible) { + if (this.isSliding) { + curValue = roundValue((float) (mousePosX - (xPosition + 4)) / (float) (width - 8)); + + if (curValue < 0.0F) { + curValue = 0.0F; + } + if (curValue > 1.0F) { + curValue = 1.0F; + } + + SetLabel(); + } + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.drawTexturedModalRect(xPosition + (int) (curValue * (float) (width - 8)), yPosition, 0, 66, 4, 20); + this.drawTexturedModalRect(xPosition + (int) (curValue * (float) (width - 8)) + 4, yPosition, 196, 66, 4, 20); + } + } + + @Override + public boolean mousePressed(Minecraft mc, int mousePosX, int mousePosY) { + if (super.mousePressed(mc, mousePosX, mousePosY)) { + curValue = roundValue((float) (mousePosX - (xPosition + 4)) / (float) (width - 8)); + + if (curValue < 0.0F) { + curValue = 0.0F; + } + if (curValue > 1.0F) { + curValue = 1.0F; + } + + SetLabel(); + this.isSliding = true; + return true; + } else { + return false; + } + } + + @Override + public void mouseReleased(int mousePosX, int mousePosY) { + this.isSliding = false; + } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/gui/GuiTSConfig.java b/src/main/java/deez/togglesneak/gui/GuiTSConfig.java index 1c76503..53289f8 100644 --- a/src/main/java/deez/togglesneak/gui/GuiTSConfig.java +++ b/src/main/java/deez/togglesneak/gui/GuiTSConfig.java @@ -6,10 +6,8 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -public class GuiTSConfig extends GuiScreen -{ +public class GuiTSConfig extends GuiScreen { private GuiScreen parentScreen; - private GuiButton btnToggleSneak; private GuiButton btnToggleSprint; private GuiButton btnShowHUDText; @@ -18,232 +16,218 @@ public class GuiTSConfig extends GuiScreen private GuiButton btnOptionsButton; private GuiButton btnSaveSettings; private GuiButton btnCancelChanges; - + private GuiSlideControl sliderHUDTextPosX; private GuiSlideControl sliderHUDTextPosY; private GuiSlideControl sliderFlyBoostAmount; private GuiButton lastPressed; - + private boolean changedShowHUD; private boolean changedToggleSprint; - + private int headerPos; private int footerPos; - + private byte byte0 = -16; - - public GuiTSConfig(GuiScreen parent) - { + + public GuiTSConfig(GuiScreen parent) { this.parentScreen = parent; } - + @Override - public void initGui() - { + public void initGui() { this.buttonList.clear(); - + headerPos = this.height / 4 - 52; footerPos = this.height - 29; - - this.btnToggleSneak = new GuiButton(1, this.width / 2 - 98, getRowPos(1), 60, 20, String.valueOf(ToggleSneakMod.optionToggleSneak)); - this.btnToggleSprint = new GuiButton(2, this.width / 2 + 102, getRowPos(1), 60, 20, String.valueOf(ToggleSneakMod.optionToggleSprint)); - this.btnShowHUDText = new GuiButton(3, this.width / 2 + 2, getRowPos(2), 60, 20, String.valueOf(ToggleSneakMod.optionShowHUDText)); - - this.sliderHUDTextPosX = new GuiSlideControl(50, this.width / 2 + 2, getRowPos(3), 150, 20, "X Pos: ", 1, width - 25, ToggleSneakMod.optionHUDTextPosX, true); - this.sliderHUDTextPosY = new GuiSlideControl(60, this.width / 2 + 2, getRowPos(4), 150, 20, "Y Pos: ", 1, height - 8, ToggleSneakMod.optionHUDTextPosY, true); - - this.btnDoubleTap = new GuiButton(4, this.width / 2 + 2, getRowPos(5), 60, 20, String.valueOf(ToggleSneakMod.optionDoubleTap)); - this.btnFlyBoost = new GuiButton(5, this.width / 2 - 113,getRowPos(6), 60, 20, String.valueOf(ToggleSneakMod.optionEnableFlyBoost)); - - this.sliderFlyBoostAmount = new GuiSlideControl(70, this.width / 2 + 57, getRowPos(6), 150, 20, "x", 0.0F, 10.0F, (float)ToggleSneakMod.optionFlyBoostAmount, false); - - this.btnOptionsButton = new GuiButton(6, this.width / 2 + 2, getRowPos(7), 60, 20, ToggleSneakMod.optionButtonPosition == 1 ? "Left" : "Right"); - - this.btnSaveSettings = new GuiButton(100, this.width / 2 - 155, footerPos, 150, 20, "Save Settings"); - this.btnCancelChanges = new GuiButton(110, this.width / 2 + 5, footerPos, 150, 20, "Cancel Changes"); - + + this.btnToggleSneak = new GuiButton(1, this.width / 2 - 98, getRowPos(1), 60, 20, String.valueOf(ToggleSneakMod.optionToggleSneak)); + this.btnToggleSprint = new GuiButton(2, this.width / 2 + 102, getRowPos(1), 60, 20, String.valueOf(ToggleSneakMod.optionToggleSprint)); + this.btnShowHUDText = new GuiButton(3, this.width / 2 + 2, getRowPos(2), 60, 20, String.valueOf(ToggleSneakMod.optionShowHUDText)); + + this.sliderHUDTextPosX = new GuiSlideControl(50, this.width / 2 + 2, getRowPos(3), 150, 20, "X Pos: ", 1, width - 25, ToggleSneakMod.optionHUDTextPosX, true); + this.sliderHUDTextPosY = new GuiSlideControl(60, this.width / 2 + 2, getRowPos(4), 150, 20, "Y Pos: ", 1, height - 8, ToggleSneakMod.optionHUDTextPosY, true); + + this.btnDoubleTap = new GuiButton(4, this.width / 2 + 2, getRowPos(5), 60, 20, String.valueOf(ToggleSneakMod.optionDoubleTap)); + this.btnFlyBoost = new GuiButton(5, this.width / 2 - 113, getRowPos(6), 60, 20, String.valueOf(ToggleSneakMod.optionEnableFlyBoost)); + + this.sliderFlyBoostAmount = new GuiSlideControl(70, this.width / 2 + 57, getRowPos(6), 150, 20, "x", 0.0F, 10.0F, (float) ToggleSneakMod.optionFlyBoostAmount, false); + + this.btnOptionsButton = new GuiButton(6, this.width / 2 + 2, getRowPos(7), 60, 20, ToggleSneakMod.optionButtonPosition == 1 ? "Left" : "Right"); + + this.btnSaveSettings = new GuiButton(100, this.width / 2 - 155, footerPos, 150, 20, "Save Settings"); + this.btnCancelChanges = new GuiButton(110, this.width / 2 + 5, footerPos, 150, 20, "Cancel Changes"); + this.buttonList.add(btnToggleSneak); this.buttonList.add(btnToggleSprint); this.buttonList.add(btnShowHUDText); - - this.buttonList.add((GuiButton)sliderHUDTextPosX); - this.buttonList.add((GuiButton)sliderHUDTextPosY); - + + this.buttonList.add(sliderHUDTextPosX); + this.buttonList.add(sliderHUDTextPosY); + this.buttonList.add(btnDoubleTap); this.buttonList.add(btnFlyBoost); - this.buttonList.add((GuiButton)sliderFlyBoostAmount); - + this.buttonList.add(sliderFlyBoostAmount); + this.buttonList.add(btnOptionsButton); - + this.buttonList.add(btnSaveSettings); this.buttonList.add(btnCancelChanges); } - - public int getRowPos(int rowNumber) - { - return this.height / 4 + 0 + ((24 * rowNumber) - 24) + byte0; + + public int getRowPos(int rowNumber) { + return this.height / 4 + ((24 * rowNumber) - 24) + byte0; } - + @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) - { - if (mouseButton == 0) - { - for (int l = 0; l < this.buttonList.size(); ++l) - { - GuiButton guibutton = (GuiButton)this.buttonList.get(l); - - if (guibutton.mousePressed(this.mc, mouseX, mouseY)) - { - lastPressed = guibutton; - actionPerformed(guibutton); - } - } - } - } - + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) { + if (mouseButton == 0) { + for (int l = 0; l < this.buttonList.size(); ++l) { + GuiButton guibutton = this.buttonList.get(l); + + if (guibutton.mousePressed(this.mc, mouseX, mouseY)) { + lastPressed = guibutton; + actionPerformed(guibutton); + } + } + } + } + // Update values when sliding the SlideControl - @Override - protected void mouseReleased(int mouseX, int mouseY, int which) - { - if (this.lastPressed != null && which == 0) - { - lastPressed.mouseReleased(mouseX, mouseY); - - actionPerformed_MouseUp(lastPressed); - - lastPressed = null; - } - } - + @Override + protected void mouseReleased(int mouseX, int mouseY, int which) { + if (this.lastPressed != null && which == 0) { + lastPressed.mouseReleased(mouseX, mouseY); + + actionPerformed_MouseUp(lastPressed); + + lastPressed = null; + } + } + // Update values if the mouse was clicked and dragged - protected void actionPerformed_MouseUp(GuiButton button) - { - if(button instanceof GuiSlideControl) - { - actionPerformed(button); - } - } - - @Override - protected void actionPerformed(GuiButton button) - { - switch(button.id) - { + protected void actionPerformed_MouseUp(GuiButton button) { + if (button instanceof GuiSlideControl) { + actionPerformed(button); + } + } + + @Override + protected void actionPerformed(GuiButton button) { + switch (button.id) { // btnToggleSneak case 1: ToggleSneakMod.optionToggleSneak = !ToggleSneakMod.optionToggleSneak; this.btnToggleSneak.displayString = String.valueOf(ToggleSneakMod.optionToggleSneak); break; - + // btnToggleSprint case 2: ToggleSneakMod.optionToggleSprint = !ToggleSneakMod.optionToggleSprint; this.btnToggleSprint.displayString = String.valueOf(ToggleSneakMod.optionToggleSprint); changedToggleSprint = true; break; - + // btnShowHUDText case 3: ToggleSneakMod.optionShowHUDText = !ToggleSneakMod.optionShowHUDText; this.btnShowHUDText.displayString = String.valueOf(ToggleSneakMod.optionShowHUDText); changedShowHUD = true; break; - + // btnDoubleTap case 4: ToggleSneakMod.optionDoubleTap = !ToggleSneakMod.optionDoubleTap; this.btnDoubleTap.displayString = String.valueOf(ToggleSneakMod.optionDoubleTap); break; - + // btnFlyBoost case 5: ToggleSneakMod.optionEnableFlyBoost = !ToggleSneakMod.optionEnableFlyBoost; this.btnFlyBoost.displayString = String.valueOf(ToggleSneakMod.optionEnableFlyBoost); break; - + //btnOptionsButton case 6: - if(ToggleSneakMod.optionButtonPosition == 0) ToggleSneakMod.optionButtonPosition = 1; - else if(ToggleSneakMod.optionButtonPosition == 1) ToggleSneakMod.optionButtonPosition = 0; - + if (ToggleSneakMod.optionButtonPosition == 0) ToggleSneakMod.optionButtonPosition = 1; + else if (ToggleSneakMod.optionButtonPosition == 1) ToggleSneakMod.optionButtonPosition = 0; + this.btnOptionsButton.displayString = ToggleSneakMod.optionButtonPosition == 1 ? "Left" : "Right"; break; - + // sliderHUDTextPosX case 50: ToggleSneakMod.optionHUDTextPosX = sliderHUDTextPosX.GetValueAsInt(); break; - + // sliderHUDTextPosY case 60: ToggleSneakMod.optionHUDTextPosY = sliderHUDTextPosY.GetValueAsInt(); break; - + // sliderFlyBoostAmount case 70: ToggleSneakMod.optionFlyBoostAmount = sliderFlyBoostAmount.GetValueAsFloat(); break; - + // btnSaveSettings case 100: // Clear the HUD Text if HUD display was disabled in-game - if(changedShowHUD) RenderTextToHUD.SetHUDText(""); - + if (changedShowHUD) RenderTextToHUD.SetHUDText(""); + // Cancel ToggleSprint if active and update sprint status if disabled in-game - if(changedToggleSprint && mc.theWorld != null) ToggleSneakMod.wasSprintDisabled = true; - + if (changedToggleSprint && mc.theWorld != null) ToggleSneakMod.wasSprintDisabled = true; + ToggleSneakMod.saveConfig(); - + changedShowHUD = false; changedToggleSprint = false; - + this.mc.displayGuiScreen(this.parentScreen); break; - + // btnCancelChanges case 110: // Reload config from file to erase any changes made to values in memory ToggleSneakMod.reloadConfig(); this.mc.displayGuiScreen(this.parentScreen); - + changedShowHUD = false; changedToggleSprint = false; break; } } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) - { - String lblToggleSneak = "Enable ToggleSneak"; - String lblToggleSprint = "Enable ToggleSprint"; - String lblShowHUDText = "Show status on HUD"; - String lblHUDTextPosX = "Horizontal HUD Location"; - String lblHUDTextPosY = "Vertical HUD Location"; - String lblDoubleTap = "Enable Double-Tapping"; - String lblFlyBoost = "Enable Fly Boost"; - String lblFlyBoostAmount = "Fly Boost Multiplier"; - String lblOptionsButton = "Options Button Location"; + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + String lblToggleSneak = "Enable ToggleSneak"; + String lblToggleSprint = "Enable ToggleSprint"; + String lblShowHUDText = "Show status on HUD"; + String lblHUDTextPosX = "Horizontal HUD Location"; + String lblHUDTextPosY = "Vertical HUD Location"; + String lblDoubleTap = "Enable Double-Tapping"; + String lblFlyBoost = "Enable Fly Boost"; + String lblFlyBoostAmount = "Fly Boost Multiplier"; + String lblOptionsButton = "Options Button Location"; this.drawDefaultBackground(); - + this.drawCenteredString(this.fontRendererObj, "ToggleSneak Settings", this.width / 2, headerPos, 16777215); - - this.drawString(fontRendererObj, lblToggleSneak, this.width / 2 - 100 - this.fontRendererObj.getStringWidth(lblToggleSneak), getRowPos(1) + 6, 16777215); - this.drawString(fontRendererObj, lblToggleSprint, this.width / 2 + 100 - this.fontRendererObj.getStringWidth(lblToggleSprint), getRowPos(1) + 6, 16777215); - this.drawString(fontRendererObj, lblShowHUDText, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblShowHUDText), getRowPos(2) + 6, 16777215); - - this.drawString(fontRendererObj, lblHUDTextPosX, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblHUDTextPosX), getRowPos(3) + 6, 16777215); - this.drawString(fontRendererObj, lblHUDTextPosY, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblHUDTextPosY), getRowPos(4) + 6, 16777215); - - this.drawString(fontRendererObj, lblDoubleTap, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblDoubleTap), getRowPos(5) + 6, 16777215); - this.drawString(fontRendererObj, lblFlyBoost, this.width / 2 - 115 - this.fontRendererObj.getStringWidth(lblFlyBoost), getRowPos(6) + 6, 16777215); - this.drawString(fontRendererObj, lblFlyBoostAmount, this.width / 2 + 50 - this.fontRendererObj.getStringWidth(lblFlyBoostAmount), getRowPos(6) + 6, 16777215); - - this.drawString(fontRendererObj, lblOptionsButton, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblOptionsButton), getRowPos(7) + 6, 16777215); - + + this.drawString(fontRendererObj, lblToggleSneak, this.width / 2 - 100 - this.fontRendererObj.getStringWidth(lblToggleSneak), getRowPos(1) + 6, 16777215); + this.drawString(fontRendererObj, lblToggleSprint, this.width / 2 + 100 - this.fontRendererObj.getStringWidth(lblToggleSprint), getRowPos(1) + 6, 16777215); + this.drawString(fontRendererObj, lblShowHUDText, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblShowHUDText), getRowPos(2) + 6, 16777215); + + this.drawString(fontRendererObj, lblHUDTextPosX, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblHUDTextPosX), getRowPos(3) + 6, 16777215); + this.drawString(fontRendererObj, lblHUDTextPosY, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblHUDTextPosY), getRowPos(4) + 6, 16777215); + + this.drawString(fontRendererObj, lblDoubleTap, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblDoubleTap), getRowPos(5) + 6, 16777215); + this.drawString(fontRendererObj, lblFlyBoost, this.width / 2 - 115 - this.fontRendererObj.getStringWidth(lblFlyBoost), getRowPos(6) + 6, 16777215); + this.drawString(fontRendererObj, lblFlyBoostAmount, this.width / 2 + 50 - this.fontRendererObj.getStringWidth(lblFlyBoostAmount), getRowPos(6) + 6, 16777215); + + this.drawString(fontRendererObj, lblOptionsButton, this.width / 2 - 3 - this.fontRendererObj.getStringWidth(lblOptionsButton), getRowPos(7) + 6, 16777215); + super.drawScreen(mouseX, mouseY, partialTicks); } } \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/gui/TSGuiFactoryHandler.java b/src/main/java/deez/togglesneak/gui/TSGuiFactoryHandler.java index 5b84936..3bc5cf5 100644 --- a/src/main/java/deez/togglesneak/gui/TSGuiFactoryHandler.java +++ b/src/main/java/deez/togglesneak/gui/TSGuiFactoryHandler.java @@ -7,28 +7,24 @@ import java.util.Set; -public class TSGuiFactoryHandler implements IModGuiFactory -{ - @Override - public void initialize(Minecraft mcInstance) - { - } - - @Override - public Class mainConfigGuiClass() - { - return GuiTSConfig.class; - } - - @Override - public Set runtimeGuiCategories() - { - return null; - } - - @Override - public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) - { - return null; - } +@SuppressWarnings("unused") +public class TSGuiFactoryHandler implements IModGuiFactory { + @Override + public void initialize(Minecraft mcInstance) { + } + + @Override + public Class mainConfigGuiClass() { + return GuiTSConfig.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } } diff --git a/src/main/java/deez/togglesneak/proxy/ClientProxy.java b/src/main/java/deez/togglesneak/proxy/ClientProxy.java deleted file mode 100644 index 2df10a7..0000000 --- a/src/main/java/deez/togglesneak/proxy/ClientProxy.java +++ /dev/null @@ -1,29 +0,0 @@ -package deez.togglesneak.proxy; - -import api.player.client.ClientPlayerAPI; - -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -import net.minecraftforge.common.MinecraftForge; - -import deez.togglesneak.PlayerBase; -import deez.togglesneak.RenderTextToHUD; -import deez.togglesneak.ToggleSneakEvents; -import deez.togglesneak.ToggleSneakMod; - -public class ClientProxy extends CommonProxy -{ - @Override - public void registerEvents(FMLPreInitializationEvent event) - { - MinecraftForge.EVENT_BUS.register(RenderTextToHUD.instance); - MinecraftForge.EVENT_BUS.register(ToggleSneakEvents.instance); - } - - @Override - public void initMod() - { - RenderTextToHUD.SetHUDText(ToggleSneakMod.ModID + " for Forge - version " + ToggleSneakMod.ModVersion + " Beta!"); - ClientPlayerAPI.register("ToggleSneak", PlayerBase.class); - } -} \ No newline at end of file diff --git a/src/main/java/deez/togglesneak/proxy/CommonProxy.java b/src/main/java/deez/togglesneak/proxy/CommonProxy.java deleted file mode 100644 index 9f56f9d..0000000 --- a/src/main/java/deez/togglesneak/proxy/CommonProxy.java +++ /dev/null @@ -1,10 +0,0 @@ -package deez.togglesneak.proxy; - -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy -{ - public void registerEvents(FMLPreInitializationEvent e) {} - - public void initMod() {} -} \ No newline at end of file