diff options
Diffstat (limited to 'mapwidget.go')
-rw-r--r-- | mapwidget.go | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/mapwidget.go b/mapwidget.go index 3592e42..0727038 100644 --- a/mapwidget.go +++ b/mapwidget.go @@ -478,6 +478,52 @@ func (mw *MapWidget) GetBiomeAt(x, z int) (mcmap.Biome, bool) { return chunk.Biome(bx, bz), true } +func fixFreeze(bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) { + for y := chunk.Height(bx, bz); y >= 0; y-- { + if blk := chunk.Block(bx, y, bz); blk.ID != mcmap.BlkAir { + if (blk.ID == mcmap.BlkStationaryWater) || (blk.ID == mcmap.BlkWater) { + blk.ID = mcmap.BlkIce + newcol = blockColors[mcmap.BlkIce] + } else if blockCanSnowIn[blk.ID] { + if yFix := y + 1; yFix < mcmap.ChunkSizeY { + blkFix := chunk.Block(bx, yFix, bz) + blkFix.ID = mcmap.BlkSnow + blkFix.Data = 0x0 + newcol = blockColors[mcmap.BlkSnow] + } + } + + break + } + } + + return +} + +func fixMelt(bx, bz int, chunk *mcmap.Chunk) (newcol *gdk.Color) { + for y := chunk.Height(bx, bz); y >= 0; y-- { + if blk := chunk.Block(bx, y, bz); blk.ID != mcmap.BlkAir { + if blk.ID == mcmap.BlkIce { + blk.ID = mcmap.BlkStationaryWater + blk.Data = 0x0 + newcol = blockColors[mcmap.BlkStationaryWater] + } else if blk.ID == mcmap.BlkSnow { + blk.ID = mcmap.BlkAir + for y2 := y - 1; y2 >= 0; y2-- { + if col, ok := blockColors[chunk.Block(bx, y2, bz).ID]; ok { + newcol = col + break + } + } + } + + break + } + } + + return +} + func (mw *MapWidget) SetBiomeAt(x, z int, bio mcmap.Biome) { cx, cz, bx, bz := mcmap.BlockToChunk(x, z) pos := XZPos{cx, cz} @@ -496,38 +542,10 @@ func (mw *MapWidget) SetBiomeAt(x, z int, bio mcmap.Biome) { var newcol *gdk.Color if mw.fixSnowIce { - for y := chunk.Height(bx, bz); y >= 0; y-- { - if blk := chunk.Block(bx, y, bz); blk.ID != mcmap.BlkAir { - if coldBiome[bio] { - if (blk.ID == mcmap.BlkStationaryWater) || (blk.ID == mcmap.BlkWater) { - blk.ID = mcmap.BlkIce - newcol = blockColors[mcmap.BlkIce] - } else if blockCanSnowIn[blk.ID] { - if yFix := y + 1; yFix < mcmap.ChunkSizeY { - blkFix := chunk.Block(bx, yFix, bz) - blkFix.ID = mcmap.BlkSnow - blkFix.Data = 0x0 - newcol = blockColors[mcmap.BlkSnow] - } - } - } else { - if blk.ID == mcmap.BlkIce { - blk.ID = mcmap.BlkStationaryWater - blk.Data = 0x0 - newcol = blockColors[mcmap.BlkStationaryWater] - } else if blk.ID == mcmap.BlkSnow { - blk.ID = mcmap.BlkAir - for y2 := y - 1; y2 >= 0; y2-- { - if col, ok := blockColors[chunk.Block(bx, y2, bz).ID]; ok { - newcol = col - break - } - } - } - } - - break - } + if coldBiome[bio] { + newcol = fixFreeze(bx, bz, chunk) + } else { + newcol = fixMelt(bx, bz, chunk) } } |