-
-
Notifications
You must be signed in to change notification settings - Fork 953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dimensionChange event #3275
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36ddc2f
Add dimensionChange event
IceTank 42869f9
Refactor nether.js to fix failing tests and add resetNetherRoofToBedr…
IceTank a15ab0d
Fix linting errors
github-actions[bot] 09cd4c3
Merge branch 'master' into dimensionChange-event
rom1504 e4a34c2
Update test assertion handling
extremeheat 9336ff4
remove vec3Parser
extremeheat ca5939d
Merge branch 'master' into dimensionChange-event
extremeheat 19e49fa
add debug
extremeheat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
tasks: | ||
- command: sdk install java < /dev/null # install java v20 | ||
- command: npm install |
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
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
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 |
---|---|---|
@@ -1,52 +1,97 @@ | ||
const assert = require('assert') | ||
const Vec3 = require('vec3') | ||
const { once } = require('../../lib/promise_utils') | ||
const { onceWithCleanup, sleep } = require('../../lib/promise_utils') | ||
const { Vec3 } = require('vec3') | ||
|
||
module.exports = () => async (bot) => { | ||
// Test spawn event on death | ||
const Item = require('prismarine-item')(bot.registry) | ||
module.exports = (version) => { | ||
async function runTest (bot, testFunction) { | ||
await testFunction(bot) | ||
} | ||
|
||
const tests = [] | ||
|
||
let signItem = null | ||
for (const name in bot.registry.itemsByName) { | ||
if (name.includes('sign') && !name.includes('hanging')) signItem = bot.registry.itemsByName[name] | ||
function addTest (name, f) { | ||
tests[name] = bot => runTest(bot, f) | ||
} | ||
assert.notStrictEqual(signItem, null) | ||
|
||
const p = new Promise((resolve, reject) => { | ||
bot._client.on('open_sign_entity', (packet) => { | ||
const sign = bot.blockAt(new Vec3(packet.location)) | ||
bot.updateSign(sign, '1\n2\n3\n') | ||
|
||
setTimeout(() => { | ||
// Get updated sign | ||
const sign = bot.blockAt(bot.entity.position) | ||
|
||
assert.strictEqual(sign.signText.trimEnd(), '1\n2\n3') | ||
|
||
if (sign.blockEntity) { | ||
// Check block update | ||
bot.activateBlock(sign) | ||
assert.notStrictEqual(sign.blockEntity, undefined) | ||
} | ||
|
||
bot.test.sayEverywhere('/setblock ~ ~ ~ portal') | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ nether_portal') | ||
once(bot, 'spawn').then(resolve) | ||
}, 500) | ||
}) | ||
|
||
addTest('spawn event on death and nether sign', async (bot) => { | ||
// Test spawn event on death | ||
const Item = require('prismarine-item')(bot.registry) | ||
|
||
let signItem = null | ||
for (const name in bot.registry.itemsByName) { | ||
if (name.includes('sign') && !name.includes('hanging')) signItem = bot.registry.itemsByName[name] | ||
} | ||
assert.notStrictEqual(signItem, null, 'Could not find sign item') | ||
|
||
await bot.waitForChunksToLoad() | ||
bot.test.sayEverywhere('/setblock ~2 ~ ~ nether_portal') | ||
bot.test.sayEverywhere('/setblock ~2 ~ ~ portal') | ||
bot.test.sayEverywhere('/tp ~2 ~ ~') | ||
await onceWithCleanup(bot, 'spawn') | ||
|
||
await bot.test.resetNetherRoofToBedrock() | ||
bot.test.sayEverywhere('/tp ~ 128 ~') | ||
await onceWithCleanup(bot, 'forcedMove') | ||
await bot.waitForChunksToLoad() | ||
|
||
const lowerBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0)) | ||
await bot.lookAt(lowerBlock.position.offset(0.5, 0.5, 0.5), true) | ||
|
||
await bot.test.setInventorySlot(36, new Item(signItem.id, 1, 0)) | ||
bot.placeBlock(lowerBlock, new Vec3(0, 1, 0)).catch(err => assert.rejects(err)) | ||
|
||
const [packet] = await onceWithCleanup(bot._client, 'open_sign_entity') | ||
|
||
console.log('[test/nether] Open Sign Packet', packet) | ||
const sign = bot.blockAt(new Vec3(packet.location.x, packet.location.y, packet.location.z)) | ||
bot.updateSign(sign, '1\n2\n3\n') | ||
|
||
await sleep(500) | ||
// Get updated sign | ||
const newSign = bot.blockAt(bot.entity.position) | ||
|
||
assert.strictEqual(newSign.signText.trimEnd(), '1\n2\n3') | ||
|
||
if (newSign.blockEntity) { | ||
// Check block update | ||
bot.activateBlock(newSign) | ||
assert.notStrictEqual(newSign.blockEntity, undefined) | ||
} | ||
|
||
// Get back to the overworld | ||
bot.test.sayEverywhere('/tp ~ 128 ~') | ||
await onceWithCleanup(bot, 'forcedMove') | ||
await sleep(1000) | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ portal') | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ nether_portal') | ||
await onceWithCleanup(bot, 'spawn') | ||
await sleep(1000) | ||
}) | ||
|
||
bot.test.sayEverywhere('/setblock ~ ~ ~ nether_portal') | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ portal') | ||
await once(bot, 'spawn') | ||
bot.test.sayEverywhere('/tp 0 128 0') | ||
addTest('nether dimension change event', async (bot) => { | ||
// Test dimension change event | ||
const DimensionChangeTimeout = 10000 | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ nether_portal') | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ portal') | ||
// Start listening for dimension change event | ||
const dimensionChange = onceWithCleanup(bot, 'dimensionChange', { timeout: DimensionChangeTimeout }) | ||
await onceWithCleanup(bot, 'spawn') | ||
|
||
await once(bot, 'forcedMove') | ||
await bot.waitForChunksToLoad() | ||
const [dimensionName] = await dimensionChange | ||
assert.equal(dimensionName, 'the_nether') | ||
|
||
// Get back to the overworld | ||
await bot.test.resetNetherRoofToBedrock() | ||
bot.test.sayEverywhere('/tp ~ 128 ~') | ||
await onceWithCleanup(bot, 'forcedMove') | ||
await sleep(1000) | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ portal') | ||
bot.test.sayEverywhere('/setblock ~ ~ ~ nether_portal') | ||
// Check that the dimension change event is fired again | ||
const [dimensionName2] = await onceWithCleanup(bot, 'dimensionChange', { timeout: DimensionChangeTimeout }) | ||
assert.equal(dimensionName2, 'overworld') | ||
await sleep(1000) | ||
}) | ||
|
||
const lowerBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0)) | ||
await bot.lookAt(lowerBlock.position, true) | ||
await bot.test.setInventorySlot(36, new Item(signItem.id, 1, 0)) | ||
await bot.placeBlock(lowerBlock, new Vec3(0, 1, 0)) | ||
return p | ||
return tests | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you sure its the_nether and not world_nether?