-
-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a native mineflayer event for particles (#2813)
* Added particle stuff * linting fix * Changed from a class to a function * Rename longDistance to forceRender, detail it more in api docs * Rename particleData to speed * Rename particles to count * Bug fixes * Doctoc regen * Revert back to class, change forceRender to longDistanceRender * Improve class * Update docs * Linting fix * Remove extraData * Remove unused variable * Update definition * Added internal test * Better test * Linting fix
- Loading branch information
Showing
6 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { Vec3 } = require('vec3') | ||
|
||
module.exports = loader | ||
|
||
function loader (registry) { | ||
class Particle { | ||
constructor (id, position, offset, count = 1, movementSpeed = 0, longDistanceRender = false) { | ||
Object.assign(this, registry.particles[id]) | ||
this.id = id | ||
this.position = position | ||
this.offset = offset | ||
this.count = count | ||
this.movementSpeed = movementSpeed | ||
this.longDistanceRender = longDistanceRender | ||
} | ||
|
||
static fromNetwork (packet) { | ||
return new Particle( | ||
packet.particleId, | ||
new Vec3(packet.x, packet.y, packet.z), | ||
new Vec3(packet.offsetX, packet.offsetY, packet.offsetZ), | ||
packet.particles, | ||
packet.particleData, | ||
packet.longDistance | ||
) | ||
} | ||
} | ||
|
||
return Particle | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = inject | ||
|
||
function inject (bot, { version }) { | ||
const Particle = require('../particle')(bot.registry) | ||
|
||
bot._client.on('world_particles', (packet) => { | ||
bot.emit('particle', Particle.fromNetwork(packet)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const assert = require('assert') | ||
|
||
module.exports = () => async (bot) => { | ||
const particleData = bot.registry.particles[0] | ||
|
||
return new Promise((resolve, reject) => { | ||
function onParticleEvent (particle) { | ||
assert.strictEqual(particle.id, particleData.id) | ||
assert.strictEqual(particle.name, particleData.name) | ||
assert.strictEqual(particle.position.x, bot.entity.position.x) | ||
assert.strictEqual(particle.position.y, bot.entity.position.y) | ||
assert.strictEqual(particle.position.z, bot.entity.position.z) | ||
assert.strictEqual(particle.offset.x, 5) | ||
assert.strictEqual(particle.offset.y, 5) | ||
assert.strictEqual(particle.offset.z, 5) | ||
assert.strictEqual(particle.count, 100) | ||
assert.strictEqual(particle.movementSpeed, 0.5) | ||
assert.strictEqual(particle.longDistanceRender, true) | ||
|
||
resolve() | ||
} | ||
|
||
bot.on('particle', onParticleEvent) | ||
|
||
bot.chat(`/particle ${particleData.name} ~ ~ ~ 5 5 5 0.5 100 force`) | ||
}) | ||
} |