├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── me │ └── pepperbell │ └── anycapes │ ├── AnyCapes.java │ ├── cape │ ├── AbstractCapeProviderImpl.java │ ├── CapeProcessResult.java │ ├── CapeProvider.java │ ├── CapeProviderImpl.java │ ├── CapeTexture.java │ └── ImageDownloadCallback.java │ ├── config │ ├── ClothConfigFactory.java │ ├── Config.java │ └── ModMenuApiImpl.java │ ├── mixin │ ├── ElytraFeatureRendererAccessor.java │ └── PlayerSkinProviderMixin.java │ ├── mixinterface │ └── PlayerSkinProviderAccess.java │ └── util │ ├── ImageUtil.java │ └── ParsingUtil.java └── resources ├── anycapes.mixins.json ├── assets └── anycapes │ ├── icon.png │ └── lang │ └── en_us.json └── fabric.mod.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # gradle 2 | 3 | .gradle/ 4 | build/ 5 | out/ 6 | classes/ 7 | 8 | # eclipse 9 | 10 | *.launch 11 | 12 | # idea 13 | 14 | .idea/ 15 | *.iml 16 | *.ipr 17 | *.iws 18 | 19 | # vscode 20 | 21 | .settings/ 22 | .vscode/ 23 | bin/ 24 | .classpath 25 | .project 26 | 27 | # fabric 28 | 29 | run/ 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AnyCapes 2 | 3 | A Fabric mod that retrieves and renders capes from any cape API. 4 | 5 | CurseForge project page: https://www.curseforge.com/minecraft/mc-mods/anycapes 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'fabric-loom' version '0.7-SNAPSHOT' 3 | id 'maven-publish' 4 | } 5 | 6 | sourceCompatibility = JavaVersion.VERSION_1_8 7 | targetCompatibility = JavaVersion.VERSION_1_8 8 | 9 | archivesBaseName = project.archives_base_name 10 | version = project.mod_version 11 | group = project.maven_group 12 | 13 | repositories { 14 | maven { 15 | url = "https://maven.terraformersmc.com/" 16 | } 17 | maven { 18 | url = "https://maven.shedaniel.me/" 19 | } 20 | } 21 | 22 | dependencies { 23 | //to change the versions see the gradle.properties file 24 | minecraft "com.mojang:minecraft:${project.minecraft_version}" 25 | mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" 26 | modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" 27 | 28 | // Fabric API. This is technically optional, but you probably want it anyway. 29 | modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" 30 | 31 | modCompileOnly("com.terraformersmc:modmenu:${modmenu_version}") { 32 | exclude(group: "net.fabricmc.fabric-api") 33 | } 34 | 35 | modCompileOnly("me.shedaniel.cloth:cloth-config-fabric:${cloth_config_version}") { 36 | exclude(group: "net.fabricmc.fabric-api") 37 | } 38 | } 39 | 40 | processResources { 41 | inputs.property "version", project.version 42 | 43 | filesMatching("fabric.mod.json") { 44 | expand "version": project.version 45 | } 46 | } 47 | 48 | tasks.withType(JavaCompile).configureEach { 49 | // ensure that the encoding is set to UTF-8, no matter what the system default is 50 | // this fixes some edge cases with special characters not displaying correctly 51 | // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html 52 | // If Javadoc is generated, this must be specified in that task too. 53 | it.options.encoding = "UTF-8" 54 | 55 | // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too 56 | // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. 57 | // We'll use that if it's available, but otherwise we'll use the older option. 58 | def targetVersion = 8 59 | if (JavaVersion.current().isJava9Compatible()) { 60 | it.options.release = targetVersion 61 | } 62 | } 63 | 64 | java { 65 | // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task 66 | // if it is present. 67 | // If you remove this line, sources will not be generated. 68 | withSourcesJar() 69 | } 70 | 71 | jar { 72 | from("LICENSE") { 73 | rename { "${it}_${project.archivesBaseName}" } 74 | } 75 | } 76 | 77 | // configure the maven publication 78 | publishing { 79 | publications { 80 | mavenJava(MavenPublication) { 81 | // add all the jars that should be included when publishing to maven 82 | artifact(remapJar) { 83 | builtBy remapJar 84 | } 85 | artifact(sourcesJar) { 86 | builtBy remapSourcesJar 87 | } 88 | } 89 | } 90 | 91 | // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. 92 | repositories { 93 | // Add repositories to publish to here. 94 | // Notice: This block does NOT have the same function as the block in the top level. 95 | // The repositories here will be used for publishing your artifact, not for 96 | // retrieving dependencies. 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs = -Xmx1G 3 | 4 | # Fabric Properties 5 | # check these on https://fabricmc.net/use 6 | minecraft_version = 1.16.5 7 | # https://maven.fabricmc.net/net/fabricmc/yarn 8 | yarn_mappings = 1.16.5+build.10 9 | # https://maven.fabricmc.net/net/fabricmc/fabric-loader 10 | loader_version = 0.11.6 11 | 12 | # Mod Properties 13 | mod_version = 1.0.3+1.16 14 | maven_group = me.pepperbell 15 | archives_base_name = anycapes 16 | 17 | # Dependencies 18 | # https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api 19 | fabric_version = 0.37.0+1.16 20 | # https://maven.terraformersmc.com/releases/com/terraformersmc/modmenu 21 | modmenu_version = 1.16.10 22 | # https://www.curseforge.com/minecraft/mc-mods/cloth-config/files 23 | cloth_config_version = 4.11.26 24 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PepperCode1/AnyCapes/0002d51bf60d39e4e9e2bf53bb37c7e7f800dfdc/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MSYS* | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | gradlePluginPortal() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/AnyCapes.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes; 2 | 3 | import java.io.File; 4 | import java.nio.file.Path; 5 | 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | 9 | import me.pepperbell.anycapes.cape.CapeProviderImpl; 10 | import me.pepperbell.anycapes.config.Config; 11 | import me.pepperbell.anycapes.mixinterface.PlayerSkinProviderAccess; 12 | import net.fabricmc.api.ClientModInitializer; 13 | import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; 14 | import net.fabricmc.loader.api.FabricLoader; 15 | import net.minecraft.util.Util; 16 | 17 | public class AnyCapes implements ClientModInitializer { 18 | public static final String ID = "anycapes"; 19 | public static final Logger LOGGER = LogManager.getLogger("AnyCapes"); 20 | 21 | private static Config config; 22 | 23 | public static Config getConfig() { 24 | if (config == null) { 25 | loadConfig(); 26 | } 27 | return config; 28 | } 29 | 30 | private static void loadConfig() { 31 | Path configPath = FabricLoader.getInstance().getConfigDir(); 32 | File configFile = configPath.resolve("anycapes.json").toFile(); 33 | config = new Config(configFile); 34 | config.load(); 35 | } 36 | 37 | @Override 38 | public void onInitializeClient() { 39 | ClientLifecycleEvents.CLIENT_STARTED.register(client -> { 40 | PlayerSkinProviderAccess skinProviderAccess = (PlayerSkinProviderAccess) client.getSkinProvider(); 41 | skinProviderAccess.setCapeProvider(new CapeProviderImpl( 42 | skinProviderAccess.getSkinCacheDir(), 43 | skinProviderAccess.getTextureManager(), 44 | Util.getMainWorkerExecutor(), 45 | client.getNetworkProxy() 46 | )); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/AbstractCapeProviderImpl.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.InputStream; 6 | import java.net.HttpURLConnection; 7 | import java.net.Proxy; 8 | import java.net.URL; 9 | import java.util.List; 10 | import java.util.concurrent.CompletableFuture; 11 | import java.util.concurrent.Executor; 12 | 13 | import com.google.common.hash.Hashing; 14 | import com.mojang.authlib.GameProfile; 15 | import com.mojang.authlib.minecraft.MinecraftProfileTexture; 16 | import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; 17 | 18 | import me.pepperbell.anycapes.mixin.ElytraFeatureRendererAccessor; 19 | import net.minecraft.client.MinecraftClient; 20 | import net.minecraft.client.texture.AbstractTexture; 21 | import net.minecraft.client.texture.NativeImage; 22 | import net.minecraft.client.texture.PlayerSkinProvider.SkinTextureAvailableCallback; 23 | import net.minecraft.client.texture.TextureManager; 24 | import net.minecraft.util.Identifier; 25 | 26 | public abstract class AbstractCapeProviderImpl implements CapeProvider { 27 | protected static final Identifier DEFAULT_ELYTRA = ElytraFeatureRendererAccessor.getElytraTexture(); 28 | 29 | protected final File skinCacheDir; 30 | protected final TextureManager textureManager; 31 | protected final Executor executor; 32 | protected final Proxy proxy; 33 | 34 | public AbstractCapeProviderImpl(File skinCacheDir, TextureManager textureManager, Executor executor, Proxy proxy) { 35 | this.skinCacheDir = skinCacheDir; 36 | this.textureManager = textureManager; 37 | this.executor = executor; 38 | this.proxy = proxy; 39 | } 40 | 41 | @Override 42 | public void loadCape(GameProfile gameProfile, MinecraftProfileTexture mojangCape, SkinTextureAvailableCallback callback) { 43 | // AnyCapes.LOGGER.debug("Loading cape for profile " + gameProfile); 44 | String hash = Hashing.sha1().hashUnencodedChars("cape-" + gameProfile.getId().toString()).toString(); 45 | Identifier identifier = new Identifier("skins/" + hash); 46 | AbstractTexture texture = textureManager.getTexture(identifier); 47 | if (texture != null) { 48 | if (callback != null) { 49 | if (texture instanceof CapeTexture) { 50 | if (!((CapeTexture) texture).hasElytra()) { 51 | callback.onSkinTextureAvailable(Type.ELYTRA, DEFAULT_ELYTRA, null); 52 | } 53 | } 54 | callback.onSkinTextureAvailable(Type.CAPE, identifier, null); 55 | } 56 | } else { 57 | File cacheFile = null; 58 | if (useCaching()) { 59 | cacheFile = new File(new File(skinCacheDir, hash.length() > 2 ? hash.substring(0, 2) : "xx"), hash); 60 | } 61 | getCape(gameProfile, mojangCape == null ? null : mojangCape.getUrl(), cacheFile, (nativeImage, url) -> { 62 | MinecraftClient.getInstance().execute(() -> { 63 | CapeProcessResult result = processCapeImage(nativeImage); 64 | NativeImage capeImage = result.getProcessedImage(); 65 | boolean hasElytra = result.hasElytra(); 66 | if (!hasElytra) { 67 | callback.onSkinTextureAvailable(Type.ELYTRA, DEFAULT_ELYTRA, null); 68 | } 69 | CapeTexture capeTexture = new CapeTexture(capeImage, hasElytra); 70 | textureManager.registerTexture(identifier, capeTexture); 71 | if (callback != null) { 72 | callback.onSkinTextureAvailable(Type.CAPE, identifier, url == null ? null : new MinecraftProfileTexture(url.toString(), null)); 73 | } 74 | // AnyCapes.LOGGER.debug("Loaded cape for profile " + gameProfile + " from " + url); 75 | }); 76 | }); 77 | } 78 | } 79 | 80 | public void getCape(GameProfile gameProfile, String mojangCapeUrl, File cacheFile, ImageDownloadCallback callback) { 81 | if (cacheFile != null && cacheFile.isFile()) { 82 | NativeImage nativeImage = null; 83 | try { 84 | FileInputStream fileInputStream = new FileInputStream(cacheFile); 85 | nativeImage = NativeImage.read(fileInputStream); 86 | } catch (Exception exception) { 87 | cacheFile.delete(); 88 | } 89 | if (nativeImage != null) { 90 | callback.onSuccess(nativeImage, null); 91 | return; 92 | } 93 | } 94 | 95 | downloadCape(gameProfile, mojangCapeUrl, cacheFile, callback); 96 | } 97 | 98 | public CompletableFuture downloadCape(GameProfile gameProfile, String mojangCapeUrl, File cacheFile, ImageDownloadCallback callback) { 99 | return CompletableFuture.runAsync(() -> { 100 | downloadCape(getCapeUrls(), 0, gameProfile, mojangCapeUrl, cacheFile, callback); 101 | }, executor); 102 | } 103 | 104 | protected void downloadCape(List urls, int index, GameProfile gameProfile, String mojangCapeUrl, File cacheFile, ImageDownloadCallback callback) { 105 | if (index >= urls.size()) { 106 | return; 107 | } 108 | URL url = formatUrl(urls.get(index), gameProfile, mojangCapeUrl); 109 | if (url == null) { 110 | downloadCape(urls, index + 1, gameProfile, mojangCapeUrl, cacheFile, callback); 111 | return; 112 | } 113 | CompletableFuture future = downloadImage(url, cacheFile); 114 | future.whenCompleteAsync((nativeImage, throwable) -> { 115 | if (nativeImage != null && throwable == null) { 116 | callback.onSuccess(nativeImage, url); 117 | } else { 118 | downloadCape(urls, index + 1, gameProfile, mojangCapeUrl, cacheFile, callback); 119 | } 120 | }, executor); 121 | } 122 | 123 | public CompletableFuture downloadImage(URL url, File cacheFile) { 124 | return CompletableFuture.supplyAsync(() -> { 125 | HttpURLConnection httpURLConnection = null; 126 | NativeImage nativeImage = null; 127 | try { 128 | httpURLConnection = (HttpURLConnection) url.openConnection(proxy); 129 | httpURLConnection.connect(); 130 | if (httpURLConnection.getResponseCode() / 100 == 2) { 131 | InputStream inputStream = httpURLConnection.getInputStream(); 132 | nativeImage = NativeImage.read(inputStream); 133 | if (cacheFile != null) { 134 | nativeImage.writeFile(cacheFile); 135 | } 136 | } 137 | } catch (Exception exception) { 138 | throw new RuntimeException(exception); 139 | } finally { 140 | if (httpURLConnection != null) { 141 | httpURLConnection.disconnect(); 142 | } 143 | } 144 | return nativeImage; 145 | }, executor); 146 | } 147 | 148 | public abstract List getCapeUrls(); 149 | 150 | public abstract boolean useCaching(); 151 | 152 | public abstract URL formatUrl(String urlStr, GameProfile gameProfile, String mojangCapeUrl); 153 | 154 | public abstract CapeProcessResult processCapeImage(NativeImage capeImage); 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/CapeProcessResult.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import net.minecraft.client.texture.NativeImage; 4 | 5 | public interface CapeProcessResult { 6 | NativeImage getProcessedImage(); 7 | 8 | boolean hasElytra(); 9 | 10 | class Impl implements CapeProcessResult { 11 | private NativeImage processedImage; 12 | private boolean hasElytra; 13 | 14 | public Impl(NativeImage processedImage, boolean hasElytra) { 15 | this.processedImage = processedImage; 16 | this.hasElytra = hasElytra; 17 | } 18 | 19 | @Override 20 | public NativeImage getProcessedImage() { 21 | return processedImage; 22 | } 23 | 24 | @Override 25 | public boolean hasElytra() { 26 | return hasElytra; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/CapeProvider.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import com.mojang.authlib.minecraft.MinecraftProfileTexture; 5 | 6 | import net.minecraft.client.texture.PlayerSkinProvider.SkinTextureAvailableCallback; 7 | 8 | public interface CapeProvider { 9 | void loadCape(GameProfile gameProfile, MinecraftProfileTexture mojangCape, SkinTextureAvailableCallback callback); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/CapeProviderImpl.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import java.io.File; 4 | import java.net.MalformedURLException; 5 | import java.net.Proxy; 6 | import java.net.URL; 7 | import java.util.List; 8 | import java.util.concurrent.Executor; 9 | 10 | import com.mojang.authlib.GameProfile; 11 | 12 | import me.pepperbell.anycapes.AnyCapes; 13 | import me.pepperbell.anycapes.util.ImageUtil; 14 | import net.minecraft.client.texture.NativeImage; 15 | import net.minecraft.client.texture.TextureManager; 16 | 17 | public class CapeProviderImpl extends AbstractCapeProviderImpl { 18 | public CapeProviderImpl(File skinCacheDir, TextureManager textureManager, Executor executor, Proxy proxy) { 19 | super(skinCacheDir, textureManager, executor, proxy); 20 | } 21 | 22 | @Override 23 | public List getCapeUrls() { 24 | return AnyCapes.getConfig().getOptions().capeUrls; 25 | } 26 | 27 | @Override 28 | public boolean useCaching() { 29 | return AnyCapes.getConfig().getOptions().useCaching; 30 | } 31 | 32 | @Override 33 | public URL formatUrl(String urlStr, GameProfile gameProfile, String mojangCapeUrl) { 34 | if (urlStr.contains("{mojang}")) { 35 | if (mojangCapeUrl == null) { 36 | return null; 37 | } else { 38 | urlStr = urlStr.replace("{mojang}", mojangCapeUrl); 39 | } 40 | } 41 | 42 | urlStr = urlStr.replace("{username}", gameProfile.getName()) 43 | .replace("{uuid}", gameProfile.getId().toString().replace("-", "")) 44 | .replace("{uuid-dash}", gameProfile.getId().toString()); 45 | 46 | URL url = null; 47 | try { 48 | url = new URL(urlStr); 49 | } catch (MalformedURLException e) { 50 | AnyCapes.LOGGER.warn("Invalid URL: " + urlStr); 51 | } 52 | return url; 53 | } 54 | 55 | @Override 56 | public CapeProcessResult processCapeImage(NativeImage capeImage) { 57 | NativeImage processed; 58 | boolean hasElytra = true; 59 | 60 | if (capeImage.getWidth()%46==0 && capeImage.getHeight()%22==0) { 61 | int scale = capeImage.getWidth()/46; 62 | processed = ImageUtil.resizeCanvas(capeImage, scale*64, scale*32); 63 | } else if (capeImage.getWidth()%22==0 && capeImage.getHeight()%17==0) { 64 | int scale = capeImage.getWidth()/22; 65 | processed = ImageUtil.resizeCanvas(capeImage, scale*64, scale*32); 66 | hasElytra = false; 67 | } else if (capeImage.getWidth()%355==0 && capeImage.getHeight()%275==0) { 68 | int scale = capeImage.getWidth()/355; 69 | processed = ImageUtil.cropAndResizeCanvas(capeImage, scale*1024, scale*512, scale*2, scale*2, scale, scale); 70 | hasElytra = false; 71 | } else if (capeImage.getWidth()%352==0 && capeImage.getHeight()%275==0) { 72 | int scale = capeImage.getWidth()/352; 73 | processed = ImageUtil.cropAndResizeCanvas(capeImage, scale*1024, scale*512, 0, scale*2, 0, scale); 74 | hasElytra = false; 75 | } else if (capeImage.getWidth()%355==0 && capeImage.getHeight()%272==0) { 76 | int scale = capeImage.getWidth()/355; 77 | processed = ImageUtil.cropAndResizeCanvas(capeImage, scale*1024, scale*512, scale*2, 0, scale, 0); 78 | hasElytra = false; 79 | } else { 80 | processed = capeImage; 81 | } 82 | 83 | return new CapeProcessResult.Impl(processed, hasElytra); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/CapeTexture.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import net.minecraft.client.texture.NativeImage; 4 | import net.minecraft.client.texture.NativeImageBackedTexture; 5 | 6 | public class CapeTexture extends NativeImageBackedTexture { 7 | private boolean hasElytra; 8 | 9 | public CapeTexture(NativeImage image, boolean hasElytra) { 10 | super(image); 11 | this.hasElytra = hasElytra; 12 | } 13 | 14 | public boolean hasElytra() { 15 | return hasElytra; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/cape/ImageDownloadCallback.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.cape; 2 | 3 | import java.net.URL; 4 | 5 | import net.minecraft.client.texture.NativeImage; 6 | 7 | public interface ImageDownloadCallback { 8 | void onSuccess(NativeImage nativeImage, URL url); 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/config/ClothConfigFactory.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.config; 2 | 3 | import com.terraformersmc.modmenu.api.ConfigScreenFactory; 4 | 5 | import me.pepperbell.anycapes.util.ParsingUtil; 6 | import me.shedaniel.clothconfig2.api.ConfigBuilder; 7 | import me.shedaniel.clothconfig2.api.ConfigCategory; 8 | import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; 9 | import me.shedaniel.clothconfig2.gui.entries.StringListListEntry.StringListCell; 10 | import net.minecraft.client.gui.screen.Screen; 11 | import net.minecraft.text.TranslatableText; 12 | import net.minecraft.util.Language; 13 | 14 | public class ClothConfigFactory implements ConfigScreenFactory { 15 | private Config config; 16 | 17 | public ClothConfigFactory(Config config) { 18 | this.config = config; 19 | } 20 | 21 | @Override 22 | public Screen create(Screen parent) { 23 | ConfigBuilder builder = ConfigBuilder.create() 24 | .setParentScreen(parent) 25 | .setTitle(new TranslatableText("screen.anycapes.config.title")) 26 | .setSavingRunnable(() -> { 27 | config.save(); 28 | }); 29 | ConfigEntryBuilder entryBuilder = builder.entryBuilder(); 30 | 31 | ConfigCategory general = builder.getOrCreateCategory(new TranslatableText("category.anycapes.general")); 32 | general.addEntry(entryBuilder.startStrList(new TranslatableText("option.anycapes.cape_urls"), config.getOptions().capeUrls) 33 | .setSaveConsumer((value) -> { 34 | config.getOptions().capeUrls = value; 35 | }) 36 | .setTooltip(ParsingUtil.parseNewlines("option.anycapes.cape_urls.tooltip")) 37 | .setAddButtonTooltip(new TranslatableText("option.anycapes.cape_urls.add_url")) 38 | .setRemoveButtonTooltip(new TranslatableText("option.anycapes.cape_urls.remove_url")) 39 | .setCreateNewInstance((entry) -> { 40 | return new StringListCell(Language.getInstance().get("option.anycapes.cape_urls.new_url"), entry); 41 | }) 42 | .setDefaultValue(Config.Options.DEFAULT.capeUrls) 43 | .setExpanded(true) 44 | .setInsertInFront(false) 45 | .build()); 46 | general.addEntry(entryBuilder.startBooleanToggle(new TranslatableText("option.anycapes.use_caching"), config.getOptions().useCaching) 47 | .setSaveConsumer((value) -> { 48 | config.getOptions().useCaching = value; 49 | }) 50 | .setTooltip(ParsingUtil.parseNewlines("option.anycapes.use_caching.tooltip")) 51 | .setDefaultValue(Config.Options.DEFAULT.useCaching) 52 | .build()); 53 | 54 | return builder.build(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/config/Config.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.config; 2 | 3 | import java.io.File; 4 | import java.io.FileReader; 5 | import java.io.FileWriter; 6 | import java.io.IOException; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import com.google.gson.Gson; 11 | import com.google.gson.GsonBuilder; 12 | 13 | import me.pepperbell.anycapes.AnyCapes; 14 | 15 | public class Config { 16 | private static final Gson GSON = new GsonBuilder() 17 | .setPrettyPrinting() 18 | .create(); 19 | 20 | private File file; 21 | private Options options; 22 | 23 | public Config(File file) { 24 | this.file = file; 25 | } 26 | 27 | public Options getOptions() { 28 | return options; 29 | } 30 | 31 | public void load() { 32 | if (file.exists()) { 33 | try (FileReader reader = new FileReader(file)) { 34 | options = GSON.fromJson(reader, Options.class); 35 | } catch (IOException e) { 36 | AnyCapes.LOGGER.error("Error loading config", e); 37 | } 38 | } 39 | if (options == null) { 40 | options = new Options(); 41 | save(); 42 | } 43 | } 44 | 45 | public void save() { 46 | try (FileWriter writer = new FileWriter(file)) { 47 | writer.write(GSON.toJson(options)); 48 | } catch (IOException e) { 49 | AnyCapes.LOGGER.error("Error saving config", e); 50 | } 51 | } 52 | 53 | public static class Options { 54 | public static final Options DEFAULT = new Options(); 55 | 56 | public List capeUrls = Arrays.asList( 57 | "{mojang}", 58 | "http://s.optifine.net/capes/{username}.png", 59 | "https://minecraftcapes.net/profile/{uuid}/cape", 60 | "https://dl.labymod.net/capes/{uuid-dash}" 61 | ); 62 | public boolean useCaching = false; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/config/ModMenuApiImpl.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.config; 2 | 3 | import io.github.prospector.modmenu.api.ConfigScreenFactory; 4 | import io.github.prospector.modmenu.api.ModMenuApi; 5 | import me.pepperbell.anycapes.AnyCapes; 6 | import net.fabricmc.loader.api.FabricLoader; 7 | 8 | @SuppressWarnings("deprecation") 9 | public class ModMenuApiImpl implements ModMenuApi { 10 | @Override 11 | public ConfigScreenFactory getModConfigScreenFactory() { 12 | if (FabricLoader.getInstance().isModLoaded("cloth-config2")) { 13 | return new ClothConfigFactory(AnyCapes.getConfig()); 14 | } 15 | return screen -> null; 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/mixin/ElytraFeatureRendererAccessor.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.mixin; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.gen.Accessor; 5 | 6 | import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer; 7 | import net.minecraft.util.Identifier; 8 | 9 | @Mixin(ElytraFeatureRenderer.class) 10 | public interface ElytraFeatureRendererAccessor { 11 | @Accessor("SKIN") 12 | static Identifier getElytraTexture() { 13 | throw new AssertionError(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/mixin/PlayerSkinProviderMixin.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.mixin; 2 | 3 | import java.io.File; 4 | import java.util.Map; 5 | 6 | import org.spongepowered.asm.mixin.Mixin; 7 | import org.spongepowered.asm.mixin.Unique; 8 | import org.spongepowered.asm.mixin.gen.Accessor; 9 | import org.spongepowered.asm.mixin.injection.At; 10 | import org.spongepowered.asm.mixin.injection.Inject; 11 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 12 | import org.spongepowered.asm.mixin.injection.callback.LocalCapture; 13 | 14 | import com.mojang.authlib.GameProfile; 15 | import com.mojang.authlib.minecraft.MinecraftProfileTexture; 16 | import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type; 17 | import com.mojang.blaze3d.systems.RenderSystem; 18 | 19 | import me.pepperbell.anycapes.cape.CapeProvider; 20 | import me.pepperbell.anycapes.mixinterface.PlayerSkinProviderAccess; 21 | import net.minecraft.client.MinecraftClient; 22 | import net.minecraft.client.texture.PlayerSkinProvider; 23 | import net.minecraft.client.texture.TextureManager; 24 | 25 | @Mixin(PlayerSkinProvider.class) 26 | public abstract class PlayerSkinProviderMixin implements PlayerSkinProviderAccess { 27 | @Unique 28 | private CapeProvider capeProvider; 29 | 30 | @Override 31 | public CapeProvider getCapeProvider() { 32 | return capeProvider; 33 | } 34 | 35 | @Override 36 | public void setCapeProvider(CapeProvider capeProvider) { 37 | this.capeProvider = capeProvider; 38 | } 39 | 40 | @Override 41 | @Accessor("textureManager") 42 | public abstract TextureManager getTextureManager(); 43 | 44 | @Override 45 | @Accessor("skinCacheDir") 46 | public abstract File getSkinCacheDir(); 47 | 48 | @Inject( 49 | at = @At( 50 | value = "INVOKE", 51 | target = "Lnet/minecraft/client/MinecraftClient;execute(Ljava/lang/Runnable;)V" 52 | ), 53 | method = "method_4653(Lcom/mojang/authlib/GameProfile;ZLnet/minecraft/client/texture/PlayerSkinProvider$SkinTextureAvailableCallback;)V", 54 | locals = LocalCapture.CAPTURE_FAILHARD 55 | ) 56 | public void onLoadSkinRunnable(GameProfile profile, boolean requireSecure, PlayerSkinProvider.SkinTextureAvailableCallback callback, CallbackInfo ci, Map map) { 57 | if (capeProvider != null) { 58 | MinecraftClient.getInstance().execute(() -> { 59 | RenderSystem.recordRenderCall(() -> { 60 | capeProvider.loadCape(profile, map.remove(Type.CAPE), callback); 61 | }); 62 | }); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/mixinterface/PlayerSkinProviderAccess.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.mixinterface; 2 | 3 | import java.io.File; 4 | 5 | import me.pepperbell.anycapes.cape.CapeProvider; 6 | import net.minecraft.client.texture.TextureManager; 7 | 8 | public interface PlayerSkinProviderAccess { 9 | CapeProvider getCapeProvider(); 10 | 11 | void setCapeProvider(CapeProvider capeProvider); 12 | 13 | TextureManager getTextureManager(); 14 | 15 | File getSkinCacheDir(); 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/util/ImageUtil.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.util; 2 | 3 | import net.minecraft.client.texture.NativeImage; 4 | 5 | public class ImageUtil { 6 | public static NativeImage resizeCanvas(NativeImage nativeImage, int width, int height) { 7 | int minWidth = Math.min(nativeImage.getWidth(), width); 8 | int minHeight = Math.min(nativeImage.getHeight(), height); 9 | NativeImage resized = new NativeImage(width, height, true); 10 | for (int x = 0; x < minWidth; x++) { 11 | for (int y = 0; y < minHeight; y++) { 12 | resized.setPixelColor(x, y, nativeImage.getPixelColor(x, y)); 13 | } 14 | } 15 | nativeImage.close(); 16 | return resized; 17 | } 18 | 19 | public static NativeImage cropAndResizeCanvas(NativeImage nativeImage, int width, int height, int left, int top, int right, int bottom) { 20 | int minWidth = Math.min(nativeImage.getWidth()-left-right, width); 21 | int minHeight = Math.min(nativeImage.getHeight()-top-bottom, height); 22 | NativeImage resized = new NativeImage(width, height, true); 23 | for (int x = 0; x < minWidth; x++) { 24 | for (int y = 0; y < minHeight; y++) { 25 | resized.setPixelColor(x, y, nativeImage.getPixelColor(x+left, y+top)); 26 | } 27 | } 28 | nativeImage.close(); 29 | return resized; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/me/pepperbell/anycapes/util/ParsingUtil.java: -------------------------------------------------------------------------------- 1 | package me.pepperbell.anycapes.util; 2 | 3 | import net.minecraft.text.LiteralText; 4 | import net.minecraft.text.Text; 5 | import net.minecraft.util.Language; 6 | 7 | public class ParsingUtil { 8 | public static Text[] parseNewlines(String translationKey) { 9 | if (!Language.getInstance().hasTranslation(translationKey)) { 10 | return null; 11 | } 12 | String[] strings = Language.getInstance().get(translationKey).split("\n|\\\\n"); 13 | Text[] texts = new Text[strings.length]; 14 | for (int i = 0; i < strings.length; i++) { 15 | texts[i] = new LiteralText(strings[i]); 16 | } 17 | return texts; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/resources/anycapes.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "me.pepperbell.anycapes.mixin", 5 | "compatibilityLevel": "JAVA_8", 6 | "client": [ 7 | "ElytraFeatureRendererAccessor", 8 | "PlayerSkinProviderMixin" 9 | ], 10 | "injectors": { 11 | "defaultRequire": 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/assets/anycapes/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PepperCode1/AnyCapes/0002d51bf60d39e4e9e2bf53bb37c7e7f800dfdc/src/main/resources/assets/anycapes/icon.png -------------------------------------------------------------------------------- /src/main/resources/assets/anycapes/lang/en_us.json: -------------------------------------------------------------------------------- 1 | { 2 | "screen.anycapes.config.title": "AnyCapes Configuration", 3 | "category.anycapes.general": "General", 4 | "option.anycapes.cape_urls": "Cape URL List", 5 | "option.anycapes.cape_urls.tooltip": "Images will be downloaded top to bottom from the list.\nThe first successful download will be set as the cape.\nVisit the website for more information.", 6 | "option.anycapes.cape_urls.add_url": "Add URL", 7 | "option.anycapes.cape_urls.remove_url": "Remove URL", 8 | "option.anycapes.cape_urls.new_url": "New URL", 9 | "option.anycapes.use_caching": "Use Caching", 10 | "option.anycapes.use_caching.tooltip": "If yes, cape textures will be saved to a file.\nIf a texture has been downloaded before, it will\nload faster but will not update if it changed online." 11 | } 12 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "anycapes", 4 | "version": "${version}", 5 | 6 | "name": "AnyCapes", 7 | "description": "Retrieves and renders capes from any cape API.", 8 | "authors": [ 9 | "Pepper_Bell" 10 | ], 11 | "contact": { 12 | "homepage": "https://www.curseforge.com/minecraft/mc-mods/anycapes", 13 | "issues": "https://github.com/PepperCode1/AnyCapes/issues", 14 | "sources": "https://github.com/PepperCode1/AnyCapes" 15 | }, 16 | 17 | "license": "LGPL-3.0-only", 18 | "icon": "assets/anycapes/icon.png", 19 | 20 | "environment": "client", 21 | "entrypoints": { 22 | "client": [ 23 | "me.pepperbell.anycapes.AnyCapes" 24 | ], 25 | "modmenu": [ 26 | "me.pepperbell.anycapes.config.ModMenuApiImpl" 27 | ] 28 | }, 29 | "mixins": [ 30 | "anycapes.mixins.json" 31 | ], 32 | 33 | "depends": { 34 | "fabricloader": ">=0.7.0", 35 | "minecraft": ">=1.15", 36 | "fabric": "*" 37 | }, 38 | "recommends": { 39 | "modmenu": "*", 40 | "cloth-config2": "*" 41 | } 42 | } 43 | --------------------------------------------------------------------------------