Skip to content

Commit e285bb6

Browse files
committed
added new entities and spawn modules
1 parent 4aa28c0 commit e285bb6

File tree

6 files changed

+70
-28
lines changed

6 files changed

+70
-28
lines changed

build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
scriptcraft-version=3.1.10
1+
scriptcraft-version=3.1.11

release-notes.md

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
RELEASE NOTES
22
=============
3+
3.1.11 Release (2015 11 21)
4+
---------------------------
5+
6+
Added new modules
7+
8+
* entities
9+
* spawn
10+
11+
And new Drone function `spawn()`
12+
13+
To use:
14+
Point at a block then type...
15+
```
16+
/js spawn('ZOMBIE').fwd().times(5).right().back(5).times(6)
17+
```
18+
19+
... unleash a horde of zombies (in 5x6 grid formation).
320

421
3.1.10 Release (2015 08 16)
522
---------------------------

src/main/js/modules/entities.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*global __plugin, org, Packages, module, exports*/
2+
'use strict';
3+
var entities = {},
4+
entitytypes,
5+
t, i, name;
6+
if (__plugin.bukkit) {
7+
entitytypes = org.bukkit.entity.EntityType.values();
8+
}
9+
if (__plugin.canary) {
10+
entitytypes = Packages.net.canarymod.api.entity.EntityType.values();
11+
}
12+
for (t in entitytypes) {
13+
if (entitytypes[t] && entitytypes[t].ordinal) {
14+
name = entitytypes[t].name();
15+
entities[name] = entitytypes[t];
16+
}
17+
}
18+
module.exports = entities;

src/main/js/modules/spawn.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*global require, module, __plugin, Packages*/
2+
'use strict';
3+
var entities = require('entities');
4+
5+
module.exports = function(entityType, location){
6+
if (typeof entityType === 'string'){
7+
entityType = entities[entityType];
8+
}
9+
var world = location.world;
10+
if (__plugin.bukkit){
11+
world.spawnEntity( location, entityType);
12+
}
13+
if (__plugin.canary){
14+
var Canary = Packages.net.canarymod.Canary,
15+
entityInstance = Canary.factory().entityFactory.newEntity(entityType, location);
16+
entityInstance.spawn();
17+
}
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
var spawnFn = require('spawn'),
3+
Drone = require('drone')
4+
;
5+
function spawn(entityType){
6+
spawnFn(entityType, this.getBlock().location);
7+
}
8+
Drone.extend(spawn);

src/main/js/plugins/spawn.js

+8-27
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,12 @@ or <http://docs.visualillusionsent.net/CanaryLib/1.0.0/net/canarymod/api/entity/
2121
for a list of possible entities (creatures) which can be spawned.
2222
2323
***/
24-
var entities = [],
25-
entityType = null,
26-
entitytypes,
27-
t;
28-
if (__plugin.bukkit) {
29-
entityType = org.bukkit.entity.EntityType;
24+
var entities = require('entities'),
25+
spawn = require('spawn');
26+
var entityNames = [];
27+
for (var name in entities){
28+
entityNames.push(name);
3029
}
31-
if (__plugin.canary) {
32-
entityType = Packages.net.canarymod.api.entity.EntityType;
33-
}
34-
entitytypes = entityType.values();
35-
for (t in entitytypes) {
36-
if (entitytypes[t] && entitytypes[t].ordinal) {
37-
entities.push(entitytypes[t].name());
38-
}
39-
}
40-
4130
command('spawn', function (parameters, sender) {
4231
if (!isOp(sender)) {
4332
echo(sender, 'Only operators can perform this command');
@@ -48,14 +37,6 @@ command('spawn', function (parameters, sender) {
4837
echo(sender, 'You have no location. This command only works in-game.');
4938
return;
5039
}
51-
var world = location.world || sender.world,
52-
type = ('' + parameters[0]).toUpperCase();
53-
if (__plugin.bukkit) {
54-
world.spawnEntity(location, entityType[type]);
55-
}
56-
if (__plugin.canary) {
57-
var Canary = Packages.net.canarymod.Canary,
58-
entity = Canary.factory().entityFactory.newEntity(entityType[type], location);
59-
entity.spawn();
60-
}
61-
}, entities);
40+
var name = ('' + parameters[0]).toUpperCase();
41+
spawn( name, sender.location);
42+
}, entityNames);

0 commit comments

Comments
 (0)