From ba4906520a500232a88db1562c62ace9be5ed18b Mon Sep 17 00:00:00 2001 From: Jochen Jacobs Date: Wed, 15 Jan 2025 21:53:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20gametest=20from=2025w03a=20?= =?UTF-8?q?=20(#53)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add gametest data * Add `game_rule` attribute and style fixes * Test block and test instance block entities * Add doc comments to test_instance types * fix block entity data * add missing trailing commas * Rename --------- Co-authored-by: Misode --- java/data/gametest/mod.mcdoc | 50 +++++++++++++++++++ java/data/gametest/test_environment.mcdoc | 43 ++++++++++++++++ java/server/world/block/test_block.mcdoc | 15 ++++++ .../world/block/test_instance_block.mcdoc | 22 ++++++++ 4 files changed, 130 insertions(+) create mode 100644 java/data/gametest/mod.mcdoc create mode 100644 java/data/gametest/test_environment.mcdoc create mode 100644 java/server/world/block/test_block.mcdoc create mode 100644 java/server/world/block/test_instance_block.mcdoc diff --git a/java/data/gametest/mod.mcdoc b/java/data/gametest/mod.mcdoc new file mode 100644 index 0000000..39ddfe3 --- /dev/null +++ b/java/data/gametest/mod.mcdoc @@ -0,0 +1,50 @@ +use TestEnvironment + +dispatch minecraft:resource[test_instance] to struct TestInstance { + type: #[id="test_instance_type"] string, + ...minecraft:test_instance[[type]], +} + +dispatch minecraft:test_instance[block_based] to struct BlockBasedTestInstance { + ...TestData, +} + +dispatch minecraft:test_instance[function] to struct FunctionTestInstance { + ...TestData, + /// Test function (Java code) to run. + function: #[id="test_function"] string, +} + +struct TestData { + /// The test environment to run this test as part of. + batch: ( + #[id="test_environment"] string | + TestEnvironment | + ), + /// Structure NBT file to use for the test. + structure: #[id="structure"] string, + /// Maximum number of ticks allowed to pass before the test is considered timed out. + max_ticks: int @ 1.., + /// Ticks to wait after placing the structure before starting the test. Defaults to `0`. + setup_ticks?: int @ 0.., + /// Whether the test is considered required to pass for the full test suite to pass. Defaults to `true`. + required?: boolean, + /// Rotation to apply to the test structure. Defaults to `none`. + rotation?: Rotation, + /// If `true`, test is not included as part of automated test runs. Defaults to `false`. + manual_only?: boolean, + /// Number of attempts to run the test. Defaults to `1`. + max_attempts?: int @ 1.., + /// Number of attempts that must succeed for the test to be considered successful. Defaults to `1`. + required_successes?: int @ 1.., + /// Whether the test needs clear access to the sky. Defaults to `false`. + /// If `false`, test is enclosed in barrier blocks. If `true`, the top is left open. + sky_accesss?: boolean, +} + +enum(string) Rotation { + None = "none", + Clockwise90 = "clockwise_90", + Clockwise180 = "180", + CounterClockwise90 = "counterclockwise_90", +} diff --git a/java/data/gametest/test_environment.mcdoc b/java/data/gametest/test_environment.mcdoc new file mode 100644 index 0000000..50d5721 --- /dev/null +++ b/java/data/gametest/test_environment.mcdoc @@ -0,0 +1,43 @@ + +dispatch minecraft:resource[test_environment] to struct TestEnvironment { + type: #[id="test_environment_definition_type"] string, + ...minecraft:test_environment_definition[[type]], +} + +dispatch minecraft:test_environment_definition[all_of] to struct AllOffTestEnvironment { + definitions: [TestEnvironment], +} + +dispatch minecraft:test_environment_definition[function] to struct FunctionTestEnvironment { + setup?: #[id="function"] string, + teardown?: #[id="function"] string, +} + +dispatch minecraft:test_environment_definition[game_rules] to struct GameRulesTestEnvironment { + bool_rules: [BoolGameRule], + int_rules: [IntGameRule], +} + +struct BoolGameRule { + rule: #[game_rule(type="boolean")] string, + value: boolean, +} + +struct IntGameRule { + rule: #[game_rule(type="int")] string, + value: int, +} + +dispatch minecraft:test_environment_definition[time_of_day] to struct TimeOfDayTestEnvironment { + time: int @ 0.. +} + +dispatch minecraft:test_environment_definition[raining] to struct RainingTestEnvironment { + weather: Weather, +} + +enum(string) Weather { + Clear = "clear", + Rain = "rain", + Thunder = "thunder", +} diff --git a/java/server/world/block/test_block.mcdoc b/java/server/world/block/test_block.mcdoc new file mode 100644 index 0000000..44c189f --- /dev/null +++ b/java/server/world/block/test_block.mcdoc @@ -0,0 +1,15 @@ +dispatch minecraft:block_entity[test_block] to struct TestBlock { + ...super::BlockEntity, + mode?: TestBlockMode, + message?: string, + powered?: boolean, +} + +enum(string) TestBlockMode { + Start = "start", + Log = "log", + Fail = "fail", + Accept = "accept", +} + +dispatch minecraft:block[test_block] to minecraft:block_entity[test_block] diff --git a/java/server/world/block/test_instance_block.mcdoc b/java/server/world/block/test_instance_block.mcdoc new file mode 100644 index 0000000..190bb5f --- /dev/null +++ b/java/server/world/block/test_instance_block.mcdoc @@ -0,0 +1,22 @@ +use ::java::data::gametest::Rotation +use ::java::server::util::text::Text + +dispatch minecraft:block_entity[test_instance_block] to struct TestInstanceBlock { + ...super::BlockEntity, + data?: struct TestInstanceBlockData { + test?: #[id="test_instance"] string, + size: [int] @ 3, + rotation: Rotation, + ignore_entities: boolean, + status: TestInstanceBlockStatus, + error_message?: Text, + }, +} + +dispatch minecraft:block[test_instance_block] to minecraft:block_entity[test_instance_block] + +enum(string) TestInstanceBlockStatus { + Cleared = "cleared", + Running = "running", + Finished = "finished", +}