Skip to content

Commit 146aa82

Browse files
committed
Calculator fixes
1. fix log(base,num) giving fn is not defined error 2. fix max() not wokring 3. fix vec2. and vec3. operators not working 4. fix atan2 not working
1 parent 6429ff4 commit 146aa82

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

kubejs/server_scripts/utils/calculator.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ let calculatorDefinitions = (() => {
467467
implementation: [
468468
{
469469
arguments: ["vec2"],
470-
fn: (v) => ({ t: "number", v: Math.atan2(v[1], v[0]) }),
470+
fn: (v) => ({ t: "number", v: Math.atan2(v.v[1], v.v[0]) }),
471471
},
472472
{
473473
arguments: ["number", "number"],
@@ -566,7 +566,7 @@ let calculatorDefinitions = (() => {
566566
arguments: ["number", "number"],
567567
fn: (base, v) => ({
568568
t: "number",
569-
v: fn(JavaMath.log(v.v) / JavaMath.log(base.v)),
569+
v: JavaMath.log(v.v) / JavaMath.log(base.v),
570570
}),
571571
},
572572
{
@@ -641,25 +641,27 @@ let calculatorDefinitions = (() => {
641641
name: "max",
642642
usage: formatOverloads("max", [[["...values:number[]"]]]),
643643
description: "returns the largest of the numbers given as input",
644-
fn: function () {
645-
let args = Array.from(arguments);
646-
if (args.length === 0) {
647-
throw new Error(
648-
"wrong argument count for max: expected 1 or more, got 0",
649-
);
650-
}
651-
if (args.some((arg) => arg.t !== "number")) {
652-
throw new Error(
653-
"wrong argument types for max: expected all numbers",
654-
);
655-
}
656-
return {
657-
t: "number",
658-
v: Math.max.apply(
659-
null,
660-
args.map((arg) => arg.v),
661-
),
662-
};
644+
implementation: {
645+
fn: function () {
646+
let args = Array.from(arguments);
647+
if (args.length === 0) {
648+
throw new Error(
649+
"wrong argument count for max: expected 1 or more, got 0",
650+
);
651+
}
652+
if (args.some((arg) => arg.t !== "number")) {
653+
throw new Error(
654+
"wrong argument types for max: expected all numbers",
655+
);
656+
}
657+
return {
658+
t: "number",
659+
v: Math.max.apply(
660+
null,
661+
args.map((arg) => arg.v),
662+
),
663+
};
664+
},
663665
},
664666
},
665667
{
@@ -983,7 +985,7 @@ let calculatorDefinitions = (() => {
983985
identifier.length <= 3 &&
984986
identifier.match(/^[xy]+$/)
985987
) {
986-
return vecAccessors(value, identifier.v);
988+
return vecAccessors(value, identifier);
987989
}
988990
throw new Error(
989991
"non-existing member " + identifier + " for type " + value.t,
@@ -1006,7 +1008,7 @@ let calculatorDefinitions = (() => {
10061008
identifier.length <= 3 &&
10071009
identifier.match(/^[xyz]+$/)
10081010
) {
1009-
return vecAccessors(value, identifier.v);
1011+
return vecAccessors(value, identifier);
10101012
}
10111013
throw new Error(
10121014
"non-existing member " + identifier + " for type " + value.t,
@@ -1318,7 +1320,7 @@ let calculatorExec = (() => {
13181320
function execOverloaded(options, args, error) {
13191321
for (let option of options) {
13201322
if (option.arguments) {
1321-
if (args.every((arg, i) => option.arguments[i] === arg.t)) {
1323+
if (args.length === option.arguments.length && args.every((arg, i) => option.arguments[i] === arg.t)) {
13221324
return option.fn.apply(null, args);
13231325
}
13241326
} else {

0 commit comments

Comments
 (0)