久しぶりにやる気が出たのでちまちまとMinecraftをプレイ中。
これまでは触ってなかったModに手を出すようになり、色々と使ってます。
そんな中、気に入っているSim-U-Kraftの最新版ではNPCが建物を建築する際、その建物で実際に使用するブロックが要求されるモードが追加されています。
で、建物の必要資材が建物を選択しないとわからないのがとても不便なので、いっその事データから資材を計算して別ファイルに出しておこうという結論に至った次第。
でまぁ、ざっくりとPerlスクリプトを組んでみた。
Count.pl
以下スクリプト本文
———————————–
#ブロックIDリスト
%block_id = (
“0”,”Air”,
“1”,”Stone”,
“2”,”Grass”,
“3”,”Dirt”,
“4”,”Cobblestone”,
“5”,”Wooden Plank”,
“6”,”Sapling”,
“6:1″,”Redwood Sapling”,
“6:2″,”Birch Sapling”,
“7”,”Bedrock”,
“8”,”Water”,
“9”,”Stationary Water”,
“10”,”Lava”,
“11”,”Stationary Lava”,
“12”,”Sand”,
“13”,”Gravel”,
“14”,”Gold Ore”,
“15”,”Iron Ore”,
“16”,”Coal Ore”,
“17”,”Wood”,
“17:1″,”Redwood”,
“17:2″,”Birchwood”,
“18”,”Leaves”,
“18:1″,”Redwood Leaves”,
“18:2″,”Birchwood Leaves”,
“19”,”Sponge”,
“20”,”Glass”,
“21”,”Lapis Lazuli Ore”,
“22”,”Lapis Lazuli Block”,
“23”,”Dispenser”,
“24”,”Sandstone”,
“25”,”Note Block”,
“26”,”Bed Block”,
“27”,”Powered Rail”,
“28”,”Detector Rail”,
“29”,”Sticky Piston”,
“30”,”Web”,
“31”,”Dead Shrub”,
“31:1″,”Tall Grass”,
“31:2″,”Live Shrub”,
“32”,”Dead Shrub”,
“33”,”Piston”,
“34”,”Piston Head”,
“35”,”White Wool”,
“35:1″,”Orange Wool”,
“35:2″,”Magenta Wool”,
“35:3″,”Light Blue Wool”,
“35:4″,”Yellow Wool”,
“35:5″,”Light Green Wool”,
“35:6″,”Pink Wool”,
“35:7″,”Gray Wool”,
“35:8″,”Light Gray Wool”,
“35:9″,”Cyan Wool”,
“35:10″,”Purple Wool”,
“35:11″,”Blue Wool”,
“35:12″,”Brown Wool”,
“35:13″,”Dark Green Wool”,
“35:14″,”Red Wool”,
“35:15″,”Black Wool”,
“37”,”Dandelion”,
“38”,”Rose”,
“39”,”Brown Mushroom”,
“40”,”Red Mushroom”,
“41”,”Gold Block”,
“42”,”Iron Block”,
“43”,”Double Stone Slab”,
“43:1″,”Double Sandstone Slab”,
“43:2″,”Double Wooden Slab”,
“43:3″,”Double Cobblestone Slab”,
“43:4″,”Double Brick Slab”,
“43:5″,”Double Stone Brick Slab”,
“44”,”Stone Slab”,
“44:1″,”Sandstone Slab”,
“44:2″,”Wooden Slab”,
“44:3″,”Cobblestone Slab”,
“44:4″,”Brick Slab”,
“44:5″,”Stone Brick Slab”,
“45”,”Brick”,
“46”,”TNT”,
“47”,”Bookshelf”,
“48”,”Mossy Cobblestone”,
“49”,”Obsidian”,
“50”,”Torch”,
“51”,”Fire”,
“52”,”Monster Spawner”,
“53”,”Wooden Stairs”,
“54”,”Chest”,
“55”,”Redstone Wire”,
“56”,”Diamond Ore”,
“57”,”Diamond Block”,
“58”,”Workbench”,
“59”,”Wheat Crops”,
“60”,”Soil”,
“61”,”Furnace”,
“62”,”Burning Furnace”,
“63”,”Sign Post”,
“64”,”Wooden Door Block”,
“65”,”Ladder”,
“66”,”Rails”,
“67”,”Cobblestone Stairs”,
“68”,”Wall Sign”,
“69”,”Lever”,
“70”,”Stone Pressure Plate”,
“71”,”Iron Door Block”,
“72”,”Wooden Pressure Plate”,
“73”,”Redstone Ore”,
“74”,”Glowing Redstone Ore”,
“75”,”Redstone Torch (off)”,
“76”,”Redstone Torch (on)”,
“77”,”Stone Button”,
“78”,”Snow”,
“79”,”Ice”,
“80”,”Snow Block”,
“81”,”Cactus”,
“82”,”Clay”,
“83”,”Sugar Cane”,
“84”,”Jukebox”,
“85”,”Fence”,
“86”,”Pumpkin”,
“87”,”Netherrack”,
“88”,”Soul Sand”,
“89”,”Glowstone”,
“90”,”Portal”,
“91”,”Jack-O-Lantern”,
“92”,”Cake Block”,
“93”,”Redstone Repeater Block (off)”,
“94”,”Redstone Repeater Block (on)”,
“95”,”Locked Chest”,
“96”,”Trapdoor”,
“97”,”Stone (Silverfish)”,
“97:1″,”Cobblestone (Silverfish)”,
“97:2″,”Stone Brick (Silverfish)”,
“98”,”Stone Brick”,
“98:1″,”Mossy Stone Brick”,
“98:2″,”Cracked Stone Brick”,
“99”,”Red Mushroom Cap”,
“100”,”Brown Mushroom Cap”,
“101”,”Iron Bars”,
“102”,”Glass Pane”,
“103”,”Melon Block”,
“104”,”Pumpkin Stem”,
“105”,”Melon Stem”,
“106”,”Vines”,
“107”,”Fence Gate”,
“108”,”Brick Stairs”,
“109”,”Stone Brick Stairs”,
“110”,”Mycelium”,
“111”,”Lily Pad”,
“112”,”Nether Brick”,
“113”,”Nether Brick Fence”,
“114”,”Nether Brick Stairs”,
“115”,”Nether Wart”,
“116”,”Enchantment Table”,
“117”,”Brewing Stand”,
“118”,”Cauldron”,
“119”,”End Portal”,
“120”,”End Portal Frame”,
“121”,”End Stone”,
“122”,”Dragon Egg”,
“123”,”Redstone Lamp (inactive)”,
“124”,”Redstone Lamp (active)”,
“125”,”Double Wooden Slab”,
“126”,”Wooden Slab”,
“127”,”Cocoa Plant”,
“128”,”Sandstone Stairs”,
“129”,”Emerald Ore”,
“130”,”Ender Chest”,
“131”,”Tripwire Hook”,
“132”,”Tripwire”,
“133”,”Emerald Block”,
“134”,”Spruce Wood Stairs”,
“135”,”Birch Wood Stairs”,
“136”,”Jungle Wood Stairs”,
“137”,”Command Block”,
“138”,”Beacon Block”,
“139”,”Cobblestone Wall”,
“140”,”Flower Pot”,
“141”,”Carrots”,
“142”,”Potatoes”,
“143”,”Wooden Button”,
);
#データファイルを読み込み。
#1行目は建物のサイズ、2行目は文字とブロックIDの対応表、3行目以降が建物データ本体で1行1段。
@data = <STDIN>;
chomp @data;
2行目をハッシュにするために変換処理。現バージョンでは建築資材のチェックにデータ値を参照していないようなので外しておく。
$data[1] =~ tr/=;/,,/;
$data[1] =~ s/:\d+//g;
#ID対応表の作成。
%block_data = split(“,”,$data[1]);
#建物データを1つにまとめる
for($count = 2 ; $count <= $#data ; $count ++){
$block .= $data[$count];
}
#面倒なのでchopで後ろから1文字ずつ削り、その文字が何回目かを記録。多分これが一番楽。
while($block){
$code = chop $block;
$block_count{“$code”} ++;
}
#結果の記述。ブロック側で引っかかった文字を対応表を用いてブロック名を抜き出し、書きだす。
#なお、Control Box及びLight Blockは対応表にないので直接指定。
foreach $key(sort keys %block_count){
if($key eq ‘$’){
$block_name = “Control Box”;
}elsif($key eq ‘*’){
$block_name = “Sim-U-Lightblock”
}else{
$block_name = ($block_id{$block_data{$key}});
}
print $block_name . ” : ” . $block_count{$key} . “\n”;
}
——————————————
スクリプト以上。
多分もっとうまくする方法はあるんだろうけど、それは誰かに任せることにする。
Comments