{"id":388,"date":"2017-06-18T01:21:45","date_gmt":"2017-06-18T01:21:45","guid":{"rendered":"https:\/\/www.triptera.com.au\/wordpress\/?p=388"},"modified":"2017-06-18T02:40:23","modified_gmt":"2017-06-18T02:40:23","slug":"python-in-minecraft-4-creating-a-solid-tunnel","status":"publish","type":"post","link":"https:\/\/www.triptera.com.au\/wordpress\/2017\/06\/18\/python-in-minecraft-4-creating-a-solid-tunnel\/","title":{"rendered":"Python in Minecraft 4 &#8211; Creating a solid tunnel"},"content":{"rendered":"<p>Our next exercise it to create a tunnel of glass filled with air. Glass is useful because it is transparent. To start with the tunnel will be horizontal heading east which means the x coordinate will be increasing and the y and z coordinates will keep constant values. We could use the setBlocks command for the entire length of the tunnel. However we want to keep the code flexible enough that later on the tunnel could start ascending or descending, i.e. the y coordinate could start increasing or decreasing. The profile of the tunnel which will be a wall of glass 5 blocks across and 7 blocks high. Here is the code to create a profile of the tunnel for one value of the x coordinate.<\/p>\n<p><code>nano tunnelprofile.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\nx = -200\r\ny = 72\r\nz = -222\r\nmc.setBlocks(x,y,z-2,x,y+6,z+2,block.GLASS)\r\n<\/pre>\n<p><code>python3 tunnelprofile.py<\/code><\/p>\n<p><a href=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/tunnelprofile.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/tunnelprofile-300x169.png\" alt=\"\" width=\"300\" height=\"169\" class=\"alignnone size-medium wp-image-380\" srcset=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/tunnelprofile-300x169.png 300w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/tunnelprofile-768x432.png 768w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/tunnelprofile.png 854w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>A loop can be added which will draw the profile of the tunnel over and over again for a range of different x values. Note how important indentation is in python. I am indenting 4 spaces when in a loop.<\/p>\n<p><code>nano solidglasstunnel.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\nxmin = -224\r\nxmax = -200\r\ny = 72\r\nz = -222\r\nfor x in range(xmin,xmax+1):\r\n    mc.setBlocks(x,y,z-2,x,y+6,z+2,block.GLASS)\r\n<\/pre>\n<p><code>python3 solidglasstunnel.py<\/code><\/p>\n<p><a href=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/solidglasstunnel.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/solidglasstunnel-300x169.png\" alt=\"\" width=\"300\" height=\"169\" class=\"alignnone size-medium wp-image-378\" srcset=\"https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/solidglasstunnel-300x169.png 300w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/solidglasstunnel-768x432.png 768w, https:\/\/www.triptera.com.au\/wordpress\/wp-content\/uploads\/2017\/06\/solidglasstunnel.png 854w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our next exercise it to create a tunnel of glass filled with air. Glass is useful because it is transparent. To start with the tunnel will be horizontal heading east which means the x coordinate will be increasing and the y and z coordinates will keep constant values. We could use the setBlocks command for [&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-388","post","type-post","status-publish","format-standard","hentry","category-coderdojo"],"_links":{"self":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/388","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=388"}],"version-history":[{"count":1,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/388\/revisions"}],"predecessor-version":[{"id":389,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/posts\/388\/revisions\/389"}],"wp:attachment":[{"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/media?parent=388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/categories?post=388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.triptera.com.au\/wordpress\/wp-json\/wp\/v2\/tags?post=388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}