MINECRAFT (Java version)

python を用いた Minecraft プログラミング (7)


ドット絵を描く

  1. 'I' キーを押して 'py dot_3_1 'とタイプすると、'dot_3_1.py' が 呼び出される。
  2. C:/Users/nitta/Roaming/.minecraft-forge1.12.2/mcpi/dot_3_1.py
    import mcpi.minecraft as minecraft
    
    mc = minecraft.Minecraft.create()
    
    x, y, z = mc.player.getPos()
    
    creeper_colors = [
        [5, 5, 5, 5, 5, 5, 5, 5],
        [5, 5, 5, 5, 5, 5, 5, 5],
        [5, 15, 15, 5, 5, 15, 15, 5],
        [5, 15, 15, 5, 5, 15, 15, 5],
        [5, 5, 5, 15, 15, 5, 5, 5],
        [5, 5, 15, 15, 15, 15, 5, 5],
        [5, 5, 15, 15, 15, 15, 5, 5],
        [5, 5, 15, 5, 5, 15, 5, 5]
    ]
    
    for i in range(8):
        row = creeper_colors[i]
        for j in range(8):
            mc.setBlock(x+j, y+8-i, z, 35, row[j])
    
  3. 実行例。

  4. 'I' キーを押して 'py dot_4_1 'とタイプすると、'dot_4_1.py' が 呼び出される。
  5. C:/Users/nitta/Roaming/.minecraft-forge1.12.2/mcpi/dot_4_1.py
    import mcpi.minecraft as minecraft
    
    mc = minecraft.Minecraft.create()
    
    x, y, z = mc.player.getPos()
    
    colors = [
        [0, 0, 15, 15, 15, 15, 15, 15, 0, 0],
        [0, 15, 4, 4, 4, 4, 4, 4, 15, 0],
        [15, 4, 4, 15, 4, 4, 15, 4, 4, 15],
        [15, 4, 4, 15, 4, 4, 15, 4, 4, 15],
        [15, 4, 4, 4, 4, 4, 4, 4, 4, 15],
        [15, 4, 15, 4, 4, 4, 4, 15, 4, 15],
        [15, 4, 15, 4, 4, 4, 4, 15, 4, 15],
        [15, 4, 4, 15, 15, 15, 15, 4, 4, 15],
        [0, 15, 4, 4, 4, 4, 4, 4, 15, 0],
        [0, 0, 15, 15, 15, 15, 15, 15, 0, 0]
    ]
    
    height = len(colors)
    
    for i in range(height):
        row = colors[i]
        width = len(row)
    
  6. 実行例。