-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathDebugDisplayShapeElement.js
More file actions
70 lines (59 loc) · 2.26 KB
/
Copy pathDebugDisplayShapeElement.js
File metadata and controls
70 lines (59 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { debugDrawer } from "@minecraft/debug-utilities";
import { DebugDisplayElement } from "./DebugDisplayElement";
import { system } from "@minecraft/server";
import { Rules } from "../../../lib/canopy/Canopy";
export class DebugDisplayShapeElement extends DebugDisplayElement {
shapes = [];
visibleToPlayer;
serverSidePositionRunner = void 0;
constructor(entity, visibleToPlayer = void 0) {
super(entity);
this.visibleToPlayer = visibleToPlayer;
if (this.constructor === DebugDisplayShapeElement)
throw new TypeError("Abstract class 'DebugDisplayShapeElement' cannot be instantiated directly.");
this.createShapes();
}
destroy() {
this.clearShapes();
this.stopServerSidePositionRendering();
}
createShapes() {
throw new Error("Method 'createShapes()' must be implemented.");
}
clearShapes() {
this.shapes.forEach(shape => debugDrawer.removeShape(shape));
this.shapes.length = 0;
}
drawShape(debugShape) {
this.setupPosition(debugShape);
if (this.visibleToPlayer)
debugShape.visibleTo = [this.visibleToPlayer];
this.shapes.push(debugShape);
debugDrawer.addShape(debugShape);
}
update() {
throw new Error("Method 'update()' must be implemented.");
}
getClientSideLocation() {
throw new Error("Method 'getClientSideLocation()' must be implemented.");
}
setupPosition(debugShape) {
if (Rules.getNativeValue('serverSideCollisionBoxes')) {
this.serverSidePositionRunner = system.runInterval(() => this.updateServerSidePosition());
} else {
this.stopServerSidePositionRendering();
debugShape.attachedTo = this.entity;
}
}
updateServerSidePosition() {
const dimensionLocation = this.getClientSideLocation().add(this.entity.location);
dimensionLocation.dimension = this.entity.dimension;
this.shapes.forEach((debugShape) => debugShape.setLocation(dimensionLocation));
}
stopServerSidePositionRendering() {
if (this.serverSidePositionRunner !== void 0) {
system.clearRun(this.serverSidePositionRunner);
this.serverSidePositionRunner = void 0;
}
}
}