Skip to content

Commit fea4747

Browse files
committed
Fix invalid keyframe patching for pre/post keyframes.
Also rectify blockbench exporting keyframes as duplicate sometimes?
1 parent feee01c commit fea4747

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

plugins/geckolib/src/ts/keyframe.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,17 @@ function geckolibGetArray(data_point: number, channel: string) {
9393
}
9494
else if (Format.id === GECKOLIB_MODEL_ID) {
9595
if (this.data_points.length != 1) {
96-
result = {pre: result, post: getArray.apply(this, [1]), easing};
96+
const postResult = getArray.apply(this, [1]);
97+
98+
if (!easing && result[0] === postResult[0] && result[1] === postResult[1] && result[2] === postResult[2]) {
99+
result = {vector: result, easing};
100+
}
101+
else {
102+
result = {
103+
pre: checkAndPatchKeyframeValues(result, channel),
104+
post: checkAndPatchKeyframeValues(getArray.apply(this, [1]), channel), easing
105+
};
106+
}
97107
}
98108
else {
99109
result = {vector: result, easing};
@@ -103,14 +113,28 @@ function geckolibGetArray(data_point: number, channel: string) {
103113
result.easingArgs = easingArgs;
104114
}
105115

116+
if (result.vector)
117+
result.vector = checkAndPatchKeyframeValues(result.vector, channel);
118+
119+
return result;
120+
}
121+
122+
// Invert the molang value to match Blockbench's internal handling
123+
// Also swap out empty molang queries because Blockbench now sends them as empty quotes for some reason
124+
function checkAndPatchKeyframeValues(vector: any[], channel: string) {
125+
for (let i = 0; i <= 2; i++) {
126+
if (vector[i] === "")
127+
vector[i] = 0;
128+
}
129+
106130
if (channel === 'rotation' || channel === 'position') {
107-
result.vector[0] = invertMolang(result.vector[0])
131+
vector[0] = invertMolang(vector[0]);
108132

109133
if (channel === 'rotation')
110-
result.vector[1] = invertMolang(result.vector[1])
134+
vector[1] = invertMolang(vector[1]);
111135
}
112-
113-
return result;
136+
137+
return vector;
114138
}
115139

116140
// Replace the bedrock keyframe compilation with a custom handler

0 commit comments

Comments
 (0)