sumisoクラフト

sumisoクラフトはてなブログ拠点

広範囲fillコマンドをpythonで生成する

 

イクラのfillコマンド

 

指定した範囲内を

特定のブロックで満たすことができる

 

replaceを指定すれば

ブロックを一括で置き換えられる

 

整地・建築・検証

幅広い分野で使える

便利コマンドだ

 

しかし

一度に置換できる範囲は

32^3=32768ブロックまで

 

広範囲を置換したい場合は

何回かに分けて実行する必要がある

 

いちいちコマンドを入力するのは面倒なので

function機能を利用するが

 

sumiso-c0db8c.hatenablog.com

 

functionを書くのも面倒

 

なので、pythonでmcfunctionファイルを生成する

 

 

 

python 

1辺が32以下になるように

座標の範囲を区切り

全体が網羅できるように

組み合わせる

 

という操作をpythonに任せる

 

とは言っても

pythonの使い方が分からない

 

ので

変数の宣言から

if文の書き方

for文の書き方

絶対値のとり方

小数点以下切り上げ

関数の作り方

二次元配列の使い方

まで

 

全てググりながら

継ぎ接ぎながら作った

 

あまり参考にしないように

 

計算用の関数 calc.py

#1辺の長さを32以下になるように区切る
def bunkatu(a, b): #from a, to b, a < b
    long = abs(b-a) #長さの絶対値を取る
    count = math.ceil(long / 32) #小数点以下切り上げ

    fill = list() #分ける座標

    num = a

    fill.append(a) #開始座標

    if count > 1 : #32ずつ足していく
        for i in range(1, count):
            num = num + 32
            fill.append(num)
            
    fill.append(b) #終了座標
    
    return fill



def hani(fill): #fillコマンド用の座標にする
    fill_from = list()
    fill_to = list()


    for i in range(0, len(fill)-1):
        if i <len(fill) -2 :
            fill_from.append(fill[i])
            fill_to.append(fill[i+1] - 1)
        else: #最後は終了座標に合わせる
            fill_from.append(fill[i])
            fill_to.append(fill[i+1])

    fill_num =[fill_from, fill_to]
    
    return fill_num

 

メインの操作 seiti.py

import calc

#書き出しファイル
writefile = "replaceAnzangan.mcfunction"

#整地範囲
fill_from = (351, 5, 703)
fill_to = (486, 64, 862)

#ブロック
block = "stained_glass 7"
replace = " replace stone 5"

#32以下で区切る
x_bunkatu = calc.bunkatu(fill_from[0], fill_to[0])
y_bunkatu = calc.bunkatu(fill_from[1], fill_to[1])
z_bunkatu = calc.bunkatu(fill_from[2], fill_to[2])

#分割回数
x_len = len(x_bunkatu)
y_len = len(y_bunkatu)
z_len = len(z_bunkatu)


#コマンド用座標
x_fill = calc.hani(x_bunkatu)
y_fill = calc.hani(y_bunkatu)
z_fill = calc.hani(z_bunkatu)

#座標部分
zahyou = list()

for x in range(0, x_len -1 ):
    for y in range(0, y_len -1):
        for z in range(0, z_len -1):
            s_from= str(x_fill[0][x]) + " " + str(y_fill[0][y]) + " " + str(z_fill[0][z]) + " "
            s_to = str(x_fill[1][x]) + " " + str(y_fill[1][y]) + " " + str(z_fill[1][z]) + " "
            s = s_from + s_to
            zahyou.append(s)

#書き出し用リスト
command = list()

#fillコマンドに成形
for c in zahyou:
    s = "fill " + c + block + replace + "\n"
    command.append(s)
    


#ファイル書き出し
with open(writefile, mode="w", encoding="utf-8") as f:
    f.writelines(command)

 

変数の宣言ルールとか

超適当

 

#書き出し用ファイル

#整地範囲の座標 

#block

の部分を書き換えれば

JE、BEを問わず

使いまわせる

 

はず

 

mcfunction

 

上記のプログラムで

実際に生成したファイルは

こちら

replaceAnzangan.mcfunction

fill 351 5 703 382 36 734 stained_glass 7 replace stone 5
fill 351 5 735 382 36 766 stained_glass 7 replace stone 5
fill 351 5 767 382 36 798 stained_glass 7 replace stone 5
fill 351 5 799 382 36 830 stained_glass 7 replace stone 5
fill 351 5 831 382 36 862 stained_glass 7 replace stone 5
fill 351 37 703 382 64 734 stained_glass 7 replace stone 5
fill 351 37 735 382 64 766 stained_glass 7 replace stone 5
fill 351 37 767 382 64 798 stained_glass 7 replace stone 5
fill 351 37 799 382 64 830 stained_glass 7 replace stone 5
fill 351 37 831 382 64 862 stained_glass 7 replace stone 5
fill 383 5 703 414 36 734 stained_glass 7 replace stone 5
fill 383 5 735 414 36 766 stained_glass 7 replace stone 5
fill 383 5 767 414 36 798 stained_glass 7 replace stone 5
fill 383 5 799 414 36 830 stained_glass 7 replace stone 5
fill 383 5 831 414 36 862 stained_glass 7 replace stone 5
fill 383 37 703 414 64 734 stained_glass 7 replace stone 5
fill 383 37 735 414 64 766 stained_glass 7 replace stone 5
fill 383 37 767 414 64 798 stained_glass 7 replace stone 5
fill 383 37 799 414 64 830 stained_glass 7 replace stone 5
fill 383 37 831 414 64 862 stained_glass 7 replace stone 5
fill 415 5 703 446 36 734 stained_glass 7 replace stone 5
fill 415 5 735 446 36 766 stained_glass 7 replace stone 5
fill 415 5 767 446 36 798 stained_glass 7 replace stone 5
fill 415 5 799 446 36 830 stained_glass 7 replace stone 5
fill 415 5 831 446 36 862 stained_glass 7 replace stone 5
fill 415 37 703 446 64 734 stained_glass 7 replace stone 5
fill 415 37 735 446 64 766 stained_glass 7 replace stone 5
fill 415 37 767 446 64 798 stained_glass 7 replace stone 5
fill 415 37 799 446 64 830 stained_glass 7 replace stone 5
fill 415 37 831 446 64 862 stained_glass 7 replace stone 5
fill 447 5 703 478 36 734 stained_glass 7 replace stone 5
fill 447 5 735 478 36 766 stained_glass 7 replace stone 5
fill 447 5 767 478 36 798 stained_glass 7 replace stone 5
fill 447 5 799 478 36 830 stained_glass 7 replace stone 5
fill 447 5 831 478 36 862 stained_glass 7 replace stone 5
fill 447 37 703 478 64 734 stained_glass 7 replace stone 5
fill 447 37 735 478 64 766 stained_glass 7 replace stone 5
fill 447 37 767 478 64 798 stained_glass 7 replace stone 5
fill 447 37 799 478 64 830 stained_glass 7 replace stone 5
fill 447 37 831 478 64 862 stained_glass 7 replace stone 5
fill 479 5 703 486 36 734 stained_glass 7 replace stone 5
fill 479 5 735 486 36 766 stained_glass 7 replace stone 5
fill 479 5 767 486 36 798 stained_glass 7 replace stone 5
fill 479 5 799 486 36 830 stained_glass 7 replace stone 5
fill 479 5 831 486 36 862 stained_glass 7 replace stone 5
fill 479 37 703 486 64 734 stained_glass 7 replace stone 5
fill 479 37 735 486 64 766 stained_glass 7 replace stone 5
fill 479 37 767 486 64 798 stained_glass 7 replace stone 5
fill 479 37 799 486 64 830 stained_glass 7 replace stone 5
fill 479 37 831 486 64 862 stained_glass 7 replace stone 5

 

あってる?

 

これは統合版仕様のコマンド

安山岩をガラスに置換する

 

ブロックの指定を変えれば

Java版でも使える

 

ビヘイビアーパック

このままでは

イクラで使えないので

ビヘイビアーパックに加工する

 

java版の場合は

データパックになるので

以前の記事を参考にして欲しい

sumiso-c0db8c.hatenablog.com

 

ファイル構成

seiti/ 
 ├ manifest.json
 ├ pack_icon.png
 └ functions/
   └ replaceAnzangan.mcfunction

フォルダーはfunctions

ファイルはfunction

なので注意

 

 

manifest.json

様々な人が

生成ツールを公開しているので

利用させていただく

functionを利用する場合は

typeはdetaとなる

 

pack_icon.png

正方形の画像

無くても動作はする

 

これらをzipにし

拡張子を

.mcpackに書き換え

イクラのアイコンになったら

クリックすると

自動でマイクラが起動

インポートされる

 

コマンド実行

イクラでfunctionを実行するには

/function replaceAnzangan

/fu

ぐらいまで入力すれば

予測が出るので

そこから選べば楽

 

ファイルを入れ子にした場合は

例:

c0db8cフォルダーに

tp.mcfunction

が存在する場合は

/function c0db8c/tp

となる

 

どこかで見たな?

 

使用例

安山岩花崗岩、閃緑岩

土、砂利、水、溶岩を

ステンドグラスに置換

 

石を空気に置換すれば

 

f:id:sumiso_c0db8c:20201115114015p:plain

 

このような空間ができる

 

functionは大量のコマンドを

一度に実行するので

 

PCが重くなったり

置換漏れが発生したり

水がバグったりする

ので注意

 

実際に行ってみたい

という方は

こちらからどうぞ

www.dropbox.com

ご利用は自己責任でお願いします