mirror of
https://github.com/chylex/Minecraft-Window-Title.git
synced 2025-05-07 19:34:04 +02:00
Backport to 1.8 - 1.12
This commit is contained in:
parent
bba8a16afb
commit
cc06491313
Forge
@ -2,26 +2,20 @@ buildscript{
|
||||
repositories{
|
||||
maven{ url = 'https://files.minecraftforge.net/maven' }
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
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: 'eclipse'
|
||||
apply plugin: 'net.minecraftforge.gradle.forge'
|
||||
|
||||
def mcversion = "1.15.2"
|
||||
def forgeversion = "31.0.14"
|
||||
def mcversion = "1.12.2"
|
||||
def forgeversion = "14.23.5.2847"
|
||||
|
||||
def prefixName = 'displayName = '
|
||||
def prefixVersion = 'version = '
|
||||
|
||||
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]
|
||||
def metaName = "Custom Window Title"
|
||||
def metaVersion = "1.0.0"
|
||||
|
||||
group = 'chylex.customwindowtitle.forge'
|
||||
version = metaVersion
|
||||
@ -30,53 +24,16 @@ archivesBaseName = metaName.replaceAll('\\s', '')
|
||||
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
|
||||
|
||||
minecraft{
|
||||
mappings channel: 'snapshot', version: '20200130-1.15.1'
|
||||
|
||||
runs{
|
||||
client{
|
||||
workingDirectory file('run')
|
||||
|
||||
mods{
|
||||
customwindowtitle{
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
server{
|
||||
workingDirectory file('run')
|
||||
|
||||
mods{
|
||||
customwindowtitle{
|
||||
source sourceSets.main
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies{
|
||||
minecraft 'net.minecraftforge:forge:' + mcversion + '-' + forgeversion
|
||||
version = mcversion + '-' + forgeversion
|
||||
runDir = "run"
|
||||
mappings = "snapshot_20180814"
|
||||
makeObfSourceJar = false
|
||||
}
|
||||
|
||||
jar{
|
||||
archiveName = archivesBaseName + '-' + mcversion + '-v' + version + '.jar'
|
||||
archiveName = archivesBaseName + '-Legacy-v' + version + '.jar'
|
||||
|
||||
from('../'){
|
||||
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;
|
||||
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.config.ModConfig.Type;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
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{
|
||||
private final ConfigValue<String> configTitle;
|
||||
private static final String defaultTitle = "Minecraft {mcversion}";
|
||||
private String configTitle;
|
||||
|
||||
public CustomWindowTitle(){
|
||||
ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder();
|
||||
@EventHandler
|
||||
public void onPreInit(FMLPreInitializationEvent e){
|
||||
Path configFile = Paths.get(e.getModConfigurationDirectory().getAbsolutePath(), "customwindowtitle-client.toml");
|
||||
|
||||
configTitle = configBuilder.define("title", "Minecraft {mcversion}");
|
||||
|
||||
ModLoadingContext.get().registerConfig(Type.CLIENT, configBuilder.build());
|
||||
FMLJavaModLoadingContext.get().getModEventBus().register(this);
|
||||
try{
|
||||
String prefix = "title = ";
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientSetup(FMLClientSetupEvent e){
|
||||
e.getMinecraftSupplier().get().execute(this::updateTitle);
|
||||
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;
|
||||
import chylex.customwindowtitle.TokenException;
|
||||
import net.minecraft.util.SharedConstants;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import net.minecraftforge.fml.loading.moddiscovery.ModFileInfo;
|
||||
import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import net.minecraft.realms.RealmsSharedConstants;
|
||||
import net.minecraftforge.fml.common.Loader;
|
||||
import net.minecraftforge.fml.common.ModContainer;
|
||||
import static chylex.customwindowtitle.TitleTokens.noArgs;
|
||||
import static chylex.customwindowtitle.TitleTokens.oneArg;
|
||||
import static chylex.customwindowtitle.TitleTokens.registerToken;
|
||||
@ -15,22 +14,16 @@ final class TokenData{
|
||||
}
|
||||
|
||||
static String getMinecraftVersion(){
|
||||
return SharedConstants.getVersion().getName();
|
||||
return RealmsSharedConstants.VERSION_STRING;
|
||||
}
|
||||
|
||||
static String getModVersion(String modId){
|
||||
ModFileInfo file = ModList.get().getModFileById(modId);
|
||||
ModContainer mod = Loader.instance().getIndexedModList().get(modId);
|
||||
|
||||
if (file == null){
|
||||
throw new TokenException("mod file for '" + modId + "' not found");
|
||||
if (mod == null){
|
||||
throw new TokenException("mod info for '" + modId + "' not found");
|
||||
}
|
||||
|
||||
for(IModInfo info : file.getMods()){
|
||||
if (info.getModId().equals(modId)){
|
||||
return info.getVersion().toString();
|
||||
}
|
||||
}
|
||||
|
||||
throw new TokenException("mod info for '" + modId + "' not found");
|
||||
return mod.getMetadata().version;
|
||||
}
|
||||
}
|
||||
|
@ -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": {
|
||||
"description": "Custom Window Title",
|
||||
"pack_format": 5,
|
||||
"pack_format": 3,
|
||||
"_comment": ""
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user