4 Commits

Author SHA1 Message Date
astatin3 02a80e2dbe Forgor to release 2024-07-22 14:57:08 -06:00
astatin3 b442bc02e7 Some needed features 2024-07-22 14:52:25 -06:00
Astatin3 7b1b607b3d @Unique final MinecraftClient self = (MinecraftClient)(Object)this; 2024-07-16 08:12:56 -06:00
Astatin3 a13c585310 Make use tcp server 2024-07-16 08:05:49 -06:00
20 changed files with 136 additions and 42 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+3 -3
View File
@@ -1,10 +1,10 @@
commonProperties commonProperties
fabric.development=true fabric.development=true
fabric.remapClasspathFile=/home/astatin3/Documents/GitHub/no-more-render/.gradle/loom-cache/remapClasspath.txt fabric.remapClasspathFile=/home/astatin3/GitHub/no-more-render/.gradle/loom-cache/remapClasspath.txt
log4j.configurationFile=/home/astatin3/Documents/GitHub/no-more-render/.gradle/loom-cache/log4j.xml log4j.configurationFile=/home/astatin3/GitHub/no-more-render/.gradle/loom-cache/log4j.xml
log4j2.formatMsgNoLookups=true log4j2.formatMsgNoLookups=true
fabric.gameJarPath=/home/astatin3/.gradle/caches/fabric-loom/minecraftMaven/net/minecraft/minecraft-common/1.21-net.fabricmc.yarn.1_21.1.21+build.2-v2/minecraft-common-1.21-net.fabricmc.yarn.1_21.1.21+build.2-v2.jar fabric.gameJarPath=/home/astatin3/.gradle/caches/fabric-loom/minecraftMaven/net/minecraft/minecraft-common/1.21-net.fabricmc.yarn.1_21.1.21+build.2-v2/minecraft-common-1.21-net.fabricmc.yarn.1_21.1.21+build.2-v2.jar
fabric.classPathGroups=/home/astatin3/Documents/GitHub/no-more-render/build/classes/java/main:/home/astatin3/Documents/GitHub/no-more-render/build/resources/main:/home/astatin3/Documents/GitHub/no-more-render/build/classes/java/client:/home/astatin3/Documents/GitHub/no-more-render/build/resources/client fabric.classPathGroups=/home/astatin3/GitHub/no-more-render/build/classes/java/main:/home/astatin3/GitHub/no-more-render/build/resources/main:/home/astatin3/GitHub/no-more-render/build/classes/java/client:/home/astatin3/GitHub/no-more-render/build/resources/client
fabric.log.disableAnsi=false fabric.log.disableAnsi=false
clientArgs clientArgs
--assetIndex --assetIndex
+3
View File
@@ -2,6 +2,9 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.client.iml" filepath="$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.client.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.main.iml" filepath="$PROJECT_DIR$/.idea/modules/com.astatin3.no-more-render.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.client.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.client.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" filepath="$PROJECT_DIR$/.idea/modules/no-more-render.test.iml" />
</modules> </modules>
+2 -1
View File
@@ -6,12 +6,13 @@
<autoDetectTypes> <autoDetectTypes>
<platformType>FABRIC</platformType> <platformType>FABRIC</platformType>
<platformType>MIXIN</platformType> <platformType>MIXIN</platformType>
<platformType>MCP</platformType>
</autoDetectTypes> </autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion> <projectReimportVersion>1</projectReimportVersion>
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="McpModuleSettings"> <component name="McpModuleSettings">
<option name="srgType" value="SRG" /> <option name="minecraftVersion" value="1.21" />
</component> </component>
</module> </module>
+2 -1
View File
@@ -6,12 +6,13 @@
<autoDetectTypes> <autoDetectTypes>
<platformType>FABRIC</platformType> <platformType>FABRIC</platformType>
<platformType>MIXIN</platformType> <platformType>MIXIN</platformType>
<platformType>MCP</platformType>
</autoDetectTypes> </autoDetectTypes>
<projectReimportVersion>1</projectReimportVersion> <projectReimportVersion>1</projectReimportVersion>
</configuration> </configuration>
</facet> </facet>
</component> </component>
<component name="McpModuleSettings"> <component name="McpModuleSettings">
<option name="srgType" value="SRG" /> <option name="minecraftVersion" value="1.21" />
</component> </component>
</module> </module>
+4 -6
View File
@@ -1,16 +1,14 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" factoryName="Application" name="Minecraft Client" type="Application"> <configuration default="false" factoryName="Application" name="Minecraft Client" type="Application">
<option name="ALTERNATIVE_JRE_PATH" value="/usr/lib/jvm/temurin-22-jdk-amd64"/>
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true"/>
<option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main"/> <option name="MAIN_CLASS_NAME" value="net.fabricmc.devlaunchinjector.Main"/>
<module name="no-more-render.main"/> <module name="no-more-render.main"/>
<option name="PROGRAM_PARAMETERS" value=""/> <shortenClasspath name="ARGS_FILE"/>
<option name="VM_PARAMETERS" value="-Dfabric.dli.config=/home/astatin3/GitHub/no-more-render/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=client -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient"/> <option name="VM_PARAMETERS" value="-Dfabric.dli.config=$USER_HOME$/GitHub/no-more-render/.gradle/loom-cache/launch.cfg -Dfabric.dli.env=client -Dfabric.dli.main=net.fabricmc.loader.impl.launch.knot.KnotClient"/>
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/"/> <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/run/"/>
<method v="2"> <method v="2">
<option enabled="true" name="Make"/> <option enabled="true" name="Make"/>
</method> </method>
<envs>
</envs>
<shortenClasspath name="ARGS_FILE"/>
<classpathModifications/></configuration> <classpathModifications/></configuration>
</component> </component>
+1 -1
View File
@@ -12,5 +12,5 @@
</envs> </envs>
<shortenClasspath name="ARGS_FILE"/> <shortenClasspath name="ARGS_FILE"/>
<classpathModifications><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.26.0/659feffdd12280201c8aacb8f7be94f9a883c824/commons-compress-1.26.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.16/51cf043c87253c9f58b539c9f7e44c8894223850/httpcore-4.4.16.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-freetype/3.3.3/a0db6c84a8becc8ca05f9dbfa985edc348a824c7/lwjgl-freetype-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.3.3/2f6b0147078396a58979125a4c947664e98293a/lwjgl-opengl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.3.3/82d755ca94b102e9ca77283b9e2dc46d1b15fbe5/lwjgl-tinyfd-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.3.3/efa1eb78c5ccd840e9f329717109b5e892d72f8e/lwjgl-glfw-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.17.9/3cad216e3a7f0c19b4b394388bc9ffc446f13b14/text2speech-1.17.9.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.16.0/4e3eb3d79888d76b54e28b350915b5dc3919c9de/commons-codec-1.16.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/73.2/61ad4ef7f9131fcf6d25c34b817f90d6da06c9e9/icu4j-73.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.3.3/25dd6161988d7e65f71d5065c99902402ee32746/lwjgl-stb-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.3.3/b543467b7ff3c6920539a88ee602d34098628be5/lwjgl-jemalloc-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.3.3/daada81ceb5fc0c291fbfdd4433cb8d9423577f2/lwjgl-openal-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.jcraft/jorbis/0.0.17/8872d22b293e8f5d7d56ff92be966e6dc28ebdc6/jorbis-0.0.17.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.3.3/29589b5f87ed335a6c7e7ee6a5775f81f97ecb84/lwjgl-3.3.3.jar"/></classpathModifications></configuration> <classpathModifications><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-opengl/3.3.3/2f6b0147078396a58979125a4c947664e98293a/lwjgl-opengl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl/3.3.3/29589b5f87ed335a6c7e7ee6a5775f81f97ecb84/lwjgl-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/blocklist/1.0.10/5c685c5ffa94c4cd39496c7184c1d122e515ecef/blocklist-1.0.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/patchy/2.2.10/da05971b07cbb379d002cf7eaec6a2048211fefc/patchy-2.2.10.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-glfw/3.3.3/efa1eb78c5ccd840e9f329717109b5e892d72f8e/lwjgl-glfw-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.4.16/51cf043c87253c9f58b539c9f7e44c8894223850/httpcore-4.4.16.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-tinyfd/3.3.3/82d755ca94b102e9ca77283b9e2dc46d1b15fbe5/lwjgl-tinyfd-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.commons/commons-compress/1.26.0/659feffdd12280201c8aacb8f7be94f9a883c824/commons-compress-1.26.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.mojang/text2speech/1.17.9/3cad216e3a7f0c19b4b394388bc9ffc446f13b14/text2speech-1.17.9.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-jemalloc/3.3.3/b543467b7ff3c6920539a88ee602d34098628be5/lwjgl-jemalloc-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.jcraft/jorbis/0.0.17/8872d22b293e8f5d7d56ff92be966e6dc28ebdc6/jorbis-0.0.17.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/com.ibm.icu/icu4j/73.2/61ad4ef7f9131fcf6d25c34b817f90d6da06c9e9/icu4j-73.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.5.13/e5f6cae5ca7ecaac1ec2827a9e2d65ae2869cada/httpclient-4.5.13.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-stb/3.3.3/25dd6161988d7e65f71d5065c99902402ee32746/lwjgl-stb-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.2/4bfc12adfe4842bf07b657f0369c4cb522955686/commons-logging-1.2.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.16.0/4e3eb3d79888d76b54e28b350915b5dc3919c9de/commons-codec-1.16.0.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-freetype/3.3.3/a0db6c84a8becc8ca05f9dbfa985edc348a824c7/lwjgl-freetype-3.3.3.jar"/><entry exclude="true" path="/home/astatin3/.gradle/caches/modules-2/files-2.1/org.lwjgl/lwjgl-openal/3.3.3/daada81ceb5fc0c291fbfdd4433cb8d9423577f2/lwjgl-openal-3.3.3.jar"/></classpathModifications></configuration>
</component> </component>
+19
View File
@@ -1,3 +1,22 @@
# no-more-render # no-more-render
A Fabric mod that removes Minecraft's window rendering code, to create a headless CLI version A Fabric mod that removes Minecraft's window rendering code, to create a headless CLI version
## Usage
This mod runs a tcp server locally that allows for a command line interface
The mod runs on the port 65000, and increments this value by 1 if it cannot access that port.
You can connect to it via running `ncat localhost 65000` or other similar command
### Comamnds:
```
listelements/elems - List widgets on the screen
clickelement/celem <elem index> - Click an element on the screen
writeelement/welem <elem index> <text> - Write text into a compatable element
key <key> - Press and release a key
keydown <key> - Press a key
keyup <key> - Release a key
connect <Addr>:[Port] - Forcibly connect to a server
quit/exit - Close the game
```
+1 -1
View File
@@ -9,7 +9,7 @@ yarn_mappings=1.21+build.2
loader_version=0.15.11 loader_version=0.15.11
# Mod Properties # Mod Properties
mod_version=1.0.1 mod_version=1.0.2
maven_group=com.astatin3 maven_group=com.astatin3
archives_base_name=nomorerender archives_base_name=nomorerender
@@ -7,19 +7,26 @@ import net.minecraft.client.gl.WindowFramebuffer;
import net.minecraft.client.gui.Drawable; import net.minecraft.client.gui.Drawable;
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
import net.minecraft.client.gui.screen.world.WorldListWidget; import net.minecraft.client.gui.screen.world.WorldListWidget;
import net.minecraft.client.gui.widget.*; import net.minecraft.client.gui.widget.*;
import net.minecraft.client.render.GameRenderer;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.io.BufferedReader; import java.io.*;
import java.io.InputStreamReader; import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@@ -34,24 +41,70 @@ public class HeadlessMinecraftClient {
// System.out.println("#########################################"); // System.out.println("#########################################");
// } // }
BufferedReader reader;
PrintWriter writer;
@Shadow private Thread thread; @Shadow private Thread thread;
@Unique final MinecraftClient self = (MinecraftClient)(Object)this;
@Inject(method = "<init>", at = @At("TAIL")) @Inject(method = "<init>", at = @At("TAIL"))
private void onGameLoaded(RunArgs args, CallbackInfo ci) { private void onGameLoaded(RunArgs args, CallbackInfo ci) {
// AddonTemplate.LOG.info("Hello from ExampleMixin!"); // AddonTemplate.LOG.info("Hello from ExampleMixin!");
System.out.println("#########################################"); System.out.println("#########################################");
System.out.println("#########################################");
System.out.println("(no-more-render) This client is running a mod that disables Minecraft from opening a window!");
System.out.println("#########################################");
System.out.println("#########################################");
startCommandThread(); startCommandThread();
self.gameRenderer.onResized(10, 10);
} }
private void startCommandThread() { private void startCommandThread() {
Thread commandThread = new Thread(() -> { Thread commandThread = new Thread(() -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); // BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line; String line;
int i = 0;
try { try {
while ((line = reader.readLine()) != null) { ServerSocket serverSocket;
parseCommand(line); while(true){
try {
serverSocket = new ServerSocket(65000+i, 50, InetAddress.getByName("127.0.0.1"));
System.out.println("Server is listening on port " + (65000+i));
break;
} catch (java.net.BindException e){
System.out.println("port " + (65000+i) + " failed, trying another");
i++;
} }
}
while (true) {
Socket socket = serverSocket.accept();
System.out.println("New client connected");
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();
reader = new BufferedReader(new InputStreamReader(input));
writer = new PrintWriter(output, true);
// line = reader.readLine();
do {
line = reader.readLine();
parseCommand(line);
} while (!line.equals("bye"));
socket.close();
// reader.next
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -61,10 +114,8 @@ public class HeadlessMinecraftClient {
commandThread.start(); commandThread.start();
} }
MinecraftClient self = (MinecraftClient)(Object)this;
private void parseCommand(String command) { private void parseCommand(String command) {
if(command == null) return;
String[] split = command.split(" "); String[] split = command.split(" ");
try { try {
switch (split[0].toLowerCase()) { switch (split[0].toLowerCase()) {
@@ -72,9 +123,6 @@ public class HeadlessMinecraftClient {
case "exit": case "exit":
self.stop(); self.stop();
break; break;
case "tick":
self.tick();
break;
case "listelements": case "listelements":
case "elems": case "elems":
listElements(); listElements();
@@ -102,8 +150,25 @@ public class HeadlessMinecraftClient {
simulateKeyUp(split[1]); simulateKeyUp(split[1]);
} }
break; break;
case "connect":
if (split.length == 1)
writer.println("You must specify a server address!");
if (split.length > 3)
writer.println("Too many arguments!");
else {
int port = 25565;
if (split.length == 3)
port = Integer.parseInt(split[2]);
writer.println("Connecting to: " + split[1] + ":" + port);
connect_to_serv(new ServerAddress(split[1], port));
}
break;
default: default:
System.out.println("Unknown command: " + command); writer.println("Unknown command: " + command);
} }
}catch(Exception e){ }catch(Exception e){
e.printStackTrace(); e.printStackTrace();
@@ -113,7 +178,7 @@ public class HeadlessMinecraftClient {
private void listElements() { private void listElements() {
Screen currentScreen = self.currentScreen; Screen currentScreen = self.currentScreen;
if (currentScreen == null) { if (currentScreen == null) {
System.out.println("No screen is currently open."); writer.println("No screen is currently open.");
return; return;
} }
@@ -125,10 +190,10 @@ public class HeadlessMinecraftClient {
private void printElements(List<? extends Element> elements, int depth, AtomicInteger index) { private void printElements(List<? extends Element> elements, int depth, AtomicInteger index) {
String indent = " ".repeat(depth); String indent = " ".repeat(depth);
for (Element element : elements) { for (Element element : elements) {
System.out.printf("%s%d: %s%n", indent, index.getAndIncrement(), describeElement(element)); writer.printf("%s%d: %s%n", indent, index.getAndIncrement(), describeElement(element));
if (element instanceof ClickableWidget) { if (element instanceof ClickableWidget) {
ClickableWidget widget = (ClickableWidget) element; ClickableWidget widget = (ClickableWidget) element;
System.out.printf("%s Message: %s%n", indent, widget.getMessage().getString()); writer.printf("%s Message: %s%n", indent, widget.getMessage().getString());
} }
if (element instanceof net.minecraft.client.gui.ParentElement pe) { if (element instanceof net.minecraft.client.gui.ParentElement pe) {
printElements(pe.children(), depth + 1, index); printElements(pe.children(), depth + 1, index);
@@ -147,7 +212,7 @@ public class HeadlessMinecraftClient {
private Element findElement(int targetIndex) { private Element findElement(int targetIndex) {
Screen currentScreen = self.currentScreen; Screen currentScreen = self.currentScreen;
if (currentScreen == null) { if (currentScreen == null) {
System.out.println("No screen is currently open."); writer.println("No screen is currently open.");
return null; return null;
} }
@@ -159,7 +224,7 @@ public class HeadlessMinecraftClient {
Element targetElement = findElement(targetIndex); Element targetElement = findElement(targetIndex);
if (targetElement == null) { if (targetElement == null) {
System.out.println("Invalid element index."); writer.println("Invalid element index.");
return; return;
} }
@@ -167,12 +232,12 @@ public class HeadlessMinecraftClient {
self.execute(() -> { self.execute(() -> {
widget.onClick(widget.getX(), widget.getY()); widget.onClick(widget.getX(), widget.getY());
}); });
System.out.println("Clicked element: " + describeElement(widget)); writer.println("Clicked element: " + describeElement(widget));
if (widget.getMessage() != null) { if (widget.getMessage() != null) {
System.out.println("Message: " + widget.getMessage().getString()); writer.println("Message: " + widget.getMessage().getString());
} }
} else { } else {
System.out.println("Element is not clickable: " + describeElement(targetElement)); writer.println("Element is not clickable: " + describeElement(targetElement));
} }
} }
@@ -180,7 +245,7 @@ public class HeadlessMinecraftClient {
Element targetElement = findElement(targetIndex); Element targetElement = findElement(targetIndex);
if (targetElement == null) { if (targetElement == null) {
System.out.println("Invalid element index."); writer.println("Invalid element index.");
return; return;
} }
@@ -191,9 +256,9 @@ public class HeadlessMinecraftClient {
widget.setText(""); widget.setText("");
widget.write(text); widget.write(text);
}); });
System.out.println("Wrote in element: " + describeElement(widget)); writer.println("Wrote in element: " + describeElement(widget));
} else { } else {
System.out.println("Element is not a TextFieldWidget: " + describeElement(targetElement)); writer.println("Element is not a TextFieldWidget: " + describeElement(targetElement));
} }
} }
@@ -222,9 +287,9 @@ public class HeadlessMinecraftClient {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0); self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0);
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0); self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0);
}); });
System.out.println("Pressed key: " + keyName); writer.println("Pressed key: " + keyName);
} else { } else {
System.out.println("Unknown key: " + keyName); writer.println("Unknown key: " + keyName);
} }
} }
@@ -235,9 +300,9 @@ public class HeadlessMinecraftClient {
self.execute(() -> { self.execute(() -> {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0); self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_PRESS, 0);
}); });
System.out.println("Key down: " + keyName); writer.println("Key down: " + keyName);
} else { } else {
System.out.println("Unknown key: " + keyName); writer.println("Unknown key: " + keyName);
} }
} }
@@ -248,9 +313,9 @@ public class HeadlessMinecraftClient {
self.execute(() -> { self.execute(() -> {
self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0); self.keyboard.onKey(handle, keyCode, 0, GLFW.GLFW_RELEASE, 0);
}); });
System.out.println("Key up: " + keyName); writer.println("Key up: " + keyName);
} else { } else {
System.out.println("Unknown key: " + keyName); writer.println("Unknown key: " + keyName);
} }
} }
@@ -282,4 +347,11 @@ public class HeadlessMinecraftClient {
return GLFW.GLFW_KEY_UNKNOWN; return GLFW.GLFW_KEY_UNKNOWN;
} }
public void connect_to_serv(ServerAddress addr){
self.execute(() -> {
ConnectScreen.connect(self.currentScreen, self, addr, new ServerInfo("Test", addr.getAddress(), ServerInfo.ServerType.OTHER), true, null);
});
}
} }