Skip to content

Commit

Permalink
Merge pull request #12 from 3arthqu4ke/jline
Browse files Browse the repository at this point in the history
Jline support, appender, completions, colors, Login Command
  • Loading branch information
3arthqu4ke authored Aug 13, 2024
2 parents 06176ff + 09cd068 commit 8610a40
Show file tree
Hide file tree
Showing 176 changed files with 4,057 additions and 1,641 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
matrix:
version:
- { dir: api, mc: api, lex: api, neo: api, java: 8 }
- { dir: 1_21, mc: 1.21.1, lex: 52.0.2, neo: 4, java: 21 }
- { dir: 1_21, mc: 1.21, lex: 51.0.24, neo: 96-beta, java: 21 }
- { dir: 1_20, mc: 1.20.6, lex: 50.1.10, neo: 119, java: 21 }
- { dir: 1_20, mc: 1.20.4, lex: 49.0.38, neo: 219, java: 17 }
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
matrix:
version:
- { dir: api, mc: api, lex: api, neo: api, java: 8 }
- { dir: 1_21, mc: 1.21.1, lex: 52.0.2, neo: 4, java: 21 }
- { dir: 1_21, mc: 1.21, lex: 51.0.24, neo: 96-beta, java: 21 }
- { dir: 1_20, mc: 1.20.6, lex: 50.1.10, neo: 119, java: 21 }
#- { dir: 1_20, mc: 1.20.4, lex: 49.0.38, neo: 219, java: 17 }
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/run-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
strategy:
matrix:
version:
- { dir: 1_21, mc: 1.21.1, type: lexforge, modloader: forge, regex: .*forge.*, java: 21 }
- { dir: 1_21, mc: 1.21.1, type: neoforge, modloader: neoforge, regex: .*neoforge.*, java: 21 }
- { dir: 1_21, mc: 1.21.1, type: fabric, modloader: fabric, regex: .*fabric.*, java: 21 }
- { dir: 1_21, mc: 1.21, type: lexforge, modloader: forge, regex: .*forge.*, java: 21 }
- { dir: 1_21, mc: 1.21, type: neoforge, modloader: neoforge, regex: .*neoforge.*, java: 21 }
- { dir: 1_21, mc: 1.21, type: fabric, modloader: fabric, regex: .*fabric.*, java: 21 }
Expand Down Expand Up @@ -69,9 +72,9 @@ jobs:
- name: List mod files
run: ls ${{ matrix.version.dir }}/build/libs
- name: Copy mod jar
run: cp ${{ matrix.version.dir }}/build/libs/hmc-specifics-${{ matrix.version.mc }}-*-${{ matrix.version.type }}-release.jar run/mods
run: cp ${{ matrix.version.dir }}/build/libs/hmc-specifics-*-${{ matrix.version.type }}-release.jar run/mods
- name: Run the MC client
uses: 3arthqu4ke/mc-runtime-test@2.2.0
uses: 3arthqu4ke/mc-runtime-test@2.3.1
with:
mc: ${{ matrix.version.mc }}
modloader: ${{ matrix.version.modloader }}
Expand Down
81 changes: 53 additions & 28 deletions 1_12/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.publish.maven.MavenPublication

plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
Expand All @@ -9,12 +8,13 @@ plugins {
}

group='me.earth.headlessmc'
version "$minecraft_version-${project(':api').project_version}"
version "${project(':hmc-specifics-api').project_version}"

base {
archivesName = 'hmc-specifics'
archivesName = "hmc-specifics-${minecraft_version}"
}


sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

Expand Down Expand Up @@ -47,6 +47,19 @@ repositories {
url 'https://3arthqu4ke.github.io/maven'
}

// TODO: REMOVE!
maven {
name = "ossrh" // for MinecraftAuth SNAPSHOTS, TODO: PLEASE RELEASE ON MAVENCENTRAL!
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}
maven {
name 'JitPackMaven'
url 'https://jitpack.io'
}
maven {
name 'SuperDirMaven'
url new File(layout.projectDirectory.asFile.getParent() + "/libs").toURI().toURL().toString()
}
mavenCentral()
}

Expand Down Expand Up @@ -98,13 +111,20 @@ sourceSets {
compileClasspath += configurations.mainImplementation
runtimeClasspath += configurations.mainImplementation
}

test {
compileClasspath += main.compileClasspath
runtimeClasspath += main.compileClasspath
}
}

dependencies {
implementation ('net.minecraft:launchwrapper:1.12') {
exclude module: 'log4j-api'
exclude module: 'log4j-core'
}

lexforgeRuntimeOnly 'com.github.ImpactDevelopment:SimpleTweaker:1.2'
jarLibs 'com.github.ImpactDevelopment:SimpleTweaker:1.2'
jarLibs('org.spongepowered:mixin:0.7.11-SNAPSHOT') {
exclude module: 'launchwrapper'
Expand All @@ -113,10 +133,10 @@ dependencies {
exclude module: 'commons-io'
}

jarLibs project(':api')
jarLibs 'me.earth.headlessmc:headlessmc-api:1.8.0'
jarLibs 'me.earth.headlessmc:headlessmc-commons:1.8.0'
jarLibs 'me.earth.headlessmc:headlessmc-runtime:1.8.0'
jarLibs project(':hmc-specifics-api')
jarLibs "me.earth.headlessmc:headlessmc-api:${project(':hmc-specifics-api').headlessmc_version}"
jarLibs "me.earth.headlessmc:headlessmc-jline:${project(':hmc-specifics-api').headlessmc_version}"
jarLibs "me.earth.headlessmc:headlessmc-runtime:${project(':hmc-specifics-api').headlessmc_version}"
}

for (String platform_capitalized : ['Fabric', 'Lexforge']) {
Expand Down Expand Up @@ -151,6 +171,7 @@ tasks.withType(org.gradle.jvm.tasks.Jar).configureEach {
attributes(
'Implementation-Title': 'HMC-Specifics',
'TweakClass': 'me.earth.headlessmc.mc.tweaker.HeadlessMcMcTweaker',
'MixinConnector': 'me.earth.headlessmc.mc.tweaker.HeadlessMcMixinConnector',
'MixinConfigs': "mixins.headlessmc.json",
'Implementation-Version': project.version,
)
Expand All @@ -177,13 +198,13 @@ processLexforgeResources {
}
}

afterEvaluate {
publishing {
publications {
"${name.toLowerCase()}"(MavenPublication) {
((MavenPublication) it).groupId "${group}"
((MavenPublication) it).artifactId "${archivesBaseName.toLowerCase()}"
((MavenPublication) it).version "${version}"
publishing {
publications {
"${name.toLowerCase()}"(MavenPublication) {
((MavenPublication) it).groupId "${group}"
((MavenPublication) it).artifactId "${archivesBaseName.toLowerCase()}"
((MavenPublication) it).version "${version}"
afterEvaluate {
from components.java
for (String platform: ['Fabric', 'Lexforge']) {
String platform_lower = platform.toLowerCase()
Expand All @@ -193,23 +214,27 @@ afterEvaluate {
}
}
}
}

repositories {
if (System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL') == null) {
maven {
name = 'BuildDirMaven'
url = rootProject.projectDir.toPath().parent.resolve('build').resolve('maven')
}
} else {
maven {
name = 'GithubPagesMaven'
url = System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL')
credentials {
username = System.getenv('GITHUB_USER')
password = System.getenv('GITHUB_TOKEN')
}
repositories {
if (System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL') == null) {
maven {
name = 'BuildDirMaven'
url = layout.buildDirectory.dir('maven')
}
} else {
maven {
name = 'GithubPagesMaven'
url = System.getenv('DEPLOY_TO_GITHUB_PACKAGES_URL')
credentials {
username = System.getenv('GITHUB_USER')
password = System.getenv('GITHUB_TOKEN')
}
}
}
}
}

publish {
dependsOn build
}
6 changes: 3 additions & 3 deletions 1_12/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pluginManagement {
}
}

include 'api'
project(':api').projectDir = file('../api')
include 'hmc-specifics-api'
project(':hmc-specifics-api').projectDir = file('../hmc-specifics-api')

rootProject.name = 'hmc-specifics'
rootProject.name = "hmc-specifics-${minecraft_version}"
30 changes: 0 additions & 30 deletions 1_12/src/main/java/me/earth/headlessmc/mc/FontRendererImpl.java

This file was deleted.

50 changes: 10 additions & 40 deletions 1_12/src/main/java/me/earth/headlessmc/mc/Initializer.java
Original file line number Diff line number Diff line change
@@ -1,54 +1,24 @@
package me.earth.headlessmc.mc;

import me.earth.headlessmc.command.line.CommandLineImpl;
import me.earth.headlessmc.config.ConfigImpl;
import me.earth.headlessmc.logging.LoggingHandler;
import me.earth.headlessmc.mc.commands.MinecraftContext;
import me.earth.headlessmc.runtime.Runtime;
import me.earth.headlessmc.runtime.RuntimeApi;
import me.earth.headlessmc.api.config.ConfigImpl;
import me.earth.headlessmc.mc.mixins.IBootstrap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.io.PrintStream;

public class Initializer {
private static final Logger LOGGER = LogManager.getLogger(Initializer.class);

public static void init(Minecraft mc) throws IOException {
LoggingHandler.apply();
LOGGER.info("Loading HeadlessMc Runtime!");
CommandLineImpl commandLine = new CommandLineImpl();
if (RuntimeApi.getRuntime() != null) {
// TODO: Compatibility CommandContext which allows you to specify
// in which context to execute the command.
throw new IllegalStateException(
"RuntimeApi has already been initialized!");
public static void init(Minecraft mc) {
LOGGER.info("Loading HMC-Specifics!");
if (System.out.getClass().getName().startsWith(PrintStream.class.getName())) {
LOGGER.info("System Streams have not been replaced, wrapping Streams");
IBootstrap.invokeRedirectOutputToLog();
}

Runtime runtime = RuntimeApi.init(ConfigImpl.empty(), commandLine);
reflectiveRuntimeCheck(runtime);
runtime.setCommandContext(new MinecraftContext(runtime, mc));
commandLine.listenAsync(runtime);
}

private static void reflectiveRuntimeCheck(Runtime runtime) {
try {
Class<?> clazz = Class.forName(RuntimeApi.class.getName(), false,
ClassLoader.getSystemClassLoader());
Method method = clazz.getMethod("getRuntime");
method.setAccessible(true);
Object alreadyLoaded = method.invoke(null);
if (alreadyLoaded != null && !runtime.equals(alreadyLoaded)) {
throw new IllegalStateException(
"RuntimeApi has already been loaded by!");
}
} catch (ClassNotFoundException
| NoSuchMethodException
| IllegalAccessException
| InvocationTargetException ignored) {
}
SpecificsInitializer initializer = new SpecificsInitializer(mc);
initializer.init(ConfigImpl.empty());
}

}
14 changes: 14 additions & 0 deletions 1_12/src/main/java/me/earth/headlessmc/mc/mixins/IBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.earth.headlessmc.mc.mixins;

import net.minecraft.init.Bootstrap;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(Bootstrap.class)
public interface IBootstrap {
@Invoker("redirectOutputToLog")
static void invokeRedirectOutputToLog() {
throw new RuntimeException("IBootstrap.redirectOutputToLog has not been mixed in!");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.earth.headlessmc.mc.mixins;

import me.earth.headlessmc.mc.adventure.AdventureHelper;
import me.earth.headlessmc.mc.adventure.AdventureWrapper;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(GuiNewChat.class)
public class MixinGuiNewChat {
@Shadow
@Final
private static Logger LOGGER;

@Unique
private boolean hmc_adventureHelperInitialized = false;
@Unique
private AdventureHelper hmc_adventureHelper;

@Inject(method = "printChatMessageWithOptionalDeletion",
at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V"), cancellable = true)
private void logChatMessageHook(ITextComponent content, int id, CallbackInfo ci) {
if (AdventureWrapper.ENABLED) {
String ansiString = null;
try {
if (!hmc_adventureHelperInitialized) {
hmc_adventureHelper = AdventureWrapper.getAdventureHelper(I18n::hasKey, (s, def) -> I18n.format(s));
hmc_adventureHelperInitialized = true;
}

if (hmc_adventureHelper != null) {
// OK FOR SOME REASON IT DOESNT WORK IN 1.12.2????????? Potentially due to JLine?
// I have no clue but I do not care for legacy enough rn
ansiString = hmc_adventureHelper.toAnsiStringLegacy(content.getFormattedText());
}
} catch (Exception e) {
if (AdventureWrapper.OUTPUT_THROWABLES) {
LOGGER.error("Failed to serialize {}", content.getUnformattedText(), e);
}
}

if (ansiString != null) {
LOGGER.info("[CHAT] {}", ansiString);
ci.cancel();
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.earth.headlessmc.mc.mixins;

import me.earth.headlessmc.api.util.ReflectionUtil;
import me.earth.headlessmc.mc.gui.GuiButton;
import me.earth.headlessmc.mc.gui.GuiScreen;
import me.earth.headlessmc.mc.gui.TextField;
import me.earth.headlessmc.util.ReflectionUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.gen.Invoker;
Expand Down
Loading

0 comments on commit 8610a40

Please sign in to comment.