Help us understand the problem. What is going on with this article?

Minecraft Datapack 作成の小技1

概要

マイクラ人狼のデータパックを作ってて、
「共有して車輪の再発明を防ごう!」
と思ったので、
マイクラのコマンドで使える小技を羅列していく。

小技集

サーバに居る参加者人数を数える

タイトルそのまま。
データパックじゃなくても、コマンドブロックでもできます

NUM というスコアボードを作成して、
DUMMY というダミープレイヤーの NUM
参加者人数がストアされる。

count.mcfunction
scoreboard objectives add NUM dummy
scoreboard players set NUM 0
execute as @a run scoreboard players add DUMMY NUM 1

簡易的なタイマーを作る

データパックでしか使用できない…かな?
データパックの tick.json の機能を使用。
tick.json からは ontick.mcfunction を参照する。

(datapack)/data/minecraft/tags/functions/tick.json
{
  "replace": false,
  "values": [
    "timer:ontick"
  ]
}

準備

準備するスコアボードがいくつかある。
- TICK ... 1tickを計測
- SECOND ... 設定したいタイマーの時間をここにセット
- 20 ... 剰余計算のため

set_scoreboard.mcfunction
scoreboard objectives add TICK dummy
scoreboard objectives add SECOND dummy
scoreboard objectives add 20 dummy
scoreboard players set Timer TICK 0
scoreboard players set Timer SECOND 12000 (測りたい秒数)
scoreboard players set Timer 20 20

tick.json から参照する ontick.mcfunction は以下。

ontick.mcfunction
scoreboard players add Timer TICK 1
scoreboard players operation Timer TICK %= Timer 20
execute if score Timer TICK matches 0 unless score Timer SECOND matches 0 run scoreboard players remove Timer SECOND 1

機構

1tickごとに TICK の値が増加していき、
TICK が20で割り切れた時に、 SECOND の値を減少させていく。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away