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

@ -40,15 +40,13 @@ var global = this;
var _putBlock = function(x,y,z,blockId,metadata){
if (typeof metadata == "undefined"){
if (typeof metadata == "undefined")
metadata = 0;
}
var world = _getWorld();
if (!world)
return;
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){
var treeType = null;
switch (metadata){
@ -67,9 +65,10 @@ var global = this;
}
return world.generateTree(block.location,treeType);
}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){
@ -96,12 +95,12 @@ var global = this;
};
var _getWorld = function(){
if (__self instanceof org.bukkit.entity.Player)
return __self.location.world;
if (typeof __self == "undefined")
return;
if (__self instanceof org.bukkit.command.BlockCommandSender)
return __self.block.location.world;
if (__self instanceof org.bukkit.entity.Player)
return __self.location.world;
};
var _notifyAdministrators = function(msg){

View file

@ -574,10 +574,14 @@ var Drone = Drone || {
if (fill){
// wph 20130114 more efficient esp. for large cylinders/spheres
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);
}
}
gotoxy(xo,yo).box(block,1,height,1).move('center');
}else{
gotoxy(xo,yo).box(block,1,height,1).move('center');
}
};
//
// credit: Following code is copied almost verbatim from
@ -758,9 +762,19 @@ var Drone = Drone || {
var randomized = _rand(dist);
return this.box(randomized,w,h,d);
};
var _trees = {oak: 6 ,spruce: '6:1' ,birch: '6:2' ,jungle: '6:3' };
for (var p in _trees){
Drone.prototype[p] = function(v){return function(){ return this.box(v);};}(_trees[p]);
var _trees = {oak: org.bukkit.TreeType.BIG_TREE ,
spruce: org.bukkit.TreeType.REDWOOD ,
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)

View file

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

View file

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