Browse Source

Push files

master
Martmists 3 months ago
commit
ae89bf1606
20 changed files with 846 additions and 0 deletions
  1. +4
    -0
      .gitignore
  2. +7
    -0
      LICENSE
  3. +74
    -0
      build.gradle
  4. +14
    -0
      gradle.properties
  5. BIN
      gradle/wrapper/gradle-wrapper.jar
  6. +6
    -0
      gradle/wrapper/gradle-wrapper.properties
  7. +172
    -0
      gradlew
  8. +84
    -0
      gradlew.bat
  9. +16
    -0
      settings.gradle
  10. +24
    -0
      src/main/java/com/martmists/customtitlescreen/CustomTitleScreenMod.java
  11. +12
    -0
      src/main/java/com/martmists/customtitlescreen/buttons/LanguagesButton.java
  12. +10
    -0
      src/main/java/com/martmists/customtitlescreen/buttons/UrlButton.java
  13. +10
    -0
      src/main/java/com/martmists/customtitlescreen/config/ButtonConfig.java
  14. +13
    -0
      src/main/java/com/martmists/customtitlescreen/config/CTSConfig.java
  15. +17
    -0
      src/main/java/com/martmists/customtitlescreen/config/SingleButtonConfig.java
  16. +157
    -0
      src/main/java/com/martmists/customtitlescreen/mixin/AbstractButtonWidgetMixin.java
  17. +182
    -0
      src/main/java/com/martmists/customtitlescreen/mixin/TitleScreenMixin.java
  18. BIN
      src/main/resources/assets/customtitlescreen/textures/blank.png
  19. +14
    -0
      src/main/resources/cts.mixin.json
  20. +30
    -0
      src/main/resources/fabric.mod.json

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
build/
run/
.gradle/
.idea/

+ 7
- 0
LICENSE View File

@@ -0,0 +1,7 @@
Copyright 2019 Martmists

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 74
- 0
build.gradle View File

@@ -0,0 +1,74 @@
buildscript {
ext.kotlin_version = '1.3.61'
ext.kotlin_version_old = '1.3.60'

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
repositories {
mavenCentral()
jcenter()
}
}

plugins {
id 'fabric-loom' version '0.2.6-SNAPSHOT'
}

apply plugin: "kotlin"
apply plugin: "idea"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

archivesBaseName = project.archives_base_name
version = project.mod_version
group = project.maven_group

configurations {
compileAndInclude {
extendsFrom compile
extendsFrom include
}
}

dependencies {
// Base dependencies
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.api_version}" // Used for loading textures
modImplementation "io.github.cottonmc.cotton:cotton-config:1.0.0-rc.4" // Used for configs
}

processResources {
inputs.property "version", project.version

from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}

from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

jar {
from "LICENSE"
}

repositories {
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/kotlin/exposed"
}
maven {
url 'http://server.bbkr.space:8081/artifactory/libs-release'
}
}

+ 14
- 0
gradle.properties View File

@@ -0,0 +1,14 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx4G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.15-pre6
yarn_mappings=1.15-pre6+build.1
loader_version=0.7.2+build.174
api_version=0.4.20+build.273-1.15

# Mod Properties
mod_version = 1.15-0.0.1
maven_group = com.martmists
archives_base_name = customtitlescreen

BIN
gradle/wrapper/gradle-wrapper.jar View File


+ 6
- 0
gradle/wrapper/gradle-wrapper.properties View File

@@ -0,0 +1,6 @@
#Tue Dec 03 23:35:40 CET 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

+ 172
- 0
gradlew View File

@@ -0,0 +1,172 @@
#!/usr/bin/env sh

##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################

# 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\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null

APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"'

# 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
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar

# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi

# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "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

# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"

+ 84
- 0
gradlew.bat View File

@@ -0,0 +1,84 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m"
@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 Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_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=%*
: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

+ 16
- 0
settings.gradle View File

@@ -0,0 +1,16 @@
pluginManagement {
repositories {
jcenter()
mavenCentral()
maven {
url 'https://maven.fabricmc.net/'
}
maven {
url = "https://dl.bintray.com/kotlin/exposed"
}
gradlePluginPortal()
}
}


rootProject.name = 'customtitlescreen'

+ 24
- 0
src/main/java/com/martmists/customtitlescreen/CustomTitleScreenMod.java View File

@@ -0,0 +1,24 @@
package com.martmists.customtitlescreen;

import com.martmists.customtitlescreen.config.ButtonConfig;
import com.martmists.customtitlescreen.config.CTSConfig;
import io.github.cottonmc.cotton.config.ConfigManager;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.gui.widget.AbstractButtonWidget;

import java.util.IdentityHashMap;

public class CustomTitleScreenMod implements ClientModInitializer {
public static CTSConfig config;
public static ButtonConfig buttonConfig;
public static int screenWidth;
public static int screenHeight;
public static IdentityHashMap<AbstractButtonWidget, String> buttonCache = new IdentityHashMap<>();

@Override
public void onInitializeClient() {
config = ConfigManager.loadConfig(CTSConfig.class);
buttonConfig = ConfigManager.loadConfig(ButtonConfig.class);
System.out.println("CustomMainMenu initialized!");
}
}

+ 12
- 0
src/main/java/com/martmists/customtitlescreen/buttons/LanguagesButton.java View File

@@ -0,0 +1,12 @@
package com.martmists.customtitlescreen.buttons;

import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TexturedButtonWidget;

public class LanguagesButton extends ButtonWidget {
public LanguagesButton(TexturedButtonWidget btn, int x, int y, int width, int height, String text) {
super(x, y, width, height, text, (p)->btn.onPress());
btn.visible = false;
btn.active = false;
}
}

+ 10
- 0
src/main/java/com/martmists/customtitlescreen/buttons/UrlButton.java View File

@@ -0,0 +1,10 @@
package com.martmists.customtitlescreen.buttons;

import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.util.Util;

public class UrlButton extends ButtonWidget {
public UrlButton(int i, int j, int k, int l, String string, String url) {
super(i, j, k, l, string, (bw)-> Util.getOperatingSystem().open(url));
}
}

+ 10
- 0
src/main/java/com/martmists/customtitlescreen/config/ButtonConfig.java View File

@@ -0,0 +1,10 @@
package com.martmists.customtitlescreen.config;

import io.github.cottonmc.cotton.config.annotations.ConfigFile;

import java.util.HashMap;

@ConfigFile(name = "cts/buttons")
public class ButtonConfig {
public HashMap<String, SingleButtonConfig> buttons = new HashMap<>();
}

+ 13
- 0
src/main/java/com/martmists/customtitlescreen/config/CTSConfig.java View File

@@ -0,0 +1,13 @@
package com.martmists.customtitlescreen.config;

import io.github.cottonmc.cotton.config.annotations.ConfigFile;

@ConfigFile(name = "cts/config")
public class CTSConfig {
public boolean customEditionEnabled = false;
public String customEdition = "";
public boolean customSplashEnabled = false;
public boolean removeSplash = false;
public String[] customSplash = new String[0];
public boolean removeMinecraftLogo = false;
}

+ 17
- 0
src/main/java/com/martmists/customtitlescreen/config/SingleButtonConfig.java View File

@@ -0,0 +1,17 @@
package com.martmists.customtitlescreen.config;

import blue.endless.jankson.Comment;

public class SingleButtonConfig {
@Comment("X offset from center")
public int x = 0;
@Comment("Y offset from top")
public int y = 0;
public int width = 0;
public int height = 0;
public String text = "<default>";
public String type = "override";
public String parameter = "";
@Comment("Not currently implemented")
public String textureName = "";
}

+ 157
- 0
src/main/java/com/martmists/customtitlescreen/mixin/AbstractButtonWidgetMixin.java View File

@@ -0,0 +1,157 @@
package com.martmists.customtitlescreen.mixin;

import com.martmists.customtitlescreen.CustomTitleScreenMod;
import com.martmists.customtitlescreen.config.SingleButtonConfig;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@Mixin(AbstractButtonWidget.class)
public class AbstractButtonWidgetMixin {
@Shadow
int x;
@Shadow
int y;
@Shadow
int width;
@Shadow
int height;
@Shadow
String message;

@ModifyArg(
method="renderButton(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V",
ordinal = 0
),
index=0)
public Identifier modifyButtons(Identifier id) throws IOException {
File f = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("cmm/buttons.png").toFile();
if (f.exists()) {
TextureManager t = MinecraftClient.getInstance().getTextureManager();
if (!(t.getTexture(id) instanceof NativeImageBackedTexture)) {
t.registerTexture(id,
new NativeImageBackedTexture(NativeImage.read(new FileInputStream(f)))
);
}
}
return id;
}

@Inject(method="<init>(IIIILjava/lang/String;)V",
at=@At(value="RETURN"))
public void getX(int x, int y, int width, int height, String message, CallbackInfo ci){
int i = CustomTitleScreenMod.screenWidth / 2 - 100;
int j = CustomTitleScreenMod.screenHeight / 4 + 48;
int xScale = 12;
int yScale = 24;

if (CustomTitleScreenMod.buttonCache.containsKey(this)){
this.x = CustomTitleScreenMod.screenWidth / 2 + this.x;
this.y = CustomTitleScreenMod.screenHeight / 4 + 48 + this.y;
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get(CustomTitleScreenMod.buttonCache.get(this));
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (x == i) {
if (y == j) {
// Singleplayer
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.singleplayer");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (y == j+yScale) {
// Multiplayer
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.multiplayer");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (y == j+yScale*2) {
// Realms
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.realms");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (y == j+yScale*3) {
// Mod menu
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("modmenu.modlist");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (y == j+yScale*3.5) {
// Options
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.options");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
}
} else if (y == j+yScale*3.5) {
if (x == i - 2*xScale) {
// Language
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.language");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (x == i + xScale*8.5) {
// Quit
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.quit");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
} else if (x == i + xScale*17) {
// Accessibility
SingleButtonConfig config = CustomTitleScreenMod.buttonConfig.buttons.get("minecraft.accessibility");
if (config == null) return;
this.x = CustomTitleScreenMod.screenWidth / 2 + config.x;
this.y = j + config.y;
this.width = config.width;
this.height = config.height;
if (!config.text.equals("<default>"))
this.message = config.text;
}
}
}
}

+ 182
- 0
src/main/java/com/martmists/customtitlescreen/mixin/TitleScreenMixin.java View File

@@ -0,0 +1,182 @@
package com.martmists.customtitlescreen.mixin;

import com.martmists.customtitlescreen.CustomTitleScreenMod;
import com.martmists.customtitlescreen.buttons.LanguagesButton;
import com.martmists.customtitlescreen.config.SingleButtonConfig;
import com.martmists.customtitlescreen.buttons.UrlButton;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.widget.TexturedButtonWidget;
import net.minecraft.client.texture.NativeImage;
import net.minecraft.client.texture.NativeImageBackedTexture;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.io.*;
import java.util.Random;

@Mixin(TitleScreen.class)
class TitleScreenMixin extends Screen {
protected TitleScreenMixin(Text text) {
super(text);
}

@ModifyArg(
method="render(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/gui/screen/TitleScreen;drawString(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;III)V",
ordinal = 0
),
index=1)
public String modifyEdition(TextRenderer textRenderer, String version, int x, int y, int color){
if (CustomTitleScreenMod.config.customEditionEnabled) {
this.drawString(textRenderer, CustomTitleScreenMod.config.customEdition, x, y-10, color);
}
return version;
}

@ModifyArg(
method="render(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/gui/screen/TitleScreen;drawCenteredString(Lnet/minecraft/client/font/TextRenderer;Ljava/lang/String;III)V",
ordinal = 0
),
index=1)
public String modifySplash(String splash){
if (CustomTitleScreenMod.config.removeSplash)
return "";
String[] splashes = CustomTitleScreenMod.config.customSplash;
if (CustomTitleScreenMod.config.customSplashEnabled && splashes.length > 0) {
Random r = new Random();
r.setSeed(splash.length() + splash.codePointAt(0));
return splashes[r.nextInt(splashes.length)];
} else {
return splash;
}
}

@Inject(method="init()V", at=@At("HEAD"))
public void postInit(CallbackInfo ci){
CustomTitleScreenMod.screenWidth = width;
CustomTitleScreenMod.screenHeight = height;
}
@Override
public void setSize(int a, int b){
super.setSize(a, b);
CustomTitleScreenMod.screenWidth = width;
CustomTitleScreenMod.screenHeight = height;
}

@Inject(method="init()V", at=@At("RETURN"))
public void renderCustomButtons(CallbackInfo ci){
CustomTitleScreenMod.buttonConfig.buttons.forEach((String key, SingleButtonConfig value) ->{
switch (value.type) {
case "modify": {
break;
}
case "modifyTextured": {
// Hardcoded for Languages right now
int index;
switch (key) {
case "minecraft.language": {
index = 3;
break;
}
case "minecraft.accessibility": {
index = 5;
}
default: {
index = 0;
}
}

if (!(this.buttons.get(3) instanceof TexturedButtonWidget)){
index += 1;
}
TexturedButtonWidget old = (TexturedButtonWidget) this.buttons.get(index);
LanguagesButton button = new LanguagesButton(old, CustomTitleScreenMod.screenWidth / 2 + value.x, CustomTitleScreenMod.screenHeight / 4 + 48 + value.y, value.width, value.height, value.text);
this.buttons.remove(index);
this.children.remove(index);
this.addButton(button);
CustomTitleScreenMod.buttonCache.put(button, key);
break;
}
case "url": {
UrlButton button = new UrlButton(CustomTitleScreenMod.screenWidth / 2 + value.x, CustomTitleScreenMod.screenHeight / 4 + 48 + value.y, value.width, value.height, value.text, value.parameter);
this.addButton(button);
CustomTitleScreenMod.buttonCache.put(button, key);
break;
}
default: {
System.out.println("[CMM] Error: Unknown button type: " + value.type);
}
}
});
}

@ModifyArg(
method="render(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V",
ordinal = 0
),
index=0)
public Identifier modifyBackground(Identifier id) throws IOException {
// We use ModifyArg since I couldn't find a different way to inject at this method call
// while having access to the Identifier to register a custom texture.

File f = FabricLoader.getInstance().getConfigDirectory().toPath().resolve("cts/background.png").toFile();
if (f.exists()) {
TextureManager t = this.minecraft.getTextureManager();
if (!(t.getTexture(id) instanceof NativeImageBackedTexture)) {
t.registerTexture(id,
new NativeImageBackedTexture(NativeImage.read(new FileInputStream(f)))
);
}
}
return id;
}

@ModifyArg(
method="render(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V",
ordinal = 1
),
index=0)
public Identifier modifyTitle(Identifier id) {
if (CustomTitleScreenMod.config.removeMinecraftLogo) {
return new Identifier("customtitlescreen:textures/blank.png");
} else {
return id;
}
}

@ModifyArg(
method="render(IIF)V",
at=@At(
value="INVOKE",
target="Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V",
ordinal = 2
),
index=0)
public Identifier modifySubtitle(Identifier id) {
if (CustomTitleScreenMod.config.removeMinecraftLogo) {
return new Identifier("customtitlescreen:textures/blank.png");
} else {
return id;
}
}
}

BIN
src/main/resources/assets/customtitlescreen/textures/blank.png View File

Before After
Width: 250  |  Height: 250  |  Size: 5.5KB

+ 14
- 0
src/main/resources/cts.mixin.json View File

@@ -0,0 +1,14 @@
{
"required": true,
"package": "com.martmists.customtitlescreen.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"TitleScreenMixin",
"AbstractButtonWidgetMixin"
],
"server": [
],
"injectors": {
"defaultRequire": 1
}
}

+ 30
- 0
src/main/resources/fabric.mod.json View File

@@ -0,0 +1,30 @@
{
"schemaVersion": 1,
"id": "customtitlescreen",
"version": "${version}",
"name": "CustomTitleScreen",
"description": "Allows you to customize the main menu",
"authors": [
"Martmists"
],
"contact": {
"sources": "https://dilaton.martmists.com/martmists/custommainmenu"
},
"license": "MIT",
"icon": "assets/cts/icon.png",
"environment": "client",
"entrypoints": {
"client": [
{
"value": "com.martmists.customtitlescreen.CustomTitleScreenMod"
}
]
},
"mixins": [
"cts.mixin.json"
],
"depends": {
"fabricloader": ">=0.4.0",
"cotton-config": "*"
}
}

Loading…
Cancel
Save