-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the same block events as mineflayer (#56)
* add the same block events as mineflayer see https://github.com/PrismarineJS/mineflayer/blob/master/docs/api.md#blockupdate-oldblock-newblock working towards PrismarineJS/mineflayer#334 (comment) this will do a get at each set, making the set methods a bit slower it is needed to keep compatibility with mineflayer I think it is ok as initialize can be used to do a faster set for many blocks * fix posInChunk thing
- Loading branch information
Showing
4 changed files
with
139 additions
and
100 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const World = require('../index')('1.16') | ||
const Chunk = require('prismarine-chunk')('1.16') | ||
const Vec3 = require('vec3') | ||
|
||
function generateSimpleChunk (chunkX, chunkZ) { | ||
const chunk = new Chunk() | ||
|
||
for (let x = 0; x < 16; x++) { | ||
for (let z = 0; z < 16; z++) { | ||
chunk.setBlockType(new Vec3(x, 50, z), 2) | ||
for (let y = 0; y < 256; y++) { | ||
chunk.setSkyLight(new Vec3(x, y, z), 15) | ||
} | ||
} | ||
} | ||
|
||
return chunk | ||
} | ||
|
||
const world = new World(generateSimpleChunk) | ||
|
||
async function main () { | ||
world.on('blockUpdate', (oldBlock, newBlock) => { | ||
console.log('blockUpdate', oldBlock.stateId, newBlock.stateId) | ||
}) | ||
world.on('blockUpdate:(3, 50, 3)', (oldBlock, newBlock) => { | ||
console.log('blockUpdate:(3, 50, 3)', oldBlock.stateId, newBlock.stateId) | ||
}) | ||
const pos = new Vec3(3, 50, 3) | ||
console.log('initial', await world.getBlockStateId(pos)) | ||
await world.setBlockStateId(pos, 47) | ||
console.log('last', await world.getBlockStateId(pos)) | ||
} | ||
|
||
main() |
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