{"id":358,"date":"2017-06-02T23:29:10","date_gmt":"2017-06-02T23:29:10","guid":{"rendered":"https:\/\/www.triptera.com.au\/wordpress\/?p=358"},"modified":"2017-08-13T06:32:27","modified_gmt":"2017-08-13T06:32:27","slug":"coderdojo-minecraft-with-python-setup","status":"publish","type":"post","link":"https:\/\/www.triptera.com.au\/wordpress\/2017\/06\/02\/coderdojo-minecraft-with-python-setup\/","title":{"rendered":"CoderDojo &#8211; Minecraft with Python &#8211; setup"},"content":{"rendered":"<p>Minecraft Pi on the Raspberry Pi can be controlled using python scripts. Here we will set up a Mac, Linux or Windows PC to achieve the same functionality by using the RaspberryJuice plugin with the Spigot Minecraft server.<\/p>\n<h4>Requirements<\/h4>\n<ul>\n<li>Java from <a href=\"https:\/\/www.java.com\">https:\/\/www.java.com<\/a> (Java 8 or later recommended)<\/li>\n<li>Python from <a href=\"https:\/\/www.python.org\">https:\/\/www.python.org<\/a> (Python 3 or later recommended)<\/li>\n<li>Git from <a href=\"https:\/\/git-scm.com\">https:\/\/git-scm.com<\/a><\/li>\n<li>Spigot minecraft server from <a href=\"https:\/\/spigotmc.org\">https:\/\/spigotmc.org<\/a><\/li>\n<li>RaspberryJuice from <a href=\"https:\/\/github.com\/zhuowei\/RaspberryJuice\">https:\/\/github.com\/zhuowei\/RaspberryJuice<\/a><\/li>\n<li>(Optional) Minecraft from <a href=\"https:\/\/minecraft.net\">https:\/\/minecraft.net<\/a><\/li>\n<\/ul>\n<h4>Installation<\/h4>\n<p>Installation of Java, Git and Minecraft is straight forward following instructions from sites listed above. Installing Git provides a bash shell for Windows.<\/p>\n<h4>Python installation<\/h4>\n<p>When downloading python, choose Python 3 not Python 2.<\/p>\n<p>When installing python, tick the check box to add python to the path. This makes it easier to run python from the command line, although you will normally run python by starting the application called IDLE. Then click on &#8220;Install Now&#8221;<\/p>\n<p><a href=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/CapturePythonPath.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/CapturePythonPath-300x187.png\" alt=\"\" width=\"300\" height=\"187\" class=\"alignnone size-medium wp-image-433\" srcset=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/CapturePythonPath-300x187.png 300w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/CapturePythonPath.png 682w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>To run python on the command line, the command is <code>python3<\/code> on Mac and Linux and <code>python<\/code> on Windows. I will use <code>python3<\/code> in these instructions.<\/p>\n<h4>Windows only &#8211; python installation<\/h4>\n<p>To make <code>python3<\/code> work in the bash shell on windows, start Git-Bash and type the following command:<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\necho &quot;alias python3='winpty python.exe'&quot; &gt;&gt; .bashrc\r\n<\/pre>\n<p>The <code>winpty<\/code> is required to enable python interactive interpreter to work in git-bash the same way it works in Windows command prompt, so this alias is providing two solutions in one line. Now quit git-bash (by typing <code>exit<\/code>). Restart git-bash and type <code>python3<\/code>. You should see something like the following:<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n$ python3\r\nPython 3.6.2 (v3.6.2:5fd33b5, Jul  8 2017, 04:57:36) &#x5B;MSC v.1900 64 bit (AMD64)] on win32\r\nType &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.\r\n&gt;&gt;&gt;\r\n<\/pre>\n<p>If you forgot to click the check box to add python to the path when installing python then it can be added later by going to Control Panel > Uninstall a program and double clicking on the Python program which will be called Python 3.6.2 (64-bit) or similar. Select &#8220;Modify&#8221; to change your original setup. You don&#8217;t need to change the Optional Features so click &#8220;Next&#8221;. In the Advanced Options click the checkbox now called &#8220;Add Python to environment variables&#8221; and then click on &#8220;Install&#8221;.<\/p>\n<h4>Spigot minecraft server installation using bash shell<\/h4>\n<p>To install Spigot server, use the installer caller BuildTools.jar available from <a href=\"https:\/\/hub.spigotmc.org\/jenkins\/job\/BuildTools\/lastSuccessfulBuild\/artifact\/target\/BuildTools.jar\">https:\/\/hub.spigotmc.org\/jenkins\/job\/BuildTools\/lastSuccessfulBuild\/artifact\/target\/BuildTools.jar<\/a> . Download this file and put it in a folder you want to install the Spigot minecraft folder, then run it using java.<\/p>\n<p>These instructions show how to install using bash shell. You don&#8217;t have to use bash shell, but by using bash shell the same instructions work for all platforms. Bash shell is available on Mac OS X (Terminal), Linux (command line or Terminal) or Windows (Git-bash is available after you installed git above).<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">mkdir minecraft-spigot\r\nmv Downloads\/BuildTools.jar minecraft-spigot\/\r\ncd minecraft-spigot\r\njava -jar BuildTools.jar<\/pre>\n<p>Now edit the file <code>eula.txt<\/code> and change <code>eula=false<\/code> to <code>eula=true<\/code> . This is to acknowledge that you agree with the EULA which is necessary to run the server. You can do this with a text editor from the GUI such as Windows NotePad or Mac TextEdit. Alternatively do it from the command line using vi text editor<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">vi eula.txt<\/pre>\n<p>The <code>vi<\/code> commands are cryptic. When you start <code>vi<\/code> you will be in command mode. Use the arrow keys to move the cursor to the line you want to change. Then press the <code>[a]<\/code> key which is the command to put <code>vi<\/code> in edit (append) mode. In edit mode you can move the cursor to the word <code>false<\/code>, delete it with the <code>[delete]<\/code> key and type in <code>true<\/code>. To get out of edit mode and back into command mode, press the <code>[ESC]<\/code> key. You now have to issue the command to write the changed file, and quit <code>vi<\/code>, which is pressing the following four keys <code>[:][w][q][Enter]<\/code> .<\/p>\n<p>Return to original directory ready for next step.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">cd ..<\/pre>\n<h4>Install RaspberryJuice<\/h4>\n<p>You can get the RaspberryJuice plugin from https:\/\/github.com\/zhuowei\/RaspberryJuice\/ using Git.<code><\/code><\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">git clone https:\/\/github.com\/zhuowei\/RaspberryJuice.git\r\nmkdir -p minecraft-spigot\/plugins\r\ncp RaspberryJuice\/jars\/RaspberryJuice-1.9.jar minecraft-spigot\/plugins\/\r\n<\/pre>\n<h4>Run Spigot Server<\/h4>\n<p>Using Terminal or Command Prompt from the minecraft-spigot folder. Your spigot version number may be different.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">cd minecraft-spigot\r\njava -jar spigot-1.12.jar\r\n<\/pre>\n<p>To stop the server, type<\/p>\n<p><code>stop<\/code><\/p>\n<p>as a server command.<\/p>\n<p>You should now have a configuration file in the RaspberryJuice folder in the plugins folder called config.yml. I like to edit that file and change the<\/p>\n<p><code>location: RELATIVE<\/code><br \/>\nto<br \/>\n<code>location: ABSOLUTE<\/code><\/p>\n<p>RELATIVE makes RaspberryJuice behave the same way as Python on Minecraft Pi which uses coordinates relative to the spawn point. However on PCs it is easier to use ABSOLUTE coordinates which equate to the coordinates visible using F3 in Minecraft.<\/p>\n<p>To prepare for the next section, change back up a directory to where we first started.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">cd ..<\/pre>\n<h5>Python mcpi module for RaspberryJuice<\/h5>\n<p>To write python scripts you need to install the mcpi module. You can choose the original one, exactly as supplied for Minecraft Pi or the modded one which adds some additional commands. I prefer the modded one. They are included in the files you cloned from github.<\/p>\n<p>The following command tells you where user site-packages should be installed.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">python3 -m site --user-site<\/pre>\n<p>Use this information to link to the module in the git repository you downloaded. This has to be done for each user on computer who will want to run python scripts.<\/p>\n<p><b>Mac or Linux using Bash<\/b><\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">STARTDIR=`pwd`\r\nPKGDIR=`python3 -m site --user-site`\r\nmkdir -p &quot;$PKGDIR&quot;\r\ncd &quot;$PKGDIR&quot;\r\nln -s &quot;${STARTDIR}\/RaspberryJuice\/src\/main\/resources\/mcpi\/api\/python\/modded\/mcpi&quot;\r\ncd &quot;$STARTDIR&quot;\r\n<\/pre>\n<p><b>Windows command prompt &#8211; run as administrator<\/b><\/p>\n<pre class=\"brush: plain; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nfor \/f %a in ('python -m site --user-site') do set PKGDIR=%a\r\nmkdir %PKGDIR%\r\ncd %PKGDIR%\r\nmklink \/D mcpi %HOMEPATH%\\RaspberryJuice\\src\\main\\resources\\mcpi\\api\\python\\modded\\mcpi\r\ncd %HOMEPATH%\r\n<\/pre>\n<p>Now start the spigot server<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">cd minecraft-spigot\r\njava -jar spigot-1.12.jar\r\n<\/pre>\n<p>In another bash shell, create a python script to send a chat message. Here is command using vi.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">vi mychat.py<\/pre>\n<pre class=\"brush: python; title: ; wrap-lines: false; notranslate\" title=\"\">import mcpi.minecraft as minecraft\r\nmc = minecraft.Minecraft.create()\r\nmc.postToChat(&quot;hello&quot;)\r\n<\/pre>\n<p>Run this script and you should see your message in the first bash shell.<\/p>\n<pre class=\"brush: bash; gutter: false; title: ; wrap-lines: false; notranslate\" title=\"\">python3 mychat.py<\/pre>\n<h5>Troubleshooting for Windows<\/h5>\n<p>The following tests should be done in Git-Bash:<\/p>\n<p>1. Type <code>python --version<\/code>. It should return &#8220;Python 3.6.2&#8221; or similar. If it says &#8220;bash: python: command not found&#8221; then you have not ticked &#8220;Add python to PATH&#8221; when installing. See Windows only  python installation instructions above for remedy.<\/p>\n<p>2. Type <code>python3<\/code>. It should start the python interpreter shell ending with <code>>>><\/code>. If you not then you haven&#8217;t created the .bashrc file correctly. See Windows only python installation instructions. You can delete the existing .bashrc file in your home directory and try creating it again. Be extremely careful with spaces and using the correct type of quotation marks. It is best if you can copy and paste directly from this web site into Git-Bash. To paste in Git-Bash, right click the mouse and select &#8220;Paste&#8221;.<\/p>\n<p>3. Once you are in the python interpreter shell, type <code>import mcpi.minecraft<\/code>. If there is an error then there is a problem with the link you created in &#8220;Python mcpi module for RaspberryJuice&#8221;. Try creating it again.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Minecraft Pi on the Raspberry Pi can be controlled using python scripts. Here we will set up a Mac, Linux or Windows PC to achieve the same functionality by using the RaspberryJuice plugin with the Spigot Minecraft server. Requirements Java from https:\/\/www.java.com (Java 8 or later recommended) Python from https:\/\/www.python.org (Python 3 or later recommended) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[13,15],"tags":[],"class_list":["post-358","post","type-post","status-publish","format-standard","hentry","category-coderdojo","category-minecraft"],"_links":{"self":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":25,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/358\/revisions"}],"predecessor-version":[{"id":435,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/358\/revisions\/435"}],"wp:attachment":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}