【いろいろ作ってコマンドを覚えよう第一弾】銃を作ろう
コマンドを作ろうと思っても、無から作るのはとても難しいと思います。なので、この記事らをもとにたくさんのコマンドを作ってコマンドを覚えよう。では早速コマンド紹介に移る。
まず、コマンドの機構を考えよう。合理的に考えるなら下のようになるだろう。
1.リロード
2.発射機構
3.弾の当たり判定、パーティクル処理
4.弾の消える判定
こうなるだろう。一つ一つ教えていく。まず最初に
code:スコアボードを作るコマンド
scoreboard objectives add ReloadTime dummy ReloadTime
scoreboard objectives add BulletRest dummy BulletRest
scoreboard objectives add BulletTime dummy BulletTime
この3つのコマンドを実行しよう。これはスコアボードを作るコマンドだ。次は以下のコマンドタワーを建てよう。https://scrapbox.io/files/68d9252344ecc52b709a648f.png
完成したらこのような感じになるよ。
code:1番右のコマンドタワー
1.リピート 無条件 動力が必要
execute as @ahasitem=iron_helmet,location=slot.armor.head,scores={BulletRest=1..} at @s run tag @s add shot
2.チェーン 無条件 動力が必要
execute as @atag=shot at @s run replaceitem entity @s slot.armor.head 0 air 1 1
3.チェーン 無条件 動力が必要
execute as @atag=shot at @s positioned ~~1000~ run summon ender_crystal ~~~ ~ ~ none bullet
4.チェーン 無条件 動力が必要
execute as @atag=shot at @s run scoreboard players remove @s BulletRest 1
5.チェーン 無条件 動力が必要
execute as @atag=shot at @s run tag @s remove shot
code:右から2番目のコマンドタワー
1.リピート 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s run tp @s ^^^1
2.チェーン 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s positioned ~~-1000~ run damage @er=1 8 self_destruct
3.チェーン 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s positioned ~~-1000~ run particle minecraft:balloon_gas_particle ~~~
4.チェーン 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s run effect @s resistance 1 5
5.チェーン 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s run effect @s invisibility 1 1
code:右から3番目のコマンドタワー
1.リピート 無条件 動力が必要
execute as @ahasitem=iron_nagget,location=slot.weapon.mainhand at @s if entity @sy=~1.4,dx=0 unless entity @sy=~1.5,dx=0 run scoreboard players add @s ReloadTime 1
2.チェーン 無条件 動力が必要
execute as @ascores={ReloadTime=60..} at @s run scoreboard players set @s BulletRest 24
3.チェーン 無条件 動力が必要
execute as @ascores={ReloadTime=60..} at @s run scoreboard players set @s ReloadTime 0
4.チェーン 無条件 動力が必要
execute as @ahasitem=iron_nagget,location=slot.weapon.mainhand at @s if entity @sy=~1.4,dx=0 unless entity @sy=~1.5,dx=0 run particle minecraft:bleach ~~~
code:右から4番目のコマンドタワー
1.リピート 無条件 動力が必要
execute as @etype=ender_crystal,name=bullet at @s if blocks 10001 100 1001 9999 100 9999 ~~~ at @s run kill @s
2.チェーン 無条件 動力が必要
execute as @etype=ender_crystal,name=Bullet at @s run scoreboard players add @s BulletTime 1
3.チェーン 無条件 動力が必要
kill @etype=ender_crystal,name=bullet,scores={BulletTime=40..}
4.チェーン 無条件 動力が必要
execute as @a at @s if entity @sy=~1.4,dx=0 unless entity @sy=~1.5,dx=0 run titleraw @s actionbar{"rawtext":{"score":{"name":"*","objective":"BulletRest"}},{"text":"§g§l/24発"}}