Drone.cuboidX() - foundation of most Drone building is now async.
This commit is contained in:
parent
de113db48c
commit
ef02885613
1 changed files with 48 additions and 12 deletions
|
@ -735,6 +735,34 @@ exports.Drone = Drone;
|
||||||
*/
|
*/
|
||||||
exports.blocks = blocks;
|
exports.blocks = blocks;
|
||||||
|
|
||||||
|
Drone.queue = [];
|
||||||
|
Drone.processingQueue = false;
|
||||||
|
Drone.MAX_QUEUE_SIZE = 100000;
|
||||||
|
Drone.tick = setInterval( function() {
|
||||||
|
if ( Drone.processingQueue ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var maxOpsPerTick = Math.floor(Math.max(10,Math.sqrt(Drone.queue.length))) ;
|
||||||
|
var op;
|
||||||
|
Drone.processingQueue = true;
|
||||||
|
while ( maxOpsPerTick > 0 ) {
|
||||||
|
op = Drone.queue.shift();
|
||||||
|
if (!op){
|
||||||
|
Drone.processingQueue = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var block = op.world.getBlockAt( op.x, op.y, op.z );
|
||||||
|
block.setTypeIdAndData( op.typeid, op.meta, false );
|
||||||
|
// wph 20130210 - dont' know if this is a bug in bukkit but for chests,
|
||||||
|
// the metadata is ignored (defaults to 2 - south facing)
|
||||||
|
// only way to change data is to set it using property/bean.
|
||||||
|
block.data = op.meta;
|
||||||
|
maxOpsPerTick--;
|
||||||
|
}
|
||||||
|
Drone.processingQueue = false;
|
||||||
|
return;
|
||||||
|
}, 1);
|
||||||
|
|
||||||
//
|
//
|
||||||
// add custom methods to the Drone object using this function
|
// add custom methods to the Drone object using this function
|
||||||
//
|
//
|
||||||
|
@ -1021,12 +1049,19 @@ Drone.prototype.cuboidX = function( blockType, meta, w, h, d ) {
|
||||||
var dir = this.dir;
|
var dir = this.dir;
|
||||||
|
|
||||||
var depthFunc = function( ) {
|
var depthFunc = function( ) {
|
||||||
var block = that.world.getBlockAt( that.x, that.y, that.z );
|
var len = Drone.queue.length;
|
||||||
block.setTypeIdAndData( blockType, meta, false );
|
if ( len < Drone.MAX_QUEUE_SIZE ) {
|
||||||
// wph 20130210 - dont' know if this is a bug in bukkit but for chests,
|
Drone.queue.push({
|
||||||
// the metadata is ignored (defaults to 2 - south facing)
|
world: that.world,
|
||||||
// only way to change data is to set it using property/bean.
|
x: that.x,
|
||||||
block.data = meta;
|
y: that.y,
|
||||||
|
z:that.z,
|
||||||
|
typeid: blockType,
|
||||||
|
meta: meta
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error('Drone is too busy!');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
var heightFunc = function( ) {
|
var heightFunc = function( ) {
|
||||||
_traverse[dir].depth( that, d, depthFunc );
|
_traverse[dir].depth( that, d, depthFunc );
|
||||||
|
@ -1059,15 +1094,16 @@ Drone.prototype.cuboid0 = function( block, w, h, d ) {
|
||||||
return this.move( 'start_point' );
|
return this.move( 'start_point' );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Drone.extend( 'door', function( door ) {
|
Drone.extend( 'door', function( door ) {
|
||||||
if ( typeof door == 'undefined' ) {
|
if ( typeof door == 'undefined' ) {
|
||||||
door = 64;
|
door = 64;
|
||||||
} else {
|
} else {
|
||||||
door = 71;
|
door = 71;
|
||||||
}
|
}
|
||||||
this.cuboid( door+':' + this.dir )
|
this.cuboidX( door, this.dir )
|
||||||
.up( )
|
.up( )
|
||||||
.cuboid( door+':8' )
|
.cuboidX( door, 8 )
|
||||||
.down( );
|
.down( );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -1078,10 +1114,10 @@ Drone.extend( 'door2' , function( door ) {
|
||||||
door = 71;
|
door = 71;
|
||||||
}
|
}
|
||||||
this
|
this
|
||||||
.box( door+':' + this.dir ).up( )
|
.cuboidX( door, this.dir ).up( )
|
||||||
.box( door+':8' ).right( )
|
.cuboidX( door, 8 ).right( )
|
||||||
.box( door+':9' ).down( )
|
.cuboidX( door, 9 ).down( )
|
||||||
.box( door+':' + this.dir ).left( );
|
.cuboidX( door, this.dir ).left( );
|
||||||
} );
|
} );
|
||||||
// player dirs: 0 = east, 1 = south, 2 = west, 3 = north
|
// player dirs: 0 = east, 1 = south, 2 = west, 3 = north
|
||||||
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north
|
// block dirs: 0 = east, 1 = west, 2 = south , 3 = north
|
||||||
|
|
Reference in a new issue