On Chunk Generate 0.15

Place to get help with not working mods / modding interface.
lastone
Manual Inserter
Manual Inserter
Posts: 2
Joined: Sun May 08, 2016 2:24 pm
Contact:

On Chunk Generate 0.15

Post by lastone »

I've been trying to update Factorio World to work with 0.15.

It uses some math to take the world map and using on chunk generate to make the new map.... It's very much hard coded information... I'm trying to update for 0.15 and make it more generic. For example it doesn't know about the new tiles.

This is the main function that processes on chunk generated with script.on_event(defines.events.on_chunk_generated, on_chunk_generated).

Code: Select all

local function on_chunk_generated(event)
    local surface = event.surface
    local lt = event.area.left_top
    local rb = event.area.right_bottom
	local temp = nil
	
    local w = rb.x - lt.x
    local h = rb.y - lt.y
    print("Chunk generated: ", lt.x, lt.y, w, h)

    local tiles = {}
    for y = lt.y-1, rb.y do
        for x = lt.x-1, rb.x do
			temp = get_world_tile_name(x + spawn.x, y + spawn.y)
			if  temp == "nil" then
			temp = nil
		    else
            table.insert(tiles, {name=temp, position={x,y}})
			end
			--if surface.get_tile(x + spawn.x, y + spawn.y).LuaTile.valid == true then
			--    print(surface.get_tile(x + spawn.x, y + spawn.y).LuaTile.name)
			--end
        end
    end
    surface.set_tiles(tiles,true)
end
The previous modder used 12 hardcoded tiles. I wanted the auto generation to create the tiles.

Te end goal is to take the auto generated tile, if it's water and the mod map has water, do nothing. If it's water and the mod map is ground, make it ground (tile grass since that is the only thing that can be next to water). If it's ground and mod map is ground, do nothing. If it's ground and mod map is ground, make it water.

The current method that I have it to look at the modded map, if it's water, then force the on chunk generated water.

What i'm finding is that the on chunk generation...... I don't know what's there and what isn't. Surface.get_tile is not valid. How do I determine what the chunk that will be made? Will this need to be more complicated to create the same logic as the auto generated, meaning I should build the whole chunk?

Thank you,
Post Reply

Return to “Modding help”