Skip to content

Commit

Permalink
✨ Add gametest from 25w03a (#53)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
jacobsjo and misode authored Jan 15, 2025
1 parent 3acd599 commit ba49065
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
50 changes: 50 additions & 0 deletions java/data/gametest/mod.mcdoc
Original file line number Diff line number Diff line change
@@ -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",
}
43 changes: 43 additions & 0 deletions java/data/gametest/test_environment.mcdoc
Original file line number Diff line number Diff line change
@@ -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",
}
15 changes: 15 additions & 0 deletions java/server/world/block/test_block.mcdoc
Original file line number Diff line number Diff line change
@@ -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]
22 changes: 22 additions & 0 deletions java/server/world/block/test_instance_block.mcdoc
Original file line number Diff line number Diff line change
@@ -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",
}

0 comments on commit ba49065

Please sign in to comment.