Skip to main content
Version: Minecraft 26.2

Game Rules, Sounds, Particles, Advancements

Game rules​

GameRuleKey<Boolean> greet = mod.content().booleanRule("golems_greet_players", true, GameRuleCategory.MOBS);
GameRuleKey<Integer> multiplier = mod.content().integerRule("spark_multiplier", 1, 1, 8, GameRuleCategory.DROPS);

int value = world.gameRule(multiplier);
world.setGameRule(multiplier, 4);
  • You can change them with /gamerule <mod>:<name>, and they are saved with the world.
  • Categories: PLAYER, MOBS, SPAWNING, DROPS, UPDATES, CHAT, MISC
  • integerRule(path, default, min, max, category)

Sounds​

SoundHandle chime = mod.content().sound("chime");
world.playSound(pos, chime.id(), 1f, 1f);
world.playSound(pos, ResourceId.minecraft("block.note_block.bell"), 1, 1);

The actual sound of a sound event is set in assets/<mod>/sounds.json.

assets/my_mod/sounds.json
{
"chime": {
"sounds": ["minecraft:random/orb"],
"subtitle": "subtitles.my_mod.chime"
}
}

Particles​

ContentHandle sparkle = mod.content().particle("sparkle", ParticleDefinition.of(16).asGlowing().withTint(0xFFD54F));
world.spawnParticles(sparkle.id(), x, y, z, 12, 0.3); // count, spread
world.spawnParticles(ResourceId.minecraft("heart"), x, y, z, 5, 0.3); // game particle
  • Declare particle types on both sides (content().particle in the common entrypoint).
  • Chain withGravity, withScale, asGlowing, and withTint onto ParticleDefinition.of(lifetimeTicks).
  • Sprites are read from assets/<mod>/particles/<path>.json and textures/particle/. With several images, the sprite changes over the particle's lifetime.
  • Create particles with spawnParticles and /particle. For game particles, you can use only simple particles that need no options.
assets/my_mod/particles/sparkle.json
{"textures": ["my_mod:sparkle_0", "my_mod:sparkle_1"]}

Advancement triggers​

AdvancementTrigger usedWand = mod.content().advancementTrigger("used_wand");
usedWand.trigger(player); // on the server

player.hasAdvancement(id);
player.grantAdvancement(id);
player.revokeAdvancement(id);
  • Put advancement files in a data pack (data/<mod>/advancement/) and write <mod>:used_wand in the criterion's "trigger".
  • The mod declares the trigger and meets the criterion with trigger(player).
  • grantAdvancement/revokeAdvancement change all criteria at once. They work only for server players.
  • In a game test, check with createMockServerPlayer().
data/my_mod/advancement/used_wand.json
{
"parent": "minecraft:story/root",
"display": {
"icon": {"id": "my_mod:spark_wand"},
"title": {"translate": "advancements.my_mod.used_wand.title"},
"description": {"translate": "advancements.my_mod.used_wand.description"}
},
"criteria": {
"used": {"trigger": "my_mod:used_wand"}
}
}
Buy me a coffee