-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from 3arthqu4ke/jline
Jline support, appender, completions, colors, Login Command
- Loading branch information
Showing
176 changed files
with
4,057 additions
and
1,641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
30 changes: 0 additions & 30 deletions
30
1_12/src/main/java/me/earth/headlessmc/mc/FontRendererImpl.java
This file was deleted.
Oops, something went wrong.
50 changes: 10 additions & 40 deletions
50
1_12/src/main/java/me/earth/headlessmc/mc/Initializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
1_12/src/main/java/me/earth/headlessmc/mc/mixins/IBootstrap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
1_12/src/main/java/me/earth/headlessmc/mc/mixins/MixinGuiNewChat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
1_12/src/main/java/me/earth/headlessmc/mc/mixins/MixinGuiScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.