Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Automagically Loads Minecraft Mod
This is a mac specific script to load a mod into minecraft. In the terminal, run:
./mc_modloader.sh ModName.zip.
It will make a backup of your current minecraft jar, and attempt to merge the mod into it.
#!/bin/bash
# This will either take the provided mod, or prompt the user with a dialog.
if [ 1 -eq "$#" ]; then
mlzip=$arg1;
else
clear;
echo -e "\033[5;36mPlease Select a Minecraft Plugin\033[0m";
mlzip=`osascript -e 'tell app (path to frontmost application as Unicode text) to set new_file to POSIX path of (choose file with prompt "Select A Minecraft Plugin" of type {"ZIP", "JAR"})' 2> /dev/null`
clear
fi
if [ ! -f "$mlzip" ]; then
echo "Could not find plugin $mlzip";
exit;
fi
tmpdir="/tmp/mcmlzip";
zipdir="$tmpdir/zip";
jardir="$tmpdir/jar";
jarsource="$HOME/Library/Application Support/minecraft/bin/";
goodjar="/$jarsource/.minecraft-dont-delete.jar";
jarname="minecraft.jar";
mcjar="$jarsource/$jarname";
if [ ! -f $mlzip ]
then
echo "Could not find file \"$mlzip\"";
exit 1;
fi
if [ ! -f "$mcjar" ]
then
echo "Could not find jar \"$mcjar\"";
exit 1;
fi
if [ ! -f "$goodjar" ]
then
cp "$mcjar" "$goodjar";
fi;
if [ -d $tmpdir ]
then
rm -rf "$tmpdir";
fi
mkdir $tmpdir;
mkdir $zipdir;
mkdir $jardir;
echo "Unzipping Modloader"
unzip "$mlzip" -d "$zipdir" &> /dev/null
echo "Unzipping minecraft.jar"
unzip "$goodjar" -d "$jardir" &> /dev/null
cp $zipdir/* $jardir/
rm -rf "$jardir/META-INF";
echo "Rezipping!"
cd "$jardir";
zip -r "$tmpdir/$jarname" ./* &> /dev/null;
mv "$tmpdir/$jarname" "$mcjar"
echo "Success!";
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment