Skip to content

Commit ca3d7d7

Browse files
committed
fix: region area
1 parent 1e1b6ca commit ca3d7d7

3 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/lib/region/areas/area.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export abstract class Area<T extends JsonObject = JsonObject> {
5757

5858
isValid() {
5959
const [min, max] = this.edges
60-
return min.y > this.dimension.heightRange.min && max.y < this.dimension.heightRange.max
60+
return min.y >= this.dimension.heightRange.min && max.y <= this.dimension.heightRange.max
6161
}
6262

6363
/** Edges of the area */

src/lib/region/kinds/region.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ export class Region {
7272
): InstanceType<T> {
7373
if (this !== Region && this.regions === Region.regions) this.regions = []
7474

75+
if (!area.isValid()) throw new Error('Area ' + area.toString() + 'is invalid')
76+
7577
const region = new this(area, options, key ?? this.generateRegionKey(this.kind, area.type, area.radius))
7678
this.regions.push(region)
7779
if (this !== Region) Region.regions.push(region)

src/modules/world-edit/tools/create-region.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ class RegionTool extends WorldEditTool<Storage> {
6363

6464
const regions = storage.minDistanceSameKind ? regionType.region.getAll() : Region.regions
6565
if (storage.minDistance !== -1 && regions.some(r => r.area.isNear(player, storage.minDistance)))
66-
return player.onScreenDisplay.setActionBar(`§7Рядом другие регионы`, ActionbarPriority.High)
66+
return player.onScreenDisplay.setActionBar(noI18n`§7Рядом другие регионы`, ActionbarPriority.High)
6767

68-
const create = () =>
69-
regionType.region.create(
70-
new SphereArea({ center: player.location, radius: storage.radius }, player.dimension.type),
71-
)
68+
const area = new SphereArea({ center: player.location, radius: storage.radius }, player.dimension.type)
69+
70+
if (!area.isValid()) {
71+
const msg = noI18n.error`Area ${area.toString()} is invalid. Maybe too near to the world borders?`
72+
player.onScreenDisplay.setActionBar(msg, ActionbarPriority.High)
73+
return player.fail(msg)
74+
}
75+
76+
const create = () => regionType.region.create(area)
7277

7378
const region = create()
7479
const we = WorldEdit.forPlayer(player)

0 commit comments

Comments
 (0)