2016-10-08 13:17:42 +02:00
# ScriptCraft - Modding Minecraft with Javascript
2016-10-08 13:15:05 +02:00
2014-11-23 09:46:26 +01:00
[![Gitter ](https://badges.gitter.im/Join Chat.svg )](https://gitter.im/walterhiggins/ScriptCraft?utm_source=badge& utm_medium=badge& utm_campaign=pr-badge& utm_content=badge)
2013-12-19 11:43:37 +01:00
2016-09-09 23:18:47 +02:00
ScriptCraft lets you write Minecraft Mods using Javascript - a
programming language that's relatively easy to learn and use.
ScriptCraft is a Minecraft Server plugin which means it must be used
with a Minecraft server. Once you've downloaded and installed the
Minecraft Server, then installed the ScriptCraft Plugin you can write
your own Minecraft mods using Javascript.
2013-12-24 23:47:57 +01:00
I created ScriptCraft to make it easier for younger programmers to
2014-01-02 11:37:34 +01:00
create their own Minecraft Mods. Mods are written using the
2015-04-16 22:02:22 +02:00
JavaScript programming language. Once the ScriptCraft mod is
installed, you can add your own new Mods by adding JavaScript (.js)
2013-12-24 23:47:57 +01:00
files in a directory.
2013-12-19 11:43:37 +01:00
2015-01-11 09:26:16 +01:00
* If you're new to programming and want to start modding Minecraft, then [Start Here][yp].
2013-12-31 09:47:28 +01:00
* If you've already used [Scratch][scr], have attended a few
2015-04-16 22:02:22 +02:00
[CoderDojo][cd] sessions, or have already dabbled with JavaScript,
2013-12-31 09:47:28 +01:00
then [Start Here][cda].
2013-12-19 12:06:17 +01:00
* Watch some [demos][ytpl] of what you can do with ScriptCraft.
2016-10-08 13:15:05 +02:00
This is a simple mod in a file called greet.js in the scriptcraft/plugins directory:
2014-01-02 11:44:26 +01:00
2014-01-30 01:41:59 +01:00
```javascript
2015-01-11 09:53:41 +01:00
function greet( player ) {
echo( player, 'Hello ' + player.name );
}
exports.greet = greet;
2014-01-30 01:41:59 +01:00
```
2014-01-02 11:44:26 +01:00
2015-01-11 09:53:41 +01:00
At the in-game prompt, type:
2014-01-02 11:44:26 +01:00
2015-01-11 09:53:41 +01:00
```javascript
/js greet(self)
```
2014-01-30 01:41:59 +01:00
2016-09-09 23:18:47 +02:00
Anything you can do using the Spigot or CanaryMod APIs in Java,
2015-04-16 22:02:22 +02:00
you can do using ScriptCraft in JavaScript.
2014-01-02 11:44:26 +01:00
2013-12-19 12:06:17 +01:00
# Description
2013-12-19 11:43:37 +01:00
2013-12-31 09:47:28 +01:00
ScriptCraft is a plugin for Minecraft Servers which lets operators,
administrators and plug-in authors customize the game using
2015-04-16 22:02:22 +02:00
JavaScript. ScriptCraft makes it easier to create your own mods. Mods
2016-09-09 23:18:47 +02:00
can be written in Javscript and can use the full [SpigotMC
API][spigot] or [CanaryMod API][cm]. ScriptCraft works with all of the
following Minecraft Server software:
2015-01-11 09:53:41 +01:00
2016-09-09 23:18:47 +02:00
* [SpigotMC][spigot] (Recommended)
* [GlowStone][gs]
* [CanaryMod][cm]
2015-01-11 09:53:41 +01:00
[spigot]: http://www.spigotmc.org/
[gs]: http://www.glowstone.net/
2016-10-08 13:15:05 +02:00
[cm]: http://canarymod.net/
2015-01-11 09:53:41 +01:00
2016-09-09 23:18:47 +02:00
I recommend using SpigotMC because both CanaryMod and CraftBukkit are
no longer being actively developed. The ScriptCraft mod also lets you
enter javascript commands at the in-game prompt. To bring up the
in-game prompt press the `/` key then type `js ` followed by any
2015-01-11 09:53:41 +01:00
javascript statement. For example: `/js 1 + 1` will print 2.
2013-01-25 00:46:28 +01:00
2013-12-24 23:47:57 +01:00
ScriptCraft also includes many objects and functions to make building
2015-04-16 22:02:22 +02:00
and modding easier using JavaScript. The JavaScript `Drone` object
2013-12-24 23:47:57 +01:00
bundled with ScriptCraft provides an easy way to build at-scale in
2014-11-28 22:59:23 +01:00
Minecraft. See the attached [temple.js][temple] file for an example
2013-12-24 23:47:57 +01:00
of how you can use the sample Drone plugin to create new buildings in
2013-01-25 00:46:28 +01:00
Minecraft.
2013-01-08 03:57:27 +01:00
2013-01-25 00:46:28 +01:00
[drone]: https://github.com/walterhiggins/ScriptCraft/tree/master/src/main/javascript/drone/drone.js
2014-11-28 22:59:23 +01:00
[cottage]: https://github.com/walterhiggins/ScriptCraft/tree/master/src/main/js/plugins/drone/contrib/cottage.js
[temple]: https://github.com/walterhiggins/ScriptCraft/blob/master/src/main/js/plugins/drone/contrib/temple.js
2014-01-02 11:37:34 +01:00
[bukkit]: http://dl.bukkit.org/
2013-01-08 03:57:27 +01:00
2014-01-15 00:25:00 +01:00
# Prerequisites
2016-10-08 13:15:05 +02:00
ScriptCraft is a Minecraft Server Mod which only works with Minecraft
for Personal computers (Windows, Mac and Linux). It does not work with
X-BOX, Playstation or WiiU versions of the game. You will need to have
Java version 7 or later installed. Check the version by typing `java
-version` at a command prompt.
2013-01-25 00:46:28 +01:00
2014-01-15 00:25:00 +01:00
# Installation
2016-10-08 13:15:05 +02:00
Before installing ScriptCraft you must first install SpigotMC which is
a special version of Minecraft Server that makes it easy to customize
the game.
2016-09-09 23:18:47 +02:00
## Installing and Running SpigotMC
2016-10-08 13:15:05 +02:00
Follow these steps to download and install SpigotMC.
2016-09-09 23:26:09 +02:00
2016-09-09 23:18:47 +02:00
1. Download Spigot's [BuildTools.jar][spigotdl]
2. Save the BuildTools.jar file to a new directory called spigotmc.
3. Open a terminal (Mac and Linux) or command prompt (windows) window and type `java -jar BuildTools.jar` . This will kick off a long series of commands to "build" SpigotMC.
4. When the build is done, there will be a new file beginning with `spigot` and ending in `.jar` in the spigotmc directory. Run this file by typing `java -jar spigot-1.10.2.jar` (it might not be that exact name - you can list files in the directory by typing `dir` (Windows) or `ls` (Mac and Linux).
5. The server will start up then shut down very shortly afterwards. You'll need to edit a file called `eula.txt` - change `eula=false` to `eula=true` and save the file.
2016-09-10 13:12:13 +02:00
6. Run the `java -jar spigot-1.10.2.jar` command again - this time the server will start up. Shut it down by typing `stop` at the server prompt.
2016-10-08 13:15:05 +02:00
## Installing ScriptCraft
Follow these steps to download and install ScriptCraft.
1. Download the [scriptcraft.jar][dl] plugin and save it to the `plugins` directory and restart the server by typing `java -jar spigot-1.10.2.jar` .
2. At the server prompt type `js 1 + 1` and hit enter. The result `2` should be displayed.
2016-09-09 23:18:47 +02:00
Congratulations - you've just installed your Custom Minecraft Server and are ready to begin writing your first mod!
2013-01-25 00:46:28 +01:00
2014-01-15 00:25:00 +01:00
# Post Install
2015-01-11 09:53:41 +01:00
Once installed, a new scriptcraft/plugins directory is automatically
created. All files in the scriptcraft/plugins directory will be
automatically loaded when the server starts. *Only players who are
ops can use this plugin.* You can grant a player `op` privileges by
2016-09-10 13:12:13 +02:00
typing 'op < username > ' (replacing < username > with your own Minecraft
user name) at the server console prompt or by adding the player's
username to the ops.txt file in your server directory.
2013-01-25 00:46:28 +01:00
2014-11-03 21:29:42 +01:00
Launch the server, then launch the Minecraft client and create a new
2013-01-25 00:46:28 +01:00
server connection. The IP address will be `localhost` . Once you've
2014-11-03 21:29:42 +01:00
connected to your server and have entered the game, look at a
2016-10-08 13:15:05 +02:00
ground-level block and type:
2013-01-25 00:46:28 +01:00
2014-11-03 21:29:42 +01:00
/js up().box( blocks.wool.black, 4, 9, 1 )
2013-01-25 00:46:28 +01:00
2015-04-16 22:02:22 +02:00
… This will create a black monolith structure 4 blocks wide by 9
2013-01-25 00:46:28 +01:00
blocks high by 1 block long. Take a look at the
src/main/javascript/drone/drone.js file to see what ScriptCraft's
2016-09-10 13:12:13 +02:00
drone can do.
If you're interested in customizing minecraft beyond just creating new buildings, take a look at [the homes mod][homes] for an example of how to create a more fully-featured JavaScript plugin for Minecraft.
## Your first mod - Howling blocks
Listed below is a simple mod that will make blocks 'Howl' when they're broken.
``` javascript
// copy and paste this code to a new file named 'scriptcraft/plugins/howling-blocks.js'
var sounds = require('sounds');
function howl(event){
sounds.entityWolfHowl( event.block );
}
events.blockBreak( howl );
```
2013-01-25 00:46:28 +01:00
2016-09-10 13:34:39 +02:00
If you're using CanaryMod instead of SpigotMC you can [download the equivalent code ](https://gist.github.com/walterhiggins/69cddd15160d803fb096 ).
2015-04-16 22:02:22 +02:00
A JavaScript mod for minecraft is just a JavaScript source file (.js)
2015-01-11 09:53:41 +01:00
located in the scriptcraft/plugins directory. All .js files in this
2016-09-10 13:12:13 +02:00
directory will be automatically loaded when the server starts.
To get started writing your own mod, take a look at some of the
2015-01-11 09:53:41 +01:00
[examples][examples].
2015-04-16 22:02:22 +02:00
[homes]: src/main/js/plugins/homes/homes.js
2015-01-11 09:53:41 +01:00
[examples]: src/main/js/plugins/examples/
2013-01-25 00:46:28 +01:00
2014-01-15 00:25:00 +01:00
# Additional information
2016-09-09 23:18:47 +02:00
Because the SpigotMC API is open, all of the SpigotMC API is accessible
2013-12-31 09:47:28 +01:00
via javascript once the ScriptCraft plugin is loaded. There are a
2014-11-03 21:29:42 +01:00
couple of useful Java objects exposed via javascript in the
2016-10-08 13:15:05 +02:00
ScriptCraft plugin:
2013-01-25 00:46:28 +01:00
2015-04-16 22:02:22 +02:00
* `__plugin` – the ScriptCraft Plugin itself. This is a useful
2016-09-09 23:18:47 +02:00
starting point for accessing other SpigotMC objects. The `__plugin`
object is of type [org.bukkit.plugin.Plugin][api] and all
2016-10-08 13:15:05 +02:00
of its properties and methods are accessible. For example: `js
2014-11-03 21:29:42 +01:00
__plugin.name` returns the plugin's name
2015-04-16 22:02:22 +02:00
(JavaScript is more concise than the equivalent Java code:
`__plugin.getName()` ).
2013-12-31 09:47:28 +01:00
2016-09-09 23:18:47 +02:00
* `server` – The top-level org.bukkit.Server object. See the [SpigotMC API docs][spigotapi] for reference.
2013-12-31 09:47:28 +01:00
2015-04-16 22:02:22 +02:00
* `self` – The player/command-block or server console operator who
2013-12-31 09:47:28 +01:00
invoked the `/js` command. Again, this is a good jumping off point for
2016-09-09 23:18:47 +02:00
diving into the SpigotMC API.
2013-01-25 00:46:28 +01:00
2015-01-11 09:58:33 +01:00
[dl]: http://scriptcraftjs.org/download/latest
2016-09-09 23:18:47 +02:00
[api]: https://hub.spigotmc.org/javadocs/spigot/
2014-11-03 21:29:42 +01:00
[ic]: http://canarymod.net/releases
2016-09-09 23:18:47 +02:00
[spigotdl]: https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
2014-11-03 21:29:42 +01:00
[cmapi]: https://ci.visualillusionsent.net/job/CanaryLib/javadoc/
2016-09-09 23:18:47 +02:00
[spigotapi]: https://hub.spigotmc.org/javadocs/spigot/
2012-12-27 14:21:08 +01:00
2014-01-15 00:25:00 +01:00
# Contributing
2014-01-13 22:56:21 +01:00
If you would like to contribute source code and/or documentation changes please [read contributing.md][contrib]
2014-01-15 00:25:00 +01:00
## Status
[![Travis Build Status ](https://api.travis-ci.org/walterhiggins/ScriptCraft.png )](http://travis-ci.org/walterhiggins/ScriptCraft)
2014-12-26 10:55:35 +01:00
# Bukkit Configuration
2015-03-19 15:23:23 +01:00
## (You can ignore this if using CanaryMod)
2014-01-15 00:25:00 +01:00
2016-09-09 23:18:47 +02:00
ScriptCraft works with Bukkit Plugin and uses the Bukkit Configuration
2014-01-15 00:01:20 +01:00
API. On first loading, ScriptCraft will create a config.yml file in
2016-10-08 13:15:05 +02:00
the plugins/scriptcraft/ directory. This file looks like this:
2014-01-15 00:01:20 +01:00
extract-js:
plugins: true
modules: true
lib: true
This file allows scriptcraft admins to turn on or off re-unzipping of the `modules` ,
`plugins` and `lib` folders when deploying a new version of
2015-04-16 22:02:22 +02:00
ScriptCraft. It's strongly recommended that the `lib` directory always
be set to true to get the latest core ScriptCraft code . The modules
and plugins directories are optional and not part of ScriptCraft core.
2014-01-15 00:01:20 +01:00
2014-01-15 00:25:00 +01:00
# Further Reading
2013-01-25 09:16:35 +01:00
2013-02-22 17:51:01 +01:00
ScriptCraft has [its own website][website] with further information.
2015-04-16 22:02:22 +02:00
* To get started using ScriptCraft to Learn JavaScript, read [The Young Person's Guide to Programming in Minecraft][yp].
2013-02-09 21:31:36 +01:00
* The ScriptCraft [API documentation][api].
2015-04-16 22:02:22 +02:00
* To delve deeper into creating your own minecraft mod for use by others, read [Creating a complete Minecraft Mod in JavaScript][mm].
2016-03-26 14:54:26 +01:00
* Take a look at some [examples][ex].
* Buy the Official ScriptCraft Book [A Beginner's Guide to Writing Minecraft Plugins in Javascript][book].
2013-01-25 09:16:35 +01:00
2015-06-07 12:11:39 +02:00
< a href = "http://www.amazon.co.uk/gp/product/0133930149/ref=as_li_tl?ie=UTF8&camp=1634&creative=6738&creativeASIN=0133930149&linkCode=as2&tag=walthigg-21&linkId=P3LLGB3WTATW57AZ" > < img border = "0" src = "http://ws-eu.amazon-adsystem.com/widgets/q?_encoding=UTF8&ASIN=0133930149&Format=_SL250_&ID=AsinImage&MarketPlace=GB&ServiceVersion=20070822&WS=1&tag=walthigg-21" > < / a > < img src = "http://ir-uk.amazon-adsystem.com/e/ir?t=walthigg-21&l=as2&o=2&a=0133930149" width = "1" height = "1" border = "0" alt = "" style = "border:none !important; margin:0px !important;" / >
2013-01-02 11:28:40 +01:00
You can find more information about [ScriptCraft on my blog][blog].
2015-01-11 09:26:16 +01:00
# Additional Resources
CoderDojo Athenry have some [excellent tutorials][cda] for younger
programmers who have used [Scratch][scr] and are interested in Modding
2015-04-16 22:02:22 +02:00
Minecraft using JavaScript. In particular, they have an excellent
[Scratch - to - JavaScript][sj] tutorial which explains Scratch
programs and how to do the same thing in JavaScript.
2015-01-11 09:26:16 +01:00
I highly recommend the series of [tutorials provided by CoderDojo Athenry][cda].
2016-10-08 13:15:05 +02:00
Developer Chris Cacciatore has created some interesting tools using ScriptCraft:
2015-01-11 09:26:16 +01:00
* [A wolf-bot][wb]
2016-03-26 14:54:26 +01:00
* [L-Systems (Large-scale fractal structures in Minecraft)][ls]
2015-05-26 13:14:22 +02:00
# Docker
To launch a container with CanaryMod and ScriptCraft you can just do
docker run -p 25565:25565 -it tclavier/scriptcraft
You can find all files used to build this container in github project: [docker-scriptcraft ](https://github.com/tclavier/docker-scriptcraft )
2015-01-11 09:26:16 +01:00
[wb]: https://github.com/cacciatc/wolfbot
[ls]: https://github.com/cacciatc/scriptcraft-lsystems
2013-01-02 11:28:40 +01:00
[blog]: http://walterhiggins.net/blog/cat-index-scriptcraft.html
2013-12-19 12:10:08 +01:00
[yp]: docs/YoungPersonsGuideToProgrammingMinecraft.md
2013-12-31 10:48:38 +01:00
[mm]: docs/Anatomy-of-a-Plugin.md
2015-01-11 09:26:16 +01:00
[api]: docs/API-Reference.md
2013-02-22 17:51:01 +01:00
[website]: http://scriptcraftjs.org/
2013-12-19 11:43:37 +01:00
[cd]: http://coderdojo.com/
[scr]: http://scratch.mit.edu/
[cda]: http://cdathenry.wordpress.com/category/modderdojo/
2013-12-19 12:06:17 +01:00
[ytpl]: http://www.youtube.com/watch?v=DDp20SKm43Y& list=PL4Tw0AgXQZH5BiFHqD2hXyXQi0-qFbGp_
2015-01-11 09:26:16 +01:00
[ex]: src/main/js/plugins/examples
2014-01-13 22:56:21 +01:00
[contrib]: contributing.md
2015-02-22 00:07:45 +01:00
[sj]: http://cdathenry.wordpress.com/2013/10/12/modderdojo-week-2-moving-from-scratch-to-javascript/
2015-05-26 13:14:22 +02:00
[book]: http://www.peachpit.com/store/beginners-guide-to-writing-minecraft-plugins-in-javascript-9780133930146