added new entities and spawn modules

This commit is contained in:
walterhiggins 2015-11-21 17:07:40 +00:00
parent 4aa28c0af3
commit e285bb6891
6 changed files with 70 additions and 28 deletions

View file

@ -1 +1 @@
scriptcraft-version=3.1.10
scriptcraft-version=3.1.11

View file

@ -1,5 +1,22 @@
RELEASE NOTES
=============
3.1.11 Release (2015 11 21)
---------------------------
Added new modules
* entities
* spawn
And new Drone function `spawn()`
To use:
Point at a block then type...
```
/js spawn('ZOMBIE').fwd().times(5).right().back(5).times(6)
```
... unleash a horde of zombies (in 5x6 grid formation).
3.1.10 Release (2015 08 16)
---------------------------

View file

@ -0,0 +1,18 @@
/*global __plugin, org, Packages, module, exports*/
'use strict';
var entities = {},
entitytypes,
t, i, name;
if (__plugin.bukkit) {
entitytypes = org.bukkit.entity.EntityType.values();
}
if (__plugin.canary) {
entitytypes = Packages.net.canarymod.api.entity.EntityType.values();
}
for (t in entitytypes) {
if (entitytypes[t] && entitytypes[t].ordinal) {
name = entitytypes[t].name();
entities[name] = entitytypes[t];
}
}
module.exports = entities;

View file

@ -0,0 +1,18 @@
/*global require, module, __plugin, Packages*/
'use strict';
var entities = require('entities');
module.exports = function(entityType, location){
if (typeof entityType === 'string'){
entityType = entities[entityType];
}
var world = location.world;
if (__plugin.bukkit){
world.spawnEntity( location, entityType);
}
if (__plugin.canary){
var Canary = Packages.net.canarymod.Canary,
entityInstance = Canary.factory().entityFactory.newEntity(entityType, location);
entityInstance.spawn();
}
};

View file

@ -0,0 +1,8 @@
'use strict';
var spawnFn = require('spawn'),
Drone = require('drone')
;
function spawn(entityType){
spawnFn(entityType, this.getBlock().location);
}
Drone.extend(spawn);

View file

@ -21,23 +21,12 @@ or <http://docs.visualillusionsent.net/CanaryLib/1.0.0/net/canarymod/api/entity/
for a list of possible entities (creatures) which can be spawned.
***/
var entities = [],
entityType = null,
entitytypes,
t;
if (__plugin.bukkit) {
entityType = org.bukkit.entity.EntityType;
var entities = require('entities'),
spawn = require('spawn');
var entityNames = [];
for (var name in entities){
entityNames.push(name);
}
if (__plugin.canary) {
entityType = Packages.net.canarymod.api.entity.EntityType;
}
entitytypes = entityType.values();
for (t in entitytypes) {
if (entitytypes[t] && entitytypes[t].ordinal) {
entities.push(entitytypes[t].name());
}
}
command('spawn', function (parameters, sender) {
if (!isOp(sender)) {
echo(sender, 'Only operators can perform this command');
@ -48,14 +37,6 @@ command('spawn', function (parameters, sender) {
echo(sender, 'You have no location. This command only works in-game.');
return;
}
var world = location.world || sender.world,
type = ('' + parameters[0]).toUpperCase();
if (__plugin.bukkit) {
world.spawnEntity(location, entityType[type]);
}
if (__plugin.canary) {
var Canary = Packages.net.canarymod.Canary,
entity = Canary.factory().entityFactory.newEntity(entityType[type], location);
entity.spawn();
}
}, entities);
var name = ('' + parameters[0]).toUpperCase();
spawn( name, sender.location);
}, entityNames);