#!/bin/bash


####
## CONFIGURATION
## 
#
# Player Name
PLAYER_NAME="test"
PASSWORD="test"

# JVM Memory in Megabytes < 1.5G may be unstable!
JVM_MEM="2048"

# Additional Java tunings you want to apply
JAVA_OPTS=""

## Comment this when you've finished configuring your client!
#echo "Please Edit your Configuration" && exit 1

PW_HASH=$(echo -n "EsRegnet-${PLAYER_NAME}-123-${PASSWORD}" |md5sum |cut -d ' ' -f1)
### Auth:
AUTH_RESPONSE="$(curl -s http://login.mctech.sirius-black.org/auth?user=${PLAYER_NAME}\&pw=${PW_HASH})"

AUTH_STATUS=$(echo $AUTH_RESPONSE | cut -d: -f 1)
if [[ $AUTH_STATUS != "OK" ]]; then
	AUTH_ERR=$(echo $AUTH_RESPONSE | cut -d: -f 2)
	echo "Login Failed: $AUTH_ERR"
	exit 1
fi

PLAYER_NAME="$(echo $AUTH_RESPONSE | cut -d: -f 2)"
SESSION_ID="$(echo $AUTH_RESPONSE | cut -d: -f 3)"
echo "Login OK - User '$PLAYER_NAME' - Session Id: '$SESSION_ID' "

JAVA_OPTS="$JAVA_OPTS -Xms${JVM_MEM}M -Xmx${JVM_MEM}M -XX:PermSize=256m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSIncrementalPacing -XX:ParallelGCThreads=2 -XX:+AggressiveOpts"

echo "Applying new home Dir in order to fake installation path"
export HOME="$(pwd)/MC-Tech16/"
echo "Running Minecraft! ($HOME)"
pushd "${HOME}/.minecraft/"

MCLIBS=""

# Build library arguments (path)
for i in `ls libs/`; do 
	MCLIBS="${MCLIBS}:libs/$i"
done

java $JAVA_OPTS -cp "bin/minecraft.jar${MCLIBS}" -Djava.library.path=bin/natives net.minecraft.launchwrapper.Launch --version MCTech16 --gameDir ./ --assetsDir ./assets/ --resourcePackDir ../resourcePacks --username "$PLAYER_NAME"  --session "$SESSION_ID" --tweakClass cpw.mods.fml.common.launcher.FMLTweaker --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker 


        

popd		
		
#		"%JAVA_HOME%\bin\%JAVA_EXE%" %JAVA_MEM% %JAVA_GCOPTS% %JAVA_OPTS% -cp bin/minecraft.jar;libs/* 


#-Djava.library.path=bin/natives net.minecraft.launchwrapper.Launch --version MCTech16 --gameDir ./ --assetsDir ./assets/ --resourcePackDir ../resourcePacks --username %PlayerName% --tweakClass cpw.mods.fml.common.launcher.FMLTweaker --tweakClass com.mumfrey.liteloader.launch.LiteLoaderTweaker
		
		
		