[0.8.9][NK] Modifying Biome Data

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials
Required: ModScriptClass

Using the ModScriptClass:ModifyBiomeData it is possible to modify biome data, add objects and clusters to world generation, modify lightning, sky fog and clouds.

How does it work

Each biome class has to be registered with the engine after it is defined.
Before the biome is registered it is passed to all mods using the ModifyBiomeData event function.
This allows modifying biome data, such as Objects, Clusters, Lighting, etc...

The ModifyBiomeData event function takes 2 parameters:
  • biomeName - name of the class
  • biomeData - lua table representing the biome class
    • Objects
    • Clusters
    • Lighting
    • SkyColors
    • FogSettings
    • CloudModifiers
function ExampleMod:ModifyBiomeData(biomeName, biomeData)
end

Examples

Spawn "Example Object" in SwamplandsBiome:
function ExampleMod:ModifyBiomeData(biomeName, biomeData)
if biomeName == "SwamplandsBiome" then
biomeData.Objects["Example Object"] =
{
density = 2,
minScale = 1.0,
maxScale = 1.0,
chance = 0.02
}
end
end
Spawn "Example Object" in all biomes:
function ExampleMod:ModifyBiomeData(biomeName, biomeData)
if (biomeData and biomeData.Objects) then
biomeData.Objects["Example Object"] =
{
density = 1,
minScale = 1.0,
maxScale = 1.0,
chance = 0.01
}
end
end
Spawn "Orange Tree Cluster" ("Orange Tree" + "Orange" + "Tree Sprout" + "Fruitwood Sapling"):
function WorldGenTutorial:ModifyBiomeData(biomeName, biomeData)
if (biomeData and biomeData.Clusters) then
biomeData.Clusters["Orange Tree Cluster"] =
{
density = 2,
chance = 0.2,
Objects =
{
{
name = "Orange Tree",
offset = vec3.new(0.0, 0.0, 0.0),
minScale = 1.5,
maxScale = 1.75
},
{
name = "Orange",
offset = vec3.new(1.0, 0.0, 0.0)
},
{
name = "Tree Sprout",
offset = vec3.new(7.0, 0.0, 7.0),
minScale = 0.9,
maxScale = 1.0
},
{
name = "Fruitwood Sapling",
offset = vec3.new(7.0, 0.0, 0.0),
minScale = 0.55,
maxScale = 0.65
}
}
}
end
end
My Blog
jc.png
  yt.png  t.png  

Comments

  • RawrRawr REGISTERED, Tester Posts: 511 Seed
    edited November 2015
    I like this. :+1:
    Programmer, designer, artist.
  • CharlockCharlock REGISTERED, Tester Posts: 293 Seed
    Great information as always, Johny. If your biome mod is making changes to the "Plains" biome, will the changes you've made in your custom Lua override the standard PlainsGenerator.lua data or will it append, so that your new objects/clusters appear in addition to those already established by vanilla?

    I'm still pretty new to this level of modding, but these tutorials are a major help.
    "I’ve been drunk for about a week now, and I thought it might sober me up to sit in a library."
  • Hoppa_JoelHoppa_Joel REGISTERED Posts: 191 Seed
    I'm curious about textures on blocks/objects
    I know some methods ( and not sure if NK is doing this ) are to use a png type file, thatallows texture layering to mark off certain areas.
    If this is the case, and the texture is dull coloured or greyscale, then you should be able to control the tint and hues and contrasts and lights in a biome that would also effect to a degree what we see while in that biome from plant and tree colours.
    My main question isnt the area tinting so much, but rather in block or object creation, can a grey scaled object maintain a coloured tint easily like for example a dyed thing?

    It might be easier to give my thought process to know what I am asking;

    My thoughts is along a Biomes a Plenty type mod,
    Say for example we have the basic Spotted Leafy plant as your object we are working on.
    This and its by product Spotted leafy thatch are both greyscale.
    Biomes 1 2 3 and 4 are each using this as its plant.
    Biome 1 is deserty, so a brown and yellow is assigned to layers in the png
    Biome 2 is dark forest do dark green and a pale but glowy green is assigned to the png.
    Biome 3 is underwater, so a Sea green and blue has been assigned..
    Biome 4 UNder ground, where a glowing purple and sickly green assigned.

    Now, Is there a way, to maintain the ease of using the same greyscaled png, for each of these objects, and having it translate to the said thatch for example, in the biome colours it came from, without it defaulting to what ever biome you take it into? ( say you harvest the under-dark cavern plant, and take it into a desert biome )
    Or, will you need to individually create a png for each object?
    Multiple object use can become messy/laggy over time and as a mod compilation gets bigger and more complex, so the thoughts here, is is there a way to ease the mods load some by using a single "skin" file that can be tinted by code ( which should be doable ) but the kicker here, is can we maintain that tint on the objects places elsewhere outside the biome controlled options.

    Sort of an additional step in the objects save file on the server maybe?
    an if biome is x and object is "spotted leaf" then ( colour string ) ?
    (( My coding is horrible and I have not done any for many many years so I wont attempt anything hehe))

    But I hope this makes my question clear?

    I'd love to see options of tint on objects be possible and maintainable.
    This could go farther too, into many other things.
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    Charlock said:

    Great information as always, Johny. If your biome mod is making changes to the "Plains" biome, will the changes you've made in your custom Lua override the standard PlainsGenerator.lua data or will it append, so that your new objects/clusters appear in addition to those already established by vanilla?

    I'm still pretty new to this level of modding, but these tutorials are a major help.

    Thanks. The changes would append the PlainsGenerator.lua data, but you can add and remove Objects and Clusters this way.

    For PlainsGenerator.lua modifying biomeData.Objects is the same as modifying PlainsGenerator.Objects, but in a way that is compatible with other mods and forward compatible.
    Same for biomeData.Clusters -> PlainsGenerator.Clusters and most of the other variables/tables.

    I'm curious about textures on blocks/objects
    I know some methods ( and not sure if NK is doing this ) are to use a png type file, thatallows texture layering to mark off certain areas.
    If this is the case, and the texture is dull coloured or greyscale, then you should be able to control the tint and hues and contrasts and lights in a biome that would also effect to a degree what we see while in that biome from plant and tree colours.
    My main question isnt the area tinting so much, but rather in block or object creation, can a grey scaled object maintain a coloured tint easily like for example a dyed thing?

    It might be easier to give my thought process to know what I am asking;

    My thoughts is along a Biomes a Plenty type mod,
    Say for example we have the basic Spotted Leafy plant as your object we are working on.
    This and its by product Spotted leafy thatch are both greyscale.
    Biomes 1 2 3 and 4 are each using this as its plant.
    Biome 1 is deserty, so a brown and yellow is assigned to layers in the png
    Biome 2 is dark forest do dark green and a pale but glowy green is assigned to the png.
    Biome 3 is underwater, so a Sea green and blue has been assigned..
    Biome 4 UNder ground, where a glowing purple and sickly green assigned.

    Now, Is there a way, to maintain the ease of using the same greyscaled png, for each of these objects, and having it translate to the said thatch for example, in the biome colours it came from, without it defaulting to what ever biome you take it into? ( say you harvest the under-dark cavern plant, and take it into a desert biome )
    Or, will you need to individually create a png for each object?
    Multiple object use can become messy/laggy over time and as a mod compilation gets bigger and more complex, so the thoughts here, is is there a way to ease the mods load some by using a single "skin" file that can be tinted by code ( which should be doable ) but the kicker here, is can we maintain that tint on the objects places elsewhere outside the biome controlled options.

    Sort of an additional step in the objects save file on the server maybe?
    an if biome is x and object is "spotted leaf" then ( colour string ) ?
    (( My coding is horrible and I have not done any for many many years so I wont attempt anything hehe))

    But I hope this makes my question clear?

    I'd love to see options of tint on objects be possible and maintainable.
    This could go farther too, into many other things.

    Unfortunately we don't have color blending, so it would require multiple textures for each type.

    Texture swapping can be used to contain all of the textures within 1 object and then do the swapping using NKSetSubmeshTexture (+saving and restoring the type/texture on the object).

    Texture swapping and model swapping (StaticGraphics) tutorial is on my todo list.

    While it might be more mess, it will definitely not be more laggy or else your GPU start running out of memory. Using additional textures to do layering would require more GPU power, so it would be performance vs memory trade off (and TUG is GPU intense already).

    Simple color blending (full texture blending) shouldn't be too intense on the GPU, but layering would be really GPU intense and would also require additional memory for each layer.
    My Blog
    jc.png
      yt.png  t.png  
  • CharlockCharlock REGISTERED, Tester Posts: 293 Seed

    Charlock said:

    Great information as always, Johny. If your biome mod is making changes to the "Plains" biome, will the changes you've made in your custom Lua override the standard PlainsGenerator.lua data or will it append, so that your new objects/clusters appear in addition to those already established by vanilla?

    I'm still pretty new to this level of modding, but these tutorials are a major help.

    Thanks. The changes would append the PlainsGenerator.lua data, but you can add and remove Objects and Clusters this way.

    For PlainsGenerator.lua modifying biomeData.Objects is the same as modifying PlainsGenerator.Objects, but in a way that is compatible with other mods and forward compatible.
    Same for biomeData.Clusters -> PlainsGenerator.Clusters and most of the other variables/tables
    Perfect! That's exactly what I was looking for. This gives me something to tool around with while I'm off work for the holiday. :)
    "I’ve been drunk for about a week now, and I thought it might sober me up to sit in a library."
  • Hoppa_JoelHoppa_Joel REGISTERED Posts: 191 Seed
    oh okies, :)
  • RawrRawr REGISTERED, Tester Posts: 511 Seed
    Could we have a more detailed explanation?
    I tried to piece things together but still not sure about it. Here's what I found for flat world.

    Within Data/Generators/Generators.txt there's the following
    Generators
    {	
    	Flat World
    	{
    		Flat
    	}
    }
    Within Data/Generation/Generation_v3.txt there's the following
    Generation
    {
    	version = 2
    	Generators
    	{
    		Barren Flat
    		{
    			TerrainSettings
    			{
    				biomeSize = 0.6
    				biomeOverlap = 0.7
    			}
    			Underworld
    			{
    			}
    			Biomes
    			{
    				"Barren Flat"
    			}
    		}
    	}
    	Biomes
    	{
    		Barren Flat
    		{
    			depositSet = "Plains Deposits"
    			dayAmbiance = "PlainsAmbientDay"
    			nightAmbiance = "PlainsAmbientNight"
    			mainMaterialStrength = 0.7
    			geome = "Flat"
    			skyState = "Normal"
    		}
    	Geomes
    	{
    		Flat
    		{
    			amplitude = 0.0
    			wavelength = 0.5
    			roughness = 1
    			snowHeight = 2000.0
    			noiseFunction = "TerraNoise"
    			htDistribution = "0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0"
    		}
    	}
    	Deposit Sets
    	{
    		Plains Deposits
    		{
    			Sand
    			{
    				horizontalScaleX = 10.0
    				horizontalScaleZ = 10.0
    				verticalScale = 10.0
    				frequency = 0.8
    				perlinShift = 1989
    				minDepth = 2
    				maxDepth = 550
    			}
    			Sandstone
    			{
    				horizontalScaleX = 10.0
    				horizontalScaleZ = 10.0
    				verticalScale = 10.0
    				frequency = 0.7
    				perlinShift = 1974
    				minDepth = 2
    				maxDepth = 550
    			}
    			Gravel
    			{
    				horizontalScaleX = 8.0
    				horizontalScaleZ = 8.0
    				verticalScale = 8.0
    				frequency = 0.8
    				perlinShift = 673
    				minDepth = 2
    				maxDepth = 550
    			}
    			Clay
    			{
    				horizontalScaleX = 10.0
    				horizontalScaleZ = 10.0
    				verticalScale = 10.0
    				frequency = 0.6
    				perlinShift = 1234
    				minDepth = 2
    				maxDepth = 550
    			}
    			Sulfur
    			{
    				horizontalScaleX = 6.0
    				horizontalScaleZ = 6.0
    				verticalScale = 6.0
    				frequency = 0.5
    				perlinShift = 1098
    				minDepth = 10
    				maxDepth = 1000
    			}
    			Tin Ore
    			{
    				horizontalScaleX = 4.0
    				horizontalScaleZ = 4.0
    				verticalScale = 4.0
    				frequency = 0.5
    				perlinShift = 6452
    				minDepth = 10
    				maxDepth = 1000
    			}
    			Iron Ore
    			{
    				horizontalScaleX = 3.0
    				horizontalScaleZ = 3.0
    				verticalScale = 3.0
    				frequency = 0.4
    				perlinShift = 647
    				minDepth = 20
    				maxDepth = 3000
    			}
    			Coal
    			{
    				horizontalScaleX = 6.0
    				horizontalScaleZ = 6.0
    				verticalScale = 6.0
    				frequency = 0.8
    				perlinShift = 5156
    				minDepth = 2
    				maxDepth = 5000
    			}
    		}
    	}
    }
    - Have I mistaken Barren Flat for data that Flat World uses?

    - Why do we have generators within generation_v3 and a separate generators folder/file?

    And then I find Data/Biomes/test.biome
    Biomes
    {
    	Flat
    	{
    		script = "FlatWorld.lua"
    		weight = 6
    		minSize = 3
    		maxSize = 3
    	}
    }
    Now as for that FlatWorld.lua script:
    if FlatWorld == nil then
    	FlatWorld = EternusEngine.BiomeClass.Subclass("FlatWorld")
    end
    
    function FlatWorld:BuildTree()
    	local theWorld = self:Constant(10040)
    	return theWorld, self:Material("Green Hills")
    end
    
    FlatWorld.Lighting =
    {
    	AmbientColor = vec3.new(1.0, 0.0, 0.0),
    	Intensity = 1.0,
    	DayColor = vec3.new(1.0, 0.0, 0.0),
    	NightColor = vec3.new(1.0, 0.0, 0.0)
    }
    FlatWorld.Clusters = {}
    Eternus.ScriptManager:NKRegisterGeneratorClass(FlatWorld)
    - Have I missed anything with regards to the Flat World?

    - Are there any files/folders which are old/unused?

    - Where should I be looking next? (Scripts/Core/BiomeManager.lua doesn't look like the whole story)
    Programmer, designer, artist.
  • johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
    All of the Data/Generation/Generation_v*.txt files are deprecated and no longer used.
    The Data/Generators/generators.txt file contains the world type definitions with all of the biomes.
    The Data/Biomes/ contains definitions of the biomes (with script, size, weight and restrictions).
    My Blog
    jc.png
      yt.png  t.png  
Sign In or Register to comment.