Modding:Content Tutorial Simple Worldgen

From Vintage Story Wiki
This page contains changes which are not marked for translation.

This page was last verified for Vintage Story version 1.19.7.


Introduction

In progress! Please come back soon.

Objective

Much of Vintage Story's world generation is modifiable and extendable through JSON. In this tutorial, you will be shown two simple ways of adding to the world generation: blockpatches and deposits. You will also learn how to modify these methods to increase or decrease the commodity of them spawning.

Assets

Before starting, it is recommended you download the workspace and assets for this tutorial. The completed files can also be found here.

This tutorial starts with the following assets:

  • Mod Setup & Folder Structure
  • Incomplete 'loosesticks' blockpatches file
  • Incomplete 'sand' deposits file

Prerequisites

This tutorial will assume you understand the following topics:

It is recommended to understand the following concept:

Navigating Assets

This tutorial only contains world generation assets. You will be adding in new world generation rules that use existing game content. Take a look at the following files:

  • assets/worldgen/blockpatches/loosesticks.json
  • assets/worldgen/deposits/sand.json

Block Patches

Block patches refer to a type of world generation where new blocks are added into a world - essentially replacing empty air blocks. In the base game, block patches are used for berry bushes, tall grass, mushrooms, underground gears, and a lot more. Files that define blockpatches must be created in the blockpatches folder.

Loose Sticks

To begin with, you will be creating a JSON file that will generate a number of loose sticks on the surface. Open worldgen/blockpatches/loosesticks.json and you should see the following partially-made script:

[
	{
		"comment": "Small groups of loose sticks everywhere",
		
	}
]

As you can see, there exists a single property. This comment property has no functionality, it is merely a way of describing what the generator achieves.

Block patches all follow a very similar two-part structure. First you define what you want to generate, including the block code and the quantity, and then you define the rules of it spawning, including things such as temperature, height, fertility, as well as the 'chance' of it spawning in a chunk.

So, firstly you need to define what to generate. Using the blockCodes property, you can define an array of all the potential block types. When the generation process happens, one of these blocks will be picked randomly. In this case, just add the block code for loose sticks underneath the comment property.

"blockCodes": [ "game:loosestick-free" ],

Next, define a quantity. This is a NatFloat (natural float) type - A specific type of random number generator that uses an average and a variable amount.

"quantity": {
	"avg": 4,
	"var": 2
},

NatFloats can be considerably more complex - However in this example it will return a value between (avg - var) and (avg + var). In effect, this will pick a random number between 2 and 6, and generate that number of sticks in a localized group.

After you have defined what to spawn and how many of them to spawn in a single group, you can add a number of optional criteria for the block spawning.

The following properties will limit loose sticks from spawning in some areas:

"minTemp": -2,
"minForest": 0,

There are many more optional criteria that can be used. These include:

  • MinTemp and MaxTemp
  • MinRain and MaxRain
  • MinForest and MaxForest
  • MinShrub and MaxShrub (for how much shrubbery and bushes are in the current area)
  • MinFertility and MaxFertility
  • MinY and MaxY (for elevation, as a 0-1 decimal relative to the map height. A Y of 0 is the very bottom of the world, a Y of 1 is the world height, and a Y of around 0.43 is sea-level)

After adding in the optional criteria, you need to add in a chance property:

"chance": 3

This value effects how the chance of this rule spawning per chunk. The chance can be a decimal value. For example, a chance of 0.5 means there is a 50% chance per chunk that the blockpatch will be generated. A chance of 3 means that there will be 3 instances of this generating per chunk.

If you run the game with your mod, you will be able to see sticks generating most places in the surface. If you want to increase the spawn rate, increase the value of the chance property.

loosesticks.json
[
	{
		"comment": "Single loose sticks everywhere",
		"blockCodes": [ "game:loosestick-free" ],
		"minTemp": -2,
		"minForest": 0,
		"quantity": {
			"avg": 4,
			"var": 2
		},
		"chance": 3
	}
]

Underground Bones

There's more to be done with blockpatches. Create a new file in the blockpatches folder called "bones.json" and fill it with this code:

[
	{
		"comment": "Lots of bones and carcasses underground",
		
	}
]

This file will be very similar to the previous one - Add in the following for the blockcodes, the quantity, and the chance.

"blockCodes": [ "game:bonyremains-cowskull-up", "game:bonyremains-ribcage", "game:drycarcass-humanoid1", "game:drycarcass-humanoid2", "game:drycarcass-tiny", "game:drycarcass-small", "game:drycarcass-medium", "game:drycarcass-large" ],
"quantity": {
	"avg": 1,
	"var": 0
},
"chance": 120,

So this will add in a random carcass or bony remains. Using a quantity average of 1 with a var of 0 means this will always spawn a single carcass. There exists some further criteria for blockpatches. An additional placement property will allow you to define a more specific criteria on where the worldgen will place things.

"placement": "Underground"

This particular value will allow the blocks to be placed underground. Since there is now a much larger area to work with, the chance property for this entry is considerably higher. The following values can be used for placement:

  • ReplaceSurface
  • OnSurface (Default)
  • NearWater
  • Anywhere
  • Underground
  • UnderWater
  • NearSeaWater
  • UnderSeaWater
  • UnderTrees
  • OnTrees
  • OnSurfacePlusUnderTrees

When this is specified, you can test the mod. You should begin seeing carcasses and other bones spawning underground.

bones.json
[
	{
		"comment": "Lots of bones and carcasses underground",
		"blockCodes": [ "game:bonyremains-cowskull-up", "game:bonyremains-ribcage", "game:drycarcass-humanoid1", "game:drycarcass-humanoid2", "game:drycarcass-tiny", "game:drycarcass-small", "game:drycarcass-medium", "game:drycarcass-large" ],
		"quantity": {
			"avg": 1,
			"var": 0
		},
		"chance": 120,
		"placement": "Underground"
	}
]

Deposits

Deposits are a little more complicated than blockpatches. This type of world generation is used to replace certain blocks with other blocks. Blocks such as ores, clay/peat, and cracked stone all spawn using a deposit generation. Deposits must be defined in the deposits folder in worldgen. Open the tutorial file at worldgen/deposits/sand.json and you'll see this code sample:

[
  {
    "code": "sand",
    
  }
]

Conclusion

Congratulations, you have created a load of new recipes without using the crafting grid! You should know how to create barrel, clayforming, knapping, and smithing recipes now, as well as understanding how variants can be used within all types of recipes.

Next Steps...

If you want to test your knowledge, consider doing the tasks under the Going Further section below.

With the knowledge in the completed tutorials, you should be well on your way to knowing how to create detailed and in-depth content mods! From here on, tutorials may start getting more specific. When you're ready, consider moving on to 9. Simple World Generation.

Going Further

Not much here this time! Perhaps try to design and make your own new recipes.


Content Modding
Basics Content Mods Developing a Content Mod
Tutorials
Concepts Modding Concepts Variants Domains Patching Remapping World Properties
Uncategorized
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository