Added lightning module
This commit is contained in:
parent
46405978f5
commit
aa42b74119
7 changed files with 224 additions and 14 deletions
|
@ -89,16 +89,24 @@
|
||||||
err="${dist}/gen-api-error.log">
|
err="${dist}/gen-api-error.log">
|
||||||
<arg value="${dist}/js"/>
|
<arg value="${dist}/js"/>
|
||||||
</jscript>
|
</jscript>
|
||||||
|
|
||||||
<jscript src="src/docs/js/generateItemsDoc.js"
|
<jscript src="src/docs/js/generateItemsDoc.js"
|
||||||
out="${dist}/items.md"
|
out="${dist}/items.md"
|
||||||
err="${dist}/gen-items-error.log" />
|
err="${dist}/gen-items-error.log" />
|
||||||
|
|
||||||
|
<jscript src="src/docs/js/generateEntitiesDoc.js"
|
||||||
|
out="${dist}/entities.md"
|
||||||
|
err="${dist}/gen-entities-error.log" />
|
||||||
|
|
||||||
<concat destfile="${dist}/apiref-con.md">
|
<concat destfile="${dist}/apiref-con.md">
|
||||||
<fileset file="${dist}/apiref.md" />
|
<fileset file="${dist}/apiref.md" />
|
||||||
<fileset file="${dist}/items.md" />
|
<fileset file="${dist}/items.md" />
|
||||||
|
<fileset file="${dist}/entities.md" />
|
||||||
</concat>
|
</concat>
|
||||||
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
||||||
<target name="gen-events-helper-canary" depends="compile-docs,init">
|
<target name="gen-events-helper-canary" depends="compile-docs,init">
|
||||||
<mkdir dir="${dist}/js/lib"/>
|
<mkdir dir="${dist}/js/lib"/>
|
||||||
<jscript src="src/docs/js/generateEventsHelper.js"
|
<jscript src="src/docs/js/generateEventsHelper.js"
|
||||||
|
|
|
@ -407,12 +407,14 @@ Walter Higgins
|
||||||
* [jsp classroom command](#jsp-classroom-command)
|
* [jsp classroom command](#jsp-classroom-command)
|
||||||
* [classroom.allowScripting() function](#classroomallowscripting-function)
|
* [classroom.allowScripting() function](#classroomallowscripting-function)
|
||||||
* [Asynchronous Input Module](#asynchronous-input-module)
|
* [Asynchronous Input Module](#asynchronous-input-module)
|
||||||
|
* [Lightning module](#lightning-module)
|
||||||
|
* [Usage](#usage-3)
|
||||||
* [The recipes module](#the-recipes-module)
|
* [The recipes module](#the-recipes-module)
|
||||||
* [Example](#example-1)
|
* [Example](#example-1)
|
||||||
* [Http Module](#http-module)
|
* [Http Module](#http-module)
|
||||||
* [http.request() function](#httprequest-function)
|
* [http.request() function](#httprequest-function)
|
||||||
* [sc-mqtt module](#sc-mqtt-module)
|
* [sc-mqtt module](#sc-mqtt-module)
|
||||||
* [Usage](#usage-3)
|
* [Usage](#usage-4)
|
||||||
* [Signs Module](#signs-module)
|
* [Signs Module](#signs-module)
|
||||||
* [signs.menu() function](#signsmenu-function)
|
* [signs.menu() function](#signsmenu-function)
|
||||||
* [signs.getTargetedBy() function](#signsgettargetedby-function)
|
* [signs.getTargetedBy() function](#signsgettargetedby-function)
|
||||||
|
@ -448,22 +450,22 @@ Walter Higgins
|
||||||
* [watcher.unwatchFile() function](#watcherunwatchfile-function)
|
* [watcher.unwatchFile() function](#watcherunwatchfile-function)
|
||||||
* [watcher.unwatchDir() function](#watcherunwatchdir-function)
|
* [watcher.unwatchDir() function](#watcherunwatchdir-function)
|
||||||
* [Example Plugin #1 - A simple extension to Minecraft.](#example-plugin-1---a-simple-extension-to-minecraft)
|
* [Example Plugin #1 - A simple extension to Minecraft.](#example-plugin-1---a-simple-extension-to-minecraft)
|
||||||
* [Usage:](#usage-4)
|
|
||||||
* [Example Plugin #2 - Making extensions available for all players.](#example-plugin-2---making-extensions-available-for-all-players)
|
|
||||||
* [Usage:](#usage-5)
|
* [Usage:](#usage-5)
|
||||||
* [Example Plugin #3 - Limiting use of commands to operators only.](#example-plugin-3---limiting-use-of-commands-to-operators-only)
|
* [Example Plugin #2 - Making extensions available for all players.](#example-plugin-2---making-extensions-available-for-all-players)
|
||||||
* [Usage:](#usage-6)
|
* [Usage:](#usage-6)
|
||||||
* [Example Plugin #4 - Using parameters in commands.](#example-plugin-4---using-parameters-in-commands)
|
* [Example Plugin #3 - Limiting use of commands to operators only.](#example-plugin-3---limiting-use-of-commands-to-operators-only)
|
||||||
* [Usage:](#usage-7)
|
* [Usage:](#usage-7)
|
||||||
* [Example Plugin #5 - Re-use - Using your own and others modules.](#example-plugin-5---re-use---using-your-own-and-others-modules)
|
* [Example Plugin #4 - Using parameters in commands.](#example-plugin-4---using-parameters-in-commands)
|
||||||
* [Usage:](#usage-8)
|
* [Usage:](#usage-8)
|
||||||
* [Example Plugin #6 - Re-use - Using 'utils' to get Player objects.](#example-plugin-6---re-use---using-utils-to-get-player-objects)
|
* [Example Plugin #5 - Re-use - Using your own and others modules.](#example-plugin-5---re-use---using-your-own-and-others-modules)
|
||||||
* [Usage:](#usage-9)
|
* [Usage:](#usage-9)
|
||||||
|
* [Example Plugin #6 - Re-use - Using 'utils' to get Player objects.](#example-plugin-6---re-use---using-utils-to-get-player-objects)
|
||||||
|
* [Usage:](#usage-10)
|
||||||
* [Example Plugin #7 - Listening for events, Greet players when they join the game.](#example-plugin-7---listening-for-events-greet-players-when-they-join-the-game)
|
* [Example Plugin #7 - Listening for events, Greet players when they join the game.](#example-plugin-7---listening-for-events-greet-players-when-they-join-the-game)
|
||||||
* [Arrows Plugin](#arrows-plugin)
|
* [Arrows Plugin](#arrows-plugin)
|
||||||
* [Usage:](#usage-10)
|
* [Usage:](#usage-11)
|
||||||
* [Spawn Plugin](#spawn-plugin)
|
* [Spawn Plugin](#spawn-plugin)
|
||||||
* [Usage](#usage-11)
|
* [Usage](#usage-12)
|
||||||
* [alias Plugin](#alias-plugin)
|
* [alias Plugin](#alias-plugin)
|
||||||
* [Examples](#examples-2)
|
* [Examples](#examples-2)
|
||||||
* [Commando Plugin](#commando-plugin)
|
* [Commando Plugin](#commando-plugin)
|
||||||
|
@ -483,7 +485,9 @@ Walter Higgins
|
||||||
* [Rules](#rules)
|
* [Rules](#rules)
|
||||||
* [Gameplay Mechanics](#gameplay-mechanics)
|
* [Gameplay Mechanics](#gameplay-mechanics)
|
||||||
* [Items module](#items-module)
|
* [Items module](#items-module)
|
||||||
* [Usage](#usage-12)
|
* [Usage](#usage-13)
|
||||||
|
* [Entities module](#entities-module)
|
||||||
|
* [Usage](#usage-14)
|
||||||
|
|
||||||
## Modules in Scriptcraft
|
## Modules in Scriptcraft
|
||||||
|
|
||||||
|
@ -4854,6 +4858,23 @@ The callback function as well as being bound to an object with the above propert
|
||||||
|
|
||||||
The `value` parameter will be the same as `this.value`, the `repeat` parameter will be the same as `this.repeat` and so on.
|
The `value` parameter will be the same as `this.value`, the `repeat` parameter will be the same as `this.repeat` and so on.
|
||||||
|
|
||||||
|
## Lightning module
|
||||||
|
|
||||||
|
Causes a bolt of lightning to strike.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
```javascript
|
||||||
|
// strike lightning wherever a player's arrow lands
|
||||||
|
var lightning = require('lightning');
|
||||||
|
events.projectileHit( function( event ){
|
||||||
|
if ( entities.arrow( event.projectile ) // it's an arrow
|
||||||
|
&& entities.player( event.projectile.owner ) // it was shot by a player
|
||||||
|
) {
|
||||||
|
lightning( event.projectile ); // strike lightning at the arrow location
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## The recipes module
|
## The recipes module
|
||||||
|
|
||||||
The Recipes module provides convenience functions for adding and removing recipes
|
The Recipes module provides convenience functions for adding and removing recipes
|
||||||
|
@ -6695,3 +6716,84 @@ The following functions are provided:
|
||||||
* zombieHead()
|
* zombieHead()
|
||||||
|
|
||||||
***/
|
***/
|
||||||
|
/*********************
|
||||||
|
## Entities module
|
||||||
|
The Entities module provides a suite of functions - one for each possible entity type.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
entities.zombie(); // returns a canaryMod/Bukkit EntityType.ZOMBIE enum value
|
||||||
|
entities.zombie( mob ); // compares the entity's type to a zombie, returns true if mob type is zombie, false otherwise
|
||||||
|
entities.player( self ); // at the in-game prompt this should return true (compares self to a player entity type)
|
||||||
|
entities.rabbit( self ); // at the in-game prompt this should return false (compares self to a rabbit entity type)
|
||||||
|
|
||||||
|
The following functions are provided:
|
||||||
|
|
||||||
|
* aRMOR_STAND()
|
||||||
|
* aRROW()
|
||||||
|
* bAT()
|
||||||
|
* bLAZE()
|
||||||
|
* bOAT()
|
||||||
|
* cAVE_SPIDER()
|
||||||
|
* cHICKEN()
|
||||||
|
* cOMPLEX_PART()
|
||||||
|
* cOW()
|
||||||
|
* cREEPER()
|
||||||
|
* dROPPED_ITEM()
|
||||||
|
* eGG()
|
||||||
|
* eNDERMAN()
|
||||||
|
* eNDERMITE()
|
||||||
|
* eNDER_CRYSTAL()
|
||||||
|
* eNDER_DRAGON()
|
||||||
|
* eNDER_PEARL()
|
||||||
|
* eNDER_SIGNAL()
|
||||||
|
* eXPERIENCE_ORB()
|
||||||
|
* fALLING_BLOCK()
|
||||||
|
* fIREBALL()
|
||||||
|
* fIREWORK()
|
||||||
|
* fISHING_HOOK()
|
||||||
|
* gHAST()
|
||||||
|
* gIANT()
|
||||||
|
* gUARDIAN()
|
||||||
|
* hORSE()
|
||||||
|
* iRON_GOLEM()
|
||||||
|
* iTEM_FRAME()
|
||||||
|
* lEASH_HITCH()
|
||||||
|
* lIGHTNING()
|
||||||
|
* mAGMA_CUBE()
|
||||||
|
* mINECART()
|
||||||
|
* mINECART_CHEST()
|
||||||
|
* mINECART_COMMAND()
|
||||||
|
* mINECART_FURNACE()
|
||||||
|
* mINECART_HOPPER()
|
||||||
|
* mINECART_MOB_SPAWNER()
|
||||||
|
* mINECART_TNT()
|
||||||
|
* mUSHROOM_COW()
|
||||||
|
* oCELOT()
|
||||||
|
* pAINTING()
|
||||||
|
* pIG()
|
||||||
|
* pIG_ZOMBIE()
|
||||||
|
* pLAYER()
|
||||||
|
* pRIMED_TNT()
|
||||||
|
* rABBIT()
|
||||||
|
* sHEEP()
|
||||||
|
* sILVERFISH()
|
||||||
|
* sKELETON()
|
||||||
|
* sLIME()
|
||||||
|
* sMALL_FIREBALL()
|
||||||
|
* sNOWBALL()
|
||||||
|
* sNOWMAN()
|
||||||
|
* sPIDER()
|
||||||
|
* sPLASH_POTION()
|
||||||
|
* sQUID()
|
||||||
|
* tHROWN_EXP_BOTTLE()
|
||||||
|
* uNKNOWN()
|
||||||
|
* vILLAGER()
|
||||||
|
* wEATHER()
|
||||||
|
* wITCH()
|
||||||
|
* wITHER()
|
||||||
|
* wITHER_SKULL()
|
||||||
|
* wOLF()
|
||||||
|
* zOMBIE()
|
||||||
|
|
||||||
|
***/
|
||||||
|
|
40
src/docs/js/generateEntitiesDoc.js
Normal file
40
src/docs/js/generateEntitiesDoc.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
args = Array.prototype.slice.call(args,1);
|
||||||
|
// [0] = type, [1] = lib.jar [2] = blockX, [3] = classX
|
||||||
|
var out = java.lang.System.out,
|
||||||
|
err = java.lang.System.err,
|
||||||
|
entry = null;
|
||||||
|
var content = [
|
||||||
|
'/*********************',
|
||||||
|
'## Entities module',
|
||||||
|
'The Entities module provides a suite of functions - one for each possible entity type.',
|
||||||
|
'',
|
||||||
|
'### Usage',
|
||||||
|
'',
|
||||||
|
' entities.zombie(); // returns a canaryMod/Bukkit EntityType.ZOMBIE enum value',
|
||||||
|
' entities.zombie( mob ); // compares the entity\'s type to a zombie, returns true if mob type is zombie, false otherwise',
|
||||||
|
' entities.player( self ); // at the in-game prompt this should return true (compares self to a player entity type)',
|
||||||
|
' entities.rabbit( self ); // at the in-game prompt this should return false (compares self to a rabbit entity type)',
|
||||||
|
'',
|
||||||
|
'The following functions are provided:',
|
||||||
|
''
|
||||||
|
];
|
||||||
|
|
||||||
|
var enumVals = [], t, i, name;
|
||||||
|
var entitytypes = org.bukkit.entity.EntityType.values();
|
||||||
|
for (t in entitytypes) {
|
||||||
|
if (entitytypes[t] && entitytypes[t].ordinal) {
|
||||||
|
name = entitytypes[t].name();
|
||||||
|
name = ('' + name).replace(/^(.)/,function(a){ return a.toLowerCase(); });
|
||||||
|
enumVals.push(' * ' + name + '()');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
enumVals.sort();
|
||||||
|
content = content.concat(enumVals);
|
||||||
|
content.push('');
|
||||||
|
content.push('***/');
|
||||||
|
for (i = 0; i< content.length; i++){
|
||||||
|
out.println(content[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*global __plugin, org, Packages, module, exports*/
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
/*global __plugin, org, Packages, module, exports*/
|
||||||
var entities = {},
|
var entities = {},
|
||||||
entitytypes,
|
entitytypes,
|
||||||
t, i, name;
|
t, i, name;
|
||||||
|
@ -9,10 +9,30 @@ if (__plugin.bukkit) {
|
||||||
if (__plugin.canary) {
|
if (__plugin.canary) {
|
||||||
entitytypes = Packages.net.canarymod.api.entity.EntityType.values();
|
entitytypes = Packages.net.canarymod.api.entity.EntityType.values();
|
||||||
}
|
}
|
||||||
|
function getEntityHandler( entityType ) {
|
||||||
|
return function( entity ){
|
||||||
|
if (arguments.length == 0){
|
||||||
|
return entityType;
|
||||||
|
}
|
||||||
|
if (arguments.length == 1){
|
||||||
|
if (entity){
|
||||||
|
if (__plugin.bukkit){
|
||||||
|
return entity.type == entityType;
|
||||||
|
}
|
||||||
|
if (__plugin.canary){
|
||||||
|
return entity.entityType == entityType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
for (t in entitytypes) {
|
for (t in entitytypes) {
|
||||||
if (entitytypes[t] && entitytypes[t].ordinal) {
|
if (entitytypes[t] && entitytypes[t].ordinal) {
|
||||||
name = entitytypes[t].name();
|
name = ('' + entitytypes[t].name()).replace(/^(.*)/,function(a){
|
||||||
entities[name] = entitytypes[t];
|
return a.toLowerCase();
|
||||||
|
});
|
||||||
|
entities[name] = getEntityHandler(entitytypes[t]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = entities;
|
module.exports = entities;
|
||||||
|
|
30
src/main/js/modules/lightning.js
Normal file
30
src/main/js/modules/lightning.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
'use strict';
|
||||||
|
/************************************************************************
|
||||||
|
## Lightning module
|
||||||
|
|
||||||
|
Causes a bolt of lightning to strike.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
```javascript
|
||||||
|
// strike lightning wherever a player's arrow lands
|
||||||
|
var lightning = require('lightning');
|
||||||
|
events.projectileHit( function( event ){
|
||||||
|
if ( entities.arrow( event.projectile ) // it's an arrow
|
||||||
|
&& entities.player( event.projectile.owner ) // it was shot by a player
|
||||||
|
) {
|
||||||
|
lightning( event.projectile ); // strike lightning at the arrow location
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
***/
|
||||||
|
module.exports = function lightning( something ) {
|
||||||
|
if (__plugin.canary && something.location){
|
||||||
|
return something.location.world.makeLightningBolt(something.location);
|
||||||
|
}
|
||||||
|
if (__plugin.bukkit && something.location){
|
||||||
|
return something.location.world.strikeLightning(something.location);
|
||||||
|
}
|
||||||
|
console.log('Need an object with a location property for lightning strike');
|
||||||
|
return null;
|
||||||
|
};
|
|
@ -3,8 +3,10 @@
|
||||||
var entities = require('entities');
|
var entities = require('entities');
|
||||||
|
|
||||||
module.exports = function(entityType, location){
|
module.exports = function(entityType, location){
|
||||||
|
var entityTypeFn;
|
||||||
if (typeof entityType === 'string'){
|
if (typeof entityType === 'string'){
|
||||||
entityType = entities[entityType];
|
entityTypeFn = entities[entityType.toLowerCase()];
|
||||||
|
entityType = entityTypeFn();
|
||||||
}
|
}
|
||||||
var world = location.world;
|
var world = location.world;
|
||||||
if (__plugin.bukkit){
|
if (__plugin.bukkit){
|
||||||
|
|
8
src/main/js/plugins/entities.js
Normal file
8
src/main/js/plugins/entities.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
'use strict';
|
||||||
|
/*global reuire, exports*/
|
||||||
|
/*
|
||||||
|
make entities a global variable for use at in-game prompt
|
||||||
|
Tab completion is a useful way to discover what entity types are available.
|
||||||
|
*/
|
||||||
|
var entities = require('entities');
|
||||||
|
exports.entities = entities;
|
Reference in a new issue