Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 20296ae

Browse files
committed
chunk stuff
1 parent cfea543 commit 20296ae

11 files changed

Lines changed: 712 additions & 126 deletions

File tree

src/pocketnode/level/Chunk.js

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/pocketnode/level/GameRule.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class GameRule {
2+
static get COMMAND_BLOCK_OUTPUT(){return "commandblockoutput"}
3+
static get DO_DAYLIGHT_CYCLE(){return "dodaylightcycle"}
4+
static get DO_ENTITY_DROPS(){return "doentitydrops"}
5+
static get DO_FIRE_TICK(){return "dofiretick"}
6+
static get DO_MOB_LOOT(){return "domobloot"}
7+
static get DO_MOB_SPAWNING(){return "domobspawning"}
8+
static get DO_TILE_DROPS(){return "dotiledrops"}
9+
static get DO_WEATHER_CYCLE(){return "doweathercycle"}
10+
static get DROWNING_DAMAGE(){return "drowningdamage"}
11+
static get FALL_DAMAGE(){return "falldamage"}
12+
static get FIRE_DAMAGE(){return "firedamage"}
13+
static get KEEP_INVENTORY(){return "keepinventory"}
14+
static get MOB_GRIEFING(){return "mobgriefing"}
15+
static get NATURAL_REGENERATION(){return "naturalregeneration"}
16+
static get PVP(){return "pvp"}
17+
static get SEND_COMMAND_FEEDBACK(){return "sedcommandfeedback"}
18+
static get SHOW_COORDINATES(){return "showcoordinates"}
19+
static get RANDOM_TICK_SPEED(){return "randomtickspeed"}
20+
static get TNT_EXPLODES(){return "tntexplodes"}
21+
22+
constructor(name, value){
23+
this.name = name;
24+
this.value = value;
25+
}
26+
27+
getName(){
28+
return this.name;
29+
}
30+
31+
getValue(){
32+
return this.value;
33+
}
34+
35+
setValue(value){
36+
if(typeof value !== typeof this.value){
37+
return false;
38+
}
39+
this.value = value;
40+
return true;
41+
}
42+
}
43+
44+
module.exports = GameRule;

src/pocketnode/level/Level.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Level {
2+
initVars(){
3+
this._server = null;
4+
this._name = "";
5+
this._id = -1;
6+
/** @type {Map<Number, Dimension>} */
7+
this._dimensions = new Map();
8+
this._defaultDimension = null;
9+
10+
/** @type {Map<String, GameRule>} */
11+
this._gameRules = new Map();
12+
}
13+
14+
constructor(server, name, id, chunks){
15+
this.initVars();
16+
17+
18+
}
19+
}
20+
21+
module.exports = Level;

src/pocketnode/level/Location.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212

1313
const Position = pocketnode("level/Position");
1414

15-
/**
16-
* A Location is a Position with added Yaw and Pitch references. Yaw and Pitch are used for rotation.
17-
* @class
18-
*/
1915
class Location extends Position {
2016
/**
2117
* Represents a Position with added Yaw and Pitch references
@@ -27,22 +23,30 @@ class Location extends Position {
2723
* @param {Number} pitch
2824
* @param {Level} level
2925
*/
26+
27+
/**
28+
* @param x {Number}
29+
* @param y {Number}
30+
* @param z {Number}
31+
* @param yaw {Number}
32+
* @param pitch {Number}
33+
* @param level {Level}
34+
*/
3035
constructor(x = 0, y = 0, z = 0, yaw = 0.0, pitch = 0.0, level = null){
3136
super(x, y, z, level);
3237
this.yaw = yaw;
3338
this.pitch = pitch;
3439
}
3540

3641
/**
37-
* @param {Vector3} pos
38-
* @param {Level | null} level
39-
* @param {Number} yaw
40-
* @param {Number} pitch
41-
*
42-
* @return {Location}
43-
*/
44-
fromObject(pos, level = null, yaw = 0.0, pitch = 0.0)
45-
{
42+
* @param pos {Vector3}
43+
* @param level {Level|null}
44+
* @param yaw {Number}
45+
* @param pitch {Number}
46+
*
47+
* @return {Location}
48+
*/
49+
static fromObject(pos, level = null, yaw = 0.0, pitch = 0.0){
4650
return new Location(pos.x, pos.y, pos.z, yaw, pitch, (level === null ? (pos instanceof Position ? pos.level : null) : level));
4751
}
4852

@@ -51,30 +55,25 @@ class Location extends Position {
5155
*
5256
* @return {Location}
5357
*/
54-
asLocation()
55-
{
58+
asLocation(){
5659
return new Location(this.x, this.y, this.z, this.yaw, this.pitch, this.level);
5760
}
5861

59-
getYaw()
60-
{
62+
getYaw(){
6163
return this.yaw;
6264
}
6365

64-
getPitch()
65-
{
66+
getPitch(){
6667
return this.pitch;
6768
}
6869

69-
__toString()
70-
{
70+
toString(){
7171
return "Location (level=" + (this.isValid() ? this.getLevel().getName() : "null") + ", x=" + this.x + ", y=" + this.y + ", z=" + this.z + ", yaw=" + this.yaw + ", pitch=" + this.pitch + ")";
7272
}
7373

74-
equals(v)
75-
{
74+
equals(v){
7675
if(v instanceof Location){
77-
return super.equals(v) && v.yaw == this.yaw && v.pitch == this.pitch;
76+
return super.equals(v) && v.yaw === this.yaw && v.pitch === this.pitch;
7877
}
7978
return super.equals(v);
8079
}

src/pocketnode/level/Position.js

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,22 @@
1212

1313
const 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

Comments
 (0)