1212
1313const Vector3 = pocketnode ( "math/Vector3" ) ;
1414
15- /**
16- * A Position is a Vector3 with an added Level component
17- * @class
18- */
19- class Position extends Vector3
20- {
21-
22- initVars ( )
23- {
24- this . level = null ;
25- }
15+ class Position extends Vector3 {
2616
2717 /**
2818 * Represents a Vector3 with an added Level reference.
29- * @constructor
3019 * @param {Number } x
3120 * @param {Number } y
3221 * @param {Number } z
33- * @param {Level } level
22+ * @param {Level|null } level
3423 *
3524 */
36- constructor ( x = 0 , y = 0 , z = 0 , level = null )
37- {
38- this . x = x ;
39- this . y = y ;
40- this . z = z ;
25+ constructor ( x = 0 , y = 0 , z = 0 , level = null ) {
26+ super ( x , y , z ) ;
4127 this . level = level ;
4228 }
4329
44- fromObject ( pos , level = null )
45- {
30+ static fromObject ( pos , level = null ) {
4631 return new Position ( pos . x , pos . y , pos . z , level ) ;
4732 }
4833
@@ -51,39 +36,30 @@ class Position extends Vector3
5136 *
5237 * @return {Position }
5338 */
54- asPosition ( )
55- {
39+ asPosition ( ) {
5640 return new Position ( this . x , this . y , this . z , this . level ) ;
5741 }
5842
5943 /**
60- * Returns the target Level, or null if the target is not valid.
61- * If a reference exists to a Level which is closed, the reference will be destroyed and null will be returned.
62- *
63- * @return {Level | null }
64- */
65- getLevel ( )
66- {
44+ * @return {Level|null }
45+ */
46+ getLevel ( ) {
6747 if ( this . level !== null && this . level . isClosed ( ) ) {
68- // MainLogger.getLogger().debug("Position was holding a reference to an unloaded Level");
48+ MainLogger . getLogger ( ) . debug ( "Position was holding a reference to an unloaded Level" ) ;
6949 this . level = null ;
7050 }
51+
7152 return this . level ;
7253 }
7354
7455 /**
75- * Sets the target Level of the position.
76- *
77- * @param {Level | null } level
78- *
79- * @return {this }
80- *
81- * @throws \InvalidArgumentException if the specified Level has been closed
82- */
83- setLevel ( level = null )
84- {
56+ * Sets the target Level of the position.
57+ * @param level {Level|null}
58+ * @return {Position }
59+ */
60+ setLevel ( level = null ) {
8561 if ( level !== null && level . isClosed ( ) ) {
86- // throw new \InvalidArgumentException ("Specified level has been unloaded and cannot be used");
62+ throw new Error ( "Specified level has been unloaded and cannot be used" ) ;
8763 }
8864 this . level = level ;
8965 return this ;
@@ -94,8 +70,7 @@ class Position extends Vector3
9470 *
9571 * @return {Boolean }
9672 */
97- isValid ( )
98- {
73+ isValid ( ) {
9974 return this . getLevel ( ) instanceof Level ;
10075 }
10176
@@ -109,15 +84,13 @@ class Position extends Vector3
10984 *
11085 * @throws {LevelException }
11186 */
112- getSide ( side , step = 1 )
113- {
114- var assert = require ( 'assert' ) ;
87+ getSide ( side , step = 1 ) {
11588 assert ( this . isValid ( ) ) ;
116- return this . fromObject ( super . getSide ( side , step ) , this . level ) ;
89+
90+ return Position . fromObject ( super . getSide ( side , step ) , this . level ) ;
11791 }
11892
119- __toString ( )
120- {
93+ toString ( ) {
12194 return "Position(level=" + ( this . isValid ( ) ? this . getLevel ( ) . getName ( ) : "null" ) + ",x=" + this . x + ",y=" + this . y + ",z=" + this . z + ")" ;
12295 }
12396
@@ -128,16 +101,14 @@ class Position extends Vector3
128101 *
129102 * @return {Position }
130103 */
131- setComponents ( x , y , z )
132- {
104+ setComponents ( x , y , z ) {
133105 this . x = x ;
134106 this . y = y ;
135107 this . z = z ;
136108 return this ;
137109 }
138110
139- equals ( v )
140- {
111+ equals ( v ) {
141112 if ( v instanceof Position ) {
142113 return super . equals ( v ) && v . getLevel ( ) === this . getLevel ( ) ;
143114 }
0 commit comments