Fix water coast against non-blend tiles and soft cross-chunk borders.
Skip foam/shore toward non-blendable floors (and unloaded neighbors), and rebake soft-terrain/wet-sand neighbor chunks when a chunk loads so atlas blends meet across seams.
@@ -16,7 +16,7 @@ import
16
16
} from "/shared/render/tint.js";
17
17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";
18
18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";
19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";
20
20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";
21
21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";
22
22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";
@@ -3758,15 +3758,18 @@ export class WorldView
3758
3758
#waterCoastEdges (tileX, tileY)
3759
3759
{
3760
3760
const season = this.worldSeason;
3761
const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);
3762
const n = liquid(tileX, tileY - 1);
3763
const e = liquid(tileX + 1, tileY);
3764
const s = liquid(tileX, tileY + 1);
3765
const w = liquid(tileX - 1, tileY);
3766
const ne = liquid(tileX + 1, tileY - 1);
3767
const nw = liquid(tileX - 1, tileY - 1);
3768
const se = liquid(tileX + 1, tileY + 1);
3769
const sw = liquid(tileX - 1, tileY + 1);
3761
const continues = (x, y) => fluidCoastContinues(
3762
this.#groundTypeAt(x, y),
3763
(typeId) => isLiquidWaterGround(typeId, season)
3764
);
3765
const n = continues(tileX, tileY - 1);
3766
const e = continues(tileX + 1, tileY);
3767
const s = continues(tileX, tileY + 1);
3768
const w = continues(tileX - 1, tileY);
3769
const ne = continues(tileX + 1, tileY - 1);
3770
const nw = continues(tileX - 1, tileY - 1);
3771
const se = continues(tileX + 1, tileY + 1);
3772
const sw = continues(tileX - 1, tileY + 1);
3770
3773
return {
3771
3774
n: n ? 0 : 1,
3772
3775
e: e ? 0 : 1,
@@ -3849,7 +3852,7 @@ export class WorldView
3849
3852
{ continue; }
3850
3853
const entry = normalizeGround(ground);
3851
3854
const def = GROUND_DEFINITIONS[entry.typeId];
3852
if (!def || def.proceduralWaves)
3855
if (!def || def.proceduralWaves || !def.blendable)
3853
3856
{ continue; }
3854
3857
let spriteName = null;
3855
3858
if (preferWet && def.wetShore)
@@ -4036,15 +4039,18 @@ export class WorldView
4036
4039
4037
4040
#lavaCoastEdges (tileX, tileY)
4038
4041
{
4039
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));
4040
const n = lava(tileX, tileY - 1);
4041
const e = lava(tileX + 1, tileY);
4042
const s = lava(tileX, tileY + 1);
4043
const w = lava(tileX - 1, tileY);
4044
const ne = lava(tileX + 1, tileY - 1);
4045
const nw = lava(tileX - 1, tileY - 1);
4046
const se = lava(tileX + 1, tileY + 1);
4047
const sw = lava(tileX - 1, tileY + 1);
4042
const continues = (x, y) => fluidCoastContinues(
4043
this.#groundTypeAt(x, y),
4044
(typeId) => isLavaGround(typeId)
4045
);
4046
const n = continues(tileX, tileY - 1);
4047
const e = continues(tileX + 1, tileY);
4048
const s = continues(tileX, tileY + 1);
4049
const w = continues(tileX - 1, tileY);
4050
const ne = continues(tileX + 1, tileY - 1);
4051
const nw = continues(tileX - 1, tileY - 1);
4052
const se = continues(tileX + 1, tileY + 1);
4053
const sw = continues(tileX - 1, tileY + 1);
4048
4054
return {
4049
4055
n: n ? 0 : 1,
4050
4056
e: e ? 0 : 1,
@@ -4381,10 +4387,18 @@ export class WorldView
4381
4387
this.#bakeAndPlaceChunk(snapshot);
4382
4388
this.#relayoutChunkTiles(snapshot);
4383
4389
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.
4384
if (refreshSoftNeighbors)
4390
if (refreshSoftNeighbors && this.#needsSoftTerrainNeighborRefresh())
4385
4391
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }
4386
4392
}
4387
4393
4394
/** Soft blend / wet-sand atlas borders need a rebake when an adjacent chunk arrives. */
4395
#needsSoftTerrainNeighborRefresh ()
4396
{
4397
if (this.softTerrain)
4398
{ return true; }
4399
return Math.max(0, Number(this.settings?.wetSandBand) || 0) > 0;
4400
}
4401
4388
4402
#relayoutChunk (snapshot)
4389
4403
{
4390
4404
this.#layoutBakedChunk(snapshot);
@@ -4608,7 +4622,7 @@ export class WorldView
4608
4622
this.#scheduleIdleChunkPrefetch();
4609
4623
return;
4610
4624
}
4611
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });
4625
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: true });
4612
4626
if (this.#hasUnbakedChunks())
4613
4627
{ this.#scheduleIdleChunkPrefetch(); }
4614
4628
}
@@ -4626,7 +4640,7 @@ export class WorldView
4626
4640
{
4627
4641
const snap = this.chunks.get(key);
4628
4642
if (snap)
4629
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: false }); }
4643
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: true }); }
4630
4644
}
4631
4645
if (this.#chunkRebuildKeys.size)
4632
4646
{
@@ -16,7 +16,7 @@ import16
} from "/shared/render/tint.js";16
} from "/shared/render/tint.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";17
import { layersFromSpawnerConfig } from "/shared/appearance/layers.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";18
import { chargeSpriteFrameIndex, itemMaxCharges } from "/shared/items/charges.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS } from "/shared/definitions/tiles.js";19
import { normalizeGround, normalizeBlock, isWadeGroundInSeason, isWaterGround, isLavaGround, isLiquidWaterGround, isGroundPassable, groundLightOcclusion, LightOcclusion, blockDefinition, blockLightOcclusionForBlock, GroundType, GROUND_DEFINITIONS, fluidCoastContinues } from "/shared/definitions/tiles.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";20
import { doorSortSubOrder, doorRestingState } from "/shared/world/doors.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";21
import { spriteCenterFromPivot, spriteDrawSize, tilePivot, ySortLayer, flightSortLayer } from "/shared/render/pivot.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";22
import { bakeChunkAtlases, tileBlockSpriteEntry } from "./chunkBake.js";@@ -3758,15 +3758,18 @@ export class WorldView3758
#waterCoastEdges (tileX, tileY)3758
#waterCoastEdges (tileX, tileY)3759
{3759
{3760
const season = this.worldSeason;3760
const season = this.worldSeason;3761
const liquid = (x, y) => isLiquidWaterGround(this.#groundTypeAt(x, y), season);3761
const continues = (x, y) => fluidCoastContinues(3762
const n = liquid(tileX, tileY - 1);3762
this.#groundTypeAt(x, y),3763
const e = liquid(tileX + 1, tileY);3763
(typeId) => isLiquidWaterGround(typeId, season)3764
const s = liquid(tileX, tileY + 1);3764
);3765
const w = liquid(tileX - 1, tileY);3765
const n = continues(tileX, tileY - 1);3766
const ne = liquid(tileX + 1, tileY - 1);3766
const e = continues(tileX + 1, tileY);3767
const nw = liquid(tileX - 1, tileY - 1);3767
const s = continues(tileX, tileY + 1);3768
const se = liquid(tileX + 1, tileY + 1);3768
const w = continues(tileX - 1, tileY);3769
const sw = liquid(tileX - 1, tileY + 1);3769
const ne = continues(tileX + 1, tileY - 1);3770
const nw = continues(tileX - 1, tileY - 1);3771
const se = continues(tileX + 1, tileY + 1);3772
const sw = continues(tileX - 1, tileY + 1);3770
return {3773
return {3771
n: n ? 0 : 1,3774
n: n ? 0 : 1,3772
e: e ? 0 : 1,3775
e: e ? 0 : 1,@@ -3849,7 +3852,7 @@ export class WorldView3849
{ continue; }3852
{ continue; }3850
const entry = normalizeGround(ground);3853
const entry = normalizeGround(ground);3851
const def = GROUND_DEFINITIONS[entry.typeId];3854
const def = GROUND_DEFINITIONS[entry.typeId];3852
if (!def || def.proceduralWaves)3855
if (!def || def.proceduralWaves || !def.blendable)3853
{ continue; }3856
{ continue; }3854
let spriteName = null;3857
let spriteName = null;3855
if (preferWet && def.wetShore)3858
if (preferWet && def.wetShore)@@ -4036,15 +4039,18 @@ export class WorldView4036
4039
4037
#lavaCoastEdges (tileX, tileY)4040
#lavaCoastEdges (tileX, tileY)4038
{4041
{4039
const lava = (x, y) => isLavaGround(this.#groundTypeAt(x, y));4042
const continues = (x, y) => fluidCoastContinues(4040
const n = lava(tileX, tileY - 1);4043
this.#groundTypeAt(x, y),4041
const e = lava(tileX + 1, tileY);4044
(typeId) => isLavaGround(typeId)4042
const s = lava(tileX, tileY + 1);4045
);4043
const w = lava(tileX - 1, tileY);4046
const n = continues(tileX, tileY - 1);4044
const ne = lava(tileX + 1, tileY - 1);4047
const e = continues(tileX + 1, tileY);4045
const nw = lava(tileX - 1, tileY - 1);4048
const s = continues(tileX, tileY + 1);4046
const se = lava(tileX + 1, tileY + 1);4049
const w = continues(tileX - 1, tileY);4047
const sw = lava(tileX - 1, tileY + 1);4050
const ne = continues(tileX + 1, tileY - 1);4051
const nw = continues(tileX - 1, tileY - 1);4052
const se = continues(tileX + 1, tileY + 1);4053
const sw = continues(tileX - 1, tileY + 1);4048
return {4054
return {4049
n: n ? 0 : 1,4055
n: n ? 0 : 1,4050
e: e ? 0 : 1,4056
e: e ? 0 : 1,@@ -4381,10 +4387,18 @@ export class WorldView4381
this.#bakeAndPlaceChunk(snapshot);4387
this.#bakeAndPlaceChunk(snapshot);4382
this.#relayoutChunkTiles(snapshot);4388
this.#relayoutChunkTiles(snapshot);4383
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.4389
// Soft terrain and wet-sand shorelines both sample cross-chunk neighbors.4384
if (refreshSoftNeighbors)4390
if (refreshSoftNeighbors && this.#needsSoftTerrainNeighborRefresh())4385
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }4391
{ this.#rebuildSoftTerrainNeighborChunks(snapshot); }4386
}4392
}4387
4393
4394
/** Soft blend / wet-sand atlas borders need a rebake when an adjacent chunk arrives. */4395
#needsSoftTerrainNeighborRefresh ()4396
{4397
if (this.softTerrain)4398
{ return true; }4399
return Math.max(0, Number(this.settings?.wetSandBand) || 0) > 0;4400
}4401
4388
#relayoutChunk (snapshot)4402
#relayoutChunk (snapshot)4389
{4403
{4390
this.#layoutBakedChunk(snapshot);4404
this.#layoutBakedChunk(snapshot);@@ -4608,7 +4622,7 @@ export class WorldView4608
this.#scheduleIdleChunkPrefetch();4622
this.#scheduleIdleChunkPrefetch();4609
return;4623
return;4610
}4624
}4611
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: false });4625
this.#rebuildChunk(snapshot, { refreshSoftNeighbors: true });4612
if (this.#hasUnbakedChunks())4626
if (this.#hasUnbakedChunks())4613
{ this.#scheduleIdleChunkPrefetch(); }4627
{ this.#scheduleIdleChunkPrefetch(); }4614
}4628
}@@ -4626,7 +4640,7 @@ export class WorldView4626
{4640
{4627
const snap = this.chunks.get(key);4641
const snap = this.chunks.get(key);4628
if (snap)4642
if (snap)4629
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: false }); }4643
{ this.#rebuildChunk(snap, { refreshSoftNeighbors: true }); }4630
}4644
}4631
if (this.#chunkRebuildKeys.size)4645
if (this.#chunkRebuildKeys.size)4632
{4646
{@@ -1,6 +1,6 @@
1
1
import test from "node:test";
2
2
import assert from "node:assert/strict";
3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";
3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion, fluidCoastContinues, isLavaGround } from "../../shared/definitions/tiles.js";
4
4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";
5
5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";
6
6
@@ -60,3 +60,25 @@ test("shallow water freezes in winter: no wade, not liquid for coast foam", () =
60
60
"water"
61
61
);
62
62
});
63
64
test("fluid coast continues under non-blendable floors and missing neighbors", () =>
65
{
66
const sameWater = (typeId) => isLiquidWaterGround(typeId, SeasonId.summer);
67
assert.equal(fluidCoastContinues(null, sameWater), true);
68
assert.equal(fluidCoastContinues(GroundType.water, sameWater), true);
69
assert.equal(fluidCoastContinues(GroundType.deepWater, sameWater), true);
70
assert.equal(fluidCoastContinues(GroundType.wood, sameWater), true);
71
assert.equal(fluidCoastContinues(GroundType.grass, sameWater), false);
72
assert.equal(fluidCoastContinues(GroundType.sand, sameWater), false);
73
// Winter ice and lava still count as coast (distinct from liquid water).
74
assert.equal(fluidCoastContinues(GroundType.water, (typeId) => isLiquidWaterGround(typeId, SeasonId.winter)), false);
75
assert.equal(fluidCoastContinues(GroundType.lava, sameWater), false);
76
});
77
78
test("lava coast continues under wood but not blendable land", () =>
79
{
80
const sameLava = (typeId) => isLavaGround(typeId);
81
assert.equal(fluidCoastContinues(GroundType.lava, sameLava), true);
82
assert.equal(fluidCoastContinues(GroundType.wood, sameLava), true);
83
assert.equal(fluidCoastContinues(GroundType.dirt, sameLava), false);
84
});
@@ -1,6 +1,6 @@1
import test from "node:test";1
import test from "node:test";2
import assert from "node:assert/strict";2
import assert from "node:assert/strict";3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion } from "../../shared/definitions/tiles.js";3
import { GroundType, BlockType, isGroundPassable, isWadeGround, isWaterGround, isLiquidWaterGround, isWadeGroundInSeason, groundLightOcclusion, groundLightRange, blockLightRange, LightOcclusion, fluidCoastContinues, isLavaGround } from "../../shared/definitions/tiles.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";4
import { SeasonId, resolveSeasonalVisualState } from "../../shared/world/season.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";5
import { createEmptyChunkData, isChunkTilePassable, isChunkTileClearForLight, setGround } from "../src/world/chunkData.js";6
6
@@ -60,3 +60,25 @@ test("shallow water freezes in winter: no wade, not liquid for coast foam", () =60
"water"60
"water"61
);61
);62
});62
});63
64
test("fluid coast continues under non-blendable floors and missing neighbors", () =>65
{66
const sameWater = (typeId) => isLiquidWaterGround(typeId, SeasonId.summer);67
assert.equal(fluidCoastContinues(null, sameWater), true);68
assert.equal(fluidCoastContinues(GroundType.water, sameWater), true);69
assert.equal(fluidCoastContinues(GroundType.deepWater, sameWater), true);70
assert.equal(fluidCoastContinues(GroundType.wood, sameWater), true);71
assert.equal(fluidCoastContinues(GroundType.grass, sameWater), false);72
assert.equal(fluidCoastContinues(GroundType.sand, sameWater), false);73
// Winter ice and lava still count as coast (distinct from liquid water).74
assert.equal(fluidCoastContinues(GroundType.water, (typeId) => isLiquidWaterGround(typeId, SeasonId.winter)), false);75
assert.equal(fluidCoastContinues(GroundType.lava, sameWater), false);76
});77
78
test("lava coast continues under wood but not blendable land", () =>79
{80
const sameLava = (typeId) => isLavaGround(typeId);81
assert.equal(fluidCoastContinues(GroundType.lava, sameLava), true);82
assert.equal(fluidCoastContinues(GroundType.wood, sameLava), true);83
assert.equal(fluidCoastContinues(GroundType.dirt, sameLava), false);84
});