-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using ticking areas to load chunks instead
- Loading branch information
Showing
5 changed files
with
87 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,32 @@ | ||
import { Server, Vector } from "@notbeer-api"; | ||
import { Vector3, Dimension } from "@minecraft/server"; | ||
import { Vector3, Dimension, world } from "@minecraft/server"; | ||
|
||
export function addTickingArea(start: Vector3, end: Vector3, dimension: Dimension, name: string, preload = false) { | ||
return Server.runCommand(`tickingarea add ${Vector.from(start).print()} ${Vector.from(end).print()} ${name} ${preload}`, dimension).error; | ||
const DIMENSIONS = [world.getDimension("overworld"), world.getDimension("nether"), world.getDimension("the_end")]; | ||
|
||
/** | ||
* Sets a ticking area in a cuboid region to load chunks. Note that chunks don't get loaded immediately. | ||
* @returns `true` when created successfully; `false` otherwise. | ||
*/ | ||
export function setTickingArea(start: Vector3, end: Vector3, dimension: Dimension, name: string) { | ||
const removed = removeTickingArea(name, dimension); | ||
return !!Server.runCommand(`tickingarea add ${Vector.from(start).print()} ${Vector.from(end).print()} ${name}`, dimension).successCount || removed; | ||
} | ||
|
||
/** | ||
* Sets a ticking area in a circular region to load chunks. Note that chunks don't get loaded immediately. | ||
* @returns `true` when created successfully; `false` otherwise. | ||
*/ | ||
export function setTickingAreaCircle(center: Vector3, radius: 1 | 2 | 3 | 4, dimension: Dimension, name: string) { | ||
const removed = removeTickingArea(name, dimension); | ||
const result = Server.runCommand(`tickingarea add circle ${Vector.from(center).print()} ${radius} ${name}`, dimension); | ||
return !!result.successCount || removed; | ||
} | ||
|
||
export function removeTickingArea(name: string, dimension: Dimension) { | ||
return Server.runCommand(`tickingarea remove ${name}`, dimension).error; | ||
/** Removes a ticking area. */ | ||
export function removeTickingArea(name: string, dimension?: Dimension) { | ||
if (dimension) { | ||
return !!Server.runCommand(`tickingarea remove ${name}`, dimension).successCount; | ||
} else { | ||
DIMENSIONS.forEach((d) => Server.runCommand(`tickingarea remove ${name}`, d)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters