@@ -149,7 +149,7 @@ globalThis.modapi_postinit = "(" + (() => {
149
149
}
150
150
if ( xOut && typeof xOut === "object" && ! Array . isArray ( xOut ) ) {
151
151
if ( corrective ) {
152
- return new Proxy ( outputValue . data , CorrectiveRecursive ) ;
152
+ return new Proxy ( xOut , CorrectiveRecursive ) ;
153
153
}
154
154
return new Proxy ( xOut , ModAPI . util . TeaVM_to_Recursive_BaseData_ProxyConf ) ;
155
155
}
@@ -209,6 +209,7 @@ globalThis.modapi_postinit = "(" + (() => {
209
209
210
210
ModAPI . hooks . regenerateClassMap = function ( ) {
211
211
ModAPI . hooks . _rippedConstructorKeys = Object . keys ( ModAPI . hooks . _rippedConstructors ) ;
212
+ ModAPI . hooks . _rippedInternalConstructorKeys = Object . keys ( ModAPI . hooks . _rippedInternalConstructors ) ;
212
213
ModAPI . hooks . _rippedMethodKeys = Object . keys ( ModAPI . hooks . _rippedMethodTypeMap ) ;
213
214
214
215
var compiledNames = new Set ( ) ;
@@ -255,6 +256,7 @@ globalThis.modapi_postinit = "(" + (() => {
255
256
"id" : classId ,
256
257
"binaryName" : item ?. $meta ?. binaryName || null ,
257
258
"constructors" : [ ] ,
259
+ "internalConstructors" : [ ] ,
258
260
"methods" : { } ,
259
261
"staticMethods" : { } ,
260
262
"staticVariables" : { } ,
@@ -268,9 +270,11 @@ globalThis.modapi_postinit = "(" + (() => {
268
270
}
269
271
}
270
272
if ( typeof item ?. $meta ?. superclass === "function" && item ?. $meta ?. superclass ?. $meta ) {
271
- ModAPI . hooks . _classMap [ compiledName ] . superclass = item . $meta . superclass . $meta . name ;
273
+ ModAPI . hooks . _classMap [ compiledName ] . superclassName = item . $meta . superclass . $meta . name ;
274
+ ModAPI . hooks . _classMap [ compiledName ] . superclass = item . $meta . superclass ;
272
275
} else {
273
276
ModAPI . hooks . _classMap [ compiledName ] . superclass = null ;
277
+ ModAPI . hooks . _classMap [ compiledName ] . superclassName = null ;
274
278
}
275
279
ModAPI . hooks . _classMap [ compiledName ] . staticVariableNames = ModAPI . hooks . _rippedStaticIndexer [ compiledName ] ;
276
280
ModAPI . hooks . _classMap [ compiledName ] . staticVariables = ModAPI . hooks . _rippedStaticProperties [ compiledName ] ;
@@ -286,6 +290,13 @@ globalThis.modapi_postinit = "(" + (() => {
286
290
}
287
291
} ) ;
288
292
}
293
+
294
+ ModAPI . hooks . _rippedInternalConstructorKeys . forEach ( initialiser => { // Find internal constructors/initialisers. Used for calling super() on custom classes. (They are the different implementations of a classes constructor, that don't automatically create an object. Thus, it is identical to calling super)
295
+ if ( initialiser . startsWith ( compiledName + "__init_" ) && ! initialiser . includes ( "$lambda$" ) ) {
296
+ ModAPI . hooks . _classMap [ compiledName ] . internalConstructors . push ( ModAPI . hooks . _rippedInternalConstructors [ initialiser ] ) ;
297
+ }
298
+ } ) ;
299
+
289
300
ModAPI . hooks . _rippedMethodKeys . forEach ( ( method ) => {
290
301
if ( method . startsWith ( compiledName + "_" ) && ! method . includes ( "$lambda$" ) ) {
291
302
var targetMethodMap = ModAPI . hooks . _classMap [ compiledName ] . methods ;
@@ -319,6 +330,31 @@ globalThis.modapi_postinit = "(" + (() => {
319
330
var key = classKeys . filter ( k => { return ModAPI . hooks . _classMap [ k ] . name === className } ) [ 0 ] ;
320
331
return key ? ModAPI . hooks . _classMap [ key ] : null ;
321
332
}
333
+
334
+ //Magical function for making a subclass with a custom constructor that you can easily use super(...) on.
335
+ ModAPI . reflect . getSuper = function getSuper ( reflectClass , filter ) {
336
+ filter ||= ( ) => true ;
337
+ var initialiser = reflectClass . internalConstructors . find ( filter ) ;
338
+ return function superFunction ( thisArg , ...extra_args ) {
339
+ reflectClass . class . call ( thisArg ) ;
340
+ initialiser ( thisArg , ...extra_args ) ;
341
+ }
342
+ }
343
+
344
+ //Iteratively load the superclasses' prototype methods.
345
+ ModAPI . reflect . prototypeStack = function prototypeStack ( reflectClass , classFn ) {
346
+ var stack = [ reflectClass . class . prototype ] ;
347
+ var currentSuperclass = reflectClass . superclass ;
348
+ while ( currentSuperclass ) {
349
+ stack . push ( currentSuperclass . prototype ) ;
350
+ currentSuperclass = currentSuperclass ?. $meta ?. superclass ;
351
+ }
352
+ stack . reverse ( ) ;
353
+ stack . forEach ( proto => {
354
+ Object . assign ( classFn . prototype , proto ) ;
355
+ } ) ;
356
+ }
357
+
322
358
var reloadDeprecationWarnings = 0 ;
323
359
const TeaVMArray_To_Recursive_BaseData_ProxyConf = {
324
360
get ( target , prop , receiver ) {
@@ -556,7 +592,7 @@ globalThis.modapi_postinit = "(" + (() => {
556
592
557
593
//Function used for running @Async / @Async -dependent TeaVM methods.
558
594
ModAPI . promisify = function promisify ( fn ) {
559
- return function promisifiedJavaMethpd ( ...inArguments ) {
595
+ return function promisifiedJavaMethod ( ...inArguments ) {
560
596
return new Promise ( ( res , rej ) => {
561
597
Promise . resolve ( ) . then ( //queue microtask
562
598
( ) => {
@@ -850,10 +886,12 @@ globalThis.modapi_postinit = "(" + (() => {
850
886
ModAPI . enchantments = new Proxy ( ModAPI . hooks . _classMap [ ModAPI . util . getCompiledName ( "net.minecraft.enchantment.Enchantment" ) ] . staticVariables , StaticProps_ProxyConf ) ;
851
887
}
852
888
889
+ ModAPI . events . newEvent ( "bootstrap" , "server" ) ;
853
890
const originalBootstrap = ModAPI . hooks . methods [ ModAPI . util . getMethodFromPackage ( "net.minecraft.init.Bootstrap" , "register" ) ] ;
854
891
ModAPI . hooks . methods [ ModAPI . util . getMethodFromPackage ( "net.minecraft.init.Bootstrap" , "register" ) ] = function ( ...args ) {
855
892
var x = originalBootstrap . apply ( this , args ) ;
856
893
ModAPI . util . bootstrap ( ) ;
894
+ ModAPI . events . callEvent ( "bootstrap" , { } ) ;
857
895
console . log ( "[ModAPI] Hooked into bootstrap. .blocks, .items, .materials and .enchantments are now accessible." ) ;
858
896
return x ;
859
897
}
0 commit comments