Your First Machine
Available since 0.1.0
Build an iron smelter that turns raw iron into ingots, with its own screen. Two small files, no code.
In this guide you will build an Iron Smelter: a block you place in the world, put raw iron into, and get iron ingots out of. It will have its own screen with a progress arrow, just like a furnace. You will write exactly two small files, and you will not write any code.
Before you start, make sure you followed Installation: the mod is in your mods folder and you created the foundry_apparatus folder with a machines folder and a recipes folder inside.
Create the machine
A machine is described by one file in the machines folder.
Inside foundry_apparatus/machines/, create a new text file named iron_smelter.json.
Open it in any text editor. Notepad works; VS Code is nicer because it colors the text and points at typos. Paste this:
{
"schema_version": 1,
"id": "mypack:iron_smelter",
"display_name": "Iron Smelter",
"carrier": {
"type": "single_block"
},
"storages": [
{
"id": "input",
"resource_type": "foundry_apparatus:item",
"slots": 1,
"direction": "in"
},
{
"id": "output",
"resource_type": "foundry_apparatus:item",
"slots": 1,
"direction": "out"
}
],
"gui": {
"width": 176,
"height": 166,
"widgets": [
{
"id": "input",
"type": "foundry_apparatus:item_slot",
"x": 55,
"y": 34,
"width": 18,
"height": 18,
"target_binding": "input"
},
{
"id": "progress",
"type": "foundry_apparatus:progress_bar",
"x": 79,
"y": 35,
"width": 24,
"height": 16
},
{
"id": "output",
"type": "foundry_apparatus:item_slot",
"x": 115,
"y": 34,
"width": 18,
"height": 18,
"target_binding": "output"
},
{
"id": "inventory",
"type": "foundry_apparatus:player_inventory",
"x": 7,
"y": 83,
"width": 162,
"height": 76
}
]
}
}Save the file.
That looks like a lot, but it is only three ideas. Let's go through them.
Who the machine is
"schema_version": 1,
"id": "mypack:iron_smelter",
"display_name": "Iron Smelter",
"carrier": {
"type": "single_block"
}schema_versionis the version of the file format. It is always1for now.idis the machine's unique name. The part before the:is your pack's name (any lowercase word you like), and the part after is the machine's name. Other files use this id to point at the machine.display_nameis the name players see in game.carriersays what shape the machine has.single_blockmeans one block you place in the world.
What the machine holds
"storages": [
{
"id": "input",
"resource_type": "foundry_apparatus:item",
"slots": 1,
"direction": "in"
},
{
"id": "output",
"resource_type": "foundry_apparatus:item",
"slots": 1,
"direction": "out"
}
]A machine keeps what it works with in storages. This one has two: an input with one slot for raw iron, and an output with one slot for the ingots. "direction": "in" means hoppers and pipes can only put items into it; "direction": "out" means they can only take items out of it.
What the screen looks like
The gui part describes the screen that opens when you right-click the machine: a 176 by 166 pixel window (the size of a furnace screen) with four widgets. Each widget has a position (x, y) and a size (width, height) in pixels, counted from the top-left corner of the window:
- two
item_slotwidgets, each showing one of the storages (target_bindingsays which one), - a
progress_bar, the arrow that fills up while the machine works, - the
player_inventory, so you can move items between your inventory and the machine.
If you want to play with the layout, change an x or a y later and see the slot move.
Teach it a recipe
A machine without recipes does nothing, so let's teach it one. Create a second file, foundry_apparatus/recipes/smelt_iron.json:
{
"schema_version": 1,
"id": "mypack:smelt_iron",
"type": "foundry_apparatus:machine_recipe",
"machines": [
"mypack:iron_smelter"
],
"duration": 100,
"inputs": [
{
"type": "item",
"id": "minecraft:raw_iron",
"amount": 1
}
],
"outputs": [
{
"type": "item",
"id": "minecraft:iron_ingot",
"amount": 1
}
]
}In plain words: in the Iron Smelter, 1 raw iron becomes 1 iron ingot after 100 ticks. Minecraft runs 20 ticks per second, so this takes 5 seconds.
Notice that machines uses the same id you gave the machine, mypack:iron_smelter. That is how the recipe knows which machine it belongs to.
Try it in game
Start Minecraft (or restart it, if it was open). A new machine needs a restart; when you only change recipes later, typing /reload in game is enough.
Open a creative world and find the Iron Smelter in the Foundry Apparatus creative tab.
Place it and right-click it. Put raw iron in the left slot and watch the arrow fill. The ingot appears in the right slot.
Try putting dirt in the input slot: the machine refuses it, because none of its recipes use dirt. Hoppers get the same treatment, so junk can never clog the machine. Hoppers above and below work too: one feeds raw iron in, the other pulls ingots out.
Something not working? Don't worry: when the game loads your files, Foundry Apparatus writes every problem to the game log (logs/latest.log in your instance folder), and after a /reload it also sends a summary to operators in chat. Each problem has a code like FA-SCH-004. Look it up in Error Codes: every code has a page that tells you why it happened and how to fix it.
Next steps
You just built a machine with two storages, a screen and a recipe. Next, read The Pack Folder to learn where everything goes and when /reload is enough. Then The Basics covers each part in depth, starting with Machines.