Jump to content

Recommended Posts

Hello FuffledBeeQueen,
Don't be lazy - search for it at this forum before starting new theread :) theres a lot of them with usefull info, for example one, second, third

Recently I've created my first mod using third link, specially this comment because my goal was to create Set Piece in certain Biome.


In case of my mod I created Set Piece map (map is description for Set Piece - what it should contain, if you want to create one item you can still use map for only 1 prefab and define it in layout = {..}), it looked like this:
\scripts\map\layouts\dyp_lucky_pond_set.lua

Spoiler

--this layout describes 'Lucky Pond' Set Piece

require("constants")
local StaticLayout = require("map/static_layout")
return {
            type = LAYOUT.STATIC,
            args = nil,
            defs = {},
            ground_types = {GROUND.GRASS},
            ground = {
                    {0, 1, 1, 1, 0},
                    {1, 1, 1, 1, 1},
                    {1, 1, 1, 1, 1},
                    {1, 1, 1, 1, 1},
                    {0, 1, 1, 1, 0},
                    },
            --desctibe object which ones Set Piece should contain        
            layout = {
                    --pass Prefab name itself and coordinates where it sould be
                    pigtorch = {
                                     {x=-3, y=-3}, {x=3, y=-3},
                                     {x=-5, y=0}, {x=5, y=0},
                                     {x=-3, y=3}, {x=3, y=3},
                                     --{x=0,y=-5}, {x=0,y=5},
                                },
                    dyp_lucky_pond = {
                                    {x=0, y=0}
                                    },
                    },            
            scale = 0.4
}            

and you should create modworldgenmain.lua in root of your mod and use your map in it, in my case it looked like this:
\modworldgenmain.lua

Spoiler

--this modwordgenmain create Set Piece 'Lucky Pond'

local Layouts = GLOBAL.require("map/layouts").Layouts
Layouts["dyp_lucky_pond_set"] = GLOBAL.require("map/layouts/dyp_lucky_pond_set")

--announce rooms where pond can be spawned
local rooms_for_pond = {"MagicalDeciduous", "DeepDeciduous"}

local count = 0

--we want only one Lucky Pond to be spawned at whole world 
local function OrSpawn()
        if count == 0 then
            count = 1
            --return spawn
            return 1
        else
            --return not spawn
            return 0
        end    
    end
    
for i, v in ipairs(rooms_for_pond) do
    AddRoomPreInit(v, function(room)
        if room.contents.countstaticlayouts == nil then
            room.contents.countstaticlayouts = {}
        end
        room.contents.countstaticlayouts["dyp_lucky_pond_set"] = function() return OrSpawn() end
    end)
end

Your modworldgenmain will be applied before your mod will set up while world is generating.
I hope my code looks straight-forward, if not - ask any questions, and I'll try to help.

Edited by zyxerdima
spelling

If you want to add something to worldgen like grass, meaning something that will be in one entire biome, here and here, rather than a set piece (ensemble of things that will spawn in one place), i suggest you to use this code :

 

This add, instead of "replacing" stuff to worldgen and ensure a good compatibility between mods.

Hope it could help.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...