2019-10-17 02:16:30 +02:00
import os , psutil
2019-10-12 11:58:46 +02:00
2019-10-16 22:44:34 +02:00
# java -Xmx$RAM$ -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=$NATIVES$ -cp $LIBRARIES$ net.minecraft.launchwrapper.Launch --username $USERNAME$ --version 1.7.10-Forge10.13.4.1614-1.7.10 --gameDir $GAMEDIR$ --assetsDir $ASSETS$ --assetIndex 1.7.10 --uuid $UUID$ --accessToken $ACCESSTOKEN$ --userProperties {} --userType mojang --width $WINDOWWIDTH$ --height $WINDOWHEIGHT$ --tweakClass cpw.mods.fml.common.launcher.FMLTweaker
# $RAM$ the amount of RAM with postfix (k, M, G ...)
# $WINDOWWIDTH$, $WINDOWHEIGHT$ window width and height in pixels without the WM’ s decoration
# $USERNAME$ the username as shown in-game
# $UUID$ the player’ s uuid
# $ACCESSTOKEN$ a valid accessToken
# $NATIVES$ the directory containing the natives
# $LIBRARIES$ a colon-separated (semicolon-separated on Windowze) list of library jars
# $GAMEDIR$ the game directory IMPORTANT! Change the cwd to that directory before launch. Some mods are coded to find the standard paths by using the cwd.
# $ASSETS$ the directory containing the assets
2019-10-12 11:58:46 +02:00
game_properties = {
" window width " : " 1366 " ,
" window height " : " 768 " ,
2019-10-17 02:16:30 +02:00
" ram " : " 4G " ,
2019-10-16 22:44:34 +02:00
" username " : None ,
" uuid " : None ,
" access token " : None ,
2019-10-12 11:58:46 +02:00
" native directory " : " lib/natives " ,
" library directory " : " lib/jar " , # will be transformed by the launch function
" asset directory " : " res " ,
" game directory " : " run " ,
2019-10-17 03:46:39 +02:00
" java executable " : " java " ,
" additional arguments " : " " }
2019-10-12 11:58:46 +02:00
2019-10-16 22:44:34 +02:00
command = None
full_command = None
2019-10-17 02:16:30 +02:00
def autoram ( minram , maxram , balance ) :
ram_available = psutil . virtual_memory ( ) . available
# not enough memory
if ram_available < minram :
# TODO: raise an exception
return - 1
# plenty of memory
elif ram_available > maxram + balance :
return maxram
# enough memory but we do not want to occupy all
elif float ( ram_available ) * float ( maxram ) / float ( maxram + balance ) > minram :
return int ( float ( ram_available ) * float ( maxram ) / float ( maxram + balance ) )
# barely enough memory
elif ram_available > minram or ram_available == minram :
return ram_available
2019-10-12 11:58:46 +02:00
def launch ( ) :
2019-10-16 22:44:34 +02:00
global command
if command is None :
return 1
# TODO: Raise an exception
return os . system ( command )
2019-10-12 11:58:46 +02:00
def set_parameter ( parameter , value ) :
2019-10-16 22:44:34 +02:00
global game_propertoies
game_properties [ parameter ] = value
build_full_command ( )
def build_full_command ( ) :
global game_properties
global command
global full_command
# TODO: implement
def set_command ( minecraft_command ) :
global command
command = minecraft_command
build_full_command ( )