portablemc icon indicating copy to clipboard operation
portablemc copied to clipboard

Custom client load in API

Open andrew64dev opened this issue 3 years ago • 3 comments
trafficstars

Hi, i tried to load a custom client and from command line i can, but i can't with the API, is possible to use the API for load a custom client?

andrew64dev avatar Sep 30 '22 16:09 andrew64dev

By custom client you mean with a specific version identifier (in versions directory) ?

mindstorm38 avatar Sep 30 '22 16:09 mindstorm38

yes

andrew64dev avatar Oct 01 '22 17:10 andrew64dev

This should work, can you give the code you used?

mindstorm38 avatar Oct 02 '22 10:10 mindstorm38

Please re-open this issue if you have further issues

mindstorm38 avatar Nov 02 '22 22:11 mindstorm38

oh, sorry, i did not notice the response from you, but, im just using the code from the api documentation

andrew64dev avatar Dec 11 '22 18:12 andrew64dev

Honestly, I can't do much without a bit of code, without it, I can't understand from where can come the problem, if it's obvious or not...

mindstorm38 avatar Dec 11 '22 18:12 mindstorm38

from portablemc import Context, VersionManifest, StartOptions, Start
import os

main_dir = "{}\\.minecraft".format(os.environ.get('APPDATA'))
work_dir = "{}\\.minecraft".format(os.environ.get('APPDATA'))
ctx = Context(main_dir, work_dir)
print(ctx.work_dir)  
print(ctx.versions_dir) 
print(ctx.assets_dir) 
print(ctx.libraries_dir)  
print(ctx.jvm_dir)  
print(ctx.bin_dir)  
cache_file = "{}\\.minecraft\\manifest.json".format(os.environ.get('APPDATA'))
cache_timeout = 5.0 
manifest = VersionManifest(cache_file, cache_timeout)

start_opts = StartOptions()
start_opts.disable_multiplayer = True
start_opts.username = "FrostCraftUser"
start_opts.resolution = (700, 500)


start = Start("1.8.9")
start.prepare(start_opts)
start.main_class = "net.minecraft.client.main.Main" 
start.jvm_args.append("-Dmy.jvm.arg=89")   
start.start()

andrew64dev avatar Dec 11 '22 18:12 andrew64dev

immagine

andrew64dev avatar Dec 11 '22 18:12 andrew64dev

Ok, almost ready to work :) The issue here is that Start() constructor requires a Version object, not a str.

version = Version(ctx, "1.8.9")
version.install()  # to initialize the version and install missing libraries (and JVM if you need using `jvm=True` argument)

start = Start(version)
# [...]

mindstorm38 avatar Dec 11 '22 20:12 mindstorm38