{"id":374,"date":"2017-06-17T22:52:22","date_gmt":"2017-06-17T22:52:22","guid":{"rendered":"https:\/\/www.triptera.com.au\/wordpress\/?p=374"},"modified":"2017-06-17T22:52:22","modified_gmt":"2017-06-17T22:52:22","slug":"python-in-minecraft-1-placing-a-block","status":"publish","type":"post","link":"https:\/\/www.triptera.com.au\/wordpress\/2017\/06\/17\/python-in-minecraft-1-placing-a-block\/","title":{"rendered":"Python in Minecraft 1 &#8211; Placing a block"},"content":{"rendered":"<h2>Linking to other servers<\/h2>\n<p>In your first script, mychat.py, you created a link to the minecraft server on the local host using the command<\/p>\n<p><code>mc = minecraft.Minecraft.create()<\/code><\/p>\n<p>If you want to create a link to a minecraft server on another host, provide the IP address of the minecraft server to the <code>create<\/code> function.<\/p>\n<p><code>mc = minecraft.Minecraft.create(\"192.168.17.50\")<\/code><\/p>\n<h2>Setting a block<\/h2>\n<p>This exercise will set a block at a position specified by (x,y,z) coordinates in the minceraft world. We will use the <code>setBlock<\/code> command to specify the position and type of the block. The <code>setBlock<\/code> command can be used as either<\/p>\n<p><code>mc.setBlock(x,y,z,block)<\/code><\/p>\n<p>or<\/p>\n<p><code>mc.setBlock(x,y,z,block.id,variation)<\/code><\/p>\n<p>In the following example a wool block with colour orange (variation 1 for wool) is placed at x=-219, y=73, z=-222. This example uses the <code>nano<\/code> text editor which available on Mac and Linux and easier to use than <code>vi<\/code>. It has reminders at the bottom of the screen of the special key functions. To save type <code>ctrl-o<\/code>. To exit type <code>ctrl-x<\/code>.<\/p>\n<p><code>nano placewool.py<\/code><\/p>\n<pre class=\"brush: python; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nimport mcpi.minecraft as minecraft\r\nimport mcpi.block as block\r\nmc=minecraft.Minecraft.create()\r\nmc.setBlock(-219,73,-222, block.WOOL.id, 1)\r\n<\/pre>\n<p>Run it while the server is running. The command will be<\/p>\n<p><code>python placewool.py<\/code><\/p>\n<p>If you have python 2 and python 3 on the same computer (eg Mac or Linux) then the command is most likely<\/p>\n<p><code>python3 placewool.py<\/code><\/p>\n<p>In minecraft, pressing F3 will let you see your coordinates so you can navigate (or teleport) to the coordinates to see the wool block you have placed.<\/p>\n<p><a href=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/placewoolwithf3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-375\" src=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/placewoolwithf3-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/placewoolwithf3-300x169.png 300w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/placewoolwithf3-768x432.png 768w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/placewoolwithf3.png 854w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linking to other servers In your first script, mychat.py, you created a link to the minecraft server on the local host using the command mc = minecraft.Minecraft.create() If you want to create a link to a minecraft server on another host, provide the IP address of the minecraft server to the create function. mc = [&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],"tags":[],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-coderdojo"],"_links":{"self":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/374","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=374"}],"version-history":[{"count":1,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"predecessor-version":[{"id":382,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/374\/revisions\/382"}],"wp:attachment":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}