This week's snapshot comes with a huge update to game tests! The game tests system is now accessible through data packs with the new test command. You can now run block based tests with the new test block or set up even more versatile test from code in mods.
Happy testing!
net.minecraft.gametest.Main
is present in the server jarThis new entry point automatically starts a server, runs all available game test and then exists.
Options:
--help
- Shows usage information--packs <path>
- Set a folder of datapacks to include in the worldpack.mcmeta
file is included--report <path>
- Exports results in a junit-like XML report at the given path--tests <selection>
- Specify which tests to run with a selection - a wildcard expression matching namespace test instance IDs--universe <path>
- The path to where the test server world will be createdgametestserver
--verify <boolean>
- Enables test verificationtest
or testNamespace
100 times for each 90 degree rotation stepfalse
Example usage: java -DbundlerMainClass="net.minecraft.gametest.Main" -jar server.jar --packs mytestpacks
saddle
equipment slot, driven by the equippable
component - Only mobs that normally support saddles will support riding and rendering of the saddle - Items in the saddle
slot can apply attribute modifiers as with other equipmentThe Game Tests system is a new integrated system for testing aspects of the game. Each test is an asset defining some parameters for how the test gets executed, combined with a saved structure file containing a base setup.
Generally, the test framework expects to run tests in a separate superflat world.
Test instances are defined in the registry test_instance
. They're small assets defining a test to run.
Fields:
environment
: Namespaced ID of the test environment to run this test as part ofstructure
: The namespaced ID of the structure to use for the testmax_ticks
: A positive integer representing the maximum number of ticks allowed to pass before the test is considered timed outsetup_ticks
: Optional non-negative integer (default: 0
) representing a number of ticks to wait after placing the structure before starting the testrequired
: Optional boolean (default true
) - whether the test is considered required to pass for the full test suite to passrotation
: Optional rotation to apply to the test structurenone
(default), clockwise_90
, 180
and counterclockwise_90
manual_only
: Optional boolean (default false
), set to true
for tests that are not included as part of automated test runssky_access
: Whether the test needs clear access to the skyfalse
), tests are enclosed in barrier blocks - if set to true
, the top is left openmax_attempts
: Number of attempts to run the test (default 1
)required_successes
: Number of attempts that must succeed for the test to be considered successful (default 1
)type
: The type of test - one of block_based
and function
Function tests rely on built-in functions to run a test and indicate success or failure. They have one additional field:
function
: The namespaced ID of the Test Function to runSee the "Using the Game Test Framework from Code" changelog section for more information.
Block based tests use Test Blocks in the test structure to run the test and indicate success or failure.
Test Environments are a way to group up tests and give them the right preconditions to run. A Test Environment is an asset in the test_environment
registry. Each Test Environment definition has a type
field that determines its setup:
all_of
definitions apply the setup from several sub-definitions in the definitions
fieldfunction
definitions use mcfunction files as setup and teardownsetup
: Optional namespaced ID of the mcfunction to use for setup, if anyteardown
: Optional namespaced ID of the mcfunction to use for teardown, if anygame_rules
: definitions set any number of game rulesbool_rules
: A list of boolean game rules to set and the value to setint_rules
: A list of integer game rules to set and the value to setrule
: The exact name of the rule to setvalue
: The value to setweather
definitions sets the weather stateweather
: The weather to set - one of clear
, rain
and thunder
time_of_day
definitions set a given time of daytime
: The time of day to set in number of ticks, as a non-negative integerThe game provides a single, empty Test Environment by default: minecraft:default
.
The Test Block is a block used for implementing a block-based tests. It has four modes:
start
: Triggers a redstone pulse when the test startslog
: Logs a message to the log file when powered by redstonefail
: Fails the test when powered by redstoneaccept
: Completes the test when powered by redstoneBlock-based tests are required to have at least one start
block and one accept
block in the structure.
test
CommandThe test
command is a new command used to create and run tests.
Syntax:
test clearall [<radius>]
test clearthat
test clearthese
test create <test> [<width>] [<height> <depth>]
test locate <selector>
test resetclosest
test reseetthese
test resetthat
test pos [<variable>]
test run <selector> [<numberOfTimes>] [<untilFailed>] [<rotationSteps>] [<testsPerRow>]
test runclosest [<numberOfTimes>] [<untilFailed>]
test runfailed [<numberOfTimes>] [<untilFailed>] [<rotationSteps>] [<testsPerRow>]
test runmultiple <selector> [<amount>]
test runthat [<numberOfTimes>] [<untilFailed>]
test runthese [<numberOfTimes>] [<untilFailed>]
test stop
test verify <tests>
Parameters:
radius
: The radius to clear tests withintest
: The namespaced ID of a testselector
: A wildcard-enabled selector for test IDs*
and ?
for matching namespaced IDsminecraft
*:*
- matches all IDs*
- matches everything in the minecraft
namespacecustom:folder/*_test_?
- matches IDs in the folder
folder of the custom
namespace, with a prefix followed by _test_
followed by a single valid characterwidth
: The width of the test structure - if omitted, 5
is usedheight
: The height of the test structure - if omitted, the width is useddepth
: The depth of the test structure - if omitted, the width is usedvariable
: The variable name to include in the copied code snippetnumberOfTimes
: The number of times to repeat each test - if omitted, 1
is ueduntilFailed
: Boolean (default false
) noting that the test should be stopped as soon as one iteration failsrotationSteps
: Number of extra 90 degree steps to apply to the test - if omitted, 0
is usedtestsPerRow
: Number of tests to place per row in a grid layout - if omitted, 8
is usedThese subcommands clear the structures and blocks associated with the selected tests.
This subcommand creates a test setup in the current location for the given test, preparing for a structure of the given size. This gives a starting point for creating the structure for the test.
Attempts to locate the given test. Note that only loaded chunks are searched.
These subcommands reset the structures for the selected tests, removing any surrounding barriers and placing the structure in from scatch.
Shows the local coordinates to the block pointed at in the test. If the optional variable name is specified, this variable name is used in a code fragment obtained by clicking on the coordinates in the output message.
Runs one or more tests. If multiple tests are run at once, they are placed in a grid and run in parallel, although only up to a certain limit. Beyond that limit, tests are run in rounds where each round completes before any tests from the next round are started.
For each test, loads the given structure and runs the associated test. Each test location will have a beacon beam showcasing the test status.
If a test fails, the error is shown on a lectern book and an overlay.
Note that Game Tests are designed to run on standard superflat worlds. The area around each test is replaced with stone when it runs, and the running test is encased in barrier blocks.
This stops all running tests. Note that gameplay events triggered by tests may still remain.
Verifies one or more tests by running multiple instances of the same test.
To run a test in a world, a Test Instance Block is used. This type of block represents the test as placed in the world and is used to interact with that test, to save the structure, reset or run the test.
Using the test
command to run or create a test will also place a Test Instance Block to control that test.
The Game Test Framework can also be used from code in a more versatile manner than block-based tests. For this to work, you need to mod the game to add your test functions to the test_function
registry (Registries.TEST_FUNCTION
).
Hook into some startup method (pre-registry bootstrap) to add your loader - call TestFunctionLoader.registerLoader()
with an implementation of TestFunctionLoader
. Your implementation can then use the provided register
consumer to register test functions with their namespaced IDs. This namespaced ID can then be referenced in a function
type Test Instance.
A test function is a Consumer<GameTestHelper>
, using that GameTestHelper
instance to manipulate the world and make assertions about the state of the resulting world.
The helper can be used to summon mobs, set blocks, query for blocks and entities and assert the state of the test. Most GameTestHelper
methods take test-local coordinates, which you can also find using /test pos
.
Example code that might go along with a test structure with a locked hopper containing a cod, pointed into a furnace:
public void furnace_smelts_item(final GameTestHelper helper) {
helper.setBlock(0, 4, 0, Blocks.AIR);
helper.succeedWhen(() -> helper.assertContainerContainsSingle(new BlockPos(0, 0, 0), Items.COOKED_COD));
}
More complicated setups will often use helper.startSequence()
to model sequences of events that must happen.
As opposed to block-based tests, function tests failing will often produce more helpful error messages including the location of whatever failed and what was expected at that location.
horse.saddle
item slot has been renamed to saddle
, and now supports any entity that can equip a Saddleshow_text
action:text
field has been renamed to value
#can_equip_saddle
- entities that can be equipped with a SaddleArmorItems
, HandItems
, and body_armor_item
fields have been merged into an equipment
fieldhead
, chest
, legs
, feet
, mainhand
, offhand
, body
, saddle
equipment:{chest:{id:'minecraft:diamond_chestplate'}}
equipment.saddle
field)SaddleItem
in Horse-like mobsSaddle
flag from Pigs and Stridersdrop_chances
field, as with other equipment slotsFallDistance
field has been changed from float to double and is now called fall_distance
damage_per_attack
field was renamed to item_damage_per_attack
saddle
slotbody
slot as long as the component allows it (allowed_entities
)equip_on_interaction
(boolean)true
, players can equip this item onto a target mob by right-clicking it (as long as this item can be equipped on the target at all)false
minecraft:painting
, minecraft:item_frame
), they will be applied to new entityvillager/variant
- one of desert
, jungle
, plains
, savanna
, snow
, swamp
, taiga
wolf/variant
- namespaced id from wolf_variant
registrywolf/collar
- one of 16 dye colorsfox/variant
- one of red
, snow
salmon/size
- one of small
, medium
, large
parrot/variant
- one of red_blue
, blue
, green
, yellow_blue
, gray
tropical_fish/pattern
- one of kob
, sunstreak
, snooper
, dasher
, brinely
, spotty
, flopper
, stripey
, glitter
, blockfish
, betty
, clayfish
tropical_fish/base_color
- one of 16 dye colorstropical_fish/pattern_color
- one of 16 dye colorsmooshroom/variant
- one of red
, brown
rabbit/variant
- one of brown
, white
, black
, white_splotched
, gold
, salt
, evil
pig/variant
- namespaced id from pig_variant
registryfrog/variant
- namespaced id from frog_variant
registryhorse/variant
- one of white
, creamy
, chestnut
, brown
, black
, gray
, dark_brown
painting/variant
- namespaced id from painting_variant
registryllama/variant
- one of creamy
, white
, brown
, gray
axolotl/variant
- one of lucy
, wild
, gold
, cyan
, blue
cat/variant
- namespaced id from cat_variant
registrycat/collar
- one of 16 dye colorssheep/color
- one of 16 dye colorsshulker/color
- one of 16 dye colorsminecraft:entity_data
componentminecraft:bucket_entity_data
and minecraft:entity_data
components
components
on item predicate that works on item stacks)components
predicate and variant entity components:minecraft:axolotl
minecraft:fox
minecraft:mooshroom
minecraft:rabbit
minecraft:horse
minecraft:llama
minecraft:villager
minecraft:parrot
minecraft:salmon
minecraft:tropical_fish
minecraft:painting
minecraft:cat
minecraft:frog
minecraft:wolf
minecraft:pig
color
has been removed from minecraft:sheep
sub-predicatepig_saddle
texturepig_saddle
- equipment layer for Pig saddlesstrider_saddle
- equipment layer for Strider saddlescamel_saddle
- equipment layer for Camel saddleshorse_saddle
- equipment layer for Horse saddlesdonkey_saddle
- equipment layer for Donkey saddlesmule_saddle
- equipment layer for Mule saddlesskeleton_horse_saddle
- equipment layer for Skeleton Horse saddleszombie_horse_saddle
- equipment layer for Zombie Horse saddlesentity/pig/pig_saddle.png
-> entity/equipment/pig_saddle/saddle.png
entity/strider/strider_saddle.png
-> entity/equipment/strider_saddle/saddle.png
entity/camel/camel.png
-> entity/equipment/camel_saddle/saddle.png
entity/horse/horse_<variant>.png
-> entity/equipment/horse_saddle/saddle.png
entity/horse/donkey.png
-> entity/equipment/donkey_saddle/saddle.png
entity/horse/mule.png
-> entity/equipment/mule_saddle/saddle.png
entity/horse/horse_skeleton.png
-> entity/equipment/skeleton_horse_saddle/saddle.png
entity/horse/horse_zombie.png
-> entity/equipment/zombie_horse_saddle/saddle.png
minecraft:component
Select Property
select
item model: component
component
- namespaced ID of component typecomponent
is set to minecraft:wolf/collar
, list of cases will accept dye colors, like lime