Improvements to Sphere code

This commit is contained in:
walterhiggins 2013-01-20 01:29:43 +00:00
parent dc34d2e687
commit 74fbe24f8d
4 changed files with 53 additions and 67 deletions

View file

@ -39,16 +39,14 @@ var global = this;
}; };
var _putBlock = function(x,y,z,blockId,metadata){ var _putBlock = function(x,y,z,blockId,metadata){
if (typeof metadata == "undefined"){
metadata = 0;
}
var world = _getWorld();
if (!world)
return;
var block = world.getBlockAt(x,y,z);
if (typeof metadata == "undefined")
metadata = 0;
var world = (__self instanceof org.bukkit.entity.Player)?__self.location.world:(__self instanceof org.bukkit.command.BlockCommandSender)?__self.block.location.world:null;
var block = world.getBlockAt(x,y,z);
/*
if (blockId === 6){ if (blockId === 6){
var treeType = null; var treeType = null;
switch (metadata){ switch (metadata){
@ -67,9 +65,10 @@ var global = this;
} }
return world.generateTree(block.location,treeType); return world.generateTree(block.location,treeType);
}else{ }else{
block.setTypeId(blockId); */
block.setData(metadata); if (block.typeId != blockId || block.data != metadata)
} block.setTypeIdAndData(blockId,metadata,false);
// }
}; };
var _putSign = function(texts, x, y, z, blockId, meta){ var _putSign = function(texts, x, y, z, blockId, meta){
@ -96,12 +95,12 @@ var global = this;
}; };
var _getWorld = function(){ var _getWorld = function(){
if (__self instanceof org.bukkit.entity.Player)
return __self.location.world;
if (typeof __self == "undefined") if (typeof __self == "undefined")
return; return;
if (__self instanceof org.bukkit.command.BlockCommandSender) if (__self instanceof org.bukkit.command.BlockCommandSender)
return __self.block.location.world; return __self.block.location.world;
if (__self instanceof org.bukkit.entity.Player)
return __self.location.world;
}; };
var _notifyAdministrators = function(msg){ var _notifyAdministrators = function(msg){

View file

@ -574,10 +574,14 @@ var Drone = Drone || {
if (fill){ if (fill){
// wph 20130114 more efficient esp. for large cylinders/spheres // wph 20130114 more efficient esp. for large cylinders/spheres
if (yo < 0){ if (yo < 0){
drone.fwd(yo).right(xo).box(block,1,height,Math.abs(yo*2)+1).back(yo).left(xo); drone
.fwd(yo).right(xo)
.box(block,1,height,Math.abs(yo*2)+1)
.back(yo).left(xo);
} }
} }else{
gotoxy(xo,yo).box(block,1,height,1).move('center'); gotoxy(xo,yo).box(block,1,height,1).move('center');
}
}; };
// //
// credit: Following code is copied almost verbatim from // credit: Following code is copied almost verbatim from
@ -758,9 +762,19 @@ var Drone = Drone || {
var randomized = _rand(dist); var randomized = _rand(dist);
return this.box(randomized,w,h,d); return this.box(randomized,w,h,d);
}; };
var _trees = {oak: 6 ,spruce: '6:1' ,birch: '6:2' ,jungle: '6:3' }; var _trees = {oak: org.bukkit.TreeType.BIG_TREE ,
for (var p in _trees){ spruce: org.bukkit.TreeType.REDWOOD ,
Drone.prototype[p] = function(v){return function(){ return this.box(v);};}(_trees[p]); birch: org.bukkit.TreeType.BIRCH ,
jungle: org.bukkit.TreeType.JUNGLE };
for (var p in _trees)
{
Drone.prototype[p] = function(v){
return function(){
var treeLoc = new org.bukkit.Location(__self.world,this.x,this.y,this.z);
treeLoc.world.generateTree(treeLoc,v);
return this;
};
}(_trees[p]);
} }
Drone.prototype.garden = function(w,d) Drone.prototype.garden = function(w,d)

View file

@ -3,8 +3,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 r2 = radius*radius;
for (var i = 0; i <= radius;i++){ for (var i = 0; i <= radius;i++){
var newRadius = Math.round(Math.sqrt(radius*radius - i*i)); var newRadius = Math.round(Math.sqrt(r2 - i*i));
if (newRadius == lastRadius) if (newRadius == lastRadius)
slices[slices.length-1][1]++; slices[slices.length-1][1]++;
else else
@ -20,18 +21,22 @@ Drone.extend('sphere', function(block,radius)
.down(radius-slices[0][1]); .down(radius-slices[0][1]);
var yOffset = -1; var yOffset = -1;
for (var i = 1; i < slices.length;i++){ for (var i = 1; i < slices.length;i++)
{
yOffset += slices[i-1][1]; yOffset += slices[i-1][1];
var sr = slices[i][0]; var sr = slices[i][0];
var sh = slices[i][1]; var sh = slices[i][1];
var v = radius + yOffset, h = radius-sr;
// northern hemisphere // northern hemisphere
this.up(radius + yOffset).fwd(radius-sr).right(radius-sr) this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh) .cylinder(block,sr,sh)
.left(radius - sr).back( radius - sr). down(radius + yOffset); .left(h).back(h).down(v);
// southern hemisphere // southern hemisphere
this.up(radius - (yOffset+sh+1)).fwd(radius-sr).right(radius-sr) v = radius - (yOffset+sh+1);
this.up(v).fwd(h).right(h)
.cylinder(block,sr,sh) .cylinder(block,sr,sh)
.left(radius - sr).back( radius - sr). down(radius - (yOffset+sh+1)); .left(h).back(h). down(v);
} }
return this.move('sphere'); return this.move('sphere');
}); });
@ -41,40 +46,8 @@ Drone.extend('sphere', function(block,radius)
// //
Drone.extend('sphere0', function(block,radius) Drone.extend('sphere0', function(block,radius)
{ {
var lastRadius = radius; return this.sphere(block,radius)
var slices = [[radius,0]]; .fwd().right().up()
var diameter = radius*2; .sphere(0,radius-1)
for (var i = 0; i <= radius;i++){ .back().left().down();
var newRadius = Math.round(Math.sqrt(radius*radius - i*i));
if (newRadius == lastRadius)
slices[slices.length-1][1]++;
else
slices.push([newRadius,1]);
lastRadius = newRadius;
}
this.chkpt('sphere0');
//
// mid section
//
this.up(radius - slices[0][1])
.cylinder0(block,radius,(slices[0][1]*2)-1)
.down(radius-slices[0][1]);
var yOffset = -1;
for (var i = 1; i < slices.length;i++){
yOffset += slices[i-1][1];
var sr = slices[i][0];
var sh = slices[i][1];
// northern hemisphere
this.up(radius + yOffset).fwd(radius-sr).right(radius-sr)
.cylinder0(block,sr,sh)
.left(radius - sr).back( radius - sr). down(radius + yOffset);
// southern hemisphere
this.up(radius - (yOffset+sh+1)).fwd(radius-sr).right(radius-sr)
.cylinder0(block,sr,sh)
.left(radius - sr).back( radius - sr). down(radius - (yOffset+sh+1));
}
return this.move('sphere0');
}); });

View file

@ -198,7 +198,7 @@ plugin("homes", {
"These " + potentialVisitors.length + "players can visit your home", "These " + potentialVisitors.length + "players can visit your home",
potentialVisitors.join(", ")]); potentialVisitors.join(", ")]);
}, },
invite: function(){ invite: function(params){
if (params.length == 1){ if (params.length == 1){
__self.sendMessage("You must provide a player's name"); __self.sendMessage("You must provide a player's name");
return; return;
@ -210,7 +210,7 @@ plugin("homes", {
else else
homes.invite(__self,guest); homes.invite(__self,guest);
}, },
uninvite: function(){ uninvite: function(params){
if (params.length == 1){ if (params.length == 1){
__self.sendMessage("You must provide a player's name"); __self.sendMessage("You must provide a player's name");
return; return;
@ -222,7 +222,7 @@ plugin("homes", {
else else
homes.uninvite(__self,guest); homes.uninvite(__self,guest);
}, },
'public': function(){ 'public': function(params){
homes.open(__self,params.slice(1).join(' ')); homes.open(__self,params.slice(1).join(' '));
__self.sendMessage("Your home is open to the public"); __self.sendMessage("Your home is open to the public");
}, },
@ -236,7 +236,7 @@ plugin("homes", {
else else
__self.sendMessage(homes.listall().join(", ")); __self.sendMessage(homes.listall().join(", "));
}, },
clear: function(){ clear: function(params){
if (!__self.isOp()) if (!__self.isOp())
__self.sendMessage("Only operators can do this"); __self.sendMessage("Only operators can do this");
else else
@ -256,7 +256,7 @@ plugin("homes", {
} }
var option = options[params[0]]; var option = options[params[0]];
if (option) if (option)
option(); option(params);
else{ else{
var host = getPlayerObject(params[0]); var host = getPlayerObject(params[0]);
if (!host) if (!host)