mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2025-05-23 03:34:03 +02:00
Backport to 1.8 - 1.12
This commit is contained in:
parent
bba8a16afb
commit
cc06491313
Forge
@ -2,26 +2,20 @@ buildscript{
|
|||||||
repositories{
|
repositories{
|
||||||
maven{ url = 'https://files.minecraftforge.net/maven' }
|
maven{ url = 'https://files.minecraftforge.net/maven' }
|
||||||
jcenter()
|
jcenter()
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies{
|
dependencies{
|
||||||
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
|
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'net.minecraftforge.gradle'
|
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||||
apply plugin: 'eclipse'
|
|
||||||
|
|
||||||
def mcversion = "1.15.2"
|
def mcversion = "1.12.2"
|
||||||
def forgeversion = "31.0.14"
|
def forgeversion = "14.23.5.2847"
|
||||||
|
|
||||||
def prefixName = 'displayName = '
|
def metaName = "Custom Window Title"
|
||||||
def prefixVersion = 'version = '
|
def metaVersion = "1.0.0"
|
||||||
|
|
||||||
def metaLines = file('src/main/resources/META-INF/mods.toml').readLines()
|
|
||||||
def metaName = metaLines.find { line -> line.startsWith(prefixName) }.substring(prefixName.length())[1..-2]
|
|
||||||
def metaVersion = metaLines.find { line -> line.startsWith(prefixVersion) }.substring(prefixVersion.length())[1..-2]
|
|
||||||
|
|
||||||
group = 'chylex.customwindowtitle.forge'
|
group = 'chylex.customwindowtitle.forge'
|
||||||
version = metaVersion
|
version = metaVersion
|
||||||
@ -30,53 +24,16 @@ archivesBaseName = metaName.replaceAll('\\s', '')
|
|||||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||||
|
|
||||||
minecraft{
|
minecraft{
|
||||||
mappings channel: 'snapshot', version: '20200130-1.15.1'
|
version = mcversion + '-' + forgeversion
|
||||||
|
runDir = "run"
|
||||||
runs{
|
mappings = "snapshot_20180814"
|
||||||
client{
|
makeObfSourceJar = false
|
||||||
workingDirectory file('run')
|
|
||||||
|
|
||||||
mods{
|
|
||||||
customwindowtitle{
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server{
|
|
||||||
workingDirectory file('run')
|
|
||||||
|
|
||||||
mods{
|
|
||||||
customwindowtitle{
|
|
||||||
source sourceSets.main
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies{
|
|
||||||
minecraft 'net.minecraftforge:forge:' + mcversion + '-' + forgeversion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar{
|
jar{
|
||||||
archiveName = archivesBaseName + '-' + mcversion + '-v' + version + '.jar'
|
archiveName = archivesBaseName + '-Legacy-v' + version + '.jar'
|
||||||
|
|
||||||
from('../'){
|
from('../'){
|
||||||
include 'LICENSE'
|
include 'LICENSE'
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest{
|
|
||||||
attributes([
|
|
||||||
'Specification-Title' : 'customwindowtitle',
|
|
||||||
'Specification-Version': '1',
|
|
||||||
'Specification-Vendor' : 'chylex',
|
|
||||||
|
|
||||||
'Implementation-Title' : metaName,
|
|
||||||
'Implementation-Version': metaVersion,
|
|
||||||
'Implementation-Vendor' : 'chylex',
|
|
||||||
|
|
||||||
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
|
|
||||||
])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,51 @@
|
|||||||
package chylex.customwindowtitle.forge;
|
package chylex.customwindowtitle.forge;
|
||||||
import chylex.customwindowtitle.TitleParser;
|
import chylex.customwindowtitle.TitleParser;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;
|
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.ModLoadingContext;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.config.ModConfig.Type;
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.lwjgl.opengl.Display;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@Mod("customwindowtitle")
|
@Mod(modid = "customwindowtitle", useMetadata = true, clientSideOnly = true, acceptedMinecraftVersions = "*", acceptableRemoteVersions = "*")
|
||||||
public class CustomWindowTitle{
|
public class CustomWindowTitle{
|
||||||
private final ConfigValue<String> configTitle;
|
private static final String defaultTitle = "Minecraft {mcversion}";
|
||||||
|
private String configTitle;
|
||||||
|
|
||||||
public CustomWindowTitle(){
|
@EventHandler
|
||||||
ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder();
|
public void onPreInit(FMLPreInitializationEvent e){
|
||||||
|
Path configFile = Paths.get(e.getModConfigurationDirectory().getAbsolutePath(), "customwindowtitle-client.toml");
|
||||||
|
|
||||||
configTitle = configBuilder.define("title", "Minecraft {mcversion}");
|
try{
|
||||||
|
String prefix = "title = ";
|
||||||
ModLoadingContext.get().registerConfig(Type.CLIENT, configBuilder.build());
|
|
||||||
FMLJavaModLoadingContext.get().getModEventBus().register(this);
|
if (!Files.exists(configFile)){
|
||||||
|
Files.write(configFile, Collections.singletonList(prefix + '"' + defaultTitle + '"'), StandardCharsets.UTF_8);
|
||||||
|
configTitle = defaultTitle;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
configTitle = Files
|
||||||
|
.readAllLines(configFile, StandardCharsets.UTF_8)
|
||||||
|
.stream()
|
||||||
|
.filter(line -> line.startsWith(prefix))
|
||||||
|
.map(line -> StringUtils.strip(StringUtils.removeStart(line, prefix).trim(), "\""))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(defaultTitle);
|
||||||
|
}
|
||||||
|
}catch(IOException ex){
|
||||||
|
throw new RuntimeException("CustomWindowTitle configuration error", ex);
|
||||||
|
}
|
||||||
|
|
||||||
TokenData.register();
|
TokenData.register();
|
||||||
}
|
updateTitle();
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onClientSetup(FMLClientSetupEvent e){
|
|
||||||
e.getMinecraftSupplier().get().execute(this::updateTitle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTitle(){
|
private void updateTitle(){
|
||||||
Minecraft.getInstance().getMainWindow().func_230148_b_(TitleParser.parse(configTitle.get()));
|
Display.setTitle(TitleParser.parse(configTitle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package chylex.customwindowtitle.forge;
|
package chylex.customwindowtitle.forge;
|
||||||
import chylex.customwindowtitle.TokenException;
|
import chylex.customwindowtitle.TokenException;
|
||||||
import net.minecraft.util.SharedConstants;
|
import net.minecraft.realms.RealmsSharedConstants;
|
||||||
import net.minecraftforge.fml.ModList;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
|
import net.minecraftforge.fml.common.ModContainer;
|
||||||
import net.minecraftforge.forgespi.language.IModInfo;
|
|
||||||
import static chylex.customwindowtitle.TitleTokens.noArgs;
|
import static chylex.customwindowtitle.TitleTokens.noArgs;
|
||||||
import static chylex.customwindowtitle.TitleTokens.oneArg;
|
import static chylex.customwindowtitle.TitleTokens.oneArg;
|
||||||
import static chylex.customwindowtitle.TitleTokens.registerToken;
|
import static chylex.customwindowtitle.TitleTokens.registerToken;
|
||||||
@ -15,22 +14,16 @@ final class TokenData{
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String getMinecraftVersion(){
|
static String getMinecraftVersion(){
|
||||||
return SharedConstants.getVersion().getName();
|
return RealmsSharedConstants.VERSION_STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getModVersion(String modId){
|
static String getModVersion(String modId){
|
||||||
ModFileInfo file = ModList.get().getModFileById(modId);
|
ModContainer mod = Loader.instance().getIndexedModList().get(modId);
|
||||||
|
|
||||||
if (file == null){
|
if (mod == null){
|
||||||
throw new TokenException("mod file for '" + modId + "' not found");
|
throw new TokenException("mod info for '" + modId + "' not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
for(IModInfo info : file.getMods()){
|
return mod.getMetadata().version;
|
||||||
if (info.getModId().equals(modId)){
|
|
||||||
return info.getVersion().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new TokenException("mod info for '" + modId + "' not found");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"CustomWindowTitle": "coremods/main.js"
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
modLoader = "javafml"
|
|
||||||
loaderVersion = "[31,)"
|
|
||||||
|
|
||||||
authors = "chylex"
|
|
||||||
issueTrackerURL = "https://github.com/chylex/Minecraft-Window-Title/issues"
|
|
||||||
|
|
||||||
[[mods]]
|
|
||||||
modId = "customwindowtitle"
|
|
||||||
version = "1.0.0"
|
|
||||||
displayName = "Custom Window Title"
|
|
||||||
displayURL = "https://github.com/chylex/Minecraft-Window-Title"
|
|
||||||
|
|
||||||
[[dependencies.customwindowtitle]]
|
|
||||||
modId = "minecraft"
|
|
||||||
mandatory = true
|
|
||||||
versionRange = "[1.15.2,)"
|
|
||||||
ordering = "NONE"
|
|
||||||
side = "CLIENT"
|
|
||||||
|
|
||||||
[[dependencies.customwindowtitle]]
|
|
||||||
modId = "forge"
|
|
||||||
mandatory = true
|
|
||||||
versionRange = "[31,)"
|
|
||||||
ordering = "NONE"
|
|
||||||
side = "CLIENT"
|
|
@ -1,19 +0,0 @@
|
|||||||
function initializeCoreMod(){
|
|
||||||
var opcodes = Java.type("org.objectweb.asm.Opcodes");
|
|
||||||
var InsnNode = Java.type("org.objectweb.asm.tree.InsnNode");
|
|
||||||
|
|
||||||
return {
|
|
||||||
"CustomWindowTitle": {
|
|
||||||
"target": {
|
|
||||||
"type": "METHOD",
|
|
||||||
"class": "net.minecraft.client.Minecraft",
|
|
||||||
"methodName": "func_230150_b_",
|
|
||||||
"methodDesc": "()V"
|
|
||||||
},
|
|
||||||
"transformer": function(methodNode){
|
|
||||||
methodNode.instructions.insert(new InsnNode(opcodes.RETURN));
|
|
||||||
return methodNode;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
10
Forge/src/main/resources/mcmod.info
Normal file
10
Forge/src/main/resources/mcmod.info
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"modid": "customwindowtitle",
|
||||||
|
"name": "Custom Window Title",
|
||||||
|
"description": "",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"url": "https://github.com/chylex/Minecraft-Window-Title",
|
||||||
|
"authorList": ["chylex"]
|
||||||
|
}
|
||||||
|
]
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"pack": {
|
"pack": {
|
||||||
"description": "Custom Window Title",
|
"description": "Custom Window Title",
|
||||||
"pack_format": 5,
|
"pack_format": 3,
|
||||||
"_comment": ""
|
"_comment": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user