mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-25 07:01:20 -09:00
ModAPI.array
This commit is contained in:
parent
09ccaff17b
commit
e63e3ea772
36
docs/apidoc/array.md
Normal file
36
docs/apidoc/array.md
Normal file
@ -0,0 +1,36 @@
|
||||
## ModAPI.array
|
||||
ModAPI.array contains the API for creating java arrays easily.
|
||||
|
||||
Methods:
|
||||
- `ModAPI.array.object(class: Class, jsarray: object[]) : Object[]`
|
||||
- Converts a javascript array of a class to a java array of a class.
|
||||
- `ModAPI.array.object(class: Class, size: number) : Object[]`
|
||||
- Creates a java array of a class with the specified size.
|
||||
- `ModAPI.array.boolean(jsarray: boolean[]) : Boolean[]`
|
||||
- Takes a java cript array of booleans (`true`/`false`) and converts it into a java array.
|
||||
- `ModAPI.array.boolean(size: number) : Boolean[]`
|
||||
- Creates a boolean array with the specified size.
|
||||
- `ModAPI.array.byte(jsarray: number[]) : Byte[]`
|
||||
- Takes a javascript array of numbers and converts it into a java byte array.
|
||||
- `ModAPI.array.byte(size: number) : Byte[]`
|
||||
- Creates a byte array with the specified size.
|
||||
- `ModAPI.array.char(jsarray: number[]) : Char[]`
|
||||
- Takes a javascript array of numbers and converts it into a java char array.
|
||||
- `ModAPI.array.char(size: number) : Char[]`
|
||||
- Creates a char array with the specified size.
|
||||
- `ModAPI.array.short(jsarray: number[]) : Short[]`
|
||||
- Takes a javascript array of numbers and converts it into a java short array.
|
||||
- `ModAPI.array.short(size: number) : Short[]`
|
||||
- Creates a short array with the specified size.
|
||||
- `ModAPI.array.int(jsarray: number[]) : Int[]`
|
||||
- Takes a javascript array of numbers and converts it into a java int array.
|
||||
- `ModAPI.array.int(size: number) : Int[]`
|
||||
- Creates a int array with the specified size.
|
||||
- `ModAPI.array.float(jsarray: number[]) : Float[]`
|
||||
- Takes a javascript array of numbers and converts it into a java float array.
|
||||
- `ModAPI.array.float(size: number) : Float[]`
|
||||
- Creates a float array with the specified size.
|
||||
- `ModAPI.array.double(jsarray: number[]) : Float[]`
|
||||
- Takes a javascript array of numbers and converts it into a java double array.
|
||||
- `ModAPI.array.double(size: number) : Float[]`
|
||||
- Creates a double array with the specified size.
|
@ -56,6 +56,9 @@ The global object has the following properties:
|
||||
- `ModAPI.meta`
|
||||
- This object is used to register metadata for mods such as their title, credits, icon and description.
|
||||
- More: [MetaDocumentation](meta.md)
|
||||
- `ModAPI.array`
|
||||
- This object is used to interact and create arrays easily.
|
||||
- More: [ArrayDocumentation](array.md)
|
||||
- `ModAPI.version: String`
|
||||
- The version of ModAPI.
|
||||
- `ModAPI.flavour: String`
|
||||
@ -72,10 +75,10 @@ The ModAPI object has the following methods:
|
||||
- Usage: `ModAPI.displayToChat("Hello World.")`
|
||||
- `clickMouse() : void`
|
||||
- Triggers a left click ingame.
|
||||
- Usage: `ModAPI.clickMouse()`
|
||||
- `rightClickMouse() : void`
|
||||
- Triggers a right click ingame.
|
||||
- Usage: `ModAPI.rightClickMouse()`
|
||||
- `getFPS() : int`
|
||||
- Gets the frames per second of the game
|
||||
|
||||
|
||||
## Handling strings, numbers and booleans to and from java.
|
||||
|
@ -36,4 +36,9 @@ Methods:
|
||||
- Returns the hash of a string.
|
||||
- `ModAPI.util.isCritical() : boolean`
|
||||
- Checks wether the thread is in a critical state.
|
||||
- When patching methods, it is good practice to allow the method to resume as usual if this is `true`, to avoid stack implosions. (yes, those are real)
|
||||
- When patching methods, it is good practice to allow the method to resume as usual if this is `true`, to avoid stack implosions. (yes, those are real)
|
||||
- `ModAPI.util.createArray(class, jsArray) : Object[]`
|
||||
- Makes a java array from a class and a javascript array.
|
||||
- The class parameter can be retrieved via reflect: `ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").class`
|
||||
- `ModAPI.util.wrap(obj: Object) : object`
|
||||
- Returns a wrapper around native java objects, removing prefixes and fixing method outputs.
|
@ -20,6 +20,7 @@ globalThis.modapi_postinit = `(() => {
|
||||
ModAPI.meta._developerMap = {};
|
||||
ModAPI.meta._iconMap = {};
|
||||
ModAPI.meta._versionMap = {};
|
||||
ModAPI.array = {};
|
||||
function limitSize(x, n) {
|
||||
if (x.length > n) {
|
||||
return x.substring(0, n) + "…";
|
||||
@ -113,6 +114,75 @@ globalThis.modapi_postinit = `(() => {
|
||||
});
|
||||
return name;
|
||||
}
|
||||
ModAPI.util.wrap = function (outputValue) {
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
return new Proxy(outputValue, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function") {
|
||||
return function (...args) {
|
||||
var xOut = outputValue.apply(target, args);
|
||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(xOut.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||
return new Proxy(xOut, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
return xOut;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
ModAPI.array.object = function (jclass, size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createArrayFromData(jclass, size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createArray(jclass, size);
|
||||
}
|
||||
ModAPI.array.boolean = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createBooleanArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createBooleanArray(size);
|
||||
}
|
||||
ModAPI.array.byte = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createByteArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createByteArray(size);
|
||||
}
|
||||
ModAPI.array.char = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createCharArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createCharArray(size);
|
||||
}
|
||||
ModAPI.array.short = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createShortArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createShortArray(size);
|
||||
}
|
||||
ModAPI.array.int = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createIntArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createIntArray(size);
|
||||
}
|
||||
ModAPI.array.float = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createFloatArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createFloatArray(size);
|
||||
}
|
||||
ModAPI.array.double = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createDoubleArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createDoubleArray(size);
|
||||
}
|
||||
ModAPI.version = "v2.0";
|
||||
ModAPI.flavour = "injector";
|
||||
ModAPI.GNU = "terry pratchett";
|
||||
@ -295,23 +365,9 @@ globalThis.modapi_postinit = `(() => {
|
||||
|
||||
var outProp = "$" + prop;
|
||||
var outputValue = Reflect.get(target, outProp, receiver);
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(outputValue.data, TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
return new Proxy(outputValue, TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function") {
|
||||
return function (...args) {
|
||||
var xOut = outputValue.apply(target, args);
|
||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(xOut.data, TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||
return new Proxy(xOut, TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
return xOut;
|
||||
}
|
||||
var wrapped = ModAPI.util.wrap(outputValue);
|
||||
if (wrapped) {
|
||||
return wrapped;
|
||||
}
|
||||
return outputValue;
|
||||
},
|
||||
@ -523,6 +579,10 @@ globalThis.modapi_postinit = `(() => {
|
||||
ModAPI.hooks.methods["nmc_Minecraft_rightClickMouse"](ModAPI.javaClient);
|
||||
}
|
||||
|
||||
ModAPI.getFPS = function () {
|
||||
return ModAPI.hooks.methods["nmc_Minecraft_getDebugFPS"](ModAPI.javaClient);
|
||||
}
|
||||
|
||||
const updateMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.entity.EntityPlayerSP", "onUpdate");
|
||||
const originalUpdate = ModAPI.hooks.methods[updateMethodName];
|
||||
ModAPI.hooks.methods[updateMethodName] = function (...args) {
|
||||
|
94
postinit.js
94
postinit.js
@ -20,6 +20,7 @@
|
||||
ModAPI.meta._developerMap = {};
|
||||
ModAPI.meta._iconMap = {};
|
||||
ModAPI.meta._versionMap = {};
|
||||
ModAPI.array = {};
|
||||
function limitSize(x, n) {
|
||||
if (x.length > n) {
|
||||
return x.substring(0, n) + "…";
|
||||
@ -113,6 +114,75 @@
|
||||
});
|
||||
return name;
|
||||
}
|
||||
ModAPI.util.wrap = function (outputValue) {
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
return new Proxy(outputValue, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function") {
|
||||
return function (...args) {
|
||||
var xOut = outputValue.apply(target, args);
|
||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(xOut.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||
return new Proxy(xOut, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
return xOut;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
ModAPI.array.object = function (jclass, size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createArrayFromData(jclass, size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createArray(jclass, size);
|
||||
}
|
||||
ModAPI.array.boolean = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createBooleanArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createBooleanArray(size);
|
||||
}
|
||||
ModAPI.array.byte = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createByteArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createByteArray(size);
|
||||
}
|
||||
ModAPI.array.char = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createCharArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createCharArray(size);
|
||||
}
|
||||
ModAPI.array.short = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createShortArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createShortArray(size);
|
||||
}
|
||||
ModAPI.array.int = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createIntArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createIntArray(size);
|
||||
}
|
||||
ModAPI.array.float = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createFloatArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createFloatArray(size);
|
||||
}
|
||||
ModAPI.array.double = function (size) {
|
||||
if (Array.isArray(size)) {
|
||||
return ModAPI.hooks._teavm.$rt_createDoubleArrayFromData(size);
|
||||
}
|
||||
return ModAPI.hooks._teavm.$rt_createDoubleArray(size);
|
||||
}
|
||||
ModAPI.version = "v2.0";
|
||||
ModAPI.flavour = "injector";
|
||||
ModAPI.GNU = "terry pratchett";
|
||||
@ -295,23 +365,9 @@
|
||||
|
||||
var outProp = "$" + prop;
|
||||
var outputValue = Reflect.get(target, outProp, receiver);
|
||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(outputValue.data, TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||
return new Proxy(outputValue, TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (outputValue && typeof outputValue === "function") {
|
||||
return function (...args) {
|
||||
var xOut = outputValue.apply(target, args);
|
||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||
return new Proxy(xOut.data, TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||
return new Proxy(xOut, TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
}
|
||||
return xOut;
|
||||
}
|
||||
var wrapped = ModAPI.util.wrap(outputValue);
|
||||
if (wrapped) {
|
||||
return wrapped;
|
||||
}
|
||||
return outputValue;
|
||||
},
|
||||
@ -523,6 +579,10 @@
|
||||
ModAPI.hooks.methods["nmc_Minecraft_rightClickMouse"](ModAPI.javaClient);
|
||||
}
|
||||
|
||||
ModAPI.getFPS = function () {
|
||||
return ModAPI.hooks.methods["nmc_Minecraft_getDebugFPS"](ModAPI.javaClient);
|
||||
}
|
||||
|
||||
const updateMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.entity.EntityPlayerSP", "onUpdate");
|
||||
const originalUpdate = ModAPI.hooks.methods[updateMethodName];
|
||||
ModAPI.hooks.methods[updateMethodName] = function (...args) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user