From 7a028e7193c660e88310433204d16f933e5c1b59 Mon Sep 17 00:00:00 2001 From: DemiPixel Date: Fri, 9 Oct 2015 17:30:10 -0700 Subject: [PATCH] Quick fixes, adding everything to api.md --- doc/api.md | 34 +++++++++++++++++++++++++++++++ src/lib/serverPlugins/daycycle.js | 4 ++-- src/lib/serverPlugins/tick.js | 8 ++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/doc/api.md b/doc/api.md index 8fe4b2f..88b4f45 100644 --- a/doc/api.md +++ b/doc/api.md @@ -14,11 +14,15 @@ - [serv.world](#servworld) - [serv.entities](#serventities) - [serv.bannedPlayers](#servbannedplayers) + - [serv.time](#servtime) + - [serv.tickCount](#servtickcount) + - [serv.doDaylightCycle](#servdodaylightcycle) - [Events](#events) - ["error" (error)](#error-error) - ["listening" (port)](#listening-port) - ["newPlayer" (player)](#newplayer-player) - ["banned" (banner,bannedUsername,reason)](#banned-bannerbannedusernamereason) + - ["tick" (count)](#tick-count) - [Methods](#methods) - [serv.createLog()](#servcreatelog) - [serv.log(message)](#servlogmessage) @@ -30,6 +34,8 @@ - [server.pardonUsername(username,callback)](#serverpardonusernameusernamecallback) - [server.pardon(uuid)](#serverpardonuuid) - [server.getUUIDFromUsername(username,callback)](#servergetuuidfromusernameusernamecallback) + - [server.setTime(time)](#serversettimetime) + - [server.setTickInterval(ticksPerSecond)](#serversettickintervaltickspersecond) - [Player](#player) - [Properties](#properties-1) - [player.entity](#playerentity) @@ -112,6 +118,20 @@ Example player: } ``` +#### serv.time + +Current daylight cycle time in ticks. Morning is 0, noon is 6000, evening is 12000, and night is 18000. +Resets to 0 at 24000. Use `serv.setTime(time)` to set the time. + +#### serv.tickCount + +Total number of ticks that have passed since the start of the world. +Best to use with modulo (e.g. Something every 10 seconds is `serv.tickCount % 20*10 == 0`) + +#### serv.doDaylightCycle + +Default `true`. If false, time will not automatically pass. + ### Events #### "error" (error) @@ -130,6 +150,10 @@ Fires when `player` login, allow external player plugins. `banner` banned `bannedUsername` with `reason` +#### "tick" (count) + +Fires when one tick has passed (default is 50ms). count is the total world ticks (same as serv.tickCount) + ### Methods #### serv.createLog() @@ -174,6 +198,16 @@ Gets UUID from username. Since it needs to fetch from mojang servers, it is not Arguments in format: `callback(uuid)`. `uuid` is null if no such username exists. +#### server.setTime(time) + +Set daylight cycle time in ticks. See `serv.time` for more info. + +#### server.setTickInterval(ticksPerSecond) + +Resets tick interval to occur `ticksPerSecond` times per second. + +Use `server.stopTickInterval()` if you want but this method already calls that and you can use `serv.doDaylightCycle` to stop it anyway. + ## Player ### Properties diff --git a/src/lib/serverPlugins/daycycle.js b/src/lib/serverPlugins/daycycle.js index c256510..1331193 100644 --- a/src/lib/serverPlugins/daycycle.js +++ b/src/lib/serverPlugins/daycycle.js @@ -14,8 +14,8 @@ function inject(serv, settings) { serv.time = 0; - serv.on('tick', function() { + serv.on('tick', function(count) { if (!serv.doDaylightCycle) return; - if (serv.tick % 20 == 0) serv.setTime((serv.time + 20) % 24000); // Vanilla only does it every second + if (count % 20 == 0) serv.setTime((serv.time + 20) % 24000); // Vanilla only does it every second }) } \ No newline at end of file diff --git a/src/lib/serverPlugins/tick.js b/src/lib/serverPlugins/tick.js index 802c939..a6ea6d4 100644 --- a/src/lib/serverPlugins/tick.js +++ b/src/lib/serverPlugins/tick.js @@ -4,18 +4,18 @@ module.exports = inject; function inject(serv, settings) { serv.setTickInterval = setTickInterval; serv.stopTickInterval = stopTickInterval; - serv.tick = 0; + serv.tickCount = 0; serv.setTickInterval(20); } function setTickInterval(ticksPerSecond) { var serv = this; - if (serv.tickInterval) clearInterval(serv.tickInterval); + stopTickInterval(); serv.tickInterval = setInterval(function() { - serv.tick++; - serv.emit('tick', serv.tick); + serv.tickCount++; + serv.emit('tick', serv.tickCount); }, 1000/ticksPerSecond); }