Skip to content

Commit

Permalink
test invoking multiplayer screen
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Mar 31, 2024
1 parent 7055bcb commit 67a49ed
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/main/java/lol/hub/headlessbot/Mod.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@
import lol.hub.headlessbot.behavior.nodes.composites.SequenceOneNode;
import lol.hub.headlessbot.behavior.nodes.decorators.MaybeRunNode;
import lol.hub.headlessbot.behavior.nodes.leafs.*;
import lol.hub.headlessbot.mixins.MultiplayerScreenInvoker;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.gui.screen.AccessibilityOnboardingScreen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerWarningScreen;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.util.math.BlockPos;

import java.io.IOException;
Expand Down Expand Up @@ -54,6 +61,23 @@ public void onInitializeClient() {
throw new IllegalStateException(ex.getMessage());
}

ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (screen instanceof AccessibilityOnboardingScreen) {
screen.close();
} else if (screen instanceof MultiplayerWarningScreen) {
screen.close();
} else if (screen instanceof TitleScreen titleScreen) {
Log.info("client is in main menu and ready");
var multiplayerScreen = new MultiplayerScreen(titleScreen);
((MultiplayerScreenInvoker) multiplayerScreen)
.invokeConnect(new ServerInfo(
"docker host",
"172.17.0.1",
ServerInfo.ServerType.OTHER
));
}
});

ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (client.player == null || client.world == null) return;
ticksOnline++;
Expand Down Expand Up @@ -158,6 +182,7 @@ private HttpServer webServer() throws IOException {
private void clientDefaultSettings() {
MC.client().options.getViewDistance().setValue(4);
MC.client().options.getSimulationDistance().setValue(4);
MC.client().options.skipMultiplayerWarning = true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lol.hub.headlessbot.mixins;

import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(MultiplayerScreen.class)
public interface MultiplayerScreenInvoker {

@Invoker("connect")
public void invokeConnect(ServerInfo entry);

}
3 changes: 2 additions & 1 deletion src/main/resources/headlessbot.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"mixins": [
],
"client": [
"ClientConnectionMixin"
"ClientConnectionMixin",
"MultiplayerScreenInvoker"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 67a49ed

Please sign in to comment.