<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Minecraft &#8211; リビングの魔王</title>
	<atom:link href="https://living-maou.com/tag/minecraft/feed/" rel="self" type="application/rss+xml" />
	<link>https://living-maou.com</link>
	<description></description>
	<lastBuildDate>Wed, 05 Mar 2025 01:01:52 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://living-maou.com/wp-content/uploads/2020/02/cropped-favicon-32x32.png</url>
	<title>Minecraft &#8211; リビングの魔王</title>
	<link>https://living-maou.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【マイクラ×Python】ハートを描くプログラムを改造！関数を使ってみよう</title>
		<link>https://living-maou.com/minecraft-python10/</link>
					<comments>https://living-maou.com/minecraft-python10/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Wed, 05 Mar 2025 00:50:38 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7201</guid>

					<description><![CDATA[前回、Pythonを使って「ハート」を描えがくプログラムを作りました。 でも、同じハートをちがう場所にたくさん描えがきたいとき、どうしますか？ 座標だけちがうプログラムを何度も書くのは、コードが分かりにくくなりますし、修 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10.jpg"><img fetchpriority="high" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7202" srcset="https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10.jpg 800w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>前回、Pythonを使って<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python09">「ハート」を<ruby>描<rt>えが</rt></ruby>くプログラム<span class="fa fa-external-link internal-icon anchor-icon"></span></a>を作りました。</p>
<p>でも、同じハートをちがう場所にたくさん<ruby>描<rt>えが</rt></ruby>きたいとき、どうしますか？<br />
座標だけちがうプログラムを何度も書くのは、コードが分かりにくくなりますし、修正も大変です。</p>
<p>そこで今回は、<b>関数</b>を使って効率的にハートをたくさん<ruby>描<rt>えが</rt></ruby>くプログラムを作ってみましょう！</p>
<p>&nbsp;</p>
<h2><span id="toc1">前回のプログラムのおさらい</span></h2>
<p>前回は、<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python09/">ハートを1つ<ruby>描<rt>えが</rt></ruby>くプログラム<span class="fa fa-external-link internal-icon anchor-icon"></span></a>を作りました。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

# ハートを描くスタート地点を設定
z += 5

# ハートの形を定義（2次元リスト）
# 1がブロックを置く場所、0は何も置かない
heart = [
    [0, 1, 1, 0, 1, 1, 0],
    [1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1],
    [0, 1, 1, 1, 1, 1, 0],
    [0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 1, 0, 0, 0],
]

# ハートを描画
for row in range(len(heart)):
    for col in range(len(heart[row])):
        if heart[row][col] == 1: # 1の場所にブロックを置く
            mc.setBlock(x + col, y, z + row, 35, 14) # 赤い羊毛</code></pre>
</div>
<p>このプログラムは、ハートの形を2次元のリストで作り、その形に合わせてブロックを置いています。</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python09/" title="【マインクラフト×Python】2次元リストでハートを描こう！" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マインクラフト×Python】2次元リストでハートを描こう！</div><div class="blogcard-snippet internal-blogcard-snippet">Pythonを使ってマインクラフトの世界にハートを描いてみよう！【リビングの魔王】では、2次元リストの使い方や二重ループの仕組みをやさしく解説。初心者でも楽しく挑戦できる内容です！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<p>今回は、このプログラムを改造してハートを3つ<ruby>描<rt>えが</rt></ruby>くプログラムを作ります。</p>
<p>その前に、関数の仕組みを<ruby>確認<rt>かくにん</rt></ruby>してみましょう。</p>
<h2><span id="toc2">関数は命令をひとまとめにして名前をつけたもの</span></h2>
<p><span style="color: #ff6600;"><b>関数</b></span>とは、<span class="marker-under-red">命令をひとまとめにして、何度でも使えるようにする仕組み</span>です。同じような処理をくり返し使う場合に、関数としてまとめておくと便利です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01.png" alt="Python 関数" width="800" height="450" class="aligncenter size-full wp-image-7203" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01.png 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02.png" alt="引数と戻り値" width="800" height="450" class="aligncenter size-full wp-image-7204" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02.png 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc3">関数を使ってみよう</span></h3>
<p>例として、下のかんたんなプログラムを見てみましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>def tashizan(num1, num2):
    print(num1, " + ", num2)
    num3 = num1 + num2
    return num3

kotae = tashizan(3, 9)
print("答えは", kotae)</code></pre>
</div>
<p>このプログラムでは、2つの数字を足し算して答えを表示しています。</p>
<p>実行すると、以下のように表示されます。</p>
<div class="blank-box bb-green">3 + 9<br />
答えは 12</div>
<p>&nbsp;</p>
<h3><span id="toc4">関数を定義する</span></h3>
<p>関数を使うには、まず「<b>関数を定義する</b>」必要があります。これは、命令をひとまとめにして準備する作業です。<a rel="noopener" target="_self" href="https://living-maou.com/scratch-function/">Scratchの「ブロック定義」<span class="fa fa-external-link internal-icon anchor-icon"></span></a>と同じイメージです。</p>
<p>下のコードは、足し算をする関数を定義しています。</p>
<div class="blank-box bb-green">def tashizan(num1, num2):<br />
<em>   </em> print(num1, &#8221; + &#8220;, num2)<br />
<em>   </em> num3 = num1 + num2<br />
<em>   </em> return num3</div>
<p>関数の書き方は次のようになります。</p>
<div class="blank-box bb-blue">def 関数名(引数, 引数, …):<br />
<em>   </em> 命令文<br />
<em>   </em> …<br />
<em>   </em> return 戻り値</div>
<p>def の後に関数名を書きます。defはdefinition（定義）の略です。関数名の後にカッコをつけ、その中に必要なデータ（引数）を記述します。</p>
<p>関数の中の命令文の前には、半角スペース4つ（インデント）を入れてください。</p>
<p>&nbsp;</p>
<h3><span id="toc5">関数を呼び出す</span></h3>
<p>定義した関数を使うには、「<b>関数を呼び出す</b>」必要があります。</p>
<div class="blank-box bb-green">kotae = tashizan(3, 9)</div>
<p>この例では、tashizan(3, 9)が関数の呼び出し部分です。</p>
<p>関数の呼び出しは、次のように書きます。</p>
<div class="blank-box bb-blue">関数名(引数, 引数, …)</div>
<p>&nbsp;</p>
<h3><span id="toc6">引数は関数に渡す「材料」</span></h3>
<p><span style="color: #ff6600;"><b>引数（ひきすう）</b></span>とは、<span class="marker-under-red">関数に<ruby>渡<rt>わた</rt></ruby>す値</span><span>です</span><span>。</span>この値を使って関数が処理を行います。引数は、関数名の後ろのカッコの中に記述します。</p>
<p>引数とは、関数を呼び出したときに引きわたされる値のことで、関数が処理するための材料です。関数名の後ろのカッコに引数を書きます。</p>
<div class="blank-box bb-green">def tashizan(num1, num2):</div>
<p>この場合、num1とnum2が引数です。関数を呼び出すときに<ruby>渡<rt>わた</rt></ruby><span>し</span><span>た</span><span>値</span><span>が</span>、これらの引数に格納されます。</p>
<div class="blank-box bb-green">tashizan(3, 9)</div>
<p><span>この</span><span>コード</span><span>で</span><span>は</span><span>、</span><span>3</span><span>が</span><span>num</span><span>1</span><span>に</span><span>、</span><span>9</span><span>が</span><span>num</span><span>2</span><span>に</span><ruby>渡<rt>わた</rt></ruby><span>さ</span><span>れ</span><span>ます</span><span>。</span>ちなみに引数で使う変数（例：num1やnum2）は、関数の中だけで使えるローカル変数です。関数の外では使えません。</p>
<p>&nbsp;</p>
<h3><span id="toc7">関数が処理した結果として返す「答え」</span></h3>
<p><span style="color: #ff6600;"><b>戻り値（もどりち）</b></span>とは、<span class="marker-under-red">関数が処理の結果として返す値</span>です。</p>
<div class="blank-box bb-green">return num3</div>
<p>このコードでは、num3の値が<ruby>戻<rt>もど</rt></ruby>り<ruby>値<rt>ち</rt></ruby>として返されています。returnを使うと、その時点で関数の処理は<ruby>終了<rt>しゅうりょう</rt></ruby>し、呼び出し元に<ruby>戻<rt>もど</rt></ruby>ります。</p>
<p><ruby>戻<rt>もど</rt></ruby>り<ruby>値<rt>ち</rt></ruby>を受け取るには、次のように書きます。</p>
<div class="blank-box bb-green">kotae = tashizan(3, 9)</div>
<p><span>この</span><span>場合</span><span>、</span><span>tashizan</span><span>(</span><span>3</span><span>,</span><span> </span><span>9</span><span>)</span><span>の</span><ruby>戻<rt>もど</rt></ruby><span>り</span><ruby>値<rt>ち</rt></ruby><span>（</span><span>計算</span><span>結果</span><span>）</span><span>が</span><span>kotae</span><span>に</span><span>代入</span><span>さ</span><span>れ</span><span>ます</span><span>。</span></p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05.png" alt="関数を使った簡単なプログラム" width="800" height="450" class="aligncenter size-full wp-image-7209" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05.png 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc8">プログラムの改造：関数を使ってハートを3つ描く</span></h2>
<p>前回のプログラムを改造してみましょう。完成したプログラムは以下の通りです。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

def draw_heart(mc, x, y, z):
"""
ハートを描画する関数
:param mc: Minecraftオブジェクト
:param x: 描画開始のx座標
:param y: 描画開始のy座標
:param z: 描画開始のz座標
"""
# ハートの形を定義（2次元リスト）
heart = [
    [0, 1, 1, 0, 1, 1, 0],
    [1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1],
    [0, 1, 1, 1, 1, 1, 0],
    [0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 1, 0, 0, 0],
]

# ハートを描画
for row in range(len(heart)):
    for col in range(len(heart[row])):
        if heart[row][col] == 1: # 1の場所にブロックを置く
            mc.setBlock(x + col, y, z + row, 35, 14) # 赤い羊毛

# メイン処理
if __name__ == "__main__":
    mc = minecraft.Minecraft.create()

    # プレイヤーの座標を取得
    x, y, z = mc.player.getPos()

    # ハートを描画する開始地点を設定
    z += 5

    for _ in range(3):
        # ハートを描画
        draw_heart(mc, x, y, z)
        # 次のハートの位置をずらす
        x += 8</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc9">改造ポイントの解説</span></h2>
<h3><span id="toc10">関数を使って「ハートを描く処理」を整理</span></h3>
<p><span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>く</span><span>処理</span><span>を</span><span>、</span><span>draw</span><span>_</span><span>heart</span><span>と</span><span>いう</span><span>関数</span><span>に</span><span>まとめ</span><span>ます</span><span>。</span></p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03.png" alt="ハートを描く処理を関数にまとめる" width="800" height="450" class="aligncenter size-full wp-image-7205" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03.png 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-green">def draw_heart(mc, x, y, z):</div>
<p><span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>く</span><span>処理</span><span>を</span><span>、</span><span>draw</span><span>_</span><span>heart</span><span>と</span><span>いう</span><span>関数</span><span>に</span><span>まとめ</span><span>ます</span><span>。</span></p>
<p>関数の中ではハートの形を2次元のリストで作り、その形に合わせてブロックを置く処理を実行します。</p>
<p>&nbsp;</p>
<h3><span id="toc11">メイン処理</span></h3>
<p>if __name__ == &#8220;__main__&#8221;: は、Pythonプログラムがどのように実行されているかを判定する条件式です。</p>
<p>このファイルが直接実行されたときだけ中の処理が動き、他のプログラムからインポートされた場合は実行されません。</p>
<h4>プレイヤーの座標を取得</h4>
<div class="blank-box bb-green">x, y, z = mc.player.getPos()</div>
<p><span>プレイヤー</span><span>の</span><span>位置</span><span>を</span><span>基準</span><span>に</span><span>し</span><span>て</span><span>、</span><span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>き</span><ruby>始<rt>はじ</rt></ruby><span>め</span><span>ます</span><span>。</span></p>
<p>&nbsp;</p>
<h4>ループでハートを3つ描く</h4>
<div class="blank-box bb-green">for _ in range(3):<br />
<em>   </em> draw_heart(mc, x, y, z)<br />
<em>   </em> x += 8</div>
<p>ループを使って、draw_heart関数を3回呼び出します。x座標をずらして、ハートが横に並ぶようにしています。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04.png" alt="ループを使って関数を3回呼び出す" width="800" height="450" class="aligncenter size-full wp-image-7206" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04.png 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc12">実行してみよう！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06.jpg" alt="関数を使ってハートを描くプログラム" width="800" height="450" class="aligncenter size-full wp-image-7207" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06.jpg 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-06-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>このプログラムを「heart_shape2.py」という名前で保存します。</p>
<p><span>実行</span><span>する</span><span>と</span><span>、</span><span>プレイヤー</span><span>の</span><span>位置</span><span>から</span><span>少し</span><ruby>離<rt>はな</rt></ruby><span>れ</span><span>た</span><span>場所</span><span>に</span><span>ハート</span><span>が</span><span>横</span><span>に</span><span>3</span><span>つ</span><span>並ん</span><span>で</span><ruby>描<rt>えが</rt></ruby><span>か</span><span>れ</span><span>ます</span><span>！</span></p>
<p>&nbsp;</p>
<h2><span id="toc13">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07.jpg" alt="引数に色を追加したプログラム" width="800" height="450" class="aligncenter size-full wp-image-7208" srcset="https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07.jpg 800w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2025/01/minecraft-python10-07-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回のプログラムでは、関数を使って<span>ハート</span><span>を</span><span>3</span><span>つ</span><ruby>描<rt>えが</rt></ruby><span>く</span><span>プログラム</span>プログラムを作りました。</p>
<p>関数とは、命令をひとまとめにして、何度でも使えるようにする仕組みです。</p>
<p>関数の定義</p>
<div class="blank-box bb-blue">def 関数名(引数, 引数, …):<br />
<em>   </em> 命令文<br />
<em>   </em> …<br />
<em>   </em> return 戻り値</div>
<p>関数の呼び出し</p>
<div class="blank-box bb-blue">関数名(引数, 引数, …)</div>
<ul>
<li>引　数：<span>関数</span><span>に</span><ruby>渡<rt>わた</rt></ruby><span>す</span><span>値</span></li>
<li><ruby>戻<rt>もど</rt></ruby><span>り</span><ruby>値<rt>ち</rt></ruby>：関数が処理の結果として返す値</li>
</ul>
<p>ぜひこのプログラムを改造してみましょう！たとえば、ハートの色を引数で指定できるようにすると、赤以外の色も簡単に<ruby>描<rt>えが</rt></ruby>けるようになります。</p>
<p>好きな色を指定して、カラフルなハートをたくさん<ruby>描<rt>えが</rt></ruby>いてみてください！</p>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python10/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マインクラフト×Python】2次元リストでハートを描こう！</title>
		<link>https://living-maou.com/minecraft-python09/</link>
					<comments>https://living-maou.com/minecraft-python09/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Thu, 20 Feb 2025 01:05:38 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7182</guid>

					<description><![CDATA[今回は、Pythonを使って「ハート」を描えがくプログラムを作ってみましょう。 ハートの形を表現するために2次元リストを使います。この方法を覚えれば、他ほかの形を描えがくプログラムにも応用できますよ。 それでは早速さっそ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7183" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回は、Pythonを使って「ハート」を<ruby>描<rt>えが</rt></ruby>くプログラムを作ってみましょう。</p>
<p>ハートの形を表現するために<b>2次元リスト</b>を使います。この方法を覚えれば、<ruby>他<rt>ほか</rt></ruby>の形を<ruby>描<rt>えが</rt></ruby>くプログラムにも応用できますよ。</p>
<p>それでは<ruby>早速<rt>さっそく</rt></ruby>、プログラミングを始めてみましょう！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python08/" title="【マイクラ×Python】秒で完成！広大な小麦畑をプログラミングで作る" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】秒で完成！広大な小麦畑をプログラミングで作る</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトで大きな小麦畑を作るPythonプログラムを紹介。【リビングの魔王】では、初心者にも分かりやすく図解を使い、9×9ブロックの小麦畑をならべて広大な畑を作る方法を紹介します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>Pythonでマインクラフトを動かすには、特別な準備が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前の記事でくわしく説明していますので、まだ準備ができていない人はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">このプログラムでやること</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01.png" alt="ハート" width="800" height="450" class="aligncenter size-full wp-image-7184" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回のプログラムでは、<span>以下</span><span>の</span><span>手順</span><span>で</span><span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>き</span><span>ます</span>：</p>
<ol>
<li>ハートの形を定義する<br />
2次元リストを使ってハートのデザインを作ります。<br />
リストの中で、1 がブロックを置く場所、0 が空白の場所を表します。</li>
<li>ブロックを配置して<span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>く</span><br />
リストの情報をもとに、ブロックをならべて<span>ハート</span><span>を</span><ruby>描画<rt>びょうが</rt></ruby><span>し</span><span>ます</span><span>。</span></li>
</ol>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>まずは、完成したプログラムを見てみましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

# ハートを描くスタート地点を設定
z += 5

# ハートの形を定義（2次元リスト）
# 1がブロックを置く場所、0は何も置かない
heart = [
    [0, 1, 1, 0, 1, 1, 0],
    [1, 1, 1, 1, 1, 1, 1],
    [1, 1, 1, 1, 1, 1, 1],
    [0, 1, 1, 1, 1, 1, 0],
    [0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 1, 0, 0, 0],
]

# ハートを描画
for row in range(len(heart)):
    for col in range(len(heart[row])):
        if heart[row][col] == 1:
            mc.setBlock(x + col, y, z + row, 35, 14)</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<h3><span id="toc5">2次元のリストでハートの形を定義する</span></h3>
<p>プログラムの最初の部分では、ハートの形を2次元リストで定義しています。</p>
<p><span class="marker-under-red"><span style="color: #ff6600;"><b>2次元リスト</b></span>は「リストの中にリストが入っているもの」</span>です。方眼紙のマス目のように、横の「<b>行</b>」と縦の「<b>列</b>」でデータを整理できます。</p>
<p>2次元リストを使うと、表のようなデータをコンピューターでかんたんに<ruby>扱<rt>あつか</rt></ruby>えます。たとえば、クラスの成績表やゲームのマップなど、いろいろな場面で使われています。</p>
<div class="blank-box bb-green">heart = [<br />
<em>   </em> [0, 1, 1, 0, 1, 1, 0],<br />
<em>   </em> [1, 1, 1, 1, 1, 1, 1],<br />
<em>   </em> [1, 1, 1, 1, 1, 1, 1],<br />
<em>   </em> [0, 1, 1, 1, 1, 1, 0],<br />
<em>   </em> [0, 0, 1, 1, 1, 0, 0],<br />
<em>   </em> [0, 0, 0, 1, 0, 0, 0],<br />
]</div>
<p>このリストの中で、1はブロックを置く場所を表し、0は空白の場所を表します。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02.png" alt="ハートを表で表現する" width="800" height="450" class="aligncenter size-full wp-image-7185" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc6">ハートを描く</span></h3>
<p>次に、<span>この</span><span>リスト</span><span>を</span><span>使っ</span><span>て</span><span>実際</span><span>に</span><span>ハート</span><span>を</span><ruby>描<rt>えが</rt></ruby><span>き</span><span>ます</span><span>。</span></p>
<div class="blank-box bb-green">for row in range(len(heart)):　← 外側のループ（行番号を取得）<br />
<em>   </em> for col in range(len(heart[row])):　← 内側のループ（列番号を取得）<br />
<span style="color: #999999;"><em>       </em> if heart[row][col] == 1:</span><br />
<span style="color: #999999;"><em>           </em> mc.setBlock(x + col, y, z + row, 35, 14)</span></div>
<div class="blank-box bb-blue">
<ol>
<li>行番号を取得するループ<br />
外側のループでリストの行（縦方向の位置）を管理します。<br />
このループにより、どの行を処理するかが決まります。</li>
<li>列番号を取得するループ<br />
内側のループで、行の中の列（横方向の位置）を管理します。<br />
このループにより、どの列にブロックを置くかが決まります。</li>
</ol>
</div>
<p>行番号を取得するループの中に列番号を取得するループを入れることで、リストの要素をひとつひとつ調べ、ハートの<span>形</span><span>を</span><ruby>描画<rt>びょうが</rt></ruby><span>し</span><span>ます</span><span>。</span></p>
<p>このように、ループの中にもうひとつループがある構造を<span style="color: #ff6600;"><b>二重ループ</b></span>といいます。</p>
<p>&nbsp;</p>
<h4>行番号を取得するループ</h4>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03.png" alt="行番号を取得するループ" width="800" height="450" class="aligncenter size-full wp-image-7186" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-green">for row in range(len(heart)):</div>
<p>このループは、rowに0から5までの数字を順番に代入し、リストの行<span>の</span><ruby>添<rt>そ</rt></ruby><span>え</span><ruby>字<rt>じ</rt></ruby><span>に</span><span>してい</span><span>ます。</span></p>
<p><span>len(heart)でheartの行数（縦の数）を調べ、6を返しています。<br />
</span></p>
<div class="blank-box bb-blue">len(リスト名)：リストの長さ（要素の数）を調べる</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4>列番号を取得するループ</h4>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04.png" alt="列番号を取得するループ" width="800" height="450" class="aligncenter size-full wp-image-7187" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-green">for col in range(len(heart[row])):</div>
<p>このループは、col に0から6までの数字を順番に代入し、リストの<span>列</span><span>の</span><ruby>添<rt>そ</rt></ruby><span>え</span><ruby>字<rt>じ</rt></ruby><span>に</span>しています。</p>
<p>len(heart[row])で、その行にふくまれる列の数(横の数）、7を取得します。</p>
<p>列番号を取得するループが終わったら、行番号を取得するループにもどります。</p>
<p>&nbsp;</p>
<h4>リストの1の場所に羊毛を置く</h4>
<p>リストの要素にアクセスする準備ができました。</p>
<p>heart[row][col] でrow行目のcol列目の要素をみることができます。</p>
<div class="blank-box bb-green">if heart[row][col] == 1:<br />
<em>   </em> mc.setBlock(x + col, y, z + row, 35, 14)</div>
<p>このコードでは、リスト内のrow行目のcol列目の値が 1 である場合にブロックを置きます。</p>
<p>また、x + col と z + row を使うことで、リスト内の位置をマインクラフト内の座標<span>に</span><ruby>変換<rt>へんかん</rt></ruby><span>し</span><span>ます</span><span>。</span></p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05.png" alt="リストの要素にアクセスする" width="800" height="450" class="aligncenter size-full wp-image-7188" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc7">実行してみよう！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06.jpg" alt="ハートを描くプログラム" width="800" height="450" class="aligncenter size-full wp-image-7189" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-06-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>プログラムが完成したら「heart_shape.py」という名前でファイルを保存し、実行してみましょう。</p>
<p>プレイヤーの近くにハートができているはずです。</p>
<p>&nbsp;</p>
<h3><span id="toc8">row と col の値の動きをみてみよう</span></h3>
<p>二重ループがどのように動いているのかを確認するため、外側のループと内側のループの一番最初に print 文を追加して動かしてみましょう。</p>
<div class="blank-box bb-green"># ハートを描画<br />
for row in range(len(heart)):<br />
<em>   </em> <span style="color: #ff6600;">print(f&#8221;row: {row}&#8221;)</span><br />
<em>   </em> <span style="color: #ff6600;">time.sleep(0.5)</span><br />
<em>   </em> for col in range(len(heart[row])):<br />
<em>       </em> <span style="color: #ff6600;">print(f&#8221;row: {row}, col: {col}&#8221;)</span><br />
<em>       </em> if heart[row][col] == 1:<br />
<em>           </em> mc.setBlock(x + col, y, z + row, 35, 14)<br />
<em>       </em> <span style="color: #ff6600;">time.sleep(0.5)</span></div>
<p>&nbsp;</p>
<p>これを実行すると、シェルにrowとcolの値が出力されます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07.png" alt="ループの一番最初に print 文を追加" width="800" height="450" class="aligncenter size-full wp-image-7190" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python09-07-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>シェルには次のような内容が出力されます。</p>
<div class="blank-box bb-blue">row: 0         <span style="color: #ff9900;">← print① 外側のループ1回目</span><br />
row: 0, col: 0 <span style="color: #99cc00;">← print② 内側のループ1回目</span><br />
row: 0, col: 1 <span style="color: #99cc00;">← print② 内側のループ2回目</span><br />
row: 0, col: 2 <span style="color: #99cc00;">← print② 内側のループ3回目</span><br />
row: 0, col: 3 <span style="color: #99cc00;">← print② 内側のループ4回目</span><br />
row: 0, col: 4 <span style="color: #99cc00;">← print② 内側のループ5回目</span><br />
row: 0, col: 5 <span style="color: #99cc00;">← print② 内側のループ6回目</span><br />
row: 0, col: 6 <span style="color: #99cc00;">← print② 内側のループ7回目</span><br />
row: 1         <span style="color: #ff9900;">← print① 外側のループ2回目</span><br />
row: 1, col: 0<br />
row: 1, col: 1<br />
row: 1, col: 2<br />
row: 1, col: 3<br />
row: 1, col: 4<br />
row: 1, col: 5<br />
row: 1, col: 6<br />
row: 2         <span style="color: #ff9900;">← print① 外側のループ3回目</span><br />
row: 2, col: 0<br />
row: 2, col: 1<br />
row: 2, col: 2<br />
row: 2, col: 3<br />
row: 2, col: 4<br />
row: 2, col: 5<br />
row: 2, col: 6<br />
row: 3         <span style="color: #ff9900;">← print① 外側のループ4回目</span><br />
row: 3, col: 0<br />
row: 3, col: 1<br />
row: 3, col: 2<br />
row: 3, col: 3<br />
row: 3, col: 4<br />
row: 3, col: 5<br />
row: 3, col: 6<br />
row: 4         <span style="color: #ff9900;">← print① 外側のループ5回目</span><br />
row: 4, col: 0<br />
row: 4, col: 1<br />
row: 4, col: 2<br />
row: 4, col: 3<br />
row: 4, col: 4<br />
row: 4, col: 5<br />
row: 4, col: 6<br />
row: 5         <span style="color: #ff9900;">← print① 外側のループ6回目</span><br />
row: 5, col: 0<br />
row: 5, col: 1<br />
row: 5, col: 2<br />
row: 5, col: 3<br />
row: 5, col: 4<br />
row: 5, col: 5<br />
row: 5, col: 6</div>
<p>このように、内側のループがすべて回り終わると外側のループにもどり、次の値で再び内側のループを回ることが分かります。</p>
<p><span class="marker-under-red">二重ループは、外側のループが1回回る間に、内側のループがすべて回る仕組み</span>です。</p>
<p>前回の<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python08/">小麦畑を作るプログラム<span class="fa fa-external-link internal-icon anchor-icon"></span></a>でも二重ループを使っていました。</p>
<p>&nbsp;</p>
<h2><span id="toc9">まとめ</span></h2>
<p>今回のプログラムでは、Pythonの2次元リストを使ってハートを<ruby>描<rt>えが</rt></ruby>く方法を学びました。</p>
<ul>
<li>2次元のリストを作る方法</li>
<li>ループを使ってリストからデータを取り出す方法</li>
</ul>
<p>これらを理解することで、さまざまな形を<ruby>描<rt>えが</rt></ruby>くプログラムが作れるようになりますよ。</p>
<p>&nbsp;</p>
<p>次回は、<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python10/">このプログラムを改造してハートをたくさん<ruby>描<rt>えが</rt></ruby>きます<span class="fa fa-external-link internal-icon anchor-icon"></span></a>。お楽しみに！</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python10/" title="【マイクラ×Python】ハートを描くプログラムを改造！関数を使ってみよう" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2025/01/eyecatch-minecraft-python10.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】ハートを描くプログラムを改造！関数を使ってみよう</div><div class="blogcard-snippet internal-blogcard-snippet">関数を使ってハートをたくさん描くプログラムを作ってみましょう。前回作ったハートを描くプログラムを改造します。【リビングの魔王】では、Pythonの関数の使い方をやさしく解説。初心者でも楽しく挑戦できる内容です！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python09/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】秒で完成！広大な小麦畑をプログラミングで作る</title>
		<link>https://living-maou.com/minecraft-python08/</link>
					<comments>https://living-maou.com/minecraft-python08/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Mon, 20 Jan 2025 01:28:43 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7153</guid>

					<description><![CDATA[マインクラフトの大規模な畑作り、手作業だと大変ですよね。クワで耕したり、水の位置を考えたり、種をまいたり…。 でもPythonを使えば、そんな大変な作業も一瞬いっしゅんで完了かんりょうします！この記事では、プログラムを使 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7154" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトの大規模な畑作り、手作業だと大変ですよね。クワで耕したり、水の位置を考えたり、種をまいたり…。</p>
<p>でもPythonを使えば、そんな大変な作業も<ruby>一瞬<rt>いっしゅん</rt></ruby>で<ruby>完了<rt>かんりょう</rt></ruby>します！この記事では、プログラムを使ってかんたんに大きな小麦畑を作る方法を<ruby>紹介<rt>しょうかい</rt></ruby>します。</p>
<p>プログラム初心者の人でも<ruby>大丈夫<rt>だいじょうぶ</rt></ruby>。少しずつ解説していきますので、チャレンジしてみましょう！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python07/" title="【マイクラ×Python】危険ゼロ！？安心安全の直下掘りプログラム" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】危険ゼロ！？安心安全の直下掘りプログラム</div><div class="blogcard-snippet internal-blogcard-snippet">マイクラでは危険な直下掘りもプログラムを使えば安心！Pythonを使って危険なブロックを回避し、掘れるブロックだけ掘り進める便利なプログラムを作成してみましょう！初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>Pythonでマインクラフトを動かすには、特別な準備が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前の記事でくわしく説明していますので、まだ準備ができていない人はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">小麦畑を作るプログラム概要</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01.png" alt="小麦畑を作るプログラム概要" width="800" height="450" class="aligncenter size-full wp-image-7155" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回作成するプログラムでは、9×9ブロックの小麦畑を複数並べ、大規模な畑を作ります。</p>
<p>各畑の中央には水を配置して、<ruby>全<rt>すべ</rt></ruby>ての耕地が<ruby>湿<rt>しめ</rt></ruby>るようにします。</p>
<p>完成すると、横3つ、縦2つの計6つの9×9ブロックの小麦畑が整列した広い畑になりますよ。</p>
<p>これを手作業で作ると時間がかかりますが、プログラムなら<ruby>一瞬<rt>いっしゅん</rt></ruby>です！</p>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>完成したプログラムは以下の通りです。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

# 基準になる座標を設定
cur_x = x + 1
cur_z = z + 1

# 9×9ブロックの耕地を2行×3列作成
for _ in range(2):
    for _ in range(3):

        # 空気ブロックで耕地の範囲をクリア
        mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 100, cur_z + 8, 0)
        # 耕地を作成
        mc.setBlocks(cur_x, y - 1, cur_z, cur_x + 8, -1, cur_z + 8, 60)
        # 小麦を植える
        mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 0, cur_z + 8, 59)
        # 中央に水を配置
        mc.setBlock(cur_x + 4, y - 1, cur_z + 4, 9)

        # 基準の座標（x軸）を進める
        cur_x += 9

    # 基準の座標を設定（x軸：もどす、z軸：進める）
    cur_x = x + 1
    cur_z += 9</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<h3><span id="toc5">プレイヤーの座標を取得</span></h3>
<p>最初に、プレイヤーの位置を基準として畑を作る準備をします。</p>
<div class="blank-box bb-green">x, y, z = mc.player.getPos()<br />
cur_x = x + 1<br />
cur_z = z + 1</div>
<p>mc.player.getPos()を使って、プレイヤーの現在位置（x, y, z座標）を取得します。</p>
<p>その後、基準となる座標cur_xとcur_zを設定します。これを基準に畑を配置します。</p>
<p>&nbsp;</p>
<h3><span id="toc6">9×9の小麦畑を作る</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03.jpg" alt="9×9の小麦畑を作るプログラム" width="800" height="450" class="aligncenter size-full wp-image-7156" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-03-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>中央に水ブロックのある9×9の畑をひとつ作ってみましょう。</p>
<div class="blank-box bb-green">mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 100, cur_z + 8, 0)<br />
mc.setBlocks(cur_x, y &#8211; 1, cur_z, cur_x + 8, -1, cur_z + 8, 60)<br />
mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 0, cur_z + 8, 59)<br />
mc.setBlock(cur_x + 4, y &#8211; 1, cur_z + 4, 9)</div>
<ol>
<li>畑の上を空気ブロックに置きかえる</li>
<li>地面を耕地ブロックに置きかえる</li>
<li>耕地ブロックの上に小麦を置く</li>
<li>最後に畑の中央に水を配置する</li>
</ol>
<p>水を中央に置くことで、畑全体がうるおう仕組みです。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02.png" alt="9×9の小麦畑を作る手順" width="800" height="450" class="aligncenter size-full wp-image-7157" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc7">東（xプラス）の方向に畑を広げる</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05.jpg" alt="東に畑をならべるプログラム" width="800" height="450" class="aligncenter size-full wp-image-7158" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-05-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>次に、畑を横（東方向）にならべます。9×9の畑を作る処理をfor文でくり返しましょう。</p>
<div class="blank-box bb-green"><span style="color: #ff6600;">for _ in range(3):</span><br />
<em>   </em> mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 100, cur_z + 8, 0)<br />
<em>   </em> mc.setBlocks(cur_x, y &#8211; 1, cur_z, cur_x + 8, -1, cur_z + 8, 60)<br />
<em>   </em> mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 0, cur_z + 8, 59)<br />
<em>   </em> mc.setBlock(cur_x + 4, y &#8211; 1, cur_z + 4, 9)<br />
<em>   </em> <span style="color: #ff6600;">cur_x += 9</span></div>
<p>&nbsp;</p>
<p>このループでは3つの畑を横にならべます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04.png" alt="東に畑をならべる" width="800" height="450" class="aligncenter size-full wp-image-7159" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>cur_x += 9 <span>で</span><span>x</span><ruby>軸<rt>じく</rt></ruby><span>の</span>基準座標（cur_x）を9ブロックずつ動かすことで、畑が東方向に広がります。</p>
<p>&nbsp;</p>
<h3><span id="toc8">畑を南（z方向）に広げる</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07.jpg" alt="3つ横に並んだ畑を南にならべるプログラム" width="800" height="450" class="aligncenter wp-image-7160 size-full" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-07-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今度は、3つ横にならんだ畑を縦（南方向）にならべる処理を追加します。</p>
<div class="blank-box bb-green"><span style="color: #ff6600;">for _ in range(2):</span><br />
<em>   </em> for _ in range(3):<br />
<em>       </em> mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 100, cur_z + 8, 0)<br />
<em>       </em> mc.setBlocks(cur_x, y &#8211; 1, cur_z, cur_x + 8, -1, cur_z + 8, 60)<br />
<em>       </em> mc.setBlocks(cur_x, y, cur_z, cur_x + 8, 0, cur_z + 8, 59)<br />
<em>       </em> mc.setBlock(cur_x + 4, y &#8211; 1, cur_z + 4, 9)<br />
<em>       </em> cur_x += 9<br />
<em>    </em><br />
<em style="background-color: var(--cocoon-custom-background-color); color: var(--cocoon-custom-text-color);">    </em><span style="background-color: var(--cocoon-custom-background-color); color: var(--cocoon-custom-text-color);"><span style="color: #ff6600;">cur_x = x + 1</span><br />
</span><em>   </em> <span style="color: #ff6600;">cur_z += 9</span></div>
<p>&nbsp;</p>
<p>3つ横にならんだ畑を縦に2つならべるイメージです。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06.png" alt="3つ横に並んだ畑を南にならべる手順" width="800" height="450" class="aligncenter size-full wp-image-7161" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-06-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>cur_z += 9 <span>で</span><span>z</span><ruby>軸<rt>じく</rt></ruby><span>の</span>座標を9ブロック進めることで、畑を南（zプラス）の方向に広げます。</p>
<p>各行の最初の畑は、常に同じx座標から始まるようにする必要があります。一番西の位置にもどしましょう。</p>
<p>&nbsp;</p>
<h2><span id="toc9">実行してみよう！</span></h2>
<p>プログラムが完成したら「wheat.py」という名前で保存し、実行してみましょう。</p>
<p><span>広大</span><span>な</span><span>小麦畑</span><span>が</span><ruby>瞬時<rt>しゅんじ</rt></ruby><span>に</span><span>広がる</span><span>はず</span><span>です</span><span>！</span></p>
<p>&nbsp;</p>
<h3><span id="toc10">コマンドブロックからでも実行できる！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08.png" alt="コマンドブロックからPythonプログラムを実行する" width="800" height="450" class="aligncenter size-full wp-image-7162" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08.png 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-08-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>実は、コマンドブロックからでもPythonで作ったプログラムを実行できます。</p>
<p>同じ場所で同じプログラムを何回も実行したい時に便利ですよ。</p>
<div class="blank-box bb-blue">
<ol>
<li>コマンドブロックを入手する<br />
<span>チャット</span><ruby>欄<rt>らん</rt></ruby><span>に</span><span>「</span><span>/</span><span>give</span><span> </span><span>@</span><span>p</span><span> </span><span>command</span><span>_</span><span>block</span><span>」</span><span>を</span><span>入力</span><span>し</span><span>実行</span><span>し</span><span>ます</span><span>。</span></li>
<li>コマンドブロックを設置する<br />
設置後、右クリックでコマンドブロックの設定画面を開きます。</li>
<li>コンソールコマンドにプログラムを実行するコマンドを入力<br />
今回のプログラムの場合「/py wheat」と入力します。</li>
<li>レッドストーン信号を送る</li>
</ol>
</div>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-cmd_block/">コマンドブロックの入手方法や設定方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>については、以下の記事でくわしく解説しています。まだ使ったことがない人は、ぜひ参考にしてみてください！</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-cmd_block/" title="【マイクラ】コマンドブロックの出し方と基本的な使い方" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2020/04/eyecatch_Minecraft_cmdblock.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ】コマンドブロックの出し方と基本的な使い方</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトのコマンドブロックの出し方と基本的な使い方について解説。【リビングの魔王】では初心者にも分かりやすいようにコマンドブロックを入手する手順をスクリーンショットを使って、ていねいに紹介します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<p>小麦が<span>成長</span><span>し</span><span>て</span><ruby>収穫<rt>しゅうかく</rt></ruby><span>できる</span><span>状態</span>のときに、耕地ブロックを草ブロックに変えると、植わっていた小麦がアイテムとして地面に落ちます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09.jpg" alt="小麦の収穫と種まきプログラム" width="800" height="450" class="aligncenter size-full wp-image-7163" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-09-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>アイテム化した小麦は、コマンドを使って回収すると楽です。</p>
<div class="blank-box bb-green">/tp @e[type=item] @p</div>
<p>&nbsp;</p>
<h2><span id="toc11">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10.jpg" alt="大きな小麦畑" width="800" height="450" class="aligncenter size-full wp-image-7164" srcset="https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10.jpg 800w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/minecraft-python08-10-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>この記事では、Pythonを使ってマインクラフト内に大規模な小麦畑を作る方法を<ruby>紹介<rt>しょうかい</rt></ruby>しました。</p>
<p>プログラムを使えば、大変な作業も<ruby>一瞬<rt>いっしゅん</rt></ruby>で終わりますね。</p>
<p>プログラムを自分好みにアレンジして、さらに大きな畑を作ったり、<ruby>他<rt>ほか</rt></ruby>の作物を植えたりしてみてください！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python09/" title="【マインクラフト×Python】2次元リストでハートを描こう！" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python09.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マインクラフト×Python】2次元リストでハートを描こう！</div><div class="blogcard-snippet internal-blogcard-snippet">Pythonを使ってマインクラフトの世界にハートを描いてみよう！【リビングの魔王】では、2次元リストの使い方や二重ループの仕組みをやさしく解説。初心者でも楽しく挑戦できる内容です！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python08/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】危険ゼロ！？安心安全の直下掘りプログラム</title>
		<link>https://living-maou.com/minecraft-python07/</link>
					<comments>https://living-maou.com/minecraft-python07/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Mon, 06 Jan 2025 05:13:45 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7125</guid>

					<description><![CDATA[マインクラフトで直下掘ぼり、危険ですよね？ マグマに落ちたり、どうくつに落下したり…こわい経験をした人も多いはず。 でも、プログラミングで安全に直下掘ぼりができます。 今回は、Pythonで安心安全な直下掘ぼりプログラム [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7126" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトで直下<ruby>掘<rt>ぼ</rt></ruby>り、危険ですよね？</p>
<p>マグマに落ちたり、どうくつに落下したり…こわい経験をした人も多いはず。</p>
<p>でも、プログラミングで安全に直下<ruby>掘<rt>ぼ</rt></ruby>りができます。</p>
<p>今回は、Pythonで安心安全な直下<ruby>掘<rt>ぼ</rt></ruby>りプログラムを作ってみましょう！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python06/" title="【マイクラ×Python】プログラミングで長い橋もラクラク作成！" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】プログラミングで長い橋もラクラク作成！</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトで川や谷に橋をかけたいと思ったことはありませんか？今回はPythonで繰り返し処理や条件を使って橋を作るプログラム紹介します。初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>Pythonでマインクラフトを動かすには、準備が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前の記事でくわしく説明していますので、まだ準備ができていない人はそちらを参考にしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">このプログラムでやること</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01.png" alt="直下掘りプログラムでやること" width="800" height="450" class="aligncenter size-full wp-image-7127" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>このプログラムでは、次のことを行います：</p>
<div class="blank-box bb-blue">
<ol>
<li><span>足元</span><span>が</span><ruby>岩盤<rt>がんばん</rt></ruby><span>の</span><span>場合</span><span>は</span><ruby>掘<rt>ほ</rt></ruby><span>る</span><span>の</span><span>を</span><span>やめる</span><span>。</span></li>
<li><span>足元</span><span>の</span><span>ブロック</span><span>の</span><span>さらに</span><span>下</span><span>の</span><span>ブロック</span><span>を</span><ruby>確認<rt>かくにん</rt></ruby><span>し</span><span>、</span><span>危険</span><span>が</span><span>あれ</span><span>ば</span><ruby>掘<rt>ほ</rt></ruby><span>る</span><span>の</span><span>を</span><span>やめる</span><span>。</span></li>
<li><span>足元</span><span>が</span><ruby>掘<rt>ほ</rt></ruby><span>っ</span><span>て</span><span>も</span><span>よい</span><span>ブロック</span><span>なら</span><span>、</span><span>空気</span><span>ブロック</span><span>に</span><span>変え</span><span>て</span><ruby>掘<rt>ほ</rt></ruby><span>り</span><ruby>進<rt>すす</rt></ruby><span>め</span><span>、</span><span>1</span><span>ブロック</span><span>下</span><span>に</span><span>移動</span><span>する</span><span>。</span></li>
<li><span>足元</span><span>が</span><ruby>掘<rt>ほ</rt></ruby><span>っ</span><span>て</span><span>も</span><span>よい</span><span>ブロック</span><span>以外</span><span>なら</span><span>、</span><ruby>掘<rt>ほ</rt></ruby><span>る</span><span>の</span><span>を</span><span>やめる</span><span>。</span></li>
</ol>
</div>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>まずは、完成版のプログラムを見てみましょう！</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft
import time

mc = minecraft.Minecraft.create()

# 掘ってもよいブロックのIDリスト
# 石、草、土、砂、砂利
safe_blocks = [1, 2, 3, 12, 13]

# 危険なブロックのIDリスト
#空気、溶岩、静止した溶岩
danger_blocks = [0, 10, 11]

# 直下掘りを開始
while True:
    # プレイヤーの座標を取得
    x, y, z = mc.player.getTilePos()

    # プレイヤーの足元とその下のブロックIDを取得
    block_below = mc.getBlock(x, y - 1, z)
    block_below2 = mc.getBlock(x, y - 2, z)

    # 直下のブロックが岩盤だったら、直下掘りをやめる
    if block_below == 7:
        mc.postToChat("Stop digging! Bedrock is here!")
        break

    # ふたつ下のブロックが危険なブロックだったら、直下掘りをやめる
    if block_below2 in danger_blocks:
        mc.postToChat("Danger! Lava or a cave is below.")
        break

    # 掘ってもよいブロックなら、空気（ID: 0）に変換し 1ブロック下に移動
    if block_below in safe_blocks:
        mc.setBlock(x, y - 1, z, 0)
        mc.player.setPos(x, y - 1, z)
    else:
        mc.postToChat("You found something interesting!")
        break

    # 少し待ってから次の掘削へ
    time.sleep(0.5)</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<h3><span id="toc5">リストでデータをまとめる</span></h3>
<p><ruby>掘<rt>ほ</rt></ruby><span>っ</span><span>て</span><span>も</span><span>よい</span><span>ブロック</span><span>と</span>危険なブロックをそれぞれ<a rel="noopener" target="_self" href="https://living-maou.com/scratch-list/">リスト<span class="fa fa-external-link internal-icon anchor-icon"></span></a>で管理しています。</p>
<div class="blank-box bb-green"># 掘ってもよいブロックのIDリスト<br />
safe_blocks = [1, 2, 3, 12, 13]<br />
<span style="background-color: var(--cocoon-custom-background-color); color: var(--cocoon-custom-text-color);"># 危険なブロックのIDリスト<br />
</span>danger_blocks = [0, 10, 11]</div>
<p>&nbsp;</p>
<p><span style="color: #ff6600;"><b>リスト</b></span>は、<span class="marker-under-red">いくつかのデータを順番にならべて、まとめてあつかうことができるデータの種類</span>です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02.png" alt="Python リストの基本" width="800" height="450" class="aligncenter size-full wp-image-7128" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>左側にリスト名、右側に角かっこ [] の中にデータをカンマで区切ってならべて、=でつなぐとリストを作成できます。</p>
<div class="blank-box bb-blue">リスト名 = [値1, 値2, …]</div>
<p>&nbsp;</p>
<h3><span id="toc6">ずっとくり返す</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png" alt="Python while文" width="800" height="450" class="aligncenter size-full wp-image-7108" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>Pythonでは、<span class="marker-under-red">「指定した条件を満たしている間、処理くり返す」ときに <span style="color: #ff6600;">while</span> 文</span>を使います。while 文では、条件を満たしている(True)かぎり、処理をくり返します。</p>
<p><span class="marker-under-red">条件に「True」を指定すると、プログラムを止めるまでずっとくり返し</span>ます。</p>
<div class="blank-box bb-blue">while <span style="color: #ff6600;">True</span>:<br />
<em>   </em> ずっとくり返したい処理</div>
<p>&nbsp;</p>
<h3><span id="toc7">True（真） と False（偽）</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png" alt="TrueとFalse" width="800" height="450" class="aligncenter size-full wp-image-7109" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><span class="marker-under-red"><span style="color: #ff6600;">True</span>と<span style="color: #ff6600;">False</span>は「<ruby>真<rt>しん</rt></ruby>」または「<ruby>偽<rt>ぎ</rt></ruby>」を表す<ruby>真偽値<rt>しんぎち</rt></ruby>（ブール値）</span>と呼ばれます。</p>
<p>プログラムの条件で「正しいか」「正しくないか」を判断するときに使われます。</p>
<div class="blank-box bb-blue">
<ul>
<li>True（真） ：条件が「正しい」とき</li>
<li>False（偽）：条件が「正しくない」とき</li>
</ul>
</div>
<p>Pythonでは、数値の0や空の値はFalseとして扱われ、それ以外の値はTrueとされます。</p>
<p>&nbsp;</p>
<h3><span id="toc8">足元のブロックとその下のブロックを調べる</span></h3>
<p>プレイヤーの座標を取得したら、プレイヤーの足元とその下のブロックが何か調べます。</p>
<div class="blank-box bb-green"># プレイヤーの座標を取得<br />
x, y, z = mc.player.getTilePos()<br />
<span style="background-color: var(--cocoon-custom-background-color); color: var(--cocoon-custom-text-color);"># プレイヤーの直下とその下のブロックIDを取得<br />
</span>block_below = mc.getBlock(x, <span style="color: #ff6600;">y &#8211; 1</span>, z)<br />
block_below2 = mc.getBlock(x, <span style="color: #ff6600;">y &#8211; 2</span>, z)</div>
<p>mc.getBlock(x, y, z) で、指定した座標のブロックIDを取得できます。</p>
<p>block_belowには足元のブロック、block_below2にはさらに下のブロックのブロックIDを代入します。</p>
<p>&nbsp;</p>
<h3><span id="toc9">条件によって処理を変える</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03.png" alt="Python if文" width="800" height="450" class="aligncenter size-full wp-image-7129" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><span class="marker-under-red">条件によって処理を分けるときは、<span style="color: #ff6600;">if</span> 文</span>を使います。</p>
<p>条件を満たした場合だけ特定の処理をするとき</p>
<div class="blank-box bb-blue">if 条件:<br />
<em>   </em> 条件がTrueだった時の処理</div>
<p>条件を満たした場合と、満たさなかった場合、別々の処理をするとき</p>
<div class="blank-box bb-blue">if 条件:<br />
<em>   </em> 条件がTrueだった時の処理<br />
else:<br />
<em>   </em> 条件がFalseだった時の処理</div>
<p>条件がTrue（またはFalse）だった時の処理の前には、半角スペースを4つ入れます。</p>
<p>&nbsp;</p>
<h3><span id="toc10">リストの中に特定の値があるか調べる</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04.png" alt="Python in" width="800" height="450" class="aligncenter size-full wp-image-7130" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>in や not in を使うと、「リストや文字列などの中に特定の値があるかどうか」を調べられます。</p>
<div class="blank-box bb-blue">
<ul>
<li>in    ：右辺に左辺が存在する</li>
<li>not in：右辺に左辺が存在しない</li>
</ul>
</div>
<p>&nbsp;</p>
<p>今回のプログラムでは、下のような判定をしています。</p>
<ul>
<li>if block_below == 7:<br />
→ 足元のブロック(block_below)<span>が</span><ruby>岩盤<rt>がんばん</rt></ruby><span>(</span><span>7</span><span>)</span>だったら</li>
<li>if block_below2 in danger_blocks:<br />
→ 2つ下のブロック(block_below2)が危険なブロックのリスト(danger_blocks)の中にあったら</li>
<li>if block_below in safe_blocks:<br />
→ 足元のブロック(block_below)<span>が</span><ruby>掘<rt>ほ</rt></ruby><span>っ</span><span>て</span>もよいブロックのリスト(safe_blocks)の中にあったら</li>
</ul>
<p>&nbsp;</p>
<h3><span id="toc11">ループからぬける</span></h3>
<p><span class="marker-under-red"><span style="color: #ff6600;">break</span> は、くり返し（ループ）を<ruby>途中<rt>とちゅう</rt></ruby>でぬけたいとき</span>に使います。</p>
<div class="blank-box bb-green"># 直下のブロックが岩盤だったら<br />
if block_below == 7:<br />
<em>   </em> mc.postToChat(&#8220;Stop digging! Bedrock is here!&#8221;)<br />
<em>   </em> break<br />
<span style="background-color: var(--cocoon-custom-background-color); color: var(--cocoon-custom-text-color);"># ふたつ下のブロックが危険なブロックだったら<br />
</span>if block_below2 in danger_blocks:<br />
<em>   </em> mc.postToChat(&#8220;Danger! Lava or a cave is below.&#8221;)<br />
<em>   </em> break</div>
<p>真下のブロック(block_below)<span>が</span><ruby>岩盤<rt>がんばん</rt></ruby><span>(</span><span>7</span><span>)</span><span>だっ</span><span>たり</span><span>、</span>2つ下のブロックが危険なブロックだった場合、メッセージを表示してループをぬけます。</p>
<ul>
<li>Stop digging! Bedrock is here!<span>（</span><ruby>採掘<rt>さいくつ</rt></ruby><span>ストップ</span><span>！</span><ruby>岩盤<rt>がんばん</rt></ruby><span>が</span><span>あり</span><span>ます</span><span>！</span>）</li>
<li>Danger! Lava or a cave is below.<span>（</span><span>危険</span><span>！</span><ruby>溶岩<rt>ようがん</rt></ruby><span>か</span><ruby>洞窟<rt>どうくつ</rt></ruby><span>が</span><span>下</span><span>に</span>あります）</li>
</ul>
<p>&nbsp;</p>
<h3><span id="toc12">プレイヤーを移動させる</span></h3>
<p><span>足元</span><span>の</span><span>ブロック</span><span>が</span><ruby>掘<rt>ほ</rt></ruby><span>っ</span><span>て</span><span>も</span><ruby>大丈夫<rt>だいじょうぶ</rt></ruby><span>な</span><span>ブロック</span><span>だっ</span><span>たら</span><span>、</span>空気ブロックに置きかえます。ブロックを空気に置きかえたら、プレイヤーを1マス下に移動させています。</p>
<div class="blank-box bb-green"># 掘ってもよいブロックなら、空気（ID: 0）に変換し 1ブロック下に移動<br />
if block_below in safe_blocks:<br />
<em>   </em> mc.setBlock(x, y &#8211; 1, z, 0)   # ブロックを空気（ID: 0）にして掘る<br />
<em>   </em> mc.player.setPos(x, y &#8211; 1, z) # 1ブロック下に移動<br />
else:<br />
<em>   </em> mc.postToChat(&#8220;You found something interesting!&#8221;)<br />
<em>   </em> break</div>
<p>mc.player.setPos(x, y, z)は、プレイヤーを指定した座標に移動する命令です。</p>
<p>足元のブロックが鉱石などsafe_blocksリストにないブロックだった場合は、メッセージを表示してループをぬけます。</p>
<ul>
<li>You found something interesting!（何か発見しました！）</li>
</ul>
<p>&nbsp;</p>
<h3><span id="toc13">少し待つ</span></h3>
<p><ruby>掘<rt>ほ</rt></ruby><span>る</span><span>動作</span><span>を</span><span>ゆっくり</span><span>進める</span><span>ため</span><span>に</span><span>、</span><span>time</span><span>.</span><span>sleep</span><span>(</span><span>0.5</span><span>)</span><span> </span><span>を</span><span>使っ</span><span>て</span><span>い</span><span>ます</span><span>。</span></p>
<div class="blank-box bb-green">import time<br />
time.sleep(0.5)</div>
<p><span>まず</span><span>、</span><span>import</span><span> </span><span>time</span><span>で</span><span>time</span><span> </span><span>モジュール</span><span>を</span><ruby>読<rt>よ</rt></ruby><span>み</span><ruby>込<rt>こ</rt></ruby><span>み</span><span>ます</span><span>。</span></p>
<p><span class="marker-under-red"><span style="color: #ff6600;"><b>モジュール</b></span>は、Pythonで使える便利な道具箱のようなもの</span>です。よく使う命令や関数がまとまっています。</p>
<p>たとえば、timeモジュールは「時間」をあつかう命令が集まっています。</p>
<p>time.sleep(秒数)を使えば、プログラムを指定した秒数だけ一時停止できます。time.sleep(0.5)なら0.5秒（＝500ミリ秒）待てます。</p>
<p>&nbsp;</p>
<h3><span id="toc14">実行してみよう！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05.png" alt="直下掘りプログラム" width="800" height="450" class="aligncenter size-full wp-image-7131" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>プログラムが完成したら「dig.py」という名前でファイルを保存し、実行してみましょう。</p>
<p><span>安全</span><span>に</span><ruby>掘<rt>ほ</rt></ruby><span>り</span><span>進める</span><span>プログラム</span><span>の</span><span>完成</span><span>です</span><span>！</span></p>
<p>&nbsp;</p>
<h2><span id="toc15">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06.jpg" alt="階段掘りプログラム" width="800" height="450" class="aligncenter size-full wp-image-7132" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python07-06-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><span>今回</span><span>は</span><span>、</span><span>Python</span><span>を</span><span>使っ</span><span>た</span><span>直下</span><ruby>掘<rt>ほ</rt></ruby><span>り</span><span>プログラム</span><span>を</span><ruby>紹介<rt>しょうかい</rt></ruby><span>し</span><span>まし</span><span>た</span><span>。</span></p>
<p>ただし、このプログラムですべての危険を防げるわけではありません。どんな状況が危険なのか、どうすればもっと安全にできるのか、ぜひ考えてみてくださいね！</p>
<p>最後に、今回使用した命令とPythonの構文をおさらいしておきましょう。</p>
<p>今回使用した命令</p>
<div class="blank-box bb-blue">
<ul>
<li>mc.player.setPos(x, y, z)：指定した座標にプレイヤーを移動する</li>
<li>time.sleep(秒数)：指定した秒数プログラムの動きを一時停止する（timeモジュール）</li>
</ul>
</div>
<p>Pythonの構文</p>
<p>if 文：条件によって処理を分けるときに使う。</p>
<div class="blank-box bb-blue">if 条件:<br />
<em>   </em> 条件がTrueだった時の処理<br />
else:<br />
<em>   </em> 条件がFalseだった時の処理</div>
<p>in：右辺に左辺が存在する</p>
<p><span>break</span><span>文</span><span>：</span><span>くり返し</span><span>処理</span><span>を</span><ruby>途中<rt>とちゅう</rt></ruby><span>で</span><span>ぬける</span></p>
<p>&nbsp;</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python08/" title="【マイクラ×Python】秒で完成！広大な小麦畑をプログラミングで作る" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/12/eyecatch-minecraft-python08.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】秒で完成！広大な小麦畑をプログラミングで作る</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトで大きな小麦畑を作るPythonプログラムを紹介。【リビングの魔王】では、初心者にも分かりやすく図解を使い、9×9ブロックの小麦畑をならべて広大な畑を作る方法を紹介します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python07/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】プログラミングで長い橋もラクラク作成！</title>
		<link>https://living-maou.com/minecraft-python06/</link>
					<comments>https://living-maou.com/minecraft-python06/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Fri, 20 Dec 2024 01:54:02 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7105</guid>

					<description><![CDATA[マインクラフトで川や谷に橋をかけたことはありますか？ ブロックをひとつずつ置いて長い橋を作るのは大変ですが、プログラムを使えばかんたんです。 今回は、Pythonでくり返し処理や条件を使って、東の方向に橋をのばしていくプ [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7106" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトで川や谷に橋をかけたことはありますか？</p>
<p>ブロックをひとつずつ置いて長い橋を作るのは大変ですが、プログラムを使えばかんたんです。</p>
<p>今回は、Pythonでくり返し処理や条件を使って、東の方向に橋をのばしていくプログラムを作ってみましょう！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python05/" title="【マイクラ×Python】迷子防止に役立つ！目印になるタワーを建てよう" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】迷子防止に役立つ！目印になるタワーを建てよう</div><div class="blogcard-snippet internal-blogcard-snippet">迷子防止に！Pythonでマイクラに目印タワーを作ろう。初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>Pythonでマインクラフトを動かすには、特別な準備が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前の記事でくわしく説明していますので、まだ準備ができていない人はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">このプログラムでやること</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01.jpg" alt="東側に向かって橋をかける" width="800" height="450" class="aligncenter size-full wp-image-7107" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-01-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回は、プレイヤーのいる位置から東側に向かって橋をかけるプログラムを作ります。</p>
<p>条件として、橋が100ブロック未満の長さであり、進行方向にブロックがない場合に限り、橋をのばすようにします。</p>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>まずは、完成したプログラムを見てみましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

# Minecraftに接続
mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

# 橋の長さ
length = 0

# 東の方角に橋を作る
# 前にブロックがない かつ 橋の長さが100ブロック未満
while mc.getBlock(x + 1, y - 1, z) == 0 and length &lt; 100 :
    mc.setBlock(x + 1, y - 1, z, 98) # 石レンガ(98)を置く
    length += 1                      # 橋の長さを1増やす
    x += 1                           # 1ブロック前に進む</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<h3><span id="toc5">while文で条件を満たしている間くり返す</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png" alt="Python while文" width="800" height="450" class="aligncenter size-full wp-image-7108" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>Pythonでは、<span class="marker-under-red">「指定した条件を満たしている間、処理くり返す」ときに <span style="color: #ff6600;">while</span> 文</span>を使います。</p>
<div class="blank-box bb-blue">while 条件:<br />
<em>   </em> くり返したい処理</div>
<p>while 文では、条件を満たしている(True)かぎり処理をくり返します。</p>
<p>for文と同じように最初の行の次に「くり返したい処理」を書き、この処理の前には、半角スペースを4つ入れます。</p>
<p>このプログラムでは、while文を使って「東方向に進行方向の地面が空いていること」かつ「橋が100ブロック未満の長さであること」を条件に、橋を作る処理をくり返しています。</p>
<p>&nbsp;</p>
<h3><span id="toc6">True（真） と False（偽）</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png" alt="TrueとFalse" width="800" height="450" class="aligncenter size-full wp-image-7109" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><span class="marker-under-red"><span style="color: #ff6600;">True</span>と<span style="color: #ff6600;">False</span>は「<ruby>真<rt>しん</rt></ruby>」または<span>「</span><ruby>偽<rt>ぎ</rt></ruby><span>」</span>を表す<ruby>真偽値<rt>しんぎち</rt></ruby>（ブール値）</span>と呼ばれます。</p>
<p>プログラムの条件で「正しいか」「正しくないか」を判断するときに使われます。</p>
<div class="blank-box bb-blue">
<ul>
<li>True（<ruby>真<rt>しん</rt></ruby>） ：条件が「正しい」とき</li>
<li>False（<ruby>偽<rt>ぎ</rt></ruby>）：条件が「正しくない」とき</li>
</ul>
</div>
<p>Pythonでは、数値の0や空の値はFalseとしてあつかわれ、それ以外の値はTrueとされます。</p>
<p>&nbsp;</p>
<h3><span id="toc7">条件の書き方</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04.png" alt="PythonとScratchの比較演算子" width="800" height="450" class="aligncenter size-full wp-image-7110" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><ruby>比較演算子<rt>ひかくえんざんし</rt></ruby><span></span><span>を</span><span>使って</span><span>、</span><span>さまざま</span><span>な</span><span>条件</span><span>を</span><span>設定</span><span>でき</span><span>ます</span><span>。</span></p>
<div class="scrollable-table"><table>
<tbody>
<tr>
<th>演算子</th>
<th>Trueになる条件</th>
</tr>
<tr>
<th>==</th>
<td>右辺が左辺に等しい</td>
</tr>
<tr>
<th>!=</th>
<td>右辺が左辺に等しくない</td>
</tr>
<tr>
<th>&gt;</th>
<td>右辺が左辺未満</td>
</tr>
<tr>
<th>&gt;=</th>
<td>右辺が左辺以下</td>
</tr>
<tr>
<th>&lt;</th>
<td>右辺が左辺より大きい</td>
</tr>
<tr>
<th>&lt;=</th>
<td>右辺が左辺以上</td>
</tr>
</tbody>
</table></div>
<p>&nbsp;</p>
<h3><span id="toc8">複雑な条件</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05.png" alt="論理演算子" width="800" height="450" class="aligncenter size-full wp-image-7111" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>条件を組み合わせたいときには<span>、</span><ruby>論理<rt>ろんり</rt></ruby><ruby>演算子<rt>えんざんし</rt></ruby><span>を</span>使います。</p>
<div class="scrollable-table"><table>
<tbody>
<tr>
<th>演算子</th>
<th>意味</th>
</tr>
<tr>
<th>and</th>
<td>すべての条件がTrueのときにTrue</td>
</tr>
<tr>
<th>or</th>
<td>どれか1つの条件がTrueであればTrue</td>
</tr>
<tr>
<th>not</th>
<td>FalseであればTrue、TrueであればFlse</td>
</tr>
</tbody>
</table></div>
<p>&nbsp;</p>
<h3><span id="toc9">ブロックのIDを調べる</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07.png" alt="mc.getBlock()" width="800" height="450" class="aligncenter size-full wp-image-7112" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-07-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>mc.getBlock()は指定した座標のブロックIDを取得する命令です。</p>
<p>このプログラムでは、進行方向1ブロック先の地面が空気（IDが0）かどうかを確認しています。</p>
<div class="blank-box bb-green">mc.getBlock(x + 1, y &#8211; 1, z) == 0</div>
<p>この条件で、橋をかける予定の位置にブロックがないことを確認しています。</p>
<p>&nbsp;</p>
<h3><span id="toc10">橋の長さの上限</span></h3>
<div class="blank-box bb-green">length &lt; 100</div>
<p>これは、橋の長さが100ブロック未満かどうかを判定しています。これにより、無限に橋がのびないようにしています。</p>
<p>&nbsp;</p>
<p>mc.getBlock()による空き<ruby>状況<rt>じょうきょう</rt></ruby>の確認と、length &lt; 100の条件をandで組み合わせることで、橋の長さが100ブロックをこえず、さらに進行方向にブロックがないときだけ橋をのばすようにしています。<br />
<a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06.png" alt="mc.getBlock(x + 1, y - 1, z) == 0 and length &lt; 100" width="800" height="450" class="aligncenter size-full wp-image-7113" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-06-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc11">ブロックを置く</span></h3>
<p>mc.setBlock()はマインクラフトの中にブロックを置く命令です。今回は石レンガ（IDが98）を使っています。</p>
<div class="blank-box bb-green">mc.setBlock(x + 1, y &#8211; 1, z, 98)<br />
length += 1</div>
<p>ブロックを置いた後、橋の長さ（length）を1増やします。</p>
<p>&nbsp;</p>
<h3><span id="toc12">東方向に1ブロック進む</span></h3>
<div class="blank-box bb-green">x += 1</div>
<p>この行で、東方向に1ブロック進むための処理をしています。この操作によって、次のブロックを1ブロック先の位置に置くことができます。</p>
<p>&nbsp;</p>
<h3><span id="toc13">実行してみよう！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08.png" alt="橋を作るプログラムを実行" width="800" height="450" class="aligncenter size-full wp-image-7114" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08.png 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-08-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>プログラムが完成したら「bridge.py」という名前でファイルを保存し、実行してみましょう。</p>
<p>プレイヤーの位置から東方向に石レンガの橋ができるはずです。</p>
<p>&nbsp;</p>
<h2><span id="toc14">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09.jpg" alt="空いている方向に橋をかけるプログラム" width="800" height="450" class="aligncenter size-full wp-image-7115" srcset="https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/minecraft-python05-09-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回は、Pythonを使って橋をかける<span>プログラム</span><span>を</span><ruby>紹介<rt>しょうかい</rt></ruby><span>し</span><span>まし</span><span>た</span><span>。</span></p>
<p>今回は東の方向に橋を作りましたが、コードを少し工夫すれば他の方向にも橋を作ることができます。ぜひ、自分だけの橋を作るプログラムにチャレンジしてみてくださいね！</p>
<p>&nbsp;</p>
<p>最後にくり返し処理を行うwhile文と条件の使い方をおさらいしましょう。</p>
<p>while文</p>
<div class="blank-box bb-blue">while 条件:<br />
<em>   </em> くり返したい処理</div>
<p>&nbsp;</p>
<p><ruby>比較<rt>ひかく</rt></ruby><ruby>演算子<rt>えんざんし</rt></ruby><span>の</span><ruby>例<rt>れい</rt></ruby></p>
<div class="scrollable-table"><table>
<tbody>
<tr>
<th>演算子</th>
<th>Trueになる条件</th>
</tr>
<tr>
<th>==</th>
<td>右辺が左辺に等しい</td>
</tr>
<tr>
<th>!=</th>
<td>右辺が左辺に等しくない</td>
</tr>
<tr>
<th>&gt;</th>
<td>右辺が左辺未満</td>
</tr>
<tr>
<th>&gt;=</th>
<td>右辺が左辺以下</td>
</tr>
<tr>
<th>&lt;</th>
<td>右辺が左辺より大きい</td>
</tr>
<tr>
<th>&lt;=</th>
<td>右辺が左辺以上</td>
</tr>
</tbody>
</table></div>
<p>&nbsp;</p>
<p>論理演算子</p>
<div class="scrollable-table"><table>
<tbody>
<tr>
<th>演算子</th>
<th>意味</th>
</tr>
<tr>
<th>and</th>
<td>すべての条件がTrueのときにTrue</td>
</tr>
<tr>
<th>or</th>
<td>どれか1つの条件がTrueであればTrue</td>
</tr>
<tr>
<th>not</th>
<td>FalseであればTrue、TrueであればFlse</td>
</tr>
</tbody>
</table></div>
<p>&nbsp;</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python07/" title="【マイクラ×Python】危険ゼロ！？安心安全の直下掘りプログラム" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python07.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】危険ゼロ！？安心安全の直下掘りプログラム</div><div class="blogcard-snippet internal-blogcard-snippet">マイクラでは危険な直下掘りもプログラムを使えば安心！Pythonを使って危険なブロックを回避し、掘れるブロックだけ掘り進める便利なプログラムを作成してみましょう！初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python06/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】迷子防止に役立つ！目印になるタワーを建てよう</title>
		<link>https://living-maou.com/minecraft-python05/</link>
					<comments>https://living-maou.com/minecraft-python05/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Thu, 05 Dec 2024 00:50:34 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7075</guid>

					<description><![CDATA[マインクラフトで広い世界を冒険ぼうけんしていると、知らない間に迷子まいごになってしまった…ということ、ありませんか？ 目印になるタワーを作りたいけど、自分で作ると高いところで落ちる危険がありますよね。 今回は、Pytho [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7076" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトで広い世界を<ruby>冒険<rt>ぼうけん</rt></ruby>していると、知らない間に<ruby>迷子<rt>まいご</rt></ruby>になってしまった…ということ、ありませんか？</p>
<p>目印になるタワーを作りたいけど、自分で作ると高いところで落ちる危険がありますよね。</p>
<p>今回は、Pythonで「自動タワー作りプログラム」を作ってみましょう！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python04/" title="【マイクラ×Python】あっという間に拠点が完成！かんたんプログラムで作ろう" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】あっという間に拠点が完成！かんたんプログラムで作ろう</div><div class="blogcard-snippet internal-blogcard-snippet">Pythonを使って、マインクラフトの世界にかんたんな拠点を一瞬で作るプログラムを初心者向けに解説！【リビングの魔王】では、プログラミング初心者でも迷わず取り組めるように、ステップごとにわかりやすく説明しています。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>マインクラフトをPythonで操作するためには、特定の<ruby>環境<rt>かんきょう</rt></ruby>が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span><span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前回の記事でくわしく説明しているので、まだ準備ができていない人はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">このプログラムでやること</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01.png" alt="高さ50ブロックのタワー" width="800" height="450" class="aligncenter size-full wp-image-7077" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回作成するプログラムでは、プレイヤーの近くに高さ50ブロックのタワーを立てます。</p>
<p>タワーにはガラスブロックとシーランタンを使うので、夜でも目立つし遠くからでも見つけやすい目印になります。</p>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>まずは、完成したプログラムを見てみましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

# Minecraftに接続
mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得し、変数xyzに代入
x, y, z = mc.player.getPos()

# タワーの位置をプレイヤーから少し横にずらす
x += 5

# タワーを作成
for _ in range(25):
    mc.setBlock(x, y, z, 95, 3) # ガラスブロック
    mc.setBlock(x, y + 1, z, 169) # シーランタン
    y += 2 # 次の高さを計算</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<p>ガラスブロックとシーランタンを順番に置く処理を25回くり返して、高さ50ブロックのタワーを作っています。</p>
<h3><span id="toc5">for文で同じことをくり返す</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02.png" alt="Python for文" width="800" height="450" class="aligncenter size-full wp-image-7078" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>Pythonでは、<span class="marker-under-red">「同じことを何回もくり返したいとき」に <span style="color: #ff6600;">for</span> 文を使います</span>。</p>
<div class="blank-box bb-blue">for 変数 in イテラブル:<br />
<em>   </em> くり返したい処理</div>
<p>for 文では、最初の行の次に「くり返したい処理」を書き、この処理の前には、半角スペースを4つ入れます。</p>
<p><span class="badge badge-green">関連記事</span><a rel="noopener" target="_self" href="https://living-maou.com/control-structure/">【子ども向け】プログラミングの基本構造とは？ – 順次、分岐、反復について学ぼう！<span class="fa fa-external-link internal-icon anchor-icon"></span></a></p>
<p>&nbsp;</p>
<h4>イテラブルってなに？</h4>
<p><b>イテラブル</b>とは、「ひとつずつ順番にデータを取り出せるもの」のことです。</p>
<p>リストや文字列、<span style="color: #ff6600;">range()</span> などがあり、for文を使うとデータを順番に取り出して、1つずつ使うことができます。</p>
<p>たとえば、for i in range(5) と書くと、「5回、同じ処理をくり返す」という意味になります。range(5) は「0から4までの数字を1つずつ取り出す」という役割があり、計5回のくり返しになります。</p>
<ul>
<li>1回目は i = 0</li>
<li>2回目は i = 1</li>
<li>3回目は i = 2</li>
<li>4回目は i = 3</li>
<li>5回目は i = 4</li>
</ul>
<p>このように、for 文の中で使う i に数字が順に入っていきます。</p>
<p>今回のタワー作りでは、for _ in range(25) と書いています。この<span class="marker-under-red"> _ という記号は、「変数は使わないけれど、回数だけくり返したい」というときに使います</span>。Scratchでいう「25回くり返す」ブロックと同じような動きです。</p>
<p>&nbsp;</p>
<h3><span id="toc6">ブロックを置く</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03.png" alt="ガラスとシーランタンを置く" width="800" height="450" class="aligncenter size-full wp-image-7079" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-green">mc.setBlock(x, <span style="color: #ff6600;">y</span>, z, 95, 3)   # ガラスブロック<br />
mc.setBlock(x, <span style="color: #ff6600;">y + 1</span>, z, 169) # シーランタン</div>
<p>mc.setBlock() はマインクラフトの中にブロックを置く命令です。ブロックは空色のガラス（95, 3）とシーランタン（169）を指定しています。</p>
<p>シーランタンはガラスブロックの上に置くため、y + 1 の高さに配置します。</p>
<p>&nbsp;</p>
<h3><span id="toc7">ブロックを置く高さを計算</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04.png" alt="ブロックが2つずつ順番に上へ積み上がる" width="800" height="450" class="aligncenter size-full wp-image-7080" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>y += 2 の部分は、次のブロックを置く高さを計算しています。</p>
<p>たとえば：</p>
<ul>
<li>1回目は y が 0 と 1 の高さ</li>
<li>2回目は y が 2 と 3 の高さ</li>
<li>3回目は y が 4 と 5 の高さ</li>
</ul>
<p>このように、<span class="marker-under-red">ブロックが2つずつ順番に上へ積み上がっていきます</span>。</p>
<p>&nbsp;</p>
<h3><span id="toc8">実行してみよう！</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05.png" alt="ガラスとシーランタンでできたタワー" width="800" height="450" class="aligncenter size-full wp-image-7081" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>プログラムが完成したら「tower.py」という名前でファイルを保存し、実行してみましょう。</p>
<p>プレイヤーの少し横にガラスとシーランタンでできたタワーが現れるはずです。夜や遠くからでも光って見えるので、目印にぴったりです。</p>
<p>&nbsp;</p>
<h2><span id="toc9">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06.jpg" alt="ガラスとシーランタンのタワーを作るプログラム" width="800" height="450" class="aligncenter size-full wp-image-7082" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python05-06-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><span>今回</span><span>は</span><span>、</span><span>Python</span><span>を</span><span>使っ</span><span>て</span><span>マインクラフト</span><span>の</span><span>中</span><span>に</span><span>目立つ</span><span>タワー</span><span>を</span><span>自動</span><span>で</span><span>作る</span><span>プログラム</span><span>を</span><ruby>紹介<rt>しょうかい</rt></ruby><span>し</span><span>まし</span><span>た</span><span>。</span></p>
<p>このプログラムを使えば、自動で光るタワーができ、迷子になる心配が少なくなりますね！</p>
<p>最後に、Pythonのくり返し処理（for文）の使い方を確認しておきましょう。</p>
<div class="blank-box bb-blue">for 変数 in イテラブル:<br />
<em>   </em> くり返したい処理</div>
<p>たとえば、for i in range(10) とすると、10回くり返し、変数 i は0から9まで変化します。</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python06/" title="【マイクラ×Python】プログラミングで長い橋もラクラク作成！" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-minecraft-python05.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】プログラミングで長い橋もラクラク作成！</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトで川や谷に橋をかけたいと思ったことはありませんか？今回はPythonで繰り返し処理や条件を使って橋を作るプログラム紹介します。初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python05/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Raspberry Pi】Pythonでマインクラフトパイリボーンを楽しむための環境設定ガイド</title>
		<link>https://living-maou.com/raspberrypi4-jibunpc04/</link>
					<comments>https://living-maou.com/raspberrypi4-jibunpc04/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Wed, 20 Nov 2024 02:22:47 +0000</pubDate>
				<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[RaspberryPi]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7090</guid>

					<description><![CDATA[この記事では「マインクラフトパイリボーン（Minecraft Pi Reborn）」を使って、Pythonプログラミングを学ぶ方法を紹介します。 マインクラフトの世界をPythonで操作し、楽しみながらプログラミングの基 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7091" srcset="https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/eyecatch-raspberrypi4-jibunpc04-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>この記事では「マインクラフトパイリボーン（Minecraft Pi Reborn）」を使って、Pythonプログラミングを学ぶ方法を紹介します。</p>
<p>マインクラフトの世界をPythonで操作し、楽しみながらプログラミングの基本を学べます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc03/">スクラッチ（Scratch）での操作<span class="fa fa-external-link internal-icon anchor-icon"></span></a>が気になる方には、、下の記事でくわしく解説していますので、そちらを参考にしてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc03/" title="【Raspberry Pi】Scratchでマインクラフトパイリボーンを動かす方法" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-160x90.png" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03-320x180.png 320w, https://living-maou.com/wp-content/uploads/2024/06/eyecatch-raspberrypi4-jibunpc03.png 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Raspberry Pi】Scratchでマインクラフトパイリボーンを動かす方法</div><div class="blogcard-snippet internal-blogcard-snippet">ラズベリーパイ向けに作られた「マインクラフトパイリボーン」をスクラッチで動かす方法を紹介します。【リビングの魔王】では「Scratch2MCPI」のインストール方法と、プログラミングできるようにする手順を初心者向けに詳しく解説します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc1">環境構築の方法(RaspberryPi)</span></h2>
<p>以下のステップで進めていきます。</p>
<div class="blank-box bb-blue">
<ol>
<li><a href="#step01">「RaspberryPi」の組み立て</a></li>
<li><a href="#step02">「マインクラフトパイリボーン」のインストール</a></li>
<li><a href="#step03">「Thonny（トニー）」のインストール</a></li>
<li><a href="#step04">「mcpi」のインストール</a></li>
</ol>
</div>
<p>RaspberryPiがあれば、すべて無料で利用できます。</p>
<p>&nbsp;</p>
<h3 id="step01"><span id="toc2">「RaspberryPi」の組み立て</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01.jpg" alt="Raspberry Pi4 Model B" width="800" height="450" class="aligncenter size-full wp-image-6675" srcset="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01.jpg 800w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc01-01-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>ラズベリーパイ（Raspberry Pi）は、クレジットカードサイズの小型コンピュータで、略して「ラズパイ」とも呼ばれます。</p>
<p>安価で拡張性が高く、初心者でも比較的簡単に使えるのが魅力です。</p>
<p>プログラミング学習や電子工作、IoT開発など多様な用途に利用でき、普通のパソコンのように操作できます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc01/">ラズパイの組み立てと設定方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>については、下の記事でくわしく説明しています。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc01/" title="【Raspberry Pi】ラズベリーパイでジブン専用パソコン作ってみた（子供の科学）" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Raspberry Pi】ラズベリーパイでジブン専用パソコン作ってみた（子供の科学）</div><div class="blogcard-snippet internal-blogcard-snippet">Raspberry Pi4 ModelBの組み立て方を紹介。【リビングの魔王】では『子供の科学』で紹介されている「ジブン専用パソコンキット3.5S」と同等の環境を作れるように、必要なものから組み立て方、設定手順までを、初心者にも分かりやすく紹介します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h3 id="step02"><span id="toc3">「マインクラフトパイリボーン」のインストール</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01.jpg" alt="マインクラフトパイリボーン" width="800" height="450" class="aligncenter size-full wp-image-6719" srcset="https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01.jpg 800w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/05/raspberrypi4-jibunpc02-01-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回は、Raspberry Pi専用の「マインクラフトパイリボーン」を使用します。</p>
<p>これは従来の「マインクラフトパイ（Minecraft Pi）」の後継版で、クリエイティブモードに加え、サバイバルモードでも楽しめます。</p>
<p>統合版やJava版と比べると機能は制限されていますが、Pythonでのプログラミングには十分です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc02/">マインクラフトパイリボーンのくわしいインストール手順<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、下の記事で説明しています。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/raspberrypi4-jibunpc02/" title="【Minecraft Pi Reborn】マイクラをラズパイで遊ぼう！インストール手順" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/05/eyecatch-raspberrypi4-jibunpc02.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Minecraft Pi Reborn】マイクラをラズパイで遊ぼう！インストール手順</div><div class="blogcard-snippet internal-blogcard-snippet">ラズベリーパイ向けに作られた「マインクラフトパイ」の後継版「マインクラフトパイリボーン」について紹介。【リビングの魔王】ではマインクラフトパイリボーンをインストールする方法と、遊び方を初心者向けに詳しく解説します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h3 id="step03"><span id="toc4">「Thonny（トニー）」のインストール</span></h3>
<p>「Thonny（トニー）」は、Pythonプログラムを書くための初心者向けのソフトです。</p>
<p>ラズベリーパイのOSに最初から入っていますが、ない場合は「スタートメニュー」→「設定」→「Recommended Software」からインストール可能です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01.jpg" alt="Recommended Software" width="800" height="450" class="aligncenter size-full wp-image-7092" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-01-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h4>動作確認</h4>
<p>1.「Thonny」を起動します。</p>
<p>「スタートメニュー」→「プログラミング」→「Thonny」</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02.jpg" alt="「Thonny」を起動" width="800" height="450" class="aligncenter size-full wp-image-7093" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-02-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>2.エディターに以下のプログラムを入力します。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>print('hello')</code></pre>
</div>
<p>&nbsp;</p>
<p>3.「F5」キーまたは実行ボタンを押してプログラムを実行します。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03.png" alt="プログラムを実行" width="800" height="450" class="aligncenter size-full wp-image-7094" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>エディターの下にあるshell（シェル）エリアに「hello」と表示されればOKです。</p>
<p>&nbsp;</p>
<h3 id="step04"><span id="toc5">「mcpi」のインストール</span></h3>
<p>Minecraftを操作するために「mcpi」パッケージをインストールします。</p>
<p>1.「Thonny」を起動します。</p>
<p>2.「Tools」メニュー →「Manage packages&#8230;」を選択します。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04.png" alt="「Manage packages...」を選択" width="800" height="450" class="aligncenter size-full wp-image-7095" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>3.検索ボックスに「mcpi」と入力し、「Search on PyPI」をクリックします。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05.png" alt="「mcpi」を検索" width="800" height="450" class="aligncenter size-full wp-image-7096" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>4.検索結果(Search results)から「mcpi」を選択します。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06.png" alt="「mcpi」を選択" width="800" height="450" class="aligncenter size-full wp-image-7097" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-06-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>5.「Install」をクリックします。</p>
<p>6.インストールが完了したら「Close」をクリックします。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07.png" alt="「Install」をクリックし、終わったら「close」をクリック" width="800" height="450" class="aligncenter size-full wp-image-7098" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-07-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h4>動作確認</h4>
<p>1.マイクラでワールドを作成します。</p>
<p>2.Thonnyを起動し、以下のプログラムを入力します。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>from mcpi import minecraft
mc = minecraft.Minecraft.create()
mc.postToChat("Hello World")</code></pre>
</div>
<p>3.「F5」キーをおしてプログラムを実行します。</p>
<p>マインクラフト内のチャット欄に「Hello World」と表示されれば成功です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08.jpg" alt="マインクラフト内のチャット欄に「Hello World」と表示される" width="800" height="450" class="aligncenter size-full wp-image-7099" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08.jpg 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-08-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc6">日本語にしたい場合</span></h3>
<p>Thonnyの表示を日本語に切り替えるには、次の手順を実行します。</p>
<ol>
<li>Tools → Options</li>
<li>GeneralタブでLanguageを「日本語[ALPHA]」にして「OK」をクリック</li>
<li>Thonnyを閉じて、もう一度起動する</li>
</ol>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09.png" alt="Thonnyの表示を日本語に切り替える" width="800" height="450" class="aligncenter size-full wp-image-7100" srcset="https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09.png 800w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/11/raspberrypi4-jibunpc04-09-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc7">まとめ</span></h2>
<p>「マインクラフトパイリボーン」を使ってPythonプログラミングを学ぶための方法を紹介しました。</p>
<p>マインクラフトの世界でコードを使いながら、楽しく学べるのが魅力です。ぜひ、親子で一緒にプログラミングに挑戦してみてください！</p>
<p>当ブログでは、プログラムの例を紹介しています。よかったら参考にしてみてください。</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python02/" title="【マイクラ×Python】プログラムでかんたん整地！｜初心者向けコード解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-160x90.png" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-320x180.png 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02.png 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】プログラムでかんたん整地！｜初心者向けコード解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでブロックを整地するPythonプログラムを紹介。【リビングの魔王】では、初心者にも分かりやすく図解を使い、プレイヤーの周囲を草ブロックと空気ブロックできれいに整える方法を解説します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/raspberrypi4-jibunpc04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】あっという間に拠点が完成！かんたんプログラムで作ろう</title>
		<link>https://living-maou.com/minecraft-python04/</link>
					<comments>https://living-maou.com/minecraft-python04/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Tue, 05 Nov 2024 01:25:35 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7058</guid>

					<description><![CDATA[マインクラフトで冒険ぼうけんに夢中になっていたら、いつの間にか夜に&#8230;&#8230;ということはありませんか？ ゾンビやクリーパーから身を守れる安全な拠点きょてんを、パッと作れたら便利ですよね。 この記事では、 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04.jpg" alt="" width="800" height="450" class="aligncenter size-full wp-image-7059" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python04-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトで<ruby>冒険<rt>ぼうけん</rt></ruby>に夢中になっていたら、いつの間にか夜に&#8230;&#8230;ということはありませんか？</p>
<p>ゾンビやクリーパーから身を守れる安全な<ruby>拠点<rt>きょてん</rt></ruby>を、パッと作れたら便利ですよね。</p>
<p>この記事では、Pythonを使ってマインクラフト内にかんたんな<ruby>拠点<rt>きょてん</rt></ruby>を作るプログラムを<ruby>紹介<rt>しょうかい</rt></ruby>します。</p>
<p>プログラミングで、安全に夜をすごせるシェルターを作ってみましょう！</p>
<p>&nbsp;</p>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>マインクラフトをPythonで操作するためには、特定の<ruby>環境<rt>かんきょう</rt></ruby>が必要です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>については、前回の記事でくわしく説明しているので、まだ準備ができていない方はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">マイクラでは座標を使って場所を指定する</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png" alt="マイクラの座標" width="800" height="450" class="aligncenter size-full wp-image-7020" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフト内では、ブロックを設置する際に「<b>座標</b>」を使って場所を指定します。</p>
<p>座標とは、位置を表すための数字の組み合わせです。マイクラでは「x、y、z」の3つの<ruby>軸<rt>じく</rt></ruby>で表します。</p>
<div class="blank-box bb-blue">
<ul>
<li>x<ruby>軸<rt>じく</rt></ruby> … 東西の方向（東がプラス、西がマイナス）</li>
<li>y<ruby>軸<rt>じく</rt></ruby> … 上下の方向（上がプラス、下がマイナス）</li>
<li>z<ruby>軸<rt>じく</rt></ruby> … 南北の方向（南がプラス、北がマイナス）</li>
</ul>
</div>
<p>前回の記事で<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python03/">座標の<ruby>取<rt>と</rt></ruby>り<ruby>扱<rt>あつか</rt></ruby>い方<span class="fa fa-external-link internal-icon anchor-icon"></span></a>をくわしく説明しているので、座標についてよく分からない人はそちらを確認してください。</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python03/" title="【マイクラ×Python】座標を使いこなせ！位置確認とブロックの置き方" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】座標を使いこなせ！位置確認とブロックの置き方</div><div class="blogcard-snippet internal-blogcard-snippet">Pythonを使ってマイクラ内の座標を操作し、自分の位置を確認したり、ブロックを設置する方法を初心者向けに解説！【リビングの魔王】では、プログラミング初心者でも安心して進められるよう、ステップごとにていねいに説明します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc3">プログラム概要</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04.jpg" alt="拠点を作るプログラム" width="800" height="450" class="aligncenter size-full wp-image-7060" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-04-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回作成するプログラムでは、プレイヤーの位置を基準にして、となりにオークの木材でできた立方体の建物を作ります。</p>
<p>いわゆる「とうふ建築」というやつですね。</p>
<p>建物の中にドアとベッドを置いて、かんたんな<ruby>拠点<rt>きょてん</rt></ruby>として使えるようにします。</p>
<p>&nbsp;</p>
<h2><span id="toc4">完成したソースコード</span></h2>
<p>以下は、今回作成するプログラムのソースコードです。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

# Minecraftに接続
mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

x += 1

# 立方体を設置 オークの木材
mc.setBlocks(x, y - 1, z, x + 4, y + 3, z + 4, 5, 0)

# 立方体の中をくり抜く
mc.setBlocks(x + 1, y, z + 1, x + 3, y + 2, z + 3, 0)

# ドアをつける
mc.setBlock(x + 3, y, z, 64, 1) # オークのドア下：南：閉
mc.setBlock(x + 3, y + 1, z, 64, 9) # オークのドア上：南：閉

# ベッドを設置
mc.setBlock(x + 1, y, z + 1, 26, 0) # 足側
mc.setBlock(x + 1, y, z + 2, 26, 8) # 頭側</code></pre>
</div>
<p>&nbsp;</p>
<h2><span id="toc5">プログラムの説明</span></h2>
<p>以下の手順で<ruby>拠点<rt>きょてん</rt></ruby>を作成します。</p>
<div class="blank-box bb-blue">
<ol>
<li><a href="#step01">プレイヤーの座標を取得する</a></li>
<li><a href="#step02">立方体の建物を作る</a></li>
<li><a href="#step03">立方体の中をくりぬく</a></li>
<li><a href="#step04">ドアをつける</a></li>
<li><a href="#step05">ベッドを置く</a></li>
</ol>
</div>
<h3 id="step01"><span id="toc6">プレイヤーの座標を取得する</span></h3>
<p>まず、プレイヤーの座標を取得し、その値を変数x、y、zに代入します。</p>
<div class="blank-box bb-blue">x, y, z = mc.player.getPos()</div>
<p>&nbsp;</p>
<p>次の行にある「x += 1」は、「x = x + 1」と同じ意味です。変数xの値に1を足し、その結果を再びxに代入します。</p>
<p>この処理は、プレイヤーのすぐとなり（1マス横）に建物を作って、プレイヤーが建物の中にうまらないようにするためです。</p>
<p>&nbsp;</p>
<h3 id="step02"><span id="toc7">立方体の建物を作る</span></h3>
<p>プレイヤーの位置から1マスとなりに、オークの木材で立方体の建物を作ります。</p>
<div class="blank-box bb-blue">mc.setBlocks(x, y &#8211; 1, z, x + 4, y + 3, z + 4, 5, 0)</div>
<p>&nbsp;</p>
<p><b>mc.setBlocks(x1, y1, z1, x2, y2, z2, block_id)</b>は、<span class="marker-under-red">指定した<ruby>範囲<rt>はんい</rt></ruby>にブロックを設置する命令</span>です。fillコマンドと同じように、広い場所にブロックをならべられます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02.png" alt="mc.setBlocks" width="800" height="450" class="aligncenter size-full wp-image-7061" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p><ruby>範囲<rt>はんい</rt></ruby>を指定するには、「始まり」と「終わり」の2つの点の座標を使います。x1, y1, z1が<ruby>範囲<rt>はんい</rt></ruby>の開始地点で、x2, y2, z2が<ruby>範囲<rt>はんい</rt></ruby>の<ruby>終了<rt>しゅうりょう</rt></ruby>地点です。</p>
<p>&nbsp;</p>
<p>たとえば今回の場合、「右下の角」を始まり、「左上の角」を終わりとするようなイメージです。これで、その<ruby>範囲<rt>はんい</rt></ruby>すべてにブロックを置くことができます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03.jpg" alt="「始まり」と「終わり」の座標を指定する" width="800" height="450" class="aligncenter size-full wp-image-7062" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-03-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>また、block_idで設置するブロックの種類を指定します。ここではオークの木材のID「5」を使用しています。</p>
<p>&nbsp;</p>
<h3 id="step03"><span id="toc8">立方体の中をくりぬく</span></h3>
<p>次に、作った立方体の中をくりぬきます。</p>
<div class="blank-box bb-blue">mc.setBlocks(x + 1, y, z + 1, x + 3, y + 2, z + 3, 0)</div>
<p>&nbsp;</p>
<p>立方体の座標より1マス内側に<ruby>範囲<rt>はんい</rt></ruby>を指定しています。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01.png" alt="立方体の座標より1マス内側に範囲を指定" width="800" height="450" class="aligncenter size-full wp-image-7066" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-blue">
<ul>
<li>x<ruby>軸<rt>じく</rt></ruby>：立方体の始点 x から1マス内側の x + 1 から、4マス目の x + 3 まで。</li>
<li>y<ruby>軸<rt>じく</rt></ruby>：立方体の<ruby>床<rt>ゆか</rt></ruby>（y &#8211; 1）の上にある y から始まり、<ruby>天井<rt>てんじょう</rt></ruby>の手前（y + 2 まで）。</li>
<li>z<ruby>軸<rt>じく</rt></ruby>：立方体の始点 z から1マス内側の z + 1 から、4マス目の z + 3 まで。</li>
</ul>
</div>
<p>この<ruby>範囲<rt>はんい</rt></ruby>を空気ブロック（ブロックID 0）でうめることで、立方体の内部にスペースができます。</p>
<p>&nbsp;</p>
<h3 id="step04"><span id="toc9">ドアをつける</span></h3>
<p>mc.setBlock()を使って建物の出入口にオークのドアを設置します。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07.png" alt="建物の出入口にオークのドアを設置" width="800" height="450" class="aligncenter size-full wp-image-7067" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-07-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-blue">mc.setBlock(x + 3, y, z, 64, 1)     # オークのドア下：南：閉<br />
mc.setBlock(x + 3, y + 1, z, 64, 9) # オークのドア上：南：閉</div>
<p>ドアは上下で別々のデータ番号を持っているため、下側と上側に分けて設置します。</p>
<p>&nbsp;</p>
<h3 id="step05"><span id="toc10">ベッドを置く</span></h3>
<p>最後に、建物の中にベッドを置きましょう。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08.png" alt="建物の中にベッドを置く" width="800" height="450" class="aligncenter size-full wp-image-7068" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-08-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-blue">mc.setBlock(x + 1, y, z + 1, 26, 0) # 足側<br />
mc.setBlock(x + 1, y, z + 2, 26, 8) # 頭側</div>
<p>ベッドも頭側と足側で分けて設置します。</p>
<p>&nbsp;</p>
<h3><span id="toc11">実行してみよう！</span></h3>
<p>プログラムが完成したら「shelter.py」という名前でファイルを保存し、実行してみましょう。</p>
<p>プレイヤーのとなりにオークの木材でできた建物が作られているのを確認できるはずです。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05.png"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05.png" alt="拠点内にベッド" width="800" height="450" class="aligncenter size-full wp-image-7063" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>ベッドも設置できました。これで夜も安心ですね！</p>
<p>&nbsp;</p>
<h2><span id="toc12">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06.jpg"><img loading="lazy" decoding="async" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06.jpg" alt="拠点を作るプログラム" width="800" height="450" class="aligncenter size-full wp-image-7064" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python04-06-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>Pythonを使ってマインクラフト内にかんたんな<ruby>拠点<rt>きょてん</rt></ruby>を作るプログラムを<ruby>紹介<rt>しょうかい</rt></ruby>しました。</p>
<div class="blank-box bb-green">
<ul>
<li>mc.setBlocks(x1, y1, z1, x2, y2, z2, block_id)：指定した<ruby>範囲<rt>はんい</rt></ruby>に任意の種類のブロックを設置する。<br />
x1, y1, z1：開始地点の座標<br />
x2, y2, z2：終了地点の座標<br />
block_id：設置するブロックの種類（ブロック番号とデータ番号）</li>
</ul>
</div>
<p>mc.setBlocks()を使うと、大きな建物や構造物を作成できるようになります。ぜひチャレンジしてみてくださいね！</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python05/" title="【マイクラ×Python】迷子防止に役立つ！目印になるタワーを建てよう" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python05.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】迷子防止に役立つ！目印になるタワーを建てよう</div><div class="blogcard-snippet internal-blogcard-snippet">迷子防止に！Pythonでマイクラに目印タワーを作ろう。初心者でも迷わずできるように【リビングの魔王】がステップごとに解説します！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】座標を使いこなせ！位置確認とブロックの置き方</title>
		<link>https://living-maou.com/minecraft-python03/</link>
					<comments>https://living-maou.com/minecraft-python03/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Sat, 19 Oct 2024 23:56:38 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=7018</guid>

					<description><![CDATA[マインクラフトの広大な世界で、場所を正確に知るために「座標」は欠かせません。 例えば、冒険ぼうけんに出かけたときに家の座標を覚えておけば、遠くに行っても迷子まいごになる心配はありません。座標を知っていれば、重要な場所へか [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7019" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03.jpg" alt="" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトの広大な世界で、場所を正確に知るために「<b>座標</b>」は欠かせません。</p>
<p>例えば、<ruby>冒険<rt>ぼうけん</rt></ruby>に出かけたときに家の座標を覚えておけば、遠くに行っても<ruby>迷子<rt>まいご</rt></ruby>になる心配はありません。座標を知っていれば、重要な場所へかんたんに行くことができます。</p>
<p>この記事では、Pythonというプログラミング言語を使って、自分の位置を<ruby>確認<rt>かくにん</rt></ruby>したり、指定した場所にブロックを置いたりする方法を<ruby>紹介<rt>しょうかい</rt></ruby>します。</p>
<p>座標を使いこなして、もっと便利にマイクラの世界を楽しみましょう！</p>
<p>プログラミング初心者でも安心して進められるよう、ステップごとにていねいに説明します。</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python02/" title="【マイクラ×Python】プログラムでかんたん整地！｜初心者向けコード解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-160x90.png" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-320x180.png 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02.png 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】プログラムでかんたん整地！｜初心者向けコード解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでブロックを整地するPythonプログラムを紹介。【リビングの魔王】では、初心者にも分かりやすく図解を使い、プレイヤーの周囲を草ブロックと空気ブロックできれいに整える方法を解説します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>マインクラフトをPythonで操作するには、特定の<ruby>環境<rt>かんきょう</rt></ruby>を整える必要があります。</p>
<p>くわしいセットアップ方法は、前回の記事で説明していますので、まだ準備ができていない方はそちらをチェックしてみてください。</p>
<p>&nbsp;</p>
<div class="blogcard-type bct-detail">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">マイクラでは座標を使って場所を指定する</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7020" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png" alt="マイクラの座標" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-xyz-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>まず、座標の基本的な仕組みを解説します。</p>
<p><span style="color: #ff6600;"><b><ruby>座標<rt>ざひょう</rt></ruby></b></span>とは、<span class="marker-under-red">ある位置を特定するための数字の組み合わせ</span>です。</p>
<p>マイクラではx,y,z、3つの<ruby>座標軸<rt>ざひょうじく</rt></ruby>があり、<b>原点</b>（xyzすべてが0の場所）からどれだけ<ruby>離<rt>はな</rt></ruby>れているか表しています。</p>
<div class="blank-box bb-blue">
<ul>
<li>x<ruby>軸<rt>じく</rt></ruby> … 東西の方向（東がプラス、西がマイナス）</li>
<li>y<ruby>軸<rt>じく</rt></ruby> … 上下の方向（上がプラス、下がマイナス）</li>
<li>z<ruby>軸<rt>じく</rt></ruby> … 南北の方向（南がプラス、北がマイナス）</li>
</ul>
</div>
<p>&nbsp;</p>
<h2><span id="toc3">座標を表示してみよう</span></h2>
<p>今自分がいる座標を表示するプログラムを作ってみましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得し、変数x,y,zに代入
x, y, z = mc.player.getTilePos()

# 座標をチャット欄に表示
mc.postToChat(f"X: {x}, Y: {y}, Z: {z}")</code></pre>
</div>
<p>mc.player.getTilePos()でプレイヤーの座標を取得し、mc.postToChat()でチャット<ruby>欄<rt>らん</rt></ruby>に取得した座標の値を表示しています。</p>
<div class="blank-box bb-blue">
<ul>
<li>mc.player.getTilePos()：プレイヤーの座標（ブロック単位）を取得する。</li>
<li>mc.postToChat()：マイクラのチャット<ruby>欄<rt>らん</rt></ruby>にメッセージを表示する。</li>
</ul>
</div>
<p>また、<span class="marker-under-red">「#」からその行の終わりまでは<span style="color: #ff6600;"><b>コメント</b></span>です。実行してもコメントは無視される</span>ので、プログラムの動きには関係ありません。どのような処理をしているのかメモしておくと便利です。</p>
<p>&nbsp;</p>
<p>上のプログラムを入力したら、「mcpipy」フォルダに保存しましょう。ファイル名は「position.py」にしました。</p>
<p>マイクラのワールドに入り、チャット<ruby>欄<rt>らん</rt></ruby>に以下のコマンドを入力して実行しましょう。</p>
<div class="blank-box bb-green">/py position</div>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7021" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01.png" alt="チャット欄にコマンドを入力して実行" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>実行した結果、今自分がいる座標が表示されます。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7022" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02.png" alt="自分がいる座標が表示される" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc4">ブロックを置いてみよう</span></h2>
<p>新しくファイルを作成し、以下のプログラムを入力しましょう。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# 原点にダイヤブロック(ブロック番号:57)を置く
mc.setBlock(0, 0, 0, 57)</code></pre>
</div>
<p>&nbsp;</p>
<p><b>mc.setBlock(x, y, z, block_id)</b>は、<span class="marker-under-red">指定した場所にブロックを設置する命令</span>です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7025" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06.png" alt="mc.setBlock" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-06-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>x, y, zの部分にブロックを設置する座標を指定します。具体的な数字でもいいですし、<a rel="noopener" target="_self" href="https://living-maou.com/scratch-variable/">変数<span class="fa fa-external-link internal-icon anchor-icon"></span></a>でもOKです。</p>
<p>block_idの部分には、設置するブロックの種類を指定します。各ブロックには番号が割り当てられていて、1は石、2は草ブロック、3は土などがあります。</p>
<p><a rel="noopener" target="_blank" href="https://prosense.me/textbooks/appendix/minecraft/0/">ブロックの番号の一覧<span class="fa fa-external-link external-icon anchor-icon"></span></a>は、下のサイトなどで調べられます。</p>
<div class="blogcard-type bct-reference-link">

<a rel="noopener" target="_blank" href="https://prosense.me/textbooks/appendix/minecraft/0/" title="付録０：ブロックの番号表" class="blogcard-wrap external-blogcard-wrap a-wrap cf"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://s.wordpress.com/mshots/v1/https%3A%2F%2Fprosense.me%2Ftextbooks%2Fappendix%2Fminecraft%2F0%2F?w=160&#038;h=90" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">付録０：ブロックの番号表</div><div class="blogcard-snippet external-blogcard-snippet">マインクラフト×Pythonで使えるブロックIDの一覧表</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://prosense.me/textbooks/appendix/minecraft/0/" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">prosense.me</div></div></div></div></a>
</div>
<p>今回は原点（x=0,y=0,z=0）にダイヤブロック（ブロック番号57）を置くプログラムを作成しました。</p>
<p>&nbsp;</p>
<p>プログラムができたらファイル名をつけて保存し、実行してみましょう。</p>
<p>あたりを見わたしてみると、ダイアブロックが置かれています。ここが原点です。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7023" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03.png" alt="原点に置かれたダイアブロック" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc5">東西南北にブロックを置く</span></h2>
<p>プレイヤーを中心に東西南北にブロックを置くプログラムをつくりましょう。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7026" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05.png" alt="プレイヤーを中心に東西南北にブロックを置く" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>新しくファイルを作成し、以下のプログラムを入力します。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>import mcpi.minecraft as minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得し、変数xyzに代入
x, y, z = mc.player.getPos()

# 南に青い羊毛(ブロック番号:35 データ番号:11)を置く
mc.setBlock(x, y + 3, z + 1, 35, 11)

# 北に赤い羊毛(ブロック番号:35 データ番号:14)を置く
mc.setBlock(x, y + 3, z - 1, 35, 14)

# 東に灰色の羊毛(ブロック番号:35 データ番号:7)を置く
mc.setBlock(x + 1, y + 3, z, 35, 7)

# 西に灰色の羊毛(ブロック番号:35 データ番号:7)を置く
mc.setBlock(x - 1, y + 3, z, 35, 7)</code></pre>
</div>
<p>&nbsp;</p>
<h3><span id="toc6">プレイヤーの座標を取得し 変数xyzに代入する</span></h3>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7024" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04.png" alt="mc.player.getPos()" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>下はプレイヤーの座標を取得し、その値を<a rel="noopener" target="_self" href="https://living-maou.com/scratch-variable/">変数<span class="fa fa-external-link internal-icon anchor-icon"></span></a>に記憶させる命令です。</p>
<div class="blank-box bb-blue">x, y, z = mc.player.getPos()</div>
<p>&nbsp;</p>
<h4>プレイヤーの座標を取得する</h4>
<p>「mc.player.getPos()」は、<a href="#toc3">座標を表示してみよう</a>で使った「mc.player.getTilePos()」と同じプレイヤーの座標を取得する命令ですが、ちがいがあります。</p>
<div class="blank-box bb-blue">
<ul>
<li>mc.player.getTilePos()；プレイヤーの座標（ブロック単位、<span style="color: #ff6600;">整数</span>）を取得する</li>
<li>mc.player.getPos()：プレイヤーの座標（<span style="color: #ff6600;">小数点以下の値</span>）を取得する</li>
</ul>
</div>
<p>細かい位置を知りたいときは「mc.player.getPos()」を使って、ブロックの位置だけを知りたいときは「mc.player.getTilePos()」を使うなど使い分けてみましょう。</p>
<p>&nbsp;</p>
<h4>=（イコール）で変数に値を代入する</h4>
<p>Pythonでは<span class="marker-under-red">「=（イコール）」は「等しい」という意味ではなく、「右側の値を左側の変数に代入する」</span>という意味です。</p>
<p>たとえば、「x = 10」と書いた場合、「xが10と等しい」という意味ではなく、「xという変数に10を入れる」という意味になります。</p>
<div class="blank-box bb-blue">
<ul>
<li>x = 10   ：xに10を入れる</li>
<li>y = x    ：yにxの値を入れる</li>
<li>z = y + 1：yの値に1足した結果をzに入れる</li>
</ul>
</div>
<p>&nbsp;</p>
<p>つまり、「x, y, z = mc.player.getPos()」では、mc.player.getPos()でプレイヤーの座標を取得し、それぞれ x にx座標、y にy座標、z にz座標が保存されます。</p>
<p>Scratchでいうところの</p>
<div class="blank-box bb-blue">
<ul>
<li>変数xをプレイヤーのx座標にする</li>
<li>変数yをプレイヤーのy座標にする</li>
<li>変数zをプレイヤーのz座標にする</li>
</ul>
</div>
<p>と同じ意味です（Scratchにz座標はありませんが）。一行でまとめて代入できるなんて、Pythonはとても便利ですね！</p>
<p>この変数に保存した座標を基準に、ブロックを置いていきます。</p>
<p>&nbsp;</p>
<h3><span id="toc7">南に青い羊毛を置く</span></h3>
<p>下はさっき保存したプレイヤーの座標に石ブロックを置く命令です。</p>
<div class="blank-box bb-blue">mc.setBlock(x, y, z, 1)</div>
<p>座標の指定に変数を使っています。</p>
<p>&nbsp;</p>
<p>では、この座標の1ブロック南に青い羊毛を置いてみましょう。</p>
<div class="blank-box bb-blue">mc.setBlock(x, y + 3, <span style="color: #ff6600;">z + 1</span>, 35, 11)</div>
<p>z<ruby>軸<rt>じく</rt></ruby>の値が増える方向が南なので、zは「z + 1」にします。</p>
<p>また、ブロックをプレイヤーの頭上に置くためにyは「y + 3」にしました。足元にブロックを置きたい場合は「y &#8211; 1」にするとよいでしょう。</p>
<p>&nbsp;</p>
<p>羊毛のブロック番号は35。その後ろの11はデータ番号です。</p>
<p>データ番号で色や材質を細かく指定することができます。羊毛ブロックの場合、11は青色のデータ番号になります。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7033" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07.jpg" alt="羊毛のデータ番号" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-07-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h3><span id="toc8">北に赤い羊毛を置く</span></h3>
<p>次に、1ブロック北に赤い羊毛を置いてみましょう。</p>
<div class="blank-box bb-blue">mc.setBlock(x, y + 3, <span style="color: #ff6600;">z &#8211; 1</span>, 35, 14)</div>
<p>南の逆（z<ruby>軸<rt>じく</rt></ruby>の値が減る方向）なので、zは「z &#8211; 1」にします。</p>
<p>赤い羊毛ブロックのデータ番号は14です。</p>
<p>&nbsp;</p>
<h3><span id="toc9">東西に灰色の羊毛を置く</span></h3>
<p>同じやり方で東と西にもブロックを置きましょう。</p>
<p>x<ruby>軸<rt>じく</rt></ruby>の増える方向が東で、減る方向が西です。</p>
<p>灰色の羊毛ブロックのデータ番号は7です。</p>
<p>&nbsp;</p>
<h3><span id="toc10">実行してみよう！</span></h3>
<p>プログラムできたら「compass.py」とファイル名をつけて保存し、実行してみましょう。</p>
<p>上を見上げると、羊毛が十字に置かれているはずです。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7027" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08.png" alt="羊毛が十字に置かれている" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08.png 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-08-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>上からみるとこんな感じです。</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7028" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09.jpg" alt="羊毛が十字に置かれている" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-09-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc11">まとめ</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10.jpg"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7029" src="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10.jpg" alt="東西南北に柱を立てるプログラム" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10.jpg 800w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/minecraft-python03-10-320x180.jpg 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回の記事では、座標を使って自分の位置を確認したり、指定した場所にブロックを置いたりする方法を学びました。</p>
<p>プログラミングで座標を活用することで、大きな建物を正確に配置したり、複雑な作業を自動化できるようになります。</p>
<p>今回作ったプログラムを参考に、いろいろな場所にブロックを置いてみてくださいね！</p>
<p>&nbsp;</p>
<p>最後に、今回使用した命令とPythonの構文をおさらいしておきましょう。</p>
<p>今回使用した命令</p>
<div class="blank-box bb-blue">
<ul>
<li>mc.player.getTilePos()：プレイヤーの座標（ブロック単位、整数）を取得する。</li>
<li>mc.player.getPos()：プレイヤーの座標（小数点以下の値）を取得する。</li>
<li>mc.postToChat()：マイクラのチャット<ruby>欄<rt>らん</rt></ruby>にメッセージを表示する。</li>
<li>mc.setBlock(x, y, z, block_id)：指定した座標に任意の種類のブロックを設置する。<br />
x, y, z：ブロックを置く位置の座標<br />
block_id：設置するブロックの種類（ブロック番号とデータ番号）</li>
</ul>
</div>
<p>Pythonの構文</p>
<div class="blank-box bb-blue">
<ul>
<li>#：コメント。「#」からその行の終わりまで無視される。</li>
<li>変数名 = 式 ：右側の値を左側の変数に代入する。</li>
</ul>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python03/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【マイクラ×Python】プログラムでかんたん整地！｜初心者向けコード解説</title>
		<link>https://living-maou.com/minecraft-python02/</link>
					<comments>https://living-maou.com/minecraft-python02/#respond</comments>
		
		<dc:creator><![CDATA[メソ]]></dc:creator>
		<pubDate>Sat, 05 Oct 2024 00:30:51 +0000</pubDate>
				<category><![CDATA[Python x Minecraft]]></category>
		<category><![CDATA[Minecraft]]></category>
		<category><![CDATA[Python]]></category>
		<guid isPermaLink="false">https://living-maou.com/?p=6993</guid>

					<description><![CDATA[マインクラフトでPythonプログラミングの練習をしていると、ついまちがってブロックを置いてしまったり、不要になったブロックを片付けたくなることがありますよね。 そんなとき、一つひとつ手で壊こわすのは大変です。 この記事 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-6994" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02.png" alt="" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02.png 800w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>マインクラフトでPythonプログラミングの練習をしていると、ついまちがってブロックを置いてしまったり、不要になったブロックを片付けたくなることがありますよね。</p>
<p>そんなとき、一つひとつ手で<ruby>壊<rt>こわ</rt></ruby>すのは大変です。</p>
<p>この記事では、Pythonを使ってブロックを自動で片付け、まわりを元の状態にもどすプログラムを作る方法を<ruby>紹介<rt>しょうかい</rt></ruby>します。</p>
<p>自分の周りを整地したい時にも使えますよ！</p>
<p>&nbsp;</p>
<h2><span id="toc1">マインクラフトとPythonの連携について</span></h2>
<p>マインクラフトをPythonで操作するには、特定の<ruby>環境<rt>かんきょう</rt></ruby>を整える必要があります。</p>
<p>くわしい<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/">セットアップ方法<span class="fa fa-external-link internal-icon anchor-icon"></span></a>は、前回の記事で説明していますので、まだ準備ができていない方はそちらをチェックしてみてください。</p>
<div class="blogcard-type bct-prev">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python01/" title="【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/09/eyecatch-minecraft-python01.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【Windows11】マイクラでPythonプログラミングに挑戦！環境構築のやり方を解説</div><div class="blogcard-snippet internal-blogcard-snippet">マインクラフトでPythonに挑戦！【リビングの魔王】では初心者にも分かりやすいようスクリーンショットを使いつつ、環境構築の方法を丁寧に紹介します。メッセージを表示したり建物やドット絵を作ったり楽しみながらプログラミングの基本を学びましょう！</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
<p>&nbsp;</p>
<h2><span id="toc2">きれいな状態にもどすプログラム</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-7002" src="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05.png" alt="建物が消える" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05.png 800w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-05-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>今回作るプログラムは、<b>指定した<ruby>範囲<rt>はんい</rt></ruby>のブロックをきれいに片付けてくれる</b>ものです。</p>
<p>足元のブロックをすべて草ブロックに変え、その上の空間を空気ブロックで<ruby>埋<rt>う</rt></ruby>めることで、スーパーフラットの地形にもどします。</p>
<p>このプログラムを使えば、建築の準備や失敗したブロックを消したり、整地することができます。</p>
<p>&nbsp;</p>
<h2><span id="toc3">完成したソースコード</span></h2>
<p>完成したプログラムは以下の通りです。</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-python" data-lang="Python"><code>from mcpi import minecraft

mc = minecraft.Minecraft.create()

# プレイヤーの座標を取得
x, y, z = mc.player.getPos()

# 草ブロック
mc.setBlocks(x - 100, -1, z - 100, x + 100, -1, z + 100, 2)

# 空気ブロック
mc.setBlocks(x - 100, 0, z - 100, x + 100, 200, z + 100, 0)</code></pre>
</div>
<p>&nbsp;</p>
<p>このプログラムでは、プレイヤーの座標を中心にして、100ブロック<ruby>範囲<rt>はんい</rt></ruby>内の地面に草ブロックをしきつめて、その上のブロックはすべて空気ブロックで上書きします。<br />
<a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-6995" src="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01.png" alt="プレイヤーの周りを空気と草ブロックで整地する" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01.png 800w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-01-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<div class="blank-box bb-tab bb-memo bb-blue"><span style="color: #ff6600;"><b>座標</b></span>については、「<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-xyz/">【マイクラ】座標の見かたを解説！コマンドやプログラミングで使いこなせるようになろう<span class="fa fa-external-link internal-icon anchor-icon"></span></a>」でくわしく解説しています。</div>
<p>&nbsp;</p>
<h2><span id="toc4">プログラムの説明</span></h2>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-6996" src="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02.png" alt="整地するプログラム" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02.png 800w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-02-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<h3><span id="toc5">プレイヤーの座標を取得</span></h3>
<div class="blank-box bb-blue">x, y, z = mc.player.getPos()</div>
<p>プレイヤーが現在いる座標（x, y, z）を取得します。この座標を基準にブロックを配置します。</p>
<p>&nbsp;</p>
<h3><span id="toc6">草ブロックを配置</span></h3>
<div class="blank-box bb-blue">mc.setBlocks(x &#8211; 100, -1, z &#8211; 100, x + 100, -1, z + 100, 2)</div>
<p>プレイヤーの足元から<ruby>広範囲<rt>こうはんい</rt></ruby>に草ブロック（ID: 2）をしきつめます。</p>
<p><ruby>範囲<rt>はんい</rt></ruby>は、プレイヤーを中心にx方向とz方向に100ブロックずつ広がり、y座標は地面（-1）に設定されています。</p>
<p>&nbsp;</p>
<h3><span id="toc7">空気ブロックで整地</span></h3>
<div class="blank-box bb-blue">mc.setBlocks(x &#8211; 100, 0, z &#8211; 100, x + 100, 200, z + 100, 0)</div>
<p>プレイヤーの周りにあるブロックをすべて空気ブロック（ID: 0）に置きかえます。</p>
<p>これでプレイヤーの周りがすっきりと片付きます。</p>
<p>&nbsp;</p>
<h2><span id="toc8">実行してみよう</span></h2>
<p>プログラムを「mcpipy」フォルダに保存します。今回はファイル名を「clear」にしました。</p>
<p>Minecraftのワールドに入り、チャット<ruby>欄<rt>らん</rt></ruby>に以下のコマンドを入力して実行しましょう。</p>
<div class="blank-box bb-green">/py clear</div>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-6997" src="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03.png" alt="プログラムを実行" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03.png 800w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-03-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<p>実行した結果、目の前の建物が消えました！</p>
<p><a rel="noopener" target="_self" href="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-6998" src="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04.png" alt="実行結果" width="800" height="450" srcset="https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04.png 800w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-500x281.png 500w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-300x169.png 300w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-768x432.png 768w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-120x68.png 120w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-160x90.png 160w, https://living-maou.com/wp-content/uploads/2024/09/minecraft-python02-04-320x180.png 320w" sizes="(max-width: 800px) 100vw, 800px" /></a></p>
<p>&nbsp;</p>
<h2><span id="toc9">注意点やポイント</span></h2>
<p>このプログラムを使う際に気をつけたいポイントをいくつか<ruby>紹介<rt>しょうかい</rt></ruby>します。</p>
<h3><span id="toc10">スーパーフラットで使おう</span></h3>
<p>このプログラムは、<span style="color: #ff6600;">スーパーフラットで使用する</span>ことを前提としています。</p>
<p>スーパーフラット以外の地形で使用すると、地形が大きく変わってしまう可能性があります。</p>
<h3><span id="toc11">範囲内のブロックはすべて消える</span></h3>
<p><span style="color: #ff6600;">指定した<ruby>範囲<rt>はんい</rt></ruby>にあるブロックはすべて上書きされる</span>ため、大切な建物や構造物がある場合は注意が必要です。</p>
<p>&nbsp;</p>
<h2><span id="toc12">まとめ</span></h2>
<p>今回のプログラムを使えば、マインクラフトでの整地やブロックの片付けが<ruby>一瞬<rt>いっしゅん</rt></ruby>でできちゃいます。</p>
<p>手作業での片付けがいらなくなって、作業効率が<ruby>大幅<rt>おおはば</rt></ruby>にアップすることまちがいなしです！</p>
<p>&nbsp;</p>
<p>次回は、座標を使って自分の位置を確認したり、ブロックを設置する方法を紹介します。</p>
<div class="blogcard-type bct-next">

<a rel="noopener" target="_self" href="https://living-maou.com/minecraft-python03/" title="【マイクラ×Python】座標を使いこなせ！位置確認とブロックの置き方" class="blogcard-wrap internal-blogcard-wrap a-wrap cf"><div class="blogcard internal-blogcard ib-left cf"><div class="blogcard-label internal-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail internal-blogcard-thumbnail"><img loading="lazy" decoding="async" width="160" height="90" src="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-160x90.jpg" class="blogcard-thumb-image internal-blogcard-thumb-image wp-post-image" alt="" srcset="https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-160x90.jpg 160w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-500x281.jpg 500w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-300x169.jpg 300w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-768x432.jpg 768w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-120x68.jpg 120w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03-320x180.jpg 320w, https://living-maou.com/wp-content/uploads/2024/10/eyecatch-minecraft-python03.jpg 800w" sizes="(max-width: 160px) 100vw, 160px" /></figure><div class="blogcard-content internal-blogcard-content"><div class="blogcard-title internal-blogcard-title">【マイクラ×Python】座標を使いこなせ！位置確認とブロックの置き方</div><div class="blogcard-snippet internal-blogcard-snippet">Pythonを使ってマイクラ内の座標を操作し、自分の位置を確認したり、ブロックを設置する方法を初心者向けに解説！【リビングの魔王】では、プログラミング初心者でも安心して進められるよう、ステップごとにていねいに説明します。</div></div><div class="blogcard-footer internal-blogcard-footer cf"><div class="blogcard-site internal-blogcard-site"><div class="blogcard-favicon internal-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://living-maou.com" alt="" class="blogcard-favicon-image internal-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain internal-blogcard-domain">living-maou.com</div></div></div></div></a>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://living-maou.com/minecraft-python02/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
