Skip to content

Conversation

@SpaceWalkerRS
Copy link
Member

@SpaceWalkerRS SpaceWalkerRS commented Aug 24, 2025

Adds a simple wrapper class for retrieving the current Minecraft instance. This is useful given that Minecraft::getInstance was only added in one of the 1.3 snapshots.

The class looks as follows:

public class MinecraftInstance {

	public static Minecraft get() {
		return MinecraftAccess.getInstance();
	}
}

Internally this returns the instance if it is available, and otherwise throws an IllegalStateException. The instance is available from the start of the init method until the end of the shutdown method.

@SpaceWalkerRS SpaceWalkerRS added the enhancement New feature or request label Aug 24, 2025
@ENDERZOMBI102
Copy link

does this include the server?

@SpaceWalkerRS
Copy link
Member Author

does this include the server?

It doesn't. I do want to add it but I am not sure yet exactly how it should look. For example, should such an API just return a MinecraftServer instance, or should there be another method for getting the DedicatedServer instance?

@ENDERZOMBI102
Copy link

ENDERZOMBI102 commented Aug 24, 2025

What about an injected interface with a default static method on MinecraftServer? that way one can "emulate" getInstance().
Same could be done in the client now that i think of it...

@SpaceWalkerRS
Copy link
Member Author

Do those work transitively?

@ENDERZOMBI102
Copy link

I think so, but would need to check

@SpaceWalkerRS
Copy link
Member Author

Hmm I wonder how that'll work between versions that already that method vs versions that don't. Like if we add that method to 1.2 and below, it will not be mapped to intermediary (since it's not a MC method), but in 1.3+ it will. So if you compile a mod against 1.2 it will not work in 1.3.

Unless we also inject the interface in 1.3 and above and just give the method a different name (like instance() instead of getInstance())?

@ENDERZOMBI102
Copy link

I suggest to start with the assumption that major versions aren't compatible, so the mod would need to be recompiled anyway

@SpaceWalkerRS
Copy link
Member Author

still, preferably I would avoid imposing that through OSL where feasible

@SpaceWalkerRS
Copy link
Member Author

hold on - the injected interface would be useless for this since the instance getter is static

@SpaceWalkerRS SpaceWalkerRS merged commit ddc52f9 into gen2 Aug 28, 2025
0 of 2 checks passed
@SpaceWalkerRS SpaceWalkerRS deleted the minecraft-instance-api branch September 9, 2025 12:28
SpaceWalkerRS added a commit that referenced this pull request Dec 6, 2025
[Lifecycle Events] add Minecraft instance API
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants