Page 1 of 1
[0.11.13] onchunkgenerated replacing water with sand bug
Posted: Mon Jan 26, 2015 2:49 am
by kosievdmerwe
When replacing water and deepwater with sand in the onchunkgenerated event (restricted to only the chunk given) I encounter the following:
A few things to notice:
- There are strips of grass in the sand fields (presumably on the chunk borders)
- These strips aren't straight
- Somehow trees and ores are spawning on these strips
The code:
http://pastebin.com/itSJefVs
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Mon Jan 26, 2015 4:24 am
by Xecutor
I experienced something similar in Straight World mod. I think there is some kind of postprocessing that fixes borders/transition between different terrain types.
I think that terrain changing mods need API that delays this postprocessing.
i.e. ability to make multiple changes in an atomic fashion.
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Mon Jan 26, 2015 5:23 pm
by kovarex
I believe that this is not a bug.
All you have to do is to change add also the neighbour tiles of the water tiles to the list of the tiles you want to convert.
I saw some other bug that was replacing water and all terrain by some kind of mars terrain, and it worked just fine.
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Tue Jan 27, 2015 6:41 am
by kosievdmerwe
kovarex wrote:I believe that this is not a bug.
All you have to do is to change add also the neighbour tiles of the water tiles to the list of the tiles you want to convert.
I'm not entirely sure what you mean by "add the neighbour tiles". Add them as themselves or add them if they are water tiles as well. I've tried adding them as themselves and that didn't work and adding neighbouring water tiles would be a flood fill, which would likely be too slow.
One of the issues with this is that I'm running the code on the onchunkgenerated event so I could feasibly end up with a situation where the neighbouring chunk isn't generated yet and therefore I can't look at and replace the tiles (though I stand to be corrected as you might very well be generating neighbouring chunks without processing their onchunkgenerated event). When I change the code to look at and replace water and sand tiles 2 tiles past the border of the chunk I get the same thing. However, the grid pattern is offset from the chunk grid (and the offset is dependent on the direction of exploration).
I think that unless I replace the whole body of water with sand in one go (which I've mentioned is likely unfeasible) I will end up with "edges" in the middle of the sand. Knowing nothing about your code here is my suspicion of what is happening: I replace a block of water with sand, some sand on the edges are now bordering with water, so their textures are replaced with a water-edge images (which is half-grass, half-sand in this case). When I replace the water in the adjacent block with sand, the sand bordering the first block are now adjacent to these edge blocks and hence are also replaced with half-grass, half-sand blocks (so they match up).
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Tue Jan 27, 2015 9:39 am
by kovarex
When the onchunkgenerated call is done, all the neighbour chunks have already finished tiles.
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Wed Jan 28, 2015 6:59 am
by kosievdmerwe
kovarex wrote:When the onchunkgenerated call is done, all the neighbour chunks have already finished tiles.
That's good to know
I tried adding all tiles in adjacent chunks to the set of tiles to be updated, but still no cigar: I still see the lines of grass.
Code: Select all
idx = 1
local newtiles = {}
for x=x1-32,x2+32,1 do
for y=y1-32,y2+32,1 do
if x < x1 or x > x2 or y < y1 or y > y2 then
name = game.gettile(x, y).name
newtiles[idx] = {name = name, position = {x, y}}
idx = idx + 1
elseif (x < -hsize or x > hsize) or (y < -hsize or y > hsize) then
name = game.gettile(x, y).name
if name == "water" or name == "deepwater"then
newtiles[idx] = {name = "sand", position = {x, y}}
idx = idx + 1
end
end
end
end
game.settiles(newtiles)
Either way, this is not terribly important to me to fix as I can work around it by using grass instead of sand (or alternatively just ignoring it) and 0.11.14 will fix the bug that made me have to do this. That said I'm curious how that other mod managed this.
Interestingly, the following code leads to the trees and ores generating normally (the above code only generates them on the lines of grass). There are still lines of grass on the sand, however. EDIT: I've simplified the code.
Code: Select all
idx = 1
local newtiles = {}
for x=x1-32,x2+32,1 do
for y=y1-32,y2+32,1 do
if (x < -hsize or x > hsize) or (y < -hsize or y > hsize) then
name = game.gettile(x, y).name
if name == "water" or name == "deepwater"then
newtiles[idx] = {name = "sand", position = {x, y}}
idx = idx + 1
end
end
end
end
game.settiles(newtiles)
Re: [0.11.13] onchunkgenerated replacing water with sand bug
Posted: Wed Jan 28, 2015 11:21 am
by rk84
Ignoring graphics for moment. There is no half tiles. A grass tile is automaticly placed between sand and water, because thats how it is defined in prototypes. Deep-water allows only water as neighbor. Water allow only grass as neighbor.
I can think 2 options for you.
1. Edit graphics and/or layer indexes of tiles and remove tiling limitations. Mayby easiest is to give some transparency to green areas of "water-side", "water-inner-corner" and "water-outer-corner" -images and then remove allowed_neighbors from water?
2. Add more code to change grass to sand if between sand water. Possibly allow it to "invade" couple of tiles into grass area?