2021年6月号 特設 マインクラフトでPythonレッスン5

複数データを効率よく扱う

レッスン4  レッスン6

●Minecraftの画面

動画1:ブロックの種類を変える

 

●ソースコード

from mcpi.minecraft import Minecraft
from mcpi.block import *
mc = Minecraft.create()
Pos = mc.player.getTilePos()
import time

# IDとDATAで表示可能なブロックのリスト
block_list = [[0,0], [1,0], [2,0], [3,0], [4,0], [5,0],
[6,0], [6,1], [6,2], [7,0], [8,0], [8,1],
[9,0], [9,1], [9,2], [9,3], [9,4], [9,5],
[9,6], [9,7], [10,0], [10,1], [11,0], [11,1],
[11,2], [11,3], [11,4], [11,5], [11,6], [11,7],
[12,0], [13,0], [14,0], [15,0], [16,0], [17,0],
[17,1], [17,2], [18,0], [18,1], [18,2], [18,3],
[18,4], [18,5], [18,6], [18,7], [20,0],
[21,0], [22,0], [24,0], [24,1], [24,2], [26,0],
[26,1], [26,2], [26,3], [30,0], [31,0], [31,1],
[31,3], [35,0], [35,1], [35,2], [35,3],
[35,4], [35,5], [35,6], [35,7], [35,8], [35,9],
[35,10], [35,11], [35,12], [35,13], [35,14], [35,15],
[37,0], [38,0], [39,0], [40,0], [41,0], [42,0],
[43,0], [43,1], [43,2], [43,3], [43,4], [43,5],
[43,6], [44,0], [44,1], [44,2], [44,3],
[44,4], [44,5], [44,8], [44,9], [44,10],
[44,11], [44,12], [44,13], [45,0], [46,0],
[46,1], [47,0], [48,0], [49,0], [50,5], [51,0],
[53,0], [53,1], [53,2], [53,3], [53,4], [53,5],
[53,6], [53,7], [54,0], [54,1], [54,2], [54,3],
[54,4], [56,0], [57,0], [58,0], [59,0], [59,1],
[59,2], [59,3], [59,4], [59,5], [59,6], [59,7],
[59,8], [59,9], [59,10], [59,11], [59,12], [59,13],
[59,14], [59,15], [60,0], [60,1], [61,3], [62,3],
[63,0], [63,1], [63,2], [63,3], [63,4], [63,5],
[63,6], [63,7], [63,8], [63,9], [63,10], [63,11],
[63,12], [63,13], [63,14], [63,15], [64,0], [64,1],
[64,2], [64,3], [64,4], [64,5], [64,6], [64,7],
[64,8], [64,9], [67,0], [67,1], [67,2], [67,3],
[67,4], [67,5], [67,6], [67,7], [68,2], [68,3],
[68,4], [68,5], [71,0], [71,1], [71,2], [71,3],
[71,4], [71,5], [71,6], [71,7], [71,8], [71,9],
[73,0], [78,0], [79,0], [80,0], [81,0], [82,0],
[83,0], [85,0], [87,0], [89,0], [95,0], [96,3],
[96,4], [96,5], [96,6], [96,7], [96,8], [98,0],
[98,1], [98,2], [102,0], [103,0], [105,0], [105,1],
[105,2], [105,3], [105,4], [105,5], [105,6], [105,7],
[105,8], [105,9], [105,10],[105,11],[105,12],[105,13],
[105,14],[105,15],[107,0], [107,1], [107,2], [107,3],
[107,4], [107,5], [107,6], [107,7], [108,0], [108,1],
[108,2], [108,3], [108,4], [108,5], [108,6], [108,7],
[109,0], [109,1], [109,2], [109,3], [109,4], [109,5],
[109,6], [109,7], [112,0], [114,0], [114,1], [114,2],
[114,3], [114,4], [114,5], [114,6], [114,7], [128,0],
[128,1], [128,2], [128,3], [128,4], [128,5], [128,6],
[128,7], [155,0], [155,1], [155,2], [156,0], [156,1],
[156,2], [156,3], [156,4], [156,5], [156,6], [156,7],
[245,0], [246,0], [247,0], [247,1], [247,2], [248,0],
[249,0], [253,0], [254,0], [254,1], [254,2], [255,0]]

# リストの全要素を読み込み
for i in block_list:
try:
# ブロックのidとdataで配置
mc.setBlock(Pos.x, Pos.y, Pos.z + 2, Block(i[0],i[1]))
except:
# ブロック配置に失敗したときのエラーを無視して処理を続行
pass
time.sleep(1) # 処理を一時停止