mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-30 06:30:39 -04:00
transform typeArgs function into object
This commit is contained in:
parent
bf8a7899ae
commit
9abe799715
@ -591,14 +591,22 @@ function readRestBuffer(buffer, offset, typeArgs, rootNode) {
|
||||
};
|
||||
}
|
||||
|
||||
function evalCount(count,fields)
|
||||
{
|
||||
if(fields[count["field"]] in count["map"])
|
||||
return count["map"][fields[count["field"]]];
|
||||
return count["default"];
|
||||
}
|
||||
|
||||
function readArray(buffer, offset, typeArgs, rootNode) {
|
||||
var results = {
|
||||
value: [],
|
||||
size: 0
|
||||
}
|
||||
var count;
|
||||
if (typeof typeArgs.count === "function")
|
||||
count = typeArgs.count(rootNode);
|
||||
if (typeof typeArgs.count === "object") {
|
||||
count = evalCount(typeArgs.count,rootNode);
|
||||
}
|
||||
else
|
||||
count = getField(typeArgs.count, rootNode);
|
||||
for (var i = 0; i < count; i++) {
|
||||
|
@ -358,14 +358,9 @@ module.exports= {
|
||||
{ name: "offsetZ", type: "float" },
|
||||
{ name: "particleData", type: "float" },
|
||||
{ name: "particles", type: "int" },
|
||||
{ name: "data", type: "array", typeArgs: { count: function(fields) {
|
||||
if (fields.particleId === 36)
|
||||
return 2;
|
||||
else if (fields.particleId === 37 || fields.particleId === 38)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}, type: "varint" } }
|
||||
{ name: "data", type: "array",
|
||||
typeArgs: { count: {"field":"particleId","map":{"36":2,"37":1,"38":1},"default":0},
|
||||
type: "varint" } }
|
||||
]},
|
||||
game_state_change: {id: 0x2b, fields: [
|
||||
{ name: "reason", type: "ubyte" },
|
||||
|
Loading…
x
Reference in New Issue
Block a user