Skip to content

Commit

Permalink
added new entities and spawn modules
Browse files Browse the repository at this point in the history
  • Loading branch information
walterhiggins committed Nov 21, 2015
1 parent 4aa28c0 commit e285bb6
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scriptcraft-version=3.1.10
scriptcraft-version=3.1.11
17 changes: 17 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -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)
---------------------------
Expand Down
18 changes: 18 additions & 0 deletions src/main/js/modules/entities.js
Original file line number Diff line number Diff line change
@@ -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;
18 changes: 18 additions & 0 deletions src/main/js/modules/spawn.js
Original file line number Diff line number Diff line change
@@ -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();
}
};
8 changes: 8 additions & 0 deletions src/main/js/plugins/drone/contrib/spawn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';
var spawnFn = require('spawn'),
Drone = require('drone')
;
function spawn(entityType){
spawnFn(entityType, this.getBlock().location);
}
Drone.extend(spawn);
35 changes: 8 additions & 27 deletions src/main/js/plugins/spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

0 comments on commit e285bb6

Please sign in to comment.