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