This is a Tutorial that explains step by step how to add a new Decoration Building to Foundation.

Introduction

First we will take a look at the Tools we are going to use in this Tutorial:

Also there are some important links that i will refer to in the next Steps:

  • FoundationAPI – Here you can find all puplic information about modding for Foundation.
  • Foundation Discord Channel – Here is where most Parts of the Modding Community are active and lots of Question have already been asked there.
  • Blender Documentation – Here you find all information regarding 3D moddeling with Blender

Also we are going to use my Mod Decorative Pond as an example to go trough the Steps. You can download it here.

Now that we got everything we need we can start with the Tutorial.

1. Creating a new 3D Asset

We start off with creating the 3D model in Blender, but you can technically use any 3D Editor that can export to .fbx file format. If you are not familiar with 3D moddeling you can visit the Blender Documentation to learn how to moddel with Blender.

1.1. Apply Scale, Rotation and Location

After you are done with the creation of your 3d Model you have to apply Scale, Rotation and Location of the single parts of the model.

First we select all parts of the Model

Once we selected all parts we press the keyboard combination Ctrl+ A to apply the transformations we did in Blender. A dialog pops up: Select Location

Then on the bottom left you can choose what transform values you want to apply. Select all.

1.2. Create Game Specific Objects

Next we have to create a couple of Objects in our 3D Models that are related to the Game.

In the Create Tab on the top left click Empty 2 times.

We have now created 2 empty objects that are used to tell the Game how to handle the parts of our model.

The first empty object is for our finished Building (in Foundation this part is called “Prefab”). This means you can name the first empty object whatever you want for example the Building Name. In this example we will call it “Pond“.

The second empty object we created tells the Game in which steps the Construction is build. This object defines what parts of our model should be shown when getting constructed. We will talk more about it soon, but for now we will just name it “Construction_Steps”.

1.3. Set correct Hierarchy

We have created and named the Game specific Objects already, now its time to put the parts of our model in correct hierarchy.

First we drag all parts of our 3D model onto the Pond object. Then we put all Parts of our building that show the construction into Construction_Steps object. The
hierarchy should now look like in the pictur above.

Next we take care of our Construction_Steps object. Bevore we move on in Blender let us take a closer look at construction steps:

  • Construction Steps define how the single steps during the construction of a building look
  • The Construction Steps are only visible during the construction phase of the building
  • All Objects in construction_Steps object that contain step_0 in their name are shown when the building is placed
  • All Objects in construction_Steps should contain step_ and a number
  • The number behind step_ defines when the part is shown
  • Construction Steps are optional and no must have

If you want more information about the construction steps you can also look at the API.

From what we have learned now about construction steps we know that all the parts that should show the construction progress need to be droped into Construction_Steps object and named with step_ and the number.

1.4. Textures and Materials

The next step we have to do in our 3D model creation is to take care of our textures and prepare them for the Game.

First i highly recommend you to do propper UV mapping for your model parts. If you dont know what UV mapping is you can read the basics here.

After you have mapped your 3D model parts you need to do some additional steps to make the Game register your textures:

1. Click on the materials tab

2. Press the minus to clear all materials

3. Add a new a Material by clicking the plus

1. Click the textures tab

2. Press the Plus to add new texture

3. Here you should see a Texture assigned now

Now click open and select the same texture you assigned as UV map

Its very important to do this step since the Game will not render/recognize your textures until you asign them as texture to the material.

1.5 Export

We are almost done now with the creation of our 3D asset. The last thing we have to take care of the propper export settings.

If you are using Blender pre version 2.8 you need to set your render engine to Blender Render.

First we go to File > Export> FBX

A dialog appears in the bottom left side. The options that are marked red in the picture are important for correct export settings.

I recommend you to use the Blender Units because they are the same as the ingame Units (1m) so you dont need to touch the scale option but incase your model doesnt have the desired size you can play with the scale option until the model has the correct size ingame. Also you might have to change the Forward and Up Axis if the model is not flipped correct ingame.

2. Localization and File structure

Ok so we are done with the creation of our assets and the next thing we have to take care of is the organization all the files of our mod.

2.1. File structure

So first we are going to create all folders that we need for our mod:

Create a new folder in “YourFoundationInstallation\mods\” and name it like your mod name. In our example we name it “DecorationalPond“.

Create 2 more folders inside the DecorationalPond(or whatever your mods name is) folder. The first one is named “models“ and should hold all the 3D files. The second one is named “localization” and holds all the files for ingame names and descriptions in different languages.

Create another folder inside localization and name it “en“. The name stands for english but you could also use “fr” for example for french.

Next you need to put all your exportet .fbx files and the textures you assigned into the models folder.

2.2. Localization

We have now everything setup to begin with the coding part of the Tutorial. Its time to start Visual Studio Code now:

Go to File -> OpenFolder
Then navigate to your mods folder and select “open folder”.

On the left side you should now see the folder hierarchy we created. Select the en folder.

1. Click on the New File Icon

2. A new file gets created in the en folder. Name it “text.json“.

Now the file opens in the editor and we have to give it some content:

{
	"BUILDINGS": {
		"POND01_NAME": "Pond"
	},

In this first part we define the name of our building.

	"BUILDING_DESCRIPTIONS": {
		"POND01_DESC": "Decorative Pond"
	}
}

Second we define a descrition for the Building.

The final code should look like this now:

{
	"BUILDINGS": {
		"POND01_NAME": "Pond"
	},
	"BUILDING_DESCRIPTIONS": {
		"POND01_DESC": "Decorative Pond"
	}
}

3. Register the Asset

Now that we also have set the description and the name of our building we have to tell the Game what type of building we want to add to it.

3.1. Settings for Mod

First we will tell the game some general information about our mod:

Deselect the en folder and press the New File button again. Name the file “mod.lua“. The file should be in the root directory of your mod folder.

Now its time again to put some code in the file:

local DecoPonds = foundation.createMod({
	Name = "Decorative Ponds",
	Author = "www.simon-says.me",
	Description = "Decorating Ponds"
});

First we create our mod as a variable wich we call “DecoPonds” in this tutorial.

Then we set the Name, Author and Description of our Mod in line 2-4.

DecoPonds:registerAssetId("models/pond01.fbx/Prefab/Pond", "PREFAB_POND")
DecoPonds:registerAssetId("models/pond01.fbx/Prefab/Construction_Steps", "PREFAB_POND_CONSTRUCTION")

Next we tell the Game where in our mods folder the fbx model for our building we want to create is. We also give the model an ID (“PREFAB_POND“) so we can refer to it later.

(Optional)Afterwards we also tell the Game where it can find the Construction Steps in our fbx model and also give it a unique ID (“PREFAB_POND_CONSTRUCTION“).

DecoPonds:dofile("buildings.lua")

As last step we register another lua script that we call “buildings.lua“. We will create the file in the next step and use it to define our building in Game.

The final Code should look like this:

local DecoPonds = foundation.createMod({
	Name = "Decorative Ponds",
	Author = "www.simon-says.me",
	Description = "Decorating Ponds"
});

DecoPonds:registerAssetId("models/pond01.fbx/Prefab/Pond", "PREFAB_POND")
DecoPonds:registerAssetId("models/pond01.fbx/Prefab/Construction_Steps", "PREFAB_POND_CONSTRUCTION")

DecoPonds:dofile("buildings.lua")

3.2 Set up Building

Now we can take care of the building we want to create. We will do the coding for the building in another script so we have a better overview of our code but you could also do all the code in one file.

Click on the New File Icon again (make sure you are in the root directory) and name it “buildings.lua“.

local DecoPonds = ...

In the first line we make sure that we receive our variable from our “mod.lua” so we can also work with it here.

DecoPonds:register({

	DataType = "BUILDING",

	Id = "POND01",

	Name = "POND01_NAME",

	Description = "POND01_DESC",

	BuildingType = "DECORATION",

	BuildingPartList = { "POND_PART" },

})

In the first line we register a new asset to the game.

Then we tell the Game in line 3 what type of asset we want to register.

In line 5 we give our asset a new unique ID.

In line 7 and 9 we set the name and the description of our building by calling them from our localization file we created earlier.

In line 11 we tell the Game what kind of building we want to register. Available types: “GENERAL”, “MONUMENT”, “DECORATION”, “HOUSING”

In foundation a building has different building parts. In line 13 we register the building parts for our building. In our case thats just one.

Next we need to register the building part because as we learned above a building in foundation is an assembly of building parts. You can read everything about building parts in the API.
I will not explain lines 1-7 since we talked about them allready above.

DecoPonds:register({

	DataType = "BUILDING_PART",

	Id = "POND_PART",
	Description = "POND_PART_DESC",

	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_POND"
	},

	BuildingZone = { 8, 8},
	ConstructionVisual = "PREFAB_POND_CONSTRUCTION",
	Cost = {
		UpkeepCost = {
			{ Resource = "GOLD", Quantity = 1 }
		},
		RessourcesNeeded = {
			{ Resource = "WATER", Quantity = 50 },
			{ Resource = "STONE", Quantity = 25 }
		}
	}
})

In line 8-11 we tell the game how our finished building looks like by refering to our “PREFAB_POND” that we defined earlier in our “mod.lua“.

In line 13 we define the size of our building (for example for tree removement). You can set it to the dimensions of your model if you kept the blender unit scale. If not you will propably have to try different values until it matches your building.

(Optional) In line 14 we refer to the construction steps we defined in “mod.lua“. If you dont have construction steps just remove this line.

From line 15 on we define the costs of the building in game. There are upkeep costs and needed resources to build. You can see the list of all available resources here.

The final Code should look like this:

local DecoPonds = ...

DecoPonds:register({

	DataType = "BUILDING",

	Id = "POND01",

	Name = "POND01_NAME",

	Description = "POND01_DESC",

	BuildingType = "DECORATION",

	BuildingPartList = { "POND_PART" },

})

DecoPonds:register({

	DataType = "BUILDING_PART",

	Id = "POND_PART",
	Description = "POND_PART_DESC",

	ConstructorData = {
		DataType = "BUILDING_CONSTRUCTOR_DEFAULT",
		CoreObjectPrefab = "PREFAB_POND"
	},

	BuildingZone = { 8, 8},
	ConstructionVisual = "PREFAB_POND_CONSTRUCTION",
	Cost = {
		UpkeepCost = {
			{ Resource = "GOLD", Quantity = 1 }
		},
		RessourcesNeeded = {
			{ Resource = "WATER", Quantity = 50 },
			{ Resource = "STONE", Quantity = 25 }
		}
	}
})

Ok now we are basically done with the mod you can use the mode now ingame if you want to share it continue reading the last step.

4. Publishing your Mod and final Words

If you want to share your mod you need to put all the files in your mod folder (not the actual folder though) in a new Zip archive and upload it to mod.io.

I hope the tutorial helped you to understand how to make a new building mod for the Game Foundation. If you like the tutorial or have some ideas how to make it better leave a Comment below or use the Contact Form to get in touch with me.

3 thoughts on “Tutorial: Add Building to Foundation”

  1. TheEtherealMonkey says:

    Thanks for the good tutorial! Finally I understand how it works with the construction steps…

    1. admin says:

      I’m glad that it helped 🙂

  2. Paul Hubert says:

    Hello,

    I follow you tutorial, (thanks for it!) and I have a small question : I want to create a foundry to create glass from stone, with the transporter JOB (Ok, it’s does not make sense but it’s only to try the API ^^). That’s the first step, after I will try to create a JOB and eventually a “SAND” material.

    I have created the object and I can use it “in-game”, the villagers can built it, but it does not display the “Add a villager” list, to manage the villages. I think I fucked up someting with the “BuildingFunction” attribute, I guess I should write something like this :

    BuildingFunction = {
    DataType = “BUILDING_FUNCTION_WORKPLACE”,
    WorkerCapacity = 3,
    RelatedJob = { Job = “TRANSPORTER”, Behavior = “PRODUCE_RESOURCE_IN_EXCHANGE_FOR” },
    InputInventoryCapacity = {
    { Resource = “GLASS”, Quantity = 10 }
    },
    ResourceListNeeded = {
    { Resource = “STONE”, Quantity = 1 }
    },
    ResourceProduced = {
    { Resource = “GLASS”, Quantity = 1 }
    }
    }

    Do you have some advice ?

Leave a Reply

Your email address will not be published. Required fields are marked *