@throw-out-error/minecraft-datapack
TypeScript icon, indicating that this package has built-in type declarations

1.6.18 • Public • Published

What is it?

minecraft-datapack is a module for making minecraft datapcks with node to cut down on repitition
npm version

Examples

Simple datapack

const { Datapack, Namespace } = require('minecraft-datapack')
const myDatapack = new Datapack('My datapack', __dirname, {
  description: 'my cool datapack!',
})
// You can use addNamespace to add a precreated namespace
let namespace = new Namespace('namespace')
myDatapack.addNamespace(namespace)
// Or you can use createNamespace to create and add a namespace
myDatapack.createNamespace('namespace2')
// And you can delete them with deleteNamespace
myDatapack.deleteNamespace('namespace2')
// Use the compile method of the datapack class to output the files
myDatapack.compile()

Adding tags

const { Datapack } = require('minecraft-datapack')
const datapack = new Datapack('ree', __dirname, { description: 'REE!' })
// Creates a block tag called minecraft:beacon_base_blocks, with the values ["minecraft:dirt"]
datapack.minecraft.createTag('beacon_base_blocks', 'block', ['minecraft:dirt'])
datapack.compile()
// Now when you load this in your minecraft world you can have beacon pyramids made from dirt! :D

Adding smelting recipes

const {
  Datapack,
  recipes: { SmeltingRecipe },
} = require('minecraft-datapack')
const datapack = new Datapack('stone', __dirname, {
  description:
    'adds a recipe to convert diorite, granite, and andesite to stone',
})
let stone_conversion = datapack.createNamespace('stone_conversion')
stone_conversion.createTag('stone_variants', 'item', [
  'minecraft:diorite',
  'minecraft:andesite',
  'minecraft:granite',
])
// Add a recipe using the namespace class's addRecipe method
stone_conversion.addRecipe(
  new SmeltingRecipe('stone_conversion', {
    // The ingredient can be a tag or an item id eg. minecraft:dirt, if using a tag it must be pre-fixed with a #
    ingredient: '#stone_conversion:stone_variants',
    result: 'minecraft:stone',
    experience: 1,
    // Select which smelting block you want to use eg. a furnace, blast furnace, smoker, or camp fire
    type: 'minecraft:blasting',
  })
)
datapack.compile()
// When loaded in your minecraft world you can put granite, diorite, and andesite in a blast furnace to get stone :D

Adding crafting recipes

const {
  Datapack,
  recipes: { ShapedCraftingRecipe },
} = require('minecraft-datapack')
const datapack = new Datapack('Slab crafting', __dirname, {
  description: "Let's you make blocks from slabs",
})
let slabs = datapack.createNamespace('slabs')
slabs.addRecipe(
  new ShapedCraftingRecipe('oak_planks_from_slabs', {
    pattern: [
      //The pattern can be 1x1 2x2 or 3x3
      '#',
      '#',
      //The key tells minecraft what to replace each character in the strings with
    ],
    key: {
      '#': 'minecraft:oak_slab',
    },
    result: 'minecraft:oak_planks',
  })
)
datapack.compile()

Adding loot tables

const {
  Datapack,
  loot: { ItemEntry, LootFunction },
} = require('../module')
const randomCount = (min, max) =>
  new LootFunction({ function: 'minecraft:set_count', count: { min, max } })
const datapack = new Datapack('Dirt', __dirname, {
  description: 'adds a dirt loot table for dirt lovers!',
})
datapack
  .createNamespace('dirt')
  // create the loot table
  .createLootTable('dirt')
  // add a pool to the table
  .createPool({
    rolls: 1,
  })
  // add an item to the pool
  .addEntry(new ItemEntry({ name: 'minecraft:dirt' }))
  .addFunction(randomCount(1, 64))
datapack.compile()
// if you run /loot give @s dirt:dirt ingame you will get 1-64 dirt

Adding functions

Create a datapack containing a mcfunction called myfunction, which kills every entity except players.

const { Datapack } = require("@throw-out-error/minecraft-datapack");
const {
  McFunction,
  Selector,
  SelectorTarget,
  kill
} = require("@throw-out-error/minecraft-mcfunction");

const datapack = new Datapack("Functions", __dirname, {
  description:
    "A cool datapack that adds a really mind blowing function, /function crazy_function:1"
});

const ns = datapack.createNamespace("crazy_function");

ns.addFunction(
  new McFunction(function myfunction() {
    const notPlayer = new Selector(SelectorTarget.entity, {
      type: {
        player: false
      }
    });

    kill(notPlayer);
  })
);

datapack.compile(".");

Dependencies (1)

Dev Dependencies (8)

Package Sidebar

Install

npm i @throw-out-error/minecraft-datapack

Weekly Downloads

0

Version

1.6.18

License

MIT

Unpacked Size

63.9 kB

Total Files

18

Last publish

Collaborators

  • bayugoon
  • brenttrenholme
  • creepinson
  • sebastianspeitel