From aab4036ee21679caefac72bdf547225f8eda855e Mon Sep 17 00:00:00 2001 From: a <> Date: Thu, 8 Jun 2023 16:51:00 -0400 Subject: [PATCH 1/7] add https://github.com/PrismarineJS/mineflayer/pull/1962 --- docs/api.md | 7 +++++++ examples/statistics.js | 24 ++++++++++++++++++++++++ lib/loader.js | 1 + lib/plugins/statistics.js | 29 +++++++++++++++++++++++++++++ test/externalTests/statistics.js | 9 +++++++++ 5 files changed, 70 insertions(+) create mode 100644 examples/statistics.js create mode 100644 lib/plugins/statistics.js create mode 100644 test/externalTests/statistics.js diff --git a/docs/api.md b/docs/api.md index c0db3532a..d19f725e5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -263,6 +263,7 @@ - [bot.recipesFor(itemType, metadata, minResultCount, craftingTable)](#botrecipesforitemtype-metadata-minresultcount-craftingtable) - [bot.recipesAll(itemType, metadata, craftingTable)](#botrecipesallitemtype-metadata-craftingtable) - [bot.nearestEntity(match = (entity) => { return true })](#botnearestentitymatch--entity---return-true-) + - [bot.requestStatistics()](#botrequeststatisticscb) - [Methods](#methods) - [bot.end(reason)](#botendreason) - [bot.quit(reason)](#botquitreason) @@ -1612,6 +1613,12 @@ Example: const cow = bot.nearestEntity(entity => entity.name.toLowerCase() === 'cow') // we use .toLowercase() because in 1.8 cow was capitalized, for newer versions that can be ommitted ``` +Return the nearest entity to the bot, matching the function (default to all entities). Return null if no entity is found. + +#### bot.requestStatistics() + +This function returns a `Promise`, with `object` filled by statistics. + ### Methods #### bot.end(reason) diff --git a/examples/statistics.js b/examples/statistics.js new file mode 100644 index 000000000..1493396d7 --- /dev/null +++ b/examples/statistics.js @@ -0,0 +1,24 @@ +/* + * + * A simple bot that requests statistics. + * + */ +const mineflayer = require('mineflayer') + +if (process.argv.length < 4 || process.argv.length > 6) { + console.log('Usage : node statistics.js [] []') + process.exit(1) +} + +const bot = mineflayer.createBot({ + host: process.argv[2], + port: parseInt(process.argv[3]), + username: process.argv[4] ? process.argv[4] : 'stats', + password: process.argv[5] +}) + +bot.on('spawn', () => { + bot.requestStatistics().then((data) => { + console.log(data) + }) +}) diff --git a/lib/loader.js b/lib/loader.js index 590caf942..0195626fb 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -37,6 +37,7 @@ const plugins = { sound: require('./plugins/sound'), spawn_point: require('./plugins/spawn_point'), tablist: require('./plugins/tablist'), + statistics: require('./plugins/statistics'), time: require('./plugins/time'), villager: require('./plugins/villager'), anvil: require('./plugins/anvil'), diff --git a/lib/plugins/statistics.js b/lib/plugins/statistics.js new file mode 100644 index 000000000..232cec34f --- /dev/null +++ b/lib/plugins/statistics.js @@ -0,0 +1,29 @@ +const { once } = require('events') +module.exports = inject + +function inject (bot) { + async function requestStatistics () { + if (bot.supportFeature('statisticsUsesPayload')) { + bot._client.write('client_command', { payload: 1 }) + } else { + bot._client.write('client_command', { actionId: 1 }) + } + + const packet = await once(bot._client, 'statistics') + return parseStatisticsPacket(packet) + } + + function parseStatisticsPacket (packet) { + const [{ entries: packetData }] = packet + if (bot.supportFeature('statisticsFormatChanges')) { + return packetData + } + + return Object.values(packetData).reduce((acc, { name, value }) => { + acc[name] = value + return acc + }, {}) + } + + bot.requestStatistics = requestStatistics +} diff --git a/test/externalTests/statistics.js b/test/externalTests/statistics.js new file mode 100644 index 000000000..34a835a54 --- /dev/null +++ b/test/externalTests/statistics.js @@ -0,0 +1,9 @@ +const assert = require('assert') + +module.exports = () => async (bot) => { + const stats = await bot.requestStatistics() + + console.log(stats) + + assert.strictEqual(typeof stats, 'object') +} From 56ba0efe6a03d5981b554aef27d5cf6d0b123be9 Mon Sep 17 00:00:00 2001 From: a <> Date: Thu, 8 Jun 2023 16:54:21 -0400 Subject: [PATCH 2/7] add .idea to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3721ad4cf..38f2f597d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ versions/ server_jars/ test/server_* .vscode -.DS_Store \ No newline at end of file +.DS_Store +.idea \ No newline at end of file From d6e74ddf2521333883a907b90d216604598c28ad Mon Sep 17 00:00:00 2001 From: a <> Date: Thu, 8 Jun 2023 18:14:54 -0400 Subject: [PATCH 3/7] revamp testing --- examples/statistics.js | 28 +++++++++++++++++++++++----- test/externalTests/statistics.js | 21 ++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/examples/statistics.js b/examples/statistics.js index 1493396d7..daef8b720 100644 --- a/examples/statistics.js +++ b/examples/statistics.js @@ -4,6 +4,7 @@ * */ const mineflayer = require('mineflayer') +const assert = require('assert') if (process.argv.length < 4 || process.argv.length > 6) { console.log('Usage : node statistics.js [] []') @@ -14,11 +15,28 @@ const bot = mineflayer.createBot({ host: process.argv[2], port: parseInt(process.argv[3]), username: process.argv[4] ? process.argv[4] : 'stats', - password: process.argv[5] + password: process.argv[5], + verbose: true }) -bot.on('spawn', () => { - bot.requestStatistics().then((data) => { - console.log(data) - }) +bot.on('chat', async (username, message) => { + if (username === bot.username) return + switch (message) { + case 'loaded': + await bot.waitForChunksToLoad() + bot.chat('Ready!') + break + case 'test': + // Jump Statistic + bot.setControlState('jump', true) + await bot.waitForTicks(1) + bot.setControlState('jump', false) + + // Death Statistic + bot.chat('/kill') + + const statistics = await bot.requestStatistics() + bot.chat(`deaths=${statistics['stat.deaths']};timeLastDeath=${statistics['stat.timeSinceDeath']};jumps=${statistics['stat.jump']}`) + break + } }) diff --git a/test/externalTests/statistics.js b/test/externalTests/statistics.js index 34a835a54..04e26996f 100644 --- a/test/externalTests/statistics.js +++ b/test/externalTests/statistics.js @@ -1,9 +1,28 @@ const assert = require('assert') module.exports = () => async (bot) => { + bot.chat('/kill') + const stats = await bot.requestStatistics() console.log(stats) - assert.strictEqual(typeof stats, 'object') + // Easiest Stats to Test, not dependent on any other tests + assert(stats['stat.deaths'] > 0) + assert(stats['stat.timeSinceDeath'] === 0) + assert(stats['stat.playOneMinute'] > 0) + + // Stats that are dependent on previous tests + // assert(stats['stat.craftingTableInteraction'] === 1) + // assert(stats['stat.craftItem.minecraft.ladder'] === 3) + // assert(stats['stat.craftItem.minecraft.planks'] === 4) + // assert(stats['stat.itemEnchanted'] === 1) + // assert(stats['stat.jump'] === 1) + // assert(stats['stat.mineBlock.minecraft.dirt'] === 1) + // assert(stats['stat.pickup.minecraft.dirt'] === 1) + // assert(stats['stat.sleepInBed'] === 1) + // assert(stats['stat.useItem.minecraft.bookshelf'] === 15) + // assert(stats['stat.useItem.minecraft.bread'] === 4) + // assert(stats['stat.useItem.minecraft.dirt'] === 1) + // assert(stats['stat.useItem.minecraft.enchanting_table'] === 1) } From d28b3417176cbab5ecdb775e7aee019ba5848b14 Mon Sep 17 00:00:00 2001 From: a <> Date: Thu, 8 Jun 2023 18:23:17 -0400 Subject: [PATCH 4/7] lint --- examples/statistics.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/statistics.js b/examples/statistics.js index daef8b720..f9753f586 100644 --- a/examples/statistics.js +++ b/examples/statistics.js @@ -4,7 +4,6 @@ * */ const mineflayer = require('mineflayer') -const assert = require('assert') if (process.argv.length < 4 || process.argv.length > 6) { console.log('Usage : node statistics.js [] []') @@ -26,7 +25,7 @@ bot.on('chat', async (username, message) => { await bot.waitForChunksToLoad() bot.chat('Ready!') break - case 'test': + case 'test': { // Jump Statistic bot.setControlState('jump', true) await bot.waitForTicks(1) @@ -37,6 +36,6 @@ bot.on('chat', async (username, message) => { const statistics = await bot.requestStatistics() bot.chat(`deaths=${statistics['stat.deaths']};timeLastDeath=${statistics['stat.timeSinceDeath']};jumps=${statistics['stat.jump']}`) - break + } } }) From 521087d56d43463b2da9b9fe5ee9a705d087de68 Mon Sep 17 00:00:00 2001 From: a <> Date: Tue, 13 Jun 2023 19:27:13 -0400 Subject: [PATCH 5/7] update statistics to use hardcoded mappings --- lib/plugins/statistics.js | 299 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 288 insertions(+), 11 deletions(-) diff --git a/lib/plugins/statistics.js b/lib/plugins/statistics.js index 232cec34f..ad6365f3d 100644 --- a/lib/plugins/statistics.js +++ b/lib/plugins/statistics.js @@ -1,28 +1,305 @@ const { once } = require('events') module.exports = inject +const customMappings = { + 0: 'minecraft.leave_game', + 1: 'minecraft.play_one_minute', + 2: 'minecraft.time_since_death', + 3: 'minecraft.time_since_rest', + 4: 'minecraft.sneak_time', + 5: 'minecraft.walk_one_cm', + 6: 'minecraft.crouch_one_cm', + 7: 'minecraft.sprint_one_cm', + 8: 'minecraft.walk_on_water_one_cm', + 9: 'minecraft.fall_one_cm', + 10: 'minecraft.climb_one_cm', + 11: 'minecraft.fly_one_cm', + 12: 'minecraft.walk_under_water_one_cm', + 13: 'minecraft.minecart_one_cm', + 14: 'minecraft.boat_one_cm', + 15: 'minecraft.pig_one_cm', + 16: 'minecraft.horse_one_cm', + 17: 'minecraft.aviate_one_cm', + 18: 'minecraft.swim_one_cm', + 19: 'minecraft.strider_one_cm', + 20: 'minecraft.jump', + 21: 'minecraft.drop', + 22: 'minecraft.damage_dealt', + 23: 'minecraft.damage_dealt_absorbed', + 24: 'minecraft.damage_dealt_resisted', + 25: 'minecraft.damage_taken', + 26: 'minecraft.damage_blocked_by_shield', + 27: 'minecraft.damage_absorbed', + 28: 'minecraft.damage_resisted', + 29: 'minecraft.deaths', + 30: 'minecraft.mob_kills', + 31: 'minecraft.animals_bred', + 32: 'minecraft.player_kills', + 33: 'minecraft.fish_caught', + 34: 'minecraft.talked_to_villager', + 35: 'minecraft.traded_with_villager', + 36: 'minecraft.eat_cake_slice', + 37: 'minecraft.fill_cauldron', + 38: 'minecraft.use_cauldron', + 39: 'minecraft.clean_armor', + 40: 'minecraft.clean_banner', + 41: 'minecraft.clean_shulker_box', + 42: 'minecraft.interact_with_brewingstand', + 43: 'minecraft.interact_with_beacon', + 44: 'minecraft.inspect_dropper', + 45: 'minecraft.inspect_hopper', + 46: 'minecraft.inspect_dispenser', + 47: 'minecraft.play_noteblock', + 48: 'minecraft.tune_noteblock', + 49: 'minecraft.pot_flower', + 50: 'minecraft.trigger_trapped_chest', + 51: 'minecraft.open_enderchest', + 52: 'minecraft.enchant_item', + 53: 'minecraft.play_record', + 54: 'minecraft.interact_with_furnace', + 55: 'minecraft.interact_with_crafting_table', + 56: 'minecraft.open_chest', + 57: 'minecraft.sleep_in_bed', + 58: 'minecraft.open_shulker_box', + 59: 'minecraft.open_barrel', + 60: 'minecraft.interact_with_blast_furnace', + 61: 'minecraft.interact_with_smoker', + 62: 'minecraft.interact_with_lectern', + 63: 'minecraft.interact_with_campfire', + 64: 'minecraft.interact_with_cartography_table', + 65: 'minecraft.interact_with_loom', + 66: 'minecraft.interact_with_stonecutter', + 67: 'minecraft.bell_ring', + 68: 'minecraft.raid_trigger', + 69: 'minecraft.raid_win', + 70: 'minecraft.interact_with_anvil', + 71: 'minecraft.interact_with_grindstone', + 72: 'minecraft.target_hit', + 73: 'minecraft.interact_with_smithing_table' +} + +const categoryMappings = { + 0: 'minecraft.mined', + 1: 'minecraft.crafted', + 2: 'minecraft.used', + 3: 'minecraft.broken', + 4: 'minecraft.picked_up', + 5: 'minecraft.dropped', + 6: 'minecraft.killed', + 7: 'minecraft.killed_by', + 8: 'minecraft.custom' +} + +// Conversion of 1.13 ID -> 1.16 ID +const mappings_1_13 = { + 0: 0, + 1: 1, + 2: 2, + 3: 4, + 4: 5, + 5: 6, + 6: 7, + 7: 18, + 8: 9, + 9: 10, + 10: 11, + 11: 12, // Figure out if this mapping is correct? minecraft.dive_one_cm -> minecraft.walk_under_water_one_cm + 12: 13, + 13: 14, + 14: 15, + 15: 16, + 16: 17, + 17: 20, + 18: 21, + 19: 22, + 20: 25, + 21: 29, + 22: 30, + 23: 31, + 24: 32, + 25: 33, + 26: 34, + 27: 35, + 28: 36, + 29: 37, + 30: 38, + 31: 39, + 32: 40, + 33: 42, + 34: 43, + 35: 44, + 36: 45, + 37: 46, + 38: 47, + 39: 48, + 40: 49, + 41: 50, + 42: 51, + 43: 52, + 44: 53, + 45: 54, + 46: 55, + 47: 56, + 48: 57, + 49: 58 +} + +// 1.8 Mappings -> 1.20 Mappings +const mappings_1_8 = { + 'leaveGame': 0, + 'playOneMinute': 1, + 'timeSinceDeath': 2, + 'sneakTime': 4, + 'walkOneCm': 5, + 'crouchOneCm': 6, + 'sprintOneCm': 7, + 'fallOneCm': 9, + 'climbOneCm': 10, + 'flyOneCm': 11, + 'diveOneCm': 'minecraft.dive_one_cm', + 'minecartOneCm': 13, + 'boatOneCm': 14, + 'pigOneCm': 15, + 'horseOneCm': 16, + 'aviateOneCm': 17, + 'swimOneCm': 18, + 'jump': 20, + 'drop': 21, + 'damageDealt': 22, + 'damageTaken': 25, + 'deaths': 29, + 'mobKills': 30, + 'animalsBred': 31, + 'playerKills': 32, + 'fishCaught': 33, + 'talkedToVillager': 34, + 'tradedWithVillager': 35, + 'cakeSlicesEaten': 36, + 'cauldronFilled': 37, + 'cauldronUsed': 38, + 'armorCleaned': 39, + 'bannerCleaned': 40, + 'brewingstandInteraction': 42, + 'beaconInteraction': 43, + 'dropperInspected': 44, + 'hopperInspected': 45, + 'dispenserInspected': 46, + 'noteblockPlayed': 47, + 'noteblockTuned': 48, + 'flowerPotted': 49, + 'trappedChestTriggered': 50, + 'enderchestOpened': 51, + 'itemEnchanted': 52, + 'recordPlayed': 53, + 'furnaceInteraction': 54, + 'craftingTableInteraction': 55, + 'openChest': 56, + 'chestOpened': 57, + 'shulkerBoxOpened': 58, +} + +const categoryMapping_1_8 = { + 'mineBlock': 0, + 'craftItem': 1, + 'useItem': 2, + 'breakItem': 3, + 'pickup': 4, + 'drop': 5, + 'killEntity': 6, + 'entityKilledBy': 7, +} + function inject (bot) { async function requestStatistics () { - if (bot.supportFeature('statisticsUsesPayload')) { - bot._client.write('client_command', { payload: 1 }) + bot._client.write('client_command', { actionId: 1 }) + const packet = await once(bot._client, 'statistics') + return parseStatisticsPacket(packet) + } + + // Major Versions: + // 1.8 - 1.12 + // 1.13 - 1.15 + // 1.16 - 1.20 + + // For Future Proofing + Ease of Reading + const translate = ({ categoryId, statisticId }) => { + switch (categoryId) { + case 0: + return `${categoryMappings[categoryId]}.minecraft.${bot.registry.blocks[statisticId].name}` + case 1: + case 2: + case 3: + case 4: + case 5: + return `${categoryMappings[categoryId]}.minecraft.${bot.registry.items[statisticId].name}` + case 6: + case 7: + return `${categoryMappings[categoryId]}.minecraft.${bot.registry.entities[statisticId].name}` + case 8: + default: + return customMappings[statisticId] + } + } + + const translate_1_16 = ({ categoryId, statisticId }) => { + return translate({ categoryId, statisticId }) + } + + const translate_1_13 = ({ categoryId, statisticId }) => { + if (categoryId === 8) { + return translate({ categoryId, statisticId: mappings_1_13[statisticId] }) } else { - bot._client.write('client_command', { actionId: 1 }) + return translate({ categoryId, statisticId }) + } + } + + // Converts name -> categoryId, statisticId + const translate_1_8 = (name) => { + const [type, category, other, item] = name.split('.') + const categoryId = categoryMapping_1_8[category] + + // TODO - figure this part out + if (type === 'achievement') { + return name } - const packet = await once(bot._client, 'statistics') - return parseStatisticsPacket(packet) + switch (categoryId) { + case 0: + return translate({ categoryId, statisticId: bot.registry.blocksByName[item].id }) + case 1: + case 2: + case 3: + case 4: + case 5: + return translate({ categoryId, statisticId: bot.registry.itemsByName[item].id }) + case 6: + case 7: + return translate({ categoryId, statisticId: bot.registry.entitiesByName[item].id }) + case 8: + default: + return translate({ categoryId: 8, statisticId: mappings_1_8[category] }) + } } function parseStatisticsPacket (packet) { const [{ entries: packetData }] = packet - if (bot.supportFeature('statisticsFormatChanges')) { - return packetData + const statistics = {} + + if (bot.supportFeature('statsVersionOne')) { + for (const val of packetData) { + statistics[translate_1_8(val.name)] = val.value + } + } else if (bot.supportFeature('statsVersionTwo')) { + for (const val of packetData) { + statistics[translate_1_13(val)] = val.value + } + } else if (bot.supportFeature('statsVersionThree')) { + for (const val of packetData) { + statistics[translate_1_16(val)] = val.value + } } - return Object.values(packetData).reduce((acc, { name, value }) => { - acc[name] = value - return acc - }, {}) + return statistics } bot.requestStatistics = requestStatistics From bdf336c5461ad3a47f121f3917150c3a58bce5ca Mon Sep 17 00:00:00 2001 From: a <> Date: Tue, 13 Jun 2023 20:00:01 -0400 Subject: [PATCH 6/7] update tests --- test/externalTests/statistics.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/test/externalTests/statistics.js b/test/externalTests/statistics.js index 04e26996f..91de0cb48 100644 --- a/test/externalTests/statistics.js +++ b/test/externalTests/statistics.js @@ -1,28 +1,20 @@ const assert = require('assert') module.exports = () => async (bot) => { - bot.chat('/kill') + await bot.test.wait(1000) // Make sure everything is updated? const stats = await bot.requestStatistics() console.log(stats) - // Easiest Stats to Test, not dependent on any other tests - assert(stats['stat.deaths'] > 0) - assert(stats['stat.timeSinceDeath'] === 0) - assert(stats['stat.playOneMinute'] > 0) + // Easiest Stat to Test, not dependent on any other tests + assert(stats['minecraft.play_one_minute'] > 0) - // Stats that are dependent on previous tests - // assert(stats['stat.craftingTableInteraction'] === 1) - // assert(stats['stat.craftItem.minecraft.ladder'] === 3) - // assert(stats['stat.craftItem.minecraft.planks'] === 4) - // assert(stats['stat.itemEnchanted'] === 1) - // assert(stats['stat.jump'] === 1) - // assert(stats['stat.mineBlock.minecraft.dirt'] === 1) - // assert(stats['stat.pickup.minecraft.dirt'] === 1) - // assert(stats['stat.sleepInBed'] === 1) - // assert(stats['stat.useItem.minecraft.bookshelf'] === 15) - // assert(stats['stat.useItem.minecraft.bread'] === 4) - // assert(stats['stat.useItem.minecraft.dirt'] === 1) - // assert(stats['stat.useItem.minecraft.enchanting_table'] === 1) + // Dependent On Other Tests - Free To Remove If Errors + // Test: crafting + assert(stats['minecraft.crafted.minecraft.ladder'] >= 1) + + // Test: digAndBuild + assert(stats['minecraft.mined.minecraft.dirt'] >= 1) + assert(stats['minecraft.used.minecraft.dirt'] >= 1) } From 1283978ff8e9a747d5cc5d6fe546c4bec9382ba9 Mon Sep 17 00:00:00 2001 From: a <> Date: Tue, 13 Jun 2023 20:16:14 -0400 Subject: [PATCH 7/7] lint --- lib/plugins/statistics.js | 144 +++++++++++++++++++------------------- 1 file changed, 73 insertions(+), 71 deletions(-) diff --git a/lib/plugins/statistics.js b/lib/plugins/statistics.js index ad6365f3d..62a856717 100644 --- a/lib/plugins/statistics.js +++ b/lib/plugins/statistics.js @@ -90,8 +90,10 @@ const categoryMappings = { 8: 'minecraft.custom' } -// Conversion of 1.13 ID -> 1.16 ID -const mappings_1_13 = { +// Disabling camelcase error to increase readability + +// Conversion of 1.13-1.15 ID -> 1.16-1.20 ID +const mappings_1_13 = { // eslint-disable-line camelcase 0: 0, 1: 1, 2: 2, @@ -103,7 +105,7 @@ const mappings_1_13 = { 8: 9, 9: 10, 10: 11, - 11: 12, // Figure out if this mapping is correct? minecraft.dive_one_cm -> minecraft.walk_under_water_one_cm + 11: 12, // Figure out if this mapping is correct? minecraft.dive_one_cm -> minecraft.walk_under_water_one_cm 12: 13, 13: 14, 14: 15, @@ -144,69 +146,69 @@ const mappings_1_13 = { 49: 58 } -// 1.8 Mappings -> 1.20 Mappings -const mappings_1_8 = { - 'leaveGame': 0, - 'playOneMinute': 1, - 'timeSinceDeath': 2, - 'sneakTime': 4, - 'walkOneCm': 5, - 'crouchOneCm': 6, - 'sprintOneCm': 7, - 'fallOneCm': 9, - 'climbOneCm': 10, - 'flyOneCm': 11, - 'diveOneCm': 'minecraft.dive_one_cm', - 'minecartOneCm': 13, - 'boatOneCm': 14, - 'pigOneCm': 15, - 'horseOneCm': 16, - 'aviateOneCm': 17, - 'swimOneCm': 18, - 'jump': 20, - 'drop': 21, - 'damageDealt': 22, - 'damageTaken': 25, - 'deaths': 29, - 'mobKills': 30, - 'animalsBred': 31, - 'playerKills': 32, - 'fishCaught': 33, - 'talkedToVillager': 34, - 'tradedWithVillager': 35, - 'cakeSlicesEaten': 36, - 'cauldronFilled': 37, - 'cauldronUsed': 38, - 'armorCleaned': 39, - 'bannerCleaned': 40, - 'brewingstandInteraction': 42, - 'beaconInteraction': 43, - 'dropperInspected': 44, - 'hopperInspected': 45, - 'dispenserInspected': 46, - 'noteblockPlayed': 47, - 'noteblockTuned': 48, - 'flowerPotted': 49, - 'trappedChestTriggered': 50, - 'enderchestOpened': 51, - 'itemEnchanted': 52, - 'recordPlayed': 53, - 'furnaceInteraction': 54, - 'craftingTableInteraction': 55, - 'openChest': 56, - 'chestOpened': 57, - 'shulkerBoxOpened': 58, +// 1.8-1.12 Mappings -> 1.16-1.20 Mappings +const mappings_1_8 = { // eslint-disable-line camelcase + leaveGame: 0, + playOneMinute: 1, + timeSinceDeath: 2, + sneakTime: 4, + walkOneCm: 5, + crouchOneCm: 6, + sprintOneCm: 7, + fallOneCm: 9, + climbOneCm: 10, + flyOneCm: 11, + diveOneCm: 'minecraft.dive_one_cm', + minecartOneCm: 13, + boatOneCm: 14, + pigOneCm: 15, + horseOneCm: 16, + aviateOneCm: 17, + swimOneCm: 18, + jump: 20, + drop: 21, + damageDealt: 22, + damageTaken: 25, + deaths: 29, + mobKills: 30, + animalsBred: 31, + playerKills: 32, + fishCaught: 33, + talkedToVillager: 34, + tradedWithVillager: 35, + cakeSlicesEaten: 36, + cauldronFilled: 37, + cauldronUsed: 38, + armorCleaned: 39, + bannerCleaned: 40, + brewingstandInteraction: 42, + beaconInteraction: 43, + dropperInspected: 44, + hopperInspected: 45, + dispenserInspected: 46, + noteblockPlayed: 47, + noteblockTuned: 48, + flowerPotted: 49, + trappedChestTriggered: 50, + enderchestOpened: 51, + itemEnchanted: 52, + recordPlayed: 53, + furnaceInteraction: 54, + craftingTableInteraction: 55, + openChest: 56, + chestOpened: 57, + shulkerBoxOpened: 58 } -const categoryMapping_1_8 = { - 'mineBlock': 0, - 'craftItem': 1, - 'useItem': 2, - 'breakItem': 3, - 'pickup': 4, - 'drop': 5, - 'killEntity': 6, - 'entityKilledBy': 7, +const categoryMapping_1_8 = { // eslint-disable-line camelcase + mineBlock: 0, + craftItem: 1, + useItem: 2, + breakItem: 3, + pickup: 4, + drop: 5, + killEntity: 6, + entityKilledBy: 7 } function inject (bot) { @@ -241,22 +243,22 @@ function inject (bot) { } } - const translate_1_16 = ({ categoryId, statisticId }) => { + const translate_1_16 = ({ categoryId, statisticId }) => { // eslint-disable-line camelcase return translate({ categoryId, statisticId }) } - const translate_1_13 = ({ categoryId, statisticId }) => { + const translate_1_13 = ({ categoryId, statisticId }) => { // eslint-disable-line camelcase if (categoryId === 8) { - return translate({ categoryId, statisticId: mappings_1_13[statisticId] }) + return translate({ categoryId, statisticId: mappings_1_13[statisticId] }) // eslint-disable-line camelcase } else { return translate({ categoryId, statisticId }) } } // Converts name -> categoryId, statisticId - const translate_1_8 = (name) => { - const [type, category, other, item] = name.split('.') - const categoryId = categoryMapping_1_8[category] + const translate_1_8 = (name) => { // eslint-disable-line camelcase + const [type, category, , item] = name.split('.') + const categoryId = categoryMapping_1_8[category] // eslint-disable-line camelcase // TODO - figure this part out if (type === 'achievement') { @@ -277,7 +279,7 @@ function inject (bot) { return translate({ categoryId, statisticId: bot.registry.entitiesByName[item].id }) case 8: default: - return translate({ categoryId: 8, statisticId: mappings_1_8[category] }) + return translate({ categoryId: 8, statisticId: mappings_1_8[category] }) // eslint-disable-line camelcase } }