This package contains code generators made with source_gen. With annotations Widgets, Files, Packs and Projects can be written much more consisely.


Include the package along with build_runner in your pubspec.yaml as a dev dependency:

  objd_gen: ^0.0.1

The generators put the new dart classes and functions in a new file alongside your annotated file. To make it available include it with the part statement:

import 'package:objd/core.dart';

part '[your_filename].g.dart';

After writing all your Widgets,this package generates the associated classes and functions with:

pub run build_runner build

Or if you want it to generate automatically after saving run:

pub run build_runner watch


Writing a Widget becomes much simpler with the @Wdg annotation. You can just give it a function with needed parameters which returns a new Widget and the generators will figure out a Widget class to go along with it.

One simple case would be:

Widget helloWorld() => Log('Hello World!');

After running build_runner a new Widget HelloWorld is generated(inherited from the function name), so it is advisable to use lowercase functions.

Parameters also work like you exspect and you even get access to the widget context if you need to:

Widget helloName(String name, {String lastname = '', Context context}) => For.of([
  Comment('This was generated by HelloName on version ${context.version}'),
  Log('Hello $name $lastname!'),

This would translate to a Widget in the following way, which you can use everywhere in your projects from now on:

class HelloName extends Widget {
  final String name;
  final String lastname;

    this.name, {
    this.lastname = '',

  Widget generate(Context context) => helloName(
        lastname: lastname,
        context: context,


Writing Minecrafts functions this style also becomes really easy. Just annotate a Widget variable that should be inside of your function with @Func():

final Widget load = HelloWorld();

This again would read the variable name load and generate a new variable called LoadFile, which includes the File Widget:

final File LoadFile = File(
  child: load,

Inside the parentheses of @Func() you can also provide various parameters to customize the file generation:

nameProvide a custom filename different from the variable name
pathGive a custom path for your function
executewhether to execute your File(when included somewhere in the widget tree)
createwhether to actually create the file or not


  name: 'main',
  path: 'folder',
  execute: false,
  create: true,
final Widget main_widget = Comment('main file');


The @Pck() annotation works similar to @Func. You annotate a File List variable and it generates a Widget for this Pack.

namenamespace of this pack
mainpath of the main function
loadpath of the load function

If you decide to not provide a namespace it again chooses your variable name.


@Pck(name: 'namespace', main: 'main', load: 'load')
final List<File> myPack = [

This generates this widget:

class NamespacePack extends Widget {
  Widget generate(Context context) => Pack(
        name: 'namespace',
        files: myPack,
        load: File('load', create: false),
        main: File('main', create: false),


And the last piece of creating a datapack is a @Prj. This can automatically generate a main function with all necessary pieces to actually generate all packs and files.

nameName of the datapack
versiontargeted minecraft version(as integer)
targetdirectory to generate the datapack in
descriptiona description for the pack.mcdata
genMainset this to false if you dont want a main function generated(will be generate_varname instead)

Once again we must annotate a Widget variable, that is the root of our widget tree:

  name: 'My awesome Datapack',
  target: './datapacks/',
  version: 17,
  description: 'A simple dp for demonstrating annotations',
final myProject = NamespacePack();

This generates the following in the g.dart:

void main([List<String> args = const []]) => createProject(
        name: 'My awesome Datapack',
        target: './datapacks/',
        version: 17,
        description: 'A simple dp for demonstrating annotations',
        generate: myProject,

Full example

And thats it, you can now make an entire datapack in one objD file just with some functions and variables. Of course you can extend this principle to as many dart files as you like and make your datapack as complex and modular as you like.

You can see the full example here.

I hope these code generators help with making datapacks using objD. In case you encounter any problems or have any idea or feedback, feel free to reach out via Discord or Email.