Skip to main content
Version: Minecraft 26.2

Example mods

The examples/ folder in the Poly Mod Loader source holds five Poly Mod examples. All of them are verified in the real game. The Poly Mod Loader source is private for now, so this page describes what each example shows; the code the docs need is on the Native API pages.

To start a new mod, download the mod template, not an example. See Get the mod template.

At a glance​

PathMod IDWhat it shows
examples/crystal-gardencrystal_gardenThe finished result of the Create your first Poly Mod tutorial. A growing block, stored data, commands and permissions, a join check, client drawing, game tests
examples/minimal-native-modminimal_native_modThe smallest Poly Mod. An entrypoint, server events, a shutdown task
examples/custom-system-modcustom_system_modSystem replacement (poly:game_brand)
examples/transform-demo-modtransform_demo_modCode transforms, call-site changes, ordering declarations, and access widening declared in poly.mod.json
examples/native-showcase-modnative_showcaseEvery Native API area, with in-game tests

crystal-garden​

This is the mod you build in the tutorial. Unlike the other examples, it is a standalone project built the same way as a mod author would build it (the mod plugin dev.polymodloader.mod). A crystal sprout grows in 4 stages, and using a fully grown sprout gives you a crystal.

FileContent
CrystalGardenModCommon entrypoint. Item and block declarations, entity data key, permission node, join check
CrystalSproutThe stage block state, shape and brightness per state, a block entity that grows every tick, harvesting (writes entity data and world storage)
GardenCommands/garden stats, /garden grow <pos> (permission crystal_garden:grow)
CrystalGardenClientJoin check reply, growth display above a sprout, harvest count HUD, key binding toggle_hud (default G)
GardenTests4 in-game tests

minimal-native-mod​

The smallest Poly Mod. It adds no game content such as blocks or items. It only logs that the entrypoint ran.

FileContent
poly.mod.json"minecraft": ["26.*"], common and client entrypoints, the poly dependency
MinimalNativeModCommon entrypoint. A greeting log, a shutdown task (onShutdown), ServerEvents.STARTED and STOPPING listeners
MinimalNativeModClientClient entrypoint. Only logs that it was called

custom-system-mod​

It replaces the poly:game_brand system so the brand that Minecraft reports becomes poly/example. It references no Minecraft classes.

FileContent
poly.mod.jsonNo entrypoints. Declares the provider in replacesSystems and requests the permission system.provider.replace
ExampleBrandProviderThe poly:game_brand provider

The client log shows [Poly Mod Loader] poly:game_brand reported 'poly/example' to Minecraft (CLIENT). How to declare this is in the poly.mod.json schema.

transform-demo-mod​

It changes Minecraft classes with transforms and accessWidenings in poly.mod.json. The first rule works from the declaration alone, with no Java code. The second rule uses a small hook class, TickHooks.

| Rule | Target | Action | What it does | |---|---|---| | transform_demo_mod:storage_format_name | LevelStorageSource.getName()Ljava/lang/String; | replace_returned_string_constant | Changes the display storage format name "Anvil" to "Anvil (Poly Mod Loader transform demo)" | | transform_demo_mod:tick_start_nanos | MinecraftServer.tickServer(Ljava/util/function/BooleanSupplier;)V | redirect_call, after: ["poly:server_tick_events"] | Replaces the first Util.getNanos() call with TickHooks.tickStartNanos(). It targets the same method as Poly Mod Loader's built-in start hook, so it declares an order | | Access widening | MinecraftServer.tickCount:I | accessible | Makes a private field public |

  • The failure policies are disable_rule and skip, so if the target changes, only that entry is turned off.
  • The permissions are internal.bytecode.transform, internal.callsite.intercept, and internal.member.access.
  • minecraft is ["26.2"]. It depends on game code of a specific version, so it names the exact version.

The log shows the following. From the second run on, the transform cache is used and from cache is added.

  • Transformed net/minecraft/world/level/storage/LevelStorageSource with [transform_demo_mod:storage_format_name]
  • Transformed net/minecraft/server/MinecraftServer with [poly:server_brand, poly:server_tick_events, transform_demo_mod:tick_start_nanos, poly:server_stopping_event, poly:worldgen_features, access widening by transform_demo_mod]
  • [transform_demo_mod] tickServer start time comes from the mod hook; MinecraftServer.tickCount is public: true

native-showcase-mod​

This example uses every area of the Native API in one mod. Poly Mod Loader uses it as the reference mod when it verifies the Native API in the real game. Its poly.mod.json has "minecraft": ["26.*"].

Classes​

ClassAreaContent
NativeShowcaseModCommon entrypointThe glowing block glow_block (brightness 12, needs the right tool, gives spark when used), the item spark, the food star_fruit, commands, a network channel, a join-preparation exchange, events, world storage, the config file showcase.properties, the mod creative tab showcase, and calls to declarations in other classes
MachineContentBlock state and block entitiesmachine, which faces the player, toggles powered when used, and counts ticks while on; and crate, a 27-slot inventory
AdvancedContentAdvanced contentlamp with a color property and per-state brightness, grinder with a menu layout and a progress bar, spark_wand using the item data component charge, the projectile spark_bolt, and the advancement trigger used_wand
CreatureContentMobs and gameplayThe mob golem_friend with a spawn egg, natural spawning, and riding; the status effect glowing_heart; the game rules golems_greet_players and spark_multiplier; the sound chime; damage and death events
SeekGlowBlockGoalAI goalWalks toward a glow_block within 6 blocks
VisualContentMob modelThe flying mob wisp with a box model and keyframe animation, and the particle sparkle
MovementContentShape and movementThe half-height block stone_step, the swimming mob minnow, and related game tests
WorldContentWorld generationThe biome glow_meadow, a terraced terrain generator used by the native_showcase:terraces dimension, and chunk load watching
CodeWorldgenContentCode world generationThe placed feature boulder, the density function waves of the native_showcase:waves dimension, the structure shrine, and related game tests
InteractionContentEvent priorities and interaction eventswarded_block, which protects itself and what stands on it with BlockEvents.BREAK (high priority), PLACE, PLACED, and the InteractionEvents, and 6 game tests that show each event cancels its action while the uncanceled action still works
LifecycleContentLifecycle eventsServer and overworld lifecycle log lines, a respawn counter in entity data copied by PlayerEvents.COPY, RESPAWNED, EntityEvents.JOINED_WORLD, and 2 game tests with a connected mock player
TagContentTags#native_showcase:warded (drives the warded block's protection), #native_showcase:sparkly, the warded block added to #minecraft:mineable/pickaxe, and 2 game tests
OperationsContentData, sync, and operationsA data reload listener, the entity data visits and golem_mood (including version migration), the versioned world storage world_info synced with the client, the permission nodes place and secret with a permission provider, and a join check
NativeShowcaseClientClient entrypointKey binding, HUD layer, shader pipelines glow and pulse (texture and mod uniforms), the world drawing compass, grinder block entity drawing (a lamp model per state), the dynamic texture noise, a screen, camera view, the post-processing sepia, client events, and the "Sparkly" tooltip line for items in #native_showcase:sparkly
ShowcaseScreenMod screenA greeting text, a name input field, a close button
ShowcaseGameTestsIn-game testsContent, world, entity, command, data, and permission tests

Resources are in src/main/resources/assets/native_showcase/ (block states, models, textures, names, shaders, post-processing) and src/main/resources/data/ (loot tables, recipes, tags, the dimensions pocket, terraces and waves, advancements, damage types, world generation data).

Commands, keys, and channels​

KindNameBehavior
Command/showcase infoTells you whether the block is registered
Command/showcase add <a> <b>Returns the sum of two integers as the command result
Command/showcase place <pos>Places a glow_block at that position. Needs the permission node place (default level 2)
Key bindingshow_info (default K)Shows Native Showcase: key binding works in the action bar
Payload channelnative_showcase:greetingsOn join, the server sends a welcome greeting and the client replies with thanks
Join-preparation exchangenative_showcase:handshakeBefore the player enters the world, the server asks for the client's showcase version. It rejects the connection if there is no reply or the reply does not start with showcase

Testing in the game​

Run the showcase's 52 in-game tests inside a world with /test runmultiple native_showcase:*. To write and run tests for your own mod, see In-game tests.

Buy me a coffee