mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-26 15:29:26 -09:00
commit
36da879c8b
@ -148,6 +148,10 @@ For example, take the method `setRenderViewEntity()` on `ModAPI.mcinstance`. Ins
|
|||||||
var entityIndex = 1; //Index of the entity to look for. 0 means first, which is usually the player, so 1 is usually a natural entity.
|
var entityIndex = 1; //Index of the entity to look for. 0 means first, which is usually the player, so 1 is usually a natural entity.
|
||||||
ModAPI.mc.setRenderViewEntity(ModAPI.world.loadedEntityList.get(entityIndex).getRef());
|
ModAPI.mc.setRenderViewEntity(ModAPI.world.loadedEntityList.get(entityIndex).getRef());
|
||||||
```
|
```
|
||||||
|
Note that an entry for `getRef` will not appear from `Object.keys` and similar web APIs.
|
||||||
|
|
||||||
|
## Checking if an object is a proxy
|
||||||
|
All proxied objects have a property `isModProxy` which is equal to true. Note that an entry for `isModProxy` will not appear from `Object.keys` and similar web APIs.
|
||||||
|
|
||||||
## Corrective Proxies
|
## Corrective Proxies
|
||||||
By default, accessing a global like `ModAPI.player` will return a proxy to the original player that removes $ prefixes, as well as making instance methods callable. TeaVM has a quirk where it adds numerical suffixes to some properties. For example `ModAPI.player.inGround0` instead of `ModAPI.player.inGround`. As this is a large issue due to these suffixes changing for every eaglercraft update, you can now bypass this by obtaining a corrective version of `ModAPI.player`, using `ModAPI.player.getCorrective()`.
|
By default, accessing a global like `ModAPI.player` will return a proxy to the original player that removes $ prefixes, as well as making instance methods callable. TeaVM has a quirk where it adds numerical suffixes to some properties. For example `ModAPI.player.inGround0` instead of `ModAPI.player.inGround`. As this is a large issue due to these suffixes changing for every eaglercraft update, you can now bypass this by obtaining a corrective version of `ModAPI.player`, using `ModAPI.player.getCorrective()`.
|
||||||
|
@ -58,3 +58,27 @@ Methods:
|
|||||||
console.log(multiply(2, 3));
|
console.log(multiply(2, 3));
|
||||||
//Logs 6
|
//Logs 6
|
||||||
```
|
```
|
||||||
|
- `ModAPI.util.modifyFunction(fn: Function, patcherFunction: Function) : string`
|
||||||
|
- Returns a modifies version of a function, where the patcher function can be used to modify the contents of a function. Example:
|
||||||
|
```javascript
|
||||||
|
function add(a, b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
var multiply = ModAPI.util.modifyFunction(add, (code)=>{
|
||||||
|
return code.replaceAll("a + b", "a * b");
|
||||||
|
});
|
||||||
|
console.log(multiply(2, 3));
|
||||||
|
//Logs 6
|
||||||
|
```
|
||||||
|
- `ModAPI.util.getIdFromItem(item: Item) : number`
|
||||||
|
- Gets the ID of an item
|
||||||
|
- `ModAPI.util.getItemById(id: number) : Item`
|
||||||
|
- Gets an item by it's ID
|
||||||
|
- `ModAPI.util.getItemFromBlock(block: Block) : ItemBlock`
|
||||||
|
- Gets an item from a block.
|
||||||
|
- `ModAPI.util.getIdFromBlock(block: Block) : number`
|
||||||
|
- Gets the ID of a block
|
||||||
|
- `ModAPI.util.getBlockById(id: number) : Block`
|
||||||
|
- Gets a block by it's ID
|
||||||
|
- `ModAPI.util.getBlockFromItem(item: Item) : Block`
|
||||||
|
- Gets a block from an ItemBlock instance.
|
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>EaglerForge Injector</title>
|
<title>Loading...</title>
|
||||||
<link
|
<link
|
||||||
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
|
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
|
globalThis.ModAPIVersion = "v2.4";
|
||||||
globalThis.doEaglerforge = true;
|
globalThis.doEaglerforge = true;
|
||||||
|
document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`;
|
||||||
|
document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`;
|
||||||
function wait(ms) {
|
function wait(ms) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => { resolve(); }, ms);
|
setTimeout(() => { resolve(); }, ms);
|
||||||
@ -292,7 +295,7 @@ var main;(function(){`
|
|||||||
` id="game_frame">`,
|
` id="game_frame">`,
|
||||||
` id="game_frame">
|
` id="game_frame">
|
||||||
\<script id="modapi_patchesreg_events"\>${PatchesRegistry.getEventInjectorCode()};\<\/script\>
|
\<script id="modapi_patchesreg_events"\>${PatchesRegistry.getEventInjectorCode()};\<\/script\>
|
||||||
\<script id="modapi_postinit"\>${globalThis.modapi_postinit}\<\/script\>
|
\<script id="modapi_postinit"\>${globalThis.modapi_postinit.replace("__modapi_version_code__", ModAPIVersion)}\<\/script\>
|
||||||
\<script id="modapi_postinitasync"\>${globalThis.modapi_postinitasync}\<\/script\>
|
\<script id="modapi_postinitasync"\>${globalThis.modapi_postinitasync}\<\/script\>
|
||||||
\<script id="modapi_modloader"\>${globalThis.modapi_modloader}\<\/script\>
|
\<script id="modapi_modloader"\>${globalThis.modapi_modloader}\<\/script\>
|
||||||
\<script id="modapi_guikit"\>${globalThis.modapi_guikit}\<\/script\>
|
\<script id="modapi_guikit"\>${globalThis.modapi_guikit}\<\/script\>
|
||||||
|
25
postinit.js
25
postinit.js
@ -1,4 +1,3 @@
|
|||||||
globalThis.ModAPIVersion = "v2.3.4";
|
|
||||||
globalThis.modapi_postinit = "(" + (() => {
|
globalThis.modapi_postinit = "(" + (() => {
|
||||||
//EaglerForge post initialization code.
|
//EaglerForge post initialization code.
|
||||||
//This script cannot contain backticks, escape characters, or backslashes in order to inject into the dedicated server code.
|
//This script cannot contain backticks, escape characters, or backslashes in order to inject into the dedicated server code.
|
||||||
@ -35,6 +34,17 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function easyStaticMethod(classId, methodName, autoUnpack) {
|
||||||
|
var method = ModAPI.reflect.getClassById(classId).staticMethods[methodName].method;
|
||||||
|
return function easyImpl(...args) {
|
||||||
|
return method(...(autoUnpack ? args.map(x=>{
|
||||||
|
if ((typeof x === "object") && (x.isModProxy === true)) {
|
||||||
|
return x.getRef();
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
}) : args))
|
||||||
|
}
|
||||||
|
}
|
||||||
ModAPI.meta.title = function (title) {
|
ModAPI.meta.title = function (title) {
|
||||||
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
|
||||||
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
|
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
|
||||||
@ -121,6 +131,14 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
});
|
});
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ModAPI.util.getIdFromItem = easyStaticMethod("net.minecraft.item.Item", "getIdFromItem", true);
|
||||||
|
ModAPI.util.getItemById = easyStaticMethod("net.minecraft.item.Item", "getItemById", false);
|
||||||
|
ModAPI.util.getItemFromBlock = easyStaticMethod("net.minecraft.item.Item", "getItemFromBlock", true);
|
||||||
|
ModAPI.util.getBlockById = easyStaticMethod("net.minecraft.block.Block", "getBlockById", false);
|
||||||
|
ModAPI.util.getBlockFromItem = easyStaticMethod("net.minecraft.block.Block", "getBlockFromItem", true);
|
||||||
|
ModAPI.util.getIdFromBlock = easyStaticMethod("net.minecraft.block.Block", "getIdFromBlock", true);
|
||||||
|
|
||||||
ModAPI.util.wrap = function (outputValue, target, corrective, disableFunctions) {
|
ModAPI.util.wrap = function (outputValue, target, corrective, disableFunctions) {
|
||||||
target ||= {};
|
target ||= {};
|
||||||
corrective ||= false;
|
corrective ||= false;
|
||||||
@ -427,6 +445,9 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (prop === "isModProxy") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
var outProp = "$" + prop;
|
var outProp = "$" + prop;
|
||||||
if (this._corrective) {
|
if (this._corrective) {
|
||||||
@ -1009,4 +1030,4 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
var values = [...ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry.$modapi_specmap.values()];
|
var values = [...ModAPI.reflect.getClassById("net.minecraft.block.Block").staticVariables.blockRegistry.$modapi_specmap.values()];
|
||||||
return qhash(block, values);
|
return qhash(block, values);
|
||||||
}
|
}
|
||||||
}).toString().replace("__modapi_version_code__", ModAPIVersion) + ")();";
|
}).toString() + ")();";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user