From 980465ffad433f79d31484fa0228f7c51a225106 Mon Sep 17 00:00:00 2001 From: Grooble Date: Wed, 4 Dec 2024 20:38:57 +0100 Subject: [PATCH] Fix test for 1.21.3 (#1353) * Remove debug logging * Fix benchmark tests for 1.21.3 * Start updating packetTest for 1.21.3 * Update packetTest.js with new types * Fix minecraft-compiler * Speedup tests by setting world type to flat and disabling structures. * Didn't mean to commit that --- src/datatypes/compiler-minecraft.js | 8 +-- test/benchmark.js | 17 ++++--- test/clientTest.js | 4 +- test/packetTest.js | 78 ++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/src/datatypes/compiler-minecraft.js b/src/datatypes/compiler-minecraft.js index dec9d574..864b269f 100644 --- a/src/datatypes/compiler-minecraft.js +++ b/src/datatypes/compiler-minecraft.js @@ -202,10 +202,10 @@ if (${baseName}) { } else if (${otherwiseName}) { offset = ${compiler.callType(`${otherwiseName}.length + 1`, 'varint')} for (let i = 0; i < ${otherwiseName}.length; i++) { - offset = ${compiler.callType(opts.otherwise.type)} + offset = ${compiler.callType(`${otherwiseName}[i]`, opts.otherwise.type)} } } else { - throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') + throw new Error('registryEntryHolder type requires "${opts.base.name}" or "${opts.otherwise.name}" fields to be set') } return offset `.trim()) @@ -299,10 +299,10 @@ if (${baseName}) { } else if (${otherwiseName}) { size += ${compiler.callType(`${otherwiseName}.length + 1`, 'varint')} for (let i = 0; i < ${otherwiseName}.length; i++) { - size += ${compiler.callType(opts.otherwise.type)} + size += ${compiler.callType(`${otherwiseName}[i]`, opts.otherwise.type)} } } else { - throw new Error('registryEntryHolder type requires "${baseName}" or "${otherwiseName}" fields to be set') + throw new Error('registryEntryHolder type requires "${opts.base.name}" or "${opts.otherwise.name}" fields to be set') } return size `.trim()) diff --git a/test/benchmark.js b/test/benchmark.js index a4610371..1d24cd75 100644 --- a/test/benchmark.js +++ b/test/benchmark.js @@ -5,17 +5,18 @@ const ITERATIONS = 10000 const mc = require('../') const states = mc.states -const testDataWrite = [ - { name: 'keep_alive', params: { keepAliveId: 957759560 } }, - // TODO: 1.19+ `chat` -> `player_chat` feature toggle - // { name: 'chat', params: { message: ' Hello World!' } }, - { name: 'position_look', params: { x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, onGround: true } } - // TODO: add more packets for better quality data -] - for (const supportedVersion of mc.supportedVersions) { const mcData = require('minecraft-data')(supportedVersion) const version = mcData.version + const positionFlags = mcData.isNewerOrEqualTo('1.21.3') ? { flags: { onGround: true, hasHorizontalCollision: false } } : { onGround: true } + const testDataWrite = [ + { name: 'keep_alive', params: { keepAliveId: 957759560 } }, + // TODO: 1.19+ `chat` -> `player_chat` feature toggle + // { name: 'chat', params: { message: ' Hello World!' } }, + { name: 'position_look', params: { x: 6.5, y: 65.62, stance: 67.24, z: 7.5, yaw: 0, pitch: 0, ...positionFlags } } + // TODO: add more packets for better quality data + ] + describe('benchmark ' + supportedVersion + 'v', function () { this.timeout(60 * 1000) const inputData = [] diff --git a/test/clientTest.js b/test/clientTest.js index 67eb8ece..ef46d346 100644 --- a/test/clientTest.js +++ b/test/clientTest.js @@ -59,7 +59,8 @@ for (const supportedVersion of mc.supportedVersions) { 'server-port': PORT, motd: 'test1234', 'max-players': 120, - // 'level-type': 'flat', + 'level-type': 'flat', + 'generate-structures': 'false', // 12m 'use-native-transport': 'false' // java 16 throws errors without this, https://www.spigotmc.org/threads/unable-to-access-address-of-buffer.311602 }, (err) => { if (err) reject(err) @@ -191,7 +192,6 @@ for (const supportedVersion of mc.supportedVersions) { } } else { // 1.19+ - console.log('Chat Message', data) const sender = JSON.parse(data.senderName) const msgPayload = data.formattedMessage ? JSON.parse(data.formattedMessage) : data.plainMessage const plainMessage = client.parseMessage(msgPayload).toString() diff --git a/test/packetTest.js b/test/packetTest.js index 534d28ed..7f89b95f 100644 --- a/test/packetTest.js +++ b/test/packetTest.js @@ -57,7 +57,32 @@ const nbtValue = { function getFixedPacketPayload (version, packetName) { if (packetName === 'declare_recipes') { - if (version['>=']('1.20.5')) { + if (version['>=']('1.21.3')) { + return { + recipes: [ + { + name: 'minecraft:campfire_input', + items: [ + 903, + 976 + ] + } + ], + stoneCutterRecipes: [ + { + input: { + ids: [ + 6 + ] + }, + slotDisplay: { + type: 'item_stack', + data: slotValue + } + } + ] + } + } else if (version['>=']('1.20.5')) { return { recipes: [ { @@ -241,6 +266,13 @@ const values = { suggestionType: 'minecraft:summonable_entities' } }, + bitflags: function (typeArgs, context) { + const results = {} + Object.keys(typeArgs.flags).forEach(function (index) { + results[typeArgs.flags[index]] = true + }) + return results + }, soundSource: 'master', packedChunkPos: { x: 10, @@ -263,7 +295,49 @@ const values = { isDebug: false, isFlat: false, portalCooldown: 0 - } + }, + MovementFlags: { + onGround: true, + hasHorizontalCollision: false + }, + ContainerID: 0, + PositionUpdateRelatives: { + x: true, + y: true, + z: true, + yaw: true, + pitch: true, + dx: true, + dy: true, + dz: true, + yawDelta: true + }, + RecipeDisplay: { + type: 'stonecutter', + data: { + ingredient: { type: 'empty' }, + result: { type: 'empty' }, + craftingStation: { type: 'empty' } + } + }, + SlotDisplay: { type: 'empty' }, + game_profile: { + name: 'test', + properties: [{ + key: 'foo', + value: 'bar' + }] + }, + optvarint: 1, + chat_session: { + uuid: '00112233-4455-6677-8899-aabbccddeeff', + publicKey: { + expireTime: 30, + keyBytes: [], + keySignature: [] + } + }, + IDSet: { ids: [2, 5] } } function getValue (_type, packet) {