Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ With AutoLan, your singleplayer world will automatically open to LAN whenever yo
# How to use
Just install the mod, and whenever you open a singleplayer world, AutoLan will start working automatically

## Suggested mod
# Note
As mentioned in the changelog, cheats are always enabled when opening to LAN. This is because I was not able to find a reproducible way to get whether cheats were enabled or not. This is to be addressed in a future update.

(Not that it's legal for Minecraft speedrunning anyway.)

# Suggested mod
I have another mod, [Force Port](https://modrinth.com/mod/forceport), which allows you to configure which port you want your LAN server to run on. This is useful if you want to run multiple servers at once, or for added security.

# Supported versions
AutoTorcher is available for Minecraft versions 1.21.10 and above!
AutoLan supports all versions 1.21.10 and above!

Due to the frequency of Minecraft updates now, each Minecraft version has its own .jar file. This is mainly to prevent crashes from each minor update.

# Changelog
## 1.1.0
- Optimised the CPU usage of the mod
Comment thread
GalvinPython marked this conversation as resolved.
- Open up to lan using world settings for difficulty
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changelog mentions "Open up to lan using world settings for difficulty" but the code actually uses the game mode, not difficulty. The game mode is retrieved from server.getSaveProperties().getGameMode() which returns the world's game mode (Creative, Survival, Adventure, Spectator), not its difficulty setting. The changelog should be updated to accurately reflect that game mode is being used, not difficulty.

Suggested change
- Open up to lan using world settings for difficulty
- Open up to LAN using world settings for game mode

Copilot uses AI. Check for mistakes.
- Cheats are enabled always as I was not able to find a reproducible way to get whether cheats were enabled or not
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies {

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

}

processResources {
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ org.gradle.configuration-cache=false

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.10
yarn_mappings=1.21.10+build.2
loader_version=0.17.3
loom_version=1.12-SNAPSHOT
minecraft_version=1.21.11
yarn_mappings=1.21.11+build.4
loader_version=0.18.4
loom_version=1.14-SNAPSHOT

# Mod Properties
mod_version=1.0.0+1.21.10
mod_version=1.1.0+1.21.11
maven_group=me.imgalvin
archives_base_name=auto-lan

# Dependencies
fabric_version=0.137.0+1.21.10
fabric_version=0.141.1+1.21.11
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/me/imgalvin/Autolan.java

This file was deleted.

11 changes: 11 additions & 0 deletions src/main/java/me/imgalvin/autolan/Autolan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.imgalvin.autolan;

import net.fabricmc.api.ClientModInitializer;

public class Autolan implements ClientModInitializer {

@Override
public void onInitializeClient() {
System.out.println("Autolan initialised!");
Comment on lines +5 to +9
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name "Autolan" does not follow Java naming conventions. Class names should use PascalCase with all significant words capitalized. It should be "AutoLan" to properly represent "Auto LAN" (where LAN is an acronym), making the class name more readable and consistent with naming conventions.

Suggested change
public class Autolan implements ClientModInitializer {
@Override
public void onInitializeClient() {
System.out.println("Autolan initialised!");
public class AutoLan implements ClientModInitializer {
@Override
public void onInitializeClient() {
System.out.println("AutoLan initialised!");

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spelling of "initialised" should be "initialized" (with a 'z') to maintain consistency with American English spelling conventions used throughout the codebase and standard in software development. For example, the method implemented is "onInitializeClient" (with a 'z'), not "onInitialiseClient".

Suggested change
System.out.println("Autolan initialised!");
System.out.println("Autolan initialized!");

Copilot uses AI. Check for mistakes.
}
}
66 changes: 66 additions & 0 deletions src/main/java/me/imgalvin/autolan/mixin/AutoLanMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package me.imgalvin.autolan.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.text.Text;
import net.minecraft.world.GameMode;
import org.spongepowered.asm.mixin.Mixin;
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;

import static net.minecraft.util.NetworkUtils.findLocalPort;

@Mixin(ClientPlayNetworkHandler.class)
public class AutoLanMixin {

@Unique
private boolean autolan$opened = false;
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The state variable 'autolan$opened' is stored per-instance of ClientPlayNetworkHandler, which means it could be reset to false when transitioning between worlds. This could lead to the LAN server being opened multiple times if the player switches between worlds in the same game session. Consider using a static field or a more global state management approach to ensure the flag persists across ClientPlayNetworkHandler instances, or reset the flag intentionally when switching worlds if the behavior should be per-world.

Suggested change
private boolean autolan$opened = false;
private static boolean autolan$opened = false;

Copilot uses AI. Check for mistakes.

@Inject(method = "onGameJoin", at = @At("TAIL"))
private void autolan$onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci) {
if (autolan$opened) return;

MinecraftClient client = MinecraftClient.getInstance();
IntegratedServer server = client.getServer();

if (server == null || !server.isSingleplayer() || client.player == null) {
return;
}

// Get mode of the world
GameMode gameMode = null;
try {
gameMode = server.getSaveProperties().getGameMode();
} catch (Exception e) {
try {
client.player.sendMessage(
Text.literal("Failed to get game mode: " + e.getMessage()).formatted(net.minecraft.util.Formatting.RED),
false
);
} catch (Throwable ignored) {
}
}

Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If retrieving the game mode fails (line 37), the gameMode variable remains null and is passed to server.openToLan(null, true, port) on line 50. While this may work with a fallback to a default game mode in the Minecraft API, the behavior is unclear. Consider either: 1) returning early if gameMode retrieval fails, or 2) providing an explicit fallback game mode, or 3) adding a comment explaining that passing null is intentional and will use a default.

Suggested change
// Fallback to a sensible default if game mode could not be retrieved
if (gameMode == null) {
gameMode = GameMode.SURVIVAL;
}

Copilot uses AI. Check for mistakes.
int port = findLocalPort();
try {
server.openToLan(gameMode, true, port);
autolan$opened = true;
client.player.sendMessage(
Text.literal("Opened to LAN on port " + port + " in mode: " + gameMode + ". Note: LAN worlds automatically open with cheats enabled. This will be addressed in a future update.").formatted(net.minecraft.util.Formatting.GREEN),
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The success message is excessively long and includes implementation notes that should be in the README or changelog, not shown to users every time they open a world. Consider shortening this message to something like "Opened to LAN on port [port] in [gameMode] mode" and move the note about cheats to documentation only.

Suggested change
Text.literal("Opened to LAN on port " + port + " in mode: " + gameMode + ". Note: LAN worlds automatically open with cheats enabled. This will be addressed in a future update.").formatted(net.minecraft.util.Formatting.GREEN),
Text.literal("Opened to LAN on port " + port + " in " + gameMode + " mode.").formatted(net.minecraft.util.Formatting.GREEN),

Copilot uses AI. Check for mistakes.
false
);
} catch (Exception e) {
try {
client.player.sendMessage(
Text.literal("Failed to open to LAN: " + e.getMessage()).formatted(net.minecraft.util.Formatting.RED),
false
);
} catch (Throwable ignored) {
}
}
}
}
17 changes: 17 additions & 0 deletions src/main/resources/autolan.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"required": true,
"minVersion": "0.8",
"package": "me.imgalvin.autolan.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [],
"client": [
"AutoLanMixin"
],
"server": [],
"injectors": {
"defaultRequire": 1
},
"overwrites": {
"requireAnnotations": true
}
}
9 changes: 6 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
"environment": "client",
"entrypoints": {
"client": [
"me.imgalvin.Autolan"
"me.imgalvin.autolan.Autolan"
]
},
"depends": {
"fabricloader": ">=0.16",
"minecraft": "1.21.10",
"minecraft": "1.21.11",
"java": ">=21",
"fabric-api": "*"
}
},
"mixins": [
"autolan.mixins.json"
]
}
Loading