Skip to content
DetectiveSmith edited this page Mar 8, 2015 · 25 revisions

MiniatureCraft API Documentation

Here, you can find the full documentation for the game's multiple APIs. Don't be afraid to poke around!

API Documentation

Making Our First Mod (Incomplete Tutorial)

Assuming you've checked out the above APIs, and are familiar with their functions, you can begin to create your first mod!

Adding in Assets.

Now, we're going to create a table. You can name it anything. I'll name mine "myAssets".

myAssets = {}

Simple. Now, we want to create a new asset, so we need to give it an ID. Generally, IDs that are above 500 are free, so lets use 501.

myAssets = {
  [501] = {}
}

The index of the table is the ID. The ID should always be a number. Now, lets put in some basic info. The table should have a string called "name", which is the name of our asset.

myAssets = {
  [501] = {name = "MyBlock"}
}

Now, of course you'll need more data than just a name. We can define a health. If our block is unbreakable, put unbreakable = true instead of any health variables. Assuming our block is breakable, lets put:

myAssets = {
  [501] = {name = "MyBlock", health = 10}
}

For reference, look at this: Wood Tools: 1-3 Damage Stone Tools: 2-4 Damage Iron Tools: 3-5 Damage Gold Tools: 4-6 Damage Gem Tools: 5-7 Damage

Our block is as strong as wood. Lets move on. We need our block to have a texture, so we define a texture table. Looks something like this.

texture = {backgroundColor OR none, foregroundColor, foregroundCharacter}

Lets make our asset look like bricks.

myAssets = {
  [501] = {name = "MyBlock", health = 10, texture = {colors.red, colors.white, "#"}}
}

We also need to tell the game what kind of asset this is. This is achieved by giving it a string called type. In our case, this is a block, so it will be type = "block".

myAssets = {
  [501] = {name = "MyBlock", health = 10, type = "block", texture = {colors.red, colors.white, "#"}}
}

We also want the game to drop the block when broken. Lets give it a drop table. The table goes in this format: drop = {id, amount, id, amount, id, ...}

So, we want to have the game drop 2 bricks every time one is broken. Lets add in the appropriate code.

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", texture = {colors.red, colors.white, "#"}}
}

Our brick is a special brick. We want it to only be broken by an axe. We give it a string called toolNeeded. The string "toolNeeded" should correspond to the "type" of the tool. The main tool types are "sword," "pickaxe," "axe," "shovel," and "hoe." Don't worry though, we can define our own tool types as well.

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", toolNeeded = "axe", texture = {colors.red, colors.white, "#"}}
}

Now, all of a sudden, you want your brick to flash red and blue. Simple. The texture table accepts as many textures as you like, given there's enough to form a new animation. Your texture table should always add up to a multiple of 3 (3, 6, 9, 12, etc).

Here's how we do it for our situation:

texture = {colors.red, colors.white, "#", colors.blue, colors.white, "#"}

Simple right? We just add in the extra animation part to the end of the table like shown before. Lets put it all together.

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", toolNeeded = "axe", texture = {colors.red, colors.white, "#", colors.blue, colors.white, "#"}}
}

Awesome! You finished making your first asset. Now we need the game to load it. We do this by using the function File.addMod(). This function takes a table. Lets see what it accepts.

File.addMod({_string _Name, _string _Author, _string _Info, _table _Assets}) The Assets table is the only one of these arguments that are required. Lets fill in the arguments to suit our needs.

File.addMod({"My Mod", "Tutorial", "This is an example mod.", myAssets})

Great! Now lets put it all together. Our file should look like:

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", toolNeeded = "axe", texture = {colors.red, colors.white, "#", colors.blue, colors.white, "#"}}
}

File.addMod({"My Mod", "Tutorial", "This is an example mod.", myAssets})

After you've done this, drop the file into your Mods folder, and run the game. You've just created your first mod!

Now, you didn't set the recipe for it. The only way to see it is by going into creative mode, or by spawning one in (Do /help in game to see a list of commands, they're similar to the minecraft ones).

Adding in Recipes.

Alright, you've checked out your awesome asset. Now, you want to make it craftable. This is rather easy to do. We'll be using the function Crafting.setRecipe(ID, Output, outputAmount, Input)

The "ID" (Number) is the asset ID of the crafting table we'll be referring to. We want to make our brick at a furnace, so we'll be using the ID 14.

The "Output" (Number) is the asset ID of what the player will get after using the required materials. In this case, we'll use the ID 501, the ID of our block.

The "outputAmount" (Number) is how many of "Output" we'll get. Lets say we want to get 5 bricks back.

The "Input" is a table. It's formatted in the same way our drop table is. In case you forgot, it's {ID, amount, ID, amount, ID, ...}. Lets say we want to create our bricks by using one stone and one wood. The IDs of stone and wood are one and two respectively. Lets also say it'll take three of each in order to make said bricks. The input table would look like {1, 3, 2, 3}.

All together now, our function should look like Crafting.setRecipe(14, 501, 5, {1, 3, 2, 3})

After that, slap that function right at the end of your previous mod. Make a furnace and, surprise surprise, you can create your magical bricks now!

This is what your code should look like at this point.

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", toolNeeded = "axe", texture = {colors.red, colors.white, "#", colors.blue, colors.white, "#"}}
}

File.addMod({"My Mod", "Tutorial", "This is an example mod.", myAssets})
Crafting.setRecipe(14, 501, 5, {1, 3, 2, 3})

Adding in your own crafting table.

Before I begin, please note that the term "crafting table" in the way I use it refers to any asset that is used for crafting or creating new blocks and items, not that actual thing.

Now, it's awesome making our bricks at a furnace. It's even more awesome to make it at our own magical furnace. First, we'll need to create a new asset. Using what we've learned from earlier, we can do this easily.

[502] = {name = "Magical Furnace", health = 4, drop = {502, 1}, type = "block", toolNeeded = "pickaxe", texture = {colors.orange, colors.red, "U", colors.yellow, colors.orange, "U", colors.red, colors.yellow, "U"}}

Now that we've made our asset, we need to use a function called Crafting.setCraftingTable(ID, Name, X, Y, Width, Height)

The "ID" (Number) refers to the asset that will act as a crafting table. In this case, we'll use our magical furnace, and the ID 502.

The "Name" (String) refers to the little name that shows up on the top left corner of the menu when we interact with our crafting table. The name doesn't have to be the same name as the asset we're using for the crafting table. For now, lets name it "M. Furnace" (Magical Furnace).

As far as the "X," "Y," "Width," and "Height" go, we'll be using variables already chosen for us, it being 2, 4, 18, 14. This is because these four arguments are more than likely going to be removed, with the said variables being hard coded in.

Lets look at our completed function.

Crafting.setCraftingTable(502, "M. Furnace", 2, 4, 18, 14)

Great! Now, our crafting table won't be any good if we can't even make it. Using earlier knowledge, lets set a recipe to make one of these when we use four stone at a Crafting Table (The actual in-game one).

Crafting.setRecipe(14, 502, 1, {1, 4})

Lets also change our earlier brick recipe so it can be created at our Magical Furnace.

Crafting.setRecipe(502, 501, 5, {1, 3, 2, 3})

And, for the final product:

myAssets = {
  [501] = {name = "MyBlock", health = 10, drop = {501, 2}, type = "block", toolNeeded = "axe", texture = {colors.red, colors.white, "#", colors.blue, colors.white, "#"}},
  [502] = {name = "Magical Furnace", health = 4, drop = {502, 1}, type = "block", toolNeeded = "pickaxe", texture = {colors.orange, colors.red, "U", colors.yellow, colors.orange, "U", colors.red, colors.yellow, "U"}}
}

File.addMod({"My Mod", "Tutorial", "This is an example mod.", myAssets})

Crafting.setCraftingTable(502, "M. Furnace", 2, 4, 18, 14)
Crafting.setRecipe(14, 502, 1, {1, 4})
Crafting.setRecipe(502, 501, 5, {1, 3, 2, 3})

Awesome! Your on your way of making a great mod.

Adding our own world generation code.

Creating an interface.

Interfaces are usually used for putting in your own menu, but they can also be used to interact with a block. You can make chests, doors and a lot of other interactive blocks.

Creating an interface is pretty simple.To start off, lets create a block and make a recipe for it:

myAssets = {
  [500] = {name = "Interface Block",health = 10,drop = {500, 1}, type = "block", toolNeeded = "axe", texture = {none, colors.red, "I", none, colors.white, "I"}}
}

Crafting.setRecipe(13, 500, 1, {68, 1})

Do not forget to add your mod to the game:

myAssets = {
  [500] = {name = "Interface Block", health = 10,drop = {500, 1}, type = "block", toolNeeded = "axe", texture = {none, colors.red, "I", none, colors.white, "I"}}
}

File.addMod({name = "My Mod", author = "Tutorial", info = "This is an example mod.", assets = myAssets})

Crafting.setRecipe(13, 500, 1, {68, 1})

Right now, our block doesn't have any interface tied to it. To give it one, we'll use the function 'Menu.newInterface()'. It takes 2 arguments: The interface's name and a function. Lets add that to our code:

-- Interfaces are given two arguments: the first one is a table of events, the second is the name of the player who is using the interface.
function myInterfaceFunc(eventData, player)
end

-- This will create a new interface. The name is used when referring to the interface to grab it's function.
Menu.newInterface("MyInterfaceName", myInterfaceFunc)

-- Using our earlier asset, we're going to put in something called "interface". Here, you'll put in the name of the interface you wish to use. In our case, we'll do 'interface = "MyInterfaceName".'
myAssets = {
  [500] = {name = "Interface Block", health = 10, interface = "MyInterfaceName", drop = {500, 1}, type = "block", toolNeeded = "axe", texture = {none, colors.red, "I", none, colors.white, "I"}} 
}

File.addMod({name = "My Mod", author = "Tutorial", info = "This is an example mod.", assets = myAssets})

Crafting.setRecipe(13, 500, 1, {68, 1})

Right now, the interface does nothing. You can do whatever you want in the interface's function. To close it you have to add return true somewhere in your function. Here is an example:

function myInterfaceFunc(eventData, player)
  if eventData[1] == "key" then -- The only events an interface can get currently are: Any mouse events, "char" events, and "key" events. This particular line is checking for a "key" event.
    if eventData[2] == 60 then -- This will check if the key pressed is F2.
      return true -- This will close the interface.
    end
  end
end

Menu.newInterface("MyInterfaceName", myInterfaceFunc)

myAssets = {
  [500] = {name = "Interface Block", health = 10, interface = "MyInterfaceName", drop = {500, 1}, type = "block", toolNeeded = "axe", texture = {none, colors.red, "I", none, colors.white, "I"}} 
}

File.addMod({name = "My Mod", author = "Tutorial", info = "This is an example mod.", assets = myAssets})

Crafting.setRecipe(13, 500, 1, {68, 1})

There you go! Check out this if you want some more examples on interfaces found in game.

Adding a lua script to our asset.

This tutorial will cover world generation code, interfaces, and more. For now, refer to here for the different types of assets and what they do. I look forward to your future mod!