Merge branch 'feature/lava-ranged-los'
@@ -1,24 +1,27 @@
1
1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";
2
import {
3
BlockType,
4
GroundType,
5
isBlockPassable,
6
blockLightOcclusionForBlock,
7
LightOcclusion,
8
isGroundPassable,
9
isWaterGround,
10
blockBlocksRangedAttacks,
11
normalizeGround,
12
normalizeBlock
13
} from "../../../shared/definitions/tiles.js";
2
import
3
{
4
BlockType,
5
GroundType,
6
isBlockPassable,
7
blockLightOcclusionForBlock,
8
LightOcclusion,
9
isGroundPassable,
10
isWaterGround,
11
isLavaGround,
12
blockBlocksRangedAttacks,
13
normalizeGround,
14
normalizeBlock
15
} from "../../../shared/definitions/tiles.js";
14
16
import { isDoorTraversable } from "../../../shared/world/doors.js";
15
17
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";
16
18
import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";
17
import {
18
flowerBlockState,
19
flowerColorIdFromBlockState,
20
flowerColorIdForTile
21
} from "../../../shared/definitions/dyes.js";
19
import
20
{
21
flowerBlockState,
22
flowerColorIdFromBlockState,
23
flowerColorIdForTile
24
} from "../../../shared/definitions/dyes.js";
22
25
import { normalizeSpawnerConfig } from "../../../shared/definitions/mobs.js";
23
26
import { tileIndex } from "./coordinates.js";
24
27
@@ -204,8 +207,12 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)
204
207
{
205
208
const index = tileIndex(localX, localY);
206
209
const ground = normalizeGround(data.grounds[index]);
207
// Deep (and shallow) water blocks walking but not projectiles / spell rays.
208
if (!isGroundPassable(ground.typeId) && !isWaterGround(ground.typeId))
210
// Water and lava block walking but not projectiles / spell rays.
211
if (
212
!isGroundPassable(ground.typeId)
213
&& !isWaterGround(ground.typeId)
214
&& !isLavaGround(ground.typeId)
215
)
209
216
{ return false; }
210
217
const block = data.blocks[index];
211
218
return !blockBlocksRangedAttacks(block?.typeId ?? null, block?.state ?? null, block);
@@ -1,24 +1,27 @@1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";1
import { CHUNK_SIZE, DEFAULT_WORLD_SETTINGS } from "../../../shared/protocol/constants.js";2
import {2
import3
BlockType,3
{4
GroundType,4
BlockType,5
isBlockPassable,5
GroundType,6
blockLightOcclusionForBlock,6
isBlockPassable,7
LightOcclusion,7
blockLightOcclusionForBlock,8
isGroundPassable,8
LightOcclusion,9
isWaterGround,9
isGroundPassable,10
blockBlocksRangedAttacks,10
isWaterGround,11
normalizeGround,11
isLavaGround,12
normalizeBlock12
blockBlocksRangedAttacks,13
} from "../../../shared/definitions/tiles.js";13
normalizeGround,14
normalizeBlock15
} from "../../../shared/definitions/tiles.js";14
import { isDoorTraversable } from "../../../shared/world/doors.js";16
import { isDoorTraversable } from "../../../shared/world/doors.js";15
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";17
import { tileLightOcclusionAt, bakeChunkOcclusion, ensureChunkOcclusion } from "../../../shared/lighting/chunkOcclusion.js";16
import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";18
import { collectBlockLightSources, collectGroundLightSources } from "../../../shared/lighting/blockLights.js";17
import {19
import18
flowerBlockState,20
{19
flowerColorIdFromBlockState,21
flowerBlockState,20
flowerColorIdForTile22
flowerColorIdFromBlockState,21
} from "../../../shared/definitions/dyes.js";23
flowerColorIdForTile24
} from "../../../shared/definitions/dyes.js";22
import { normalizeSpawnerConfig } from "../../../shared/definitions/mobs.js";25
import { normalizeSpawnerConfig } from "../../../shared/definitions/mobs.js";23
import { tileIndex } from "./coordinates.js";26
import { tileIndex } from "./coordinates.js";24
27
@@ -204,8 +207,12 @@ export function isChunkTileClearForRangedAttacks (data, localX, localY)204
{207
{205
const index = tileIndex(localX, localY);208
const index = tileIndex(localX, localY);206
const ground = normalizeGround(data.grounds[index]);209
const ground = normalizeGround(data.grounds[index]);207
// Deep (and shallow) water blocks walking but not projectiles / spell rays.210
// Water and lava block walking but not projectiles / spell rays.208
if (!isGroundPassable(ground.typeId) && !isWaterGround(ground.typeId))211
if (212
!isGroundPassable(ground.typeId)213
&& !isWaterGround(ground.typeId)214
&& !isLavaGround(ground.typeId)215
)209
{ return false; }216
{ return false; }210
const block = data.blocks[index];217
const block = data.blocks[index];211
return !blockBlocksRangedAttacks(block?.typeId ?? null, block?.state ?? null, block);218
return !blockBlocksRangedAttacks(block?.typeId ?? null, block?.state ?? null, block);@@ -41,7 +41,7 @@ test("deep water does not block ranged / spell line of sight", () =>
41
41
assert.equal(isChunkTilePassable(data, 6, 6), true);
42
42
});
43
43
44
test("lava is impassable, clear for light, and emits half-torch light", () =>
44
test("lava is impassable, clear for light and ranged, and emits half-torch light", () =>
45
45
{
46
46
assert.equal(isGroundPassable(GroundType.lava), false);
47
47
assert.equal(isWaterGround(GroundType.lava), false);
@@ -53,6 +53,7 @@ test("lava is impassable, clear for light, and emits half-torch light", () =>
53
53
setGround(data, 4, 4, GroundType.lava);
54
54
assert.equal(isChunkTilePassable(data, 4, 4), false);
55
55
assert.equal(isChunkTileClearForLight(data, 4, 4), true);
56
assert.equal(isChunkTileClearForRangedAttacks(data, 4, 4), true);
56
57
});
57
58
58
59
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>
@@ -41,7 +41,7 @@ test("deep water does not block ranged / spell line of sight", () =>41
assert.equal(isChunkTilePassable(data, 6, 6), true);41
assert.equal(isChunkTilePassable(data, 6, 6), true);42
});42
});43
43
44
test("lava is impassable, clear for light, and emits half-torch light", () =>44
test("lava is impassable, clear for light and ranged, and emits half-torch light", () =>45
{45
{46
assert.equal(isGroundPassable(GroundType.lava), false);46
assert.equal(isGroundPassable(GroundType.lava), false);47
assert.equal(isWaterGround(GroundType.lava), false);47
assert.equal(isWaterGround(GroundType.lava), false);@@ -53,6 +53,7 @@ test("lava is impassable, clear for light, and emits half-torch light", () =>53
setGround(data, 4, 4, GroundType.lava);53
setGround(data, 4, 4, GroundType.lava);54
assert.equal(isChunkTilePassable(data, 4, 4), false);54
assert.equal(isChunkTilePassable(data, 4, 4), false);55
assert.equal(isChunkTileClearForLight(data, 4, 4), true);55
assert.equal(isChunkTileClearForLight(data, 4, 4), true);56
assert.equal(isChunkTileClearForRangedAttacks(data, 4, 4), true);56
});57
});57
58
58
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>59
test("shallow water freezes in winter: no wade, not liquid for coast foam", () =>