smp-datapack/src/database/database.jmc
themodernhakr 58678de1d3
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
Fix macro line
2025-03-23 01:35:57 -05:00

96 lines
2.6 KiB
Plaintext

@lazy //takes name of table. metadata must already exist.
function createTable(name) {
logger(2, database.createTable, "Creating table: $name");
Array.forEach(
"ferdinland:ferdinland",
"database.tables.$name.fields",
()=>{tellraw @a {"storage":"ferdinland:ferdinland", "nbt":"database.tables.$name.fields[0]"};}
);
}
class database {
@add(__load__)
function __init__() {}
@add(this.__init__)
function schema() {}
@add(this.schema)
function tables.myTable() {
::database.tables.myTable.name = "myTable";
::database.tables.myTable.fields = ["one", "two"];
createTable(myTable);
}
}
class database.benchmark {
function arrayTest1.setup() {
::database.test.arrayTest1.array = [];
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest1.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
}
);
}
function arrayTest1.print() {
tellraw @a {"nbt":"database.test.arrayTest1.array","storage":"ferdinland:ferdinland"};
}
function arrayTest1.clean() {
::database.test.arrayTest1.array.del();
::temp.arrayTest1.del();
}
function arrayTest1.run() {
::temp.arrayTest1 = ::database.test.arrayTest1.array;
Array.forEach(
"ferdinland:ferdinland",
"temp.arrayTest1",
() => {
if (String.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "entry500")) {
logger(1, database.benchmark.arrayTest1.run, "found: entry500");
}
if (String.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "entry500")) {
return;
}
}
);
::temp.arrayTest1.del();
}
function arrayTest2.setup() {
::database.test.arrayTest2.array = [];
::database.test.arrayTest2.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest2.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest2.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest2.printArray() {
tellraw @a {"nbt":"database.test.arrayTest2.array","storage":"ferdinland:ferdinland"};
}
function arrayTest2.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest2.index","storage":"ferdinland:ferdinland"};
}
function arrayTest2.clean() {
::database.test.arrayTest2.array.del();
::database.test.arrayTest2.index.del();
}
function arrayTest2.run() {
::temp.keyword = "entry500";
execute run {
$::temp.index = ::database.test.arrayTest2.index.$(keyword);
tellraw @a {"nbt":"temp.index","storage":"ferdinland:ferdinland"};
} with ::temp.keyword;
::temp.keyword.del();
::temp.index.del();
}
}