Skip to content

Commit bcb476c

Browse files
committed
ponder: fix gregtech machines list not being present at startup
1 parent 9dead00 commit bcb476c

1 file changed

Lines changed: 59 additions & 40 deletions

File tree

  • kubejs/client_scripts/ponder
Lines changed: 59 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,99 @@
11
// priority: -100
22

33
(() => {
4-
/**
5-
* @param {"multiblock"} kind
6-
*/
7-
function getGregtechMachines(kind) {
8-
let $MultiblockMachineDefinition = Java.loadClass(
9-
"com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition"
10-
);
11-
12-
let isInstance = (clz, obj) => clz.__javaObject__.isInstance(obj);
13-
14-
let result = [];
15-
if (kind === "multiblock") {
16-
for (let def of GTRegistries.MACHINES) {
17-
if (isInstance($MultiblockMachineDefinition, def)) {
18-
result.push(def.block.idLocation);
19-
}
20-
}
21-
}
22-
23-
return result;
24-
}
25-
26-
let gtMachines = getGregtechMachines("multiblock"); //Doesnt Work rn / need to fix @n1xx1
27-
let stargateBlocks = [
28-
"sgjourney:classic_stargate",
29-
"sgjourney:classic_stargate_base_block",
30-
"sgjourney:classic_stargate_chevron_block",
31-
"sgjourney:classic_stargate_ring_block",
32-
"sgjourney:crystal_interface",
33-
"sgjourney:classic_dhd",
34-
];
4+
let getInitializationData = lazyGetter(() => {
5+
return {
6+
gregtechMultiblocks: getGregtechMachines("multiblock"),
7+
stargateTravel: [
8+
"sgjourney:classic_stargate",
9+
"sgjourney:classic_stargate_base_block",
10+
"sgjourney:classic_stargate_chevron_block",
11+
"sgjourney:classic_stargate_ring_block",
12+
"sgjourney:crystal_interface",
13+
"sgjourney:classic_dhd",
14+
],
15+
};
16+
});
3517

3618
Ponder.tags((event) => {
3719
event.createTag(
3820
"kubejs:gtceu",
39-
"gtceu:electric_blast_furnace", //use?
21+
"gtceu:electric_blast_furnace",
4022
"GregTech Multiblocks",
4123
"Informations on how to use GregTech Multiblocks",
42-
gtMachines
24+
getInitializationData().gregtechMultiblocks,
4325
);
4426

4527
event.createTag(
4628
"kubejs:stargate",
29+
"sgjourney:classic_stargate",
4730
"Stargate Travel",
4831
"Informations on how to use the Stargates of this modpack",
49-
stargateBlocks
32+
getInitializationData().stargateTravel,
5033
);
5134
});
5235

5336
Ponder.registry((event) => {
5437
event
55-
.create(stargateBlocks)
38+
.create(getInitializationData().stargateTravel)
5639
.scene(
5740
"classic_stargate",
5841
"Classic Stargate",
59-
ponderScenes["classic_stargate"]
42+
ponderScenes["classic_stargate"],
6043
);
6144

6245
event
63-
.create(gtMachines)
46+
.create(getInitializationData().gregtechMultiblocks)
6447
.scene(
6548
"multiblock_introduction",
6649
"Multiblock Introduction",
67-
ponderScenes["multiblock_introduction"]
50+
ponderScenes["multiblock_introduction"],
6851
)
6952
.scene(
7053
"multiblock_construction",
7154
"Multiblock Construction",
72-
ponderScenes["multiblock_construction"]
55+
ponderScenes["multiblock_construction"],
7356
)
7457
.scene(
7558
"multiblock_wallsharing",
7659
"Multiblock Wall Sharing",
77-
ponderScenes["multiblock_wallsharing"]
60+
ponderScenes["multiblock_wallsharing"],
7861
);
7962
});
63+
64+
/**
65+
* @template T
66+
* @param {() => T} init
67+
* @returns {() => T}
68+
*/
69+
function lazyGetter(init) {
70+
let data = null;
71+
return () => {
72+
if (!data) data = init();
73+
return data;
74+
};
75+
}
76+
77+
/**
78+
* @param {"multiblock"} kind
79+
* @returns {string[]}
80+
*/
81+
function getGregtechMachines(kind) {
82+
let $MultiblockMachineDefinition = Java.loadClass(
83+
"com.gregtechceu.gtceu.api.machine.MultiblockMachineDefinition",
84+
);
85+
86+
let isInstance = (clz, obj) => clz.__javaObject__.isInstance(obj);
87+
88+
let result = [];
89+
if (kind === "multiblock") {
90+
for (let def of GTRegistries.MACHINES) {
91+
if (isInstance($MultiblockMachineDefinition, def)) {
92+
result.push(def.block.idLocation);
93+
}
94+
}
95+
}
96+
97+
return result;
98+
}
8099
})();

0 commit comments

Comments
 (0)