optimized sphere and blocktype
This commit is contained in:
parent
2392922c01
commit
63712518dc
3 changed files with 40 additions and 20 deletions
|
@ -314,7 +314,7 @@ load(__folder + "drone.js");
|
||||||
var bmbg = null;
|
var bmbg = null;
|
||||||
if (typeof bg != "undefined")
|
if (typeof bg != "undefined")
|
||||||
bmbg = this._getBlockIdAndMeta(bg);
|
bmbg = this._getBlockIdAndMeta(bg);
|
||||||
|
var world = this._getWorld();
|
||||||
var lines = message.split("\n");
|
var lines = message.split("\n");
|
||||||
var lineCount = lines.length;
|
var lineCount = lines.length;
|
||||||
for (var h = 0;h < lineCount; h++) {
|
for (var h = 0;h < lineCount; h++) {
|
||||||
|
@ -330,12 +330,12 @@ load(__folder + "drone.js");
|
||||||
}
|
}
|
||||||
var charWidth = bits.width;
|
var charWidth = bits.width;
|
||||||
if (typeof bg != "undefined")
|
if (typeof bg != "undefined")
|
||||||
this.cuboidX(bmbg[0],bmbg[1],charWidth,7,1);
|
this.cuboidX(bmbg[0],bmbg[1],world,charWidth,7,1);
|
||||||
for (var j = 0;j < bits.pixels.length;j++){
|
for (var j = 0;j < bits.pixels.length;j++){
|
||||||
this.chkpt('btbl');
|
this.chkpt('btbl');
|
||||||
var x = bits.pixels[j][0];
|
var x = bits.pixels[j][0];
|
||||||
var y = bits.pixels[j][1];
|
var y = bits.pixels[j][1];
|
||||||
this.up(6-y).right(x).cuboidX(bmfg[0],bmfg[1]);
|
this.up(6-y).right(x).cuboidX(bmfg[0],bmfg[1],world);
|
||||||
this.move('btbl');
|
this.move('btbl');
|
||||||
}
|
}
|
||||||
this.right(charWidth-1);
|
this.right(charWidth-1);
|
||||||
|
|
|
@ -393,9 +393,10 @@ var Drone = Drone || {
|
||||||
|
|
||||||
};
|
};
|
||||||
/*
|
/*
|
||||||
faster cuboid because blockid and meta must be provided
|
faster cuboid because blockid, meta and world must be provided
|
||||||
|
use this method when you need to repeatedly place blocks
|
||||||
*/
|
*/
|
||||||
Drone.prototype.cuboidX = function(blockId, meta, w, h, d){
|
Drone.prototype.cuboidX = function(blockId, meta, world, w, h, d){
|
||||||
|
|
||||||
if (typeof h == "undefined")
|
if (typeof h == "undefined")
|
||||||
h = 1;
|
h = 1;
|
||||||
|
@ -405,9 +406,6 @@ var Drone = Drone || {
|
||||||
w = 1;
|
w = 1;
|
||||||
var that = this;
|
var that = this;
|
||||||
var dir = this.dir;
|
var dir = this.dir;
|
||||||
var pl = org.bukkit.entity.Player;
|
|
||||||
var cs = org.bukkit.command.BlockCommandSender;
|
|
||||||
var world = (self instanceof pl)?self.location.world:(self instanceof cs)?self.block.location.world:null;
|
|
||||||
|
|
||||||
var depthFunc = function(){
|
var depthFunc = function(){
|
||||||
var block = world.getBlockAt(that.x,that.y,that.z);
|
var block = world.getBlockAt(that.x,that.y,that.z);
|
||||||
|
@ -424,11 +422,16 @@ var Drone = Drone || {
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Drone.prototype._getWorld = function(){
|
||||||
|
var pl = org.bukkit.entity.Player;
|
||||||
|
var cs = org.bukkit.command.BlockCommandSender;
|
||||||
|
var world = (self instanceof pl)?self.location.world:(self instanceof cs)?self.block.location.world:null;
|
||||||
|
return world;
|
||||||
|
};
|
||||||
Drone.prototype.cuboid = function(block,w,h,d){
|
Drone.prototype.cuboid = function(block,w,h,d){
|
||||||
|
|
||||||
var bm = _getBlockIdAndMeta(block);
|
var bm = _getBlockIdAndMeta(block);
|
||||||
|
return this.cuboidX(bm[0],bm[1],this._getWorld(), w,h,d);
|
||||||
return this.cuboidX(bm[0],bm[1],w,h,d);
|
|
||||||
};
|
};
|
||||||
Drone.prototype.cuboid0 = function(block,w,h,d){
|
Drone.prototype.cuboid0 = function(block,w,h,d){
|
||||||
this.chkpt('start_point');
|
this.chkpt('start_point');
|
||||||
|
@ -592,9 +595,23 @@ var Drone = Drone || {
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
// Private variables and functions
|
// Private variables and functions
|
||||||
// ========================================================================
|
// ========================================================================
|
||||||
var _cylinderX = function(block,radius,height,drone,fill)
|
var _cylinderX = function(block,radius,height,drone,fill,exactParams)
|
||||||
{
|
{
|
||||||
drone.chkpt('cylinderX');
|
drone.chkpt('cylinderX');
|
||||||
|
var world = null;
|
||||||
|
var blockType = null;
|
||||||
|
var meta = 0;
|
||||||
|
if (typeof exactParams == "undefined"){
|
||||||
|
world = drone._getWorld();
|
||||||
|
bm = drone._getBlockIdAndMeta(block);
|
||||||
|
blockType = bm[0];
|
||||||
|
meta = bm[1];
|
||||||
|
}else{
|
||||||
|
world = exactParams.world;
|
||||||
|
blockType = exactParams.blockType;
|
||||||
|
meta = exactParams.meta;
|
||||||
|
}
|
||||||
|
|
||||||
var x0, y0, gotoxy;
|
var x0, y0, gotoxy;
|
||||||
drone.right(radius).fwd(radius).chkpt('center');
|
drone.right(radius).fwd(radius).chkpt('center');
|
||||||
switch (drone.dir){
|
switch (drone.dir){
|
||||||
|
@ -628,11 +645,11 @@ var Drone = Drone || {
|
||||||
if (yo < 0){
|
if (yo < 0){
|
||||||
drone
|
drone
|
||||||
.fwd(yo).right(xo)
|
.fwd(yo).right(xo)
|
||||||
.box(block,1,height,Math.abs(yo*2)+1)
|
.cuboidX(blockType,meta,world,1,height,Math.abs(yo*2)+1)
|
||||||
.back(yo).left(xo);
|
.back(yo).left(xo);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
gotoxy(xo,yo).box(block,1,height,1).move('center');
|
gotoxy(xo,yo).cuboidX(blockType,meta,world,1,height,1).move('center');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
|
@ -675,11 +692,11 @@ var Drone = Drone || {
|
||||||
}
|
}
|
||||||
return drone.move('cylinderX');
|
return drone.move('cylinderX');
|
||||||
}
|
}
|
||||||
var _cylinder0 = function(block,radius,height){
|
var _cylinder0 = function(block,radius,height,exactParams){
|
||||||
return _cylinderX(block,radius,height,this,false);
|
return _cylinderX(block,radius,height,this,false,exactParams);
|
||||||
};
|
};
|
||||||
var _cylinder1 = function(block,radius,height){
|
var _cylinder1 = function(block,radius,height,exactParams){
|
||||||
return _cylinderX(block,radius,height,this,true);
|
return _cylinderX(block,radius,height,this,true,exactParams);
|
||||||
};
|
};
|
||||||
var _getDirFromRotation = function(r){
|
var _getDirFromRotation = function(r){
|
||||||
// 0 = east, 1 = south, 2 = west, 3 = north
|
// 0 = east, 1 = south, 2 = west, 3 = north
|
||||||
|
|
|
@ -5,6 +5,9 @@ Drone.extend('sphere', function(block,radius)
|
||||||
var lastRadius = radius;
|
var lastRadius = radius;
|
||||||
var slices = [[radius,0]];
|
var slices = [[radius,0]];
|
||||||
var diameter = radius*2;
|
var diameter = radius*2;
|
||||||
|
var world = this._getWorld();
|
||||||
|
var bm = this._getBlockIdAndMeta(block);
|
||||||
|
|
||||||
var r2 = radius*radius;
|
var r2 = radius*radius;
|
||||||
for (var i = 0; i <= radius;i++){
|
for (var i = 0; i <= radius;i++){
|
||||||
var newRadius = Math.round(Math.sqrt(r2 - i*i));
|
var newRadius = Math.round(Math.sqrt(r2 - i*i));
|
||||||
|
@ -19,7 +22,7 @@ Drone.extend('sphere', function(block,radius)
|
||||||
// mid section
|
// mid section
|
||||||
//
|
//
|
||||||
this.up(radius - slices[0][1])
|
this.up(radius - slices[0][1])
|
||||||
.cylinder(block,radius,(slices[0][1]*2)-1)
|
.cylinder(block,radius,(slices[0][1]*2)-1,{blockType: bm[0],meta: bm[1],world: world})
|
||||||
.down(radius-slices[0][1]);
|
.down(radius-slices[0][1]);
|
||||||
|
|
||||||
var yOffset = -1;
|
var yOffset = -1;
|
||||||
|
@ -31,13 +34,13 @@ Drone.extend('sphere', function(block,radius)
|
||||||
var v = radius + yOffset, h = radius-sr;
|
var v = radius + yOffset, h = radius-sr;
|
||||||
// northern hemisphere
|
// northern hemisphere
|
||||||
this.up(v).fwd(h).right(h)
|
this.up(v).fwd(h).right(h)
|
||||||
.cylinder(block,sr,sh)
|
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1],world: world})
|
||||||
.left(h).back(h).down(v);
|
.left(h).back(h).down(v);
|
||||||
|
|
||||||
// southern hemisphere
|
// southern hemisphere
|
||||||
v = radius - (yOffset+sh+1);
|
v = radius - (yOffset+sh+1);
|
||||||
this.up(v).fwd(h).right(h)
|
this.up(v).fwd(h).right(h)
|
||||||
.cylinder(block,sr,sh)
|
.cylinder(block,sr,sh,{blockType: bm[0],meta: bm[1],world: world})
|
||||||
.left(h).back(h). down(v);
|
.left(h).back(h). down(v);
|
||||||
}
|
}
|
||||||
return this.move('sphere');
|
return this.move('sphere');
|
||||||
|
|
Reference in a new issue