objd_crafting 0.1.0

Crafting API #

The objd_crafting extension for objD gives you a customizable API for a Craftingtable, that works with nbt data. This documentation focuses on the CraftingTable and Recipe Widgets and generating a crafting package with objD. If you want to use template packages or the online generator, take a look at this article: https://stevertus.com/tools/objd_crafting

Installation #

To install the crafting module just include objd_crafting in the pubspec.yaml:

dependencies:
  ...
  objd_crafting:
  ...

CraftingTable #

The CraftingTable is the core widget to instantiate a custom crafter. It generates a pack(with a custom namespace) itself as well as the needed functions depending on the inputs. The Crafter is a modified chest with an armorstand inside to implement the logic.

Constructor(all optional)
nameyour custom namespace for the pack and all the scores
displayNamea TextComponent for the name that is displayed in the GUI
idthe starting id of your recipes(automatically increases)
recipesa list of your recipes
recipeSourceanother file location for a recipe function
recipeResultSourceanother file location for the result function
placeholderan Item that blocks all the slots that are not used
guiModelan Item that is retextured to display a GUI; replaces a placeholder by specifing the Slot of the Item
blockModelreplaces the head slot of the Armorstand to display a model for the block
invisibleHitboxbool whether to include code to make the chest invisible(default = true)
useBarrelset to true if you want to use a barrel instead
giveCommandFunctionbool whether to include a function to generate recipes in minecraft
maina List of Widgets that are executed every tick
onDestroya Widget that is executed when the crafting table is destroyed

After you specified all your wanted options and visuals, you get a fully working datapack. Ingame run the set function to create a new craftingtable at the current location. Obviously you can also trigger this with other packs as well. In this craftingtable you can then use your specified recipes.

Recipes #

The recipes of a craftingtable are instantiated in the recipes field. A basic recipe takes in ingredient Items with the slot and a result Item.

Recipe
Map<slot,Item>The ingredients as a Map with the Slot(1 to 9) on the one side and your Item on the other
Itemyour result Item
idoverrides the automatically generated id(optional)
exactlyPlacedbool that requires to leave all unused slots empty(default = false)
exactResulta number that limits the result count(optional)

Example:

Recipe(
          {
            1: Item(Block.oak_planks),
            2: Item(Block.oak_planks),
            4: Item(Block.oak_planks),
            5: Item(Block.oak_planks),
          },
          Item(Block.crafting_table,Count:2,nbt:{"MyNBT":1})
)

You can also set the Count variable of any of the items to generate a ratio. In this case you craft 2 craftingtables out of 4 oak_planks.

Recipe.shapeless #

The API also supports shapeless crafting. That means you can set the ingredients in any shape and it would be the same result.

Recipe.shapeless
ListThe ingredients in any shape(without slots)
...stays the same

Example:

Recipe.shapeless(
    [
       Item(Block.oak_planks),
       Item(ItemType.diamond)
    ],
    Item(ItemType.diamond_sword)
)

Recipe.fromJson #

With objD you can also import usual minecraft recipes in json data. objD automatically parses that and converts it to a command.

Recipe.fromJson
MapThe recipe in json form
...stays the same

Example:

Recipe.fromJson(
  {
	"type": "minecraft:crafting_shaped",
    "pattern": [
      "## ",
      "## ",
      "   "
    ],
    "key": {
      "#": {"item": "minecraft:oak_planks"}
    },
    "result": {
	    "item": "minecraft:crafting_table",
	    "Count": 2
	    "nbt": {
				"MyNBT":1
		}
    }
  }
)

Which would result into the same recipe as the beginning. Also note that the json is extended by the Count and nbt properties as well.

Example with shapeless crafting:

Recipe.fromJson(
{
    "type": "minecraft:crafting_shapeless",
    "ingredients": [
        {
            "item": "minecraft:oak_planks"
        },
        {
            "item": "minecraft:diamond"
        }
    ],
    "result": {
        "item": "minecraft:diamond_sword"
    }
}
)

0.1.0 #

  • initial API

example/example.dart

import 'package:objd/core.dart';
import 'package:objd_crafting/objd_crafting.dart';

main(List<String> args) {
  createProject(Project(
    name: "My Crafting Pack",
    target: "../",
    generate: BasicCraftingTable(),
  ));
}

class BasicCraftingTable extends Widget {
  BasicCraftingTable();

  @override
  Widget generate(Context context) {
    return CraftingTable(
      name: "craft",
      blockModel: Item(Block.crafting_table, count: 1),
      placeholder: Item(Block.gray_stained_glass_pane,
          count: 1, name: TextComponent("")),
      invisibleHitbox: false,
      recipes: [
        Recipe.fromJson(
          {
            "pattern": [
              "##",
              "##",
            ],
            "key": {
              "#": {"item": "minecraft:oak_planks"},
            },
            "result": {"item": "minecraft:crafting_table"},
          },
        ),
      ],
    );
  }
}

class ComplexCraftingTable extends Widget {
  ComplexCraftingTable();

  @override
  Widget generate(Context context) {
    return CraftingTable(
      name: "craft",
      blockModel: Item(ItemType.sheep_spawn_egg, count: 1, model: 3190001),
      onDestroy: Summon(EntityType.item, location: Location.rel(y: 0.7), nbt: {
        "Item": Item(ItemType.sheep_spawn_egg,
            name: TextComponent("Custom Crafting Table", italic: false),
            count: 1,
            model: 3190001,
            nbt: {
              "EntityTag": Summon(EntityType.armor_stand,
                  tags: ["craftPlacer"],
                  nbt: {"Invisible": 1, "Small": 1}).getMap()
            }).getMap(),
      }),
      main: [
        Execute.asat(Entity(tags: ["craftPlacer"]), children: [
          File.execute("set", create: false),
          Command("playsound minecraft:block.wood.place block @a ~ ~ ~"),
          Kill(Entity.Selected())
        ])
      ],
      placeholder: Item(ItemType.stone_hoe,
          model: 3190001, count: 1, hideFlags: 63, name: TextComponent("")),
      guiModel: Item(ItemType.stone_hoe,
          slot: Slot.chest(1),
          model: 3190002,
          count: 1,
          hideFlags: 63,
          name: TextComponent("")),
      recipes: [
        Recipe.fromJson(
          {
            "pattern": [
              "##",
              "##",
            ],
            "key": {
              "#": {"item": "minecraft:oak_planks"}
            },
            "result": {"item": "minecraft:crafting_table"}
          },
        )
      ],
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  objd_crafting: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:objd_crafting/objd_crafting.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
77
Overall:
Weighted score of the above. [more]
61
Learn more about scoring.

We analyzed this package on Aug 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:objd_crafting/objd_crafting.dart with components: io.

Health suggestions

Fix lib/widgets/recipe.dart. (-2.48 points)

Analysis of lib/widgets/recipe.dart reported 5 hints:

line 77 col 7: DO use curly braces for all flow control structures.

line 79 col 31: DO use curly braces for all flow control structures.

line 138 col 23: DO use curly braces for all flow control structures.

line 154 col 12: Use isNotEmpty instead of length

line 163 col 10: Use isNotEmpty instead of length

Fix lib/widgets/placeholder_setdetect.dart. (-0.50 points)

Analysis of lib/widgets/placeholder_setdetect.dart reported 1 hint:

line 23 col 11: DO use curly braces for all flow control structures.

Format lib/widgets/checkarea.dart.

Run dartfmt to format lib/widgets/checkarea.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/widgets/chestfile.dart (Run dartfmt to format lib/widgets/chestfile.dart.)
  • lib/widgets/craftingtable.dart (Run dartfmt to format lib/widgets/craftingtable.dart.)
  • lib/widgets/getcommand.dart (Run dartfmt to format lib/widgets/getcommand.dart.)
  • lib/widgets/setarmorstand.dart (Run dartfmt to format lib/widgets/setarmorstand.dart.)

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field https://www.stevertus.com/tools/crafting was unreachable.

The package description is too short. (-3 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
objd ^0.2.2 0.2.4
Transitive dependencies
async 2.3.0
collection 1.14.12
colorize 2.0.0
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
watcher 0.9.7+12