Archive eaglerforge-injector (tool, 1.8.8, clean-with-notes)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
## ModAPI.array
|
||||
ModAPI.array contains the API for creating java arrays easily.
|
||||
|
||||
Methods:
|
||||
- `ModAPI.array.object(class: Class|String, jsarray: object[]) : Object[]`
|
||||
- Converts a javascript array of a class to a java array of a class.
|
||||
- The class argument can be a raw java class (eg. `ModAPI.reflect.getClassByName(...).class`)
|
||||
- It can also be a string `"java.util.String"`
|
||||
- `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.
|
||||
@@ -0,0 +1,39 @@
|
||||
## ModAPI.dedicatedServer
|
||||
|
||||
This is the dedicated server module, used for modding singleplayer in more powerful ways.
|
||||
|
||||
ModAPI.dedicatedServer has the following methods:
|
||||
|
||||
- `appendCode(code: Function | String) : void`
|
||||
- Injects provided code into the dedicated server.
|
||||
|
||||
|
||||
### Modding the dedicated server
|
||||
Eaglercraft runs the dedicated server in a service worker. This means that in order to run code to mod the dedicated server, you have to change context into the service worker.
|
||||
|
||||
`ModAPI.dedicatedServer.appendCode()` allows you to inject code into the dedicates server before startup. The code injected will throw errors if it attempts to access resources outside the functions context.
|
||||
|
||||
For example, take a look at this mod, which will inject some code that does nothing into the dedicated server:
|
||||
```javascript
|
||||
var myVariable = 4;
|
||||
function myServerSideModCode() {
|
||||
function subfunction() {
|
||||
console.log("serverside!!!");
|
||||
}
|
||||
subfunction();
|
||||
//Successfully running serverside
|
||||
//However, we cannot access `myVariable`
|
||||
}
|
||||
ModAPI.dedicatedServer.appendCode(myServerSideModCode);
|
||||
```
|
||||
|
||||
You can check if a mod if running serverside using this:
|
||||
```javascript
|
||||
function myServerSideModCode(isServerSide) {
|
||||
console.log(isServerSide);
|
||||
}
|
||||
myServerSideModCode(); //logs undefined
|
||||
ModAPI.dedicatedServer.appendCode(myServerSideModCode); //when server starts, will log `true`
|
||||
```
|
||||
|
||||
Once serverside, you can only access server side events, like `serverstart` or `tick`. [See serverside events](events.md#server-side-events)
|
||||
@@ -0,0 +1,119 @@
|
||||
## Events
|
||||
Events broadcast data for use in mods.
|
||||
|
||||
- `ModAPI.addEventListener(eventName: String, callback: Function) : void`
|
||||
- Used to register an event handler. Eg:
|
||||
- ```javascript
|
||||
function myHandler(event) {
|
||||
console.log(event);
|
||||
}
|
||||
ModAPI.addEventListener("update", myHandler);
|
||||
```
|
||||
- `ModAPI.removeEventListener(eventName: String, callback: Function) : void`
|
||||
- Used to unregister an event handler. Eg:
|
||||
- ```javascript
|
||||
function myHandler(event) {
|
||||
console.log(event);
|
||||
}
|
||||
ModAPI.removeEventListener("update", myHandler);
|
||||
```
|
||||
|
||||
### Basic Events
|
||||
- `update`:
|
||||
- Called every client side tick.
|
||||
- Event object is blank.
|
||||
- `load`:
|
||||
- Called when all mods have finished loading.
|
||||
- Event object is blank.
|
||||
- `sendchatmessage`:
|
||||
- Called just before the player sends a chat message.
|
||||
- Passes an object with properties:
|
||||
- `message: String`
|
||||
- String representing the chat message.
|
||||
- `preventDefault: Boolean`
|
||||
- Boolean representing whether or not to cancel processing the chat message. Default is `false`.
|
||||
- `event`:
|
||||
- Called when any event is called. Passes an object with properties:
|
||||
- Passes an object with properties:
|
||||
- `event: String`
|
||||
- String representing the type of event being fired.
|
||||
- `data: Object`
|
||||
- Object representing the original arguments to be passed to the callback.
|
||||
- `frame`:
|
||||
- Called just when a frame is rendered on the client.
|
||||
- Event object is blank.
|
||||
- `render`:
|
||||
- Called when 3D is rendered.
|
||||
- Event object is has one property:
|
||||
- `partialTicks`: number representing the fraction of ticks passed at this frame.
|
||||
### Server Side Events
|
||||
Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md)
|
||||
- `serverstart`:
|
||||
- Called when the dedicated server starts.
|
||||
- Event object is blank.
|
||||
- `bootstrap`:
|
||||
- Called when the dedicated server registers blocks, items, materials, enchantments, etc.
|
||||
- This is when you should register cstom blocks and items.
|
||||
- Event object is blank.
|
||||
- `serverstop`:
|
||||
- Called when the dedicated server stops.
|
||||
- Event object is blank.
|
||||
- `tick`:
|
||||
- Called when the server ticks.
|
||||
- Passes an object with properties:
|
||||
- `preventDefault: Boolean`
|
||||
- Boolean representing whether or not to cancel the tick. Default is `false`.
|
||||
- `receivechatmessage`:
|
||||
- Called when the server receives a chat message.
|
||||
- Passes an object with properties:
|
||||
- `message: String`
|
||||
- String representing the chat message.
|
||||
- `preventDefault: Boolean`
|
||||
- Boolean representing whether or not to cancel processing the chat message. Default is `false`.
|
||||
- `processcommand`:
|
||||
- Called when the server receives a command.
|
||||
- Passes an object with properties:
|
||||
- `command: String`
|
||||
- String representing the command.
|
||||
- `sender: ICommandSender`
|
||||
- Object that sent the command
|
||||
- `preventDefault: Boolean`
|
||||
- Boolean representing whether or not to cancel processing the command. Default is `false`.
|
||||
|
||||
### Events Global, adding new events
|
||||
The events global, `ModAPI.events`, allows you to register new event types and call them.
|
||||
|
||||
#### ModAPI.events.newEvent(eventName: String)
|
||||
You can register new events using ModAPI, as long as the event name starts with `custom:` (`lib:` is only useful for library loading). For example, if I want to add a new event that can be used by other mods, I can use `ModAPI.events.newEvent("custom:myevent")`.
|
||||
|
||||
|
||||
#### ModAPI.events.callEvent(eventName: String, data: Object)
|
||||
You can then call events via `ModAPI.events.callEvent`. For example, to trigger `custom:myevent` with a secret code value, I can run `ModAPI.events.callEvent("custom:myevent", {secretCode: "1234"});`.
|
||||
|
||||
Here is an example on using this:
|
||||
```javascript
|
||||
// Mod #1, registers event handler for custom event
|
||||
ModAPI.addEventListener("custom:myevent", (e)=>{
|
||||
alert(e.secretCode);
|
||||
});
|
||||
```
|
||||
```javascript
|
||||
// Mod #2, registers and calls custom event
|
||||
ModAPI.events.newEvent("custom:myevent");
|
||||
ModAPI.events.callEvent("custom:myevent", {
|
||||
secretCode: "1234"
|
||||
});
|
||||
```
|
||||
|
||||
#### Using library load events
|
||||
```javascript
|
||||
// Mod #2, registers and calls lib event
|
||||
ModAPI.events.newEvent("lib:mylibrary:loaded");
|
||||
ModAPI.events.callEvent("lib:mylibrary:loaded", {});
|
||||
```
|
||||
```javascript
|
||||
// Mod #1, registers event handler for lib event
|
||||
ModAPI.addEventListener("lib:mylibrary:loaded", (e)=>{
|
||||
//Lib events function differently to normal events, as when they are called once, any new event listener with automatically fire upon being registered.
|
||||
});
|
||||
```
|
||||
@@ -0,0 +1,40 @@
|
||||
## ModAPI.hooks
|
||||
ModAPI.hooks is the global generated by actual code.
|
||||
It has quite a few propeties, but most of them are just foundations for more user friendly parts of the ModAPI, so I won't explain them.
|
||||
|
||||
### Property: ModAPI.hooks.methods
|
||||
`ModAPI.hooks.methods` is a String-to-method dictionary/object of every java method. This allows you to do pretty much whatever you want in terms of modifying and hooking into code.
|
||||
It's properties are defined by the package of the java class, as well as that methods name. For example, `net.minecraft.world.World`'s `spawnEntityInWorld` method will be named `ModAPI.hooks.methods.nmw_World_spawnEntityInWorld`, where `nmw` is `net.minecraft.world`. You can automate finding this by using `ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")`, which is an alorithm that automatically finds the key in `ModAPI.hooks.methods`.
|
||||
|
||||
Due to the injector's patches, all game code runs by calling these ModAPI.hooks.methods functions, which allows you to call, patch, replace and modify the game's source code in realtime.
|
||||
|
||||
To call a method, use `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")](argument1, argument2, etc);`.
|
||||
|
||||
Complexities with calling methods:
|
||||
Methods that are described in EaglercraftX's source code as `static` can be called by replacing boolean values `true`/`false` with `1` and `0`, respectively. Strings have to be converted by using `ModAPI.util.str("string")` or one of it's aliases. To pass data from a ModAPI proxy you have to use .getRef(), eg: `ModAPI.player.getRef(); //raw java player object`.
|
||||
|
||||
Non static methods must be called with the object they are running on (the value of the `this` keyword in the java source). Do this by using the object as the first argument. For example, look at this code:
|
||||
|
||||
```javascript
|
||||
ModAPI.require("world");
|
||||
ModAPI.hooks.methods.nmw_World_spawnEntityInWorld(ModAPI.world.getRef(), *an entity object*);
|
||||
```
|
||||
|
||||
- To replace a method with another, you can use:
|
||||
- `ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod")] = function () {}`
|
||||
- To intercept inputs to a method, you can us
|
||||
- ```javascript
|
||||
var myMethodName = ModAPI.util.getMethodFromPackage("com.package.abc.MyClass", "myMethod");
|
||||
const originalMethod = ModAPI.hooks.methods[myMethodName];
|
||||
ModAPI.hooks.methods[myMethodName] = function (...args) {
|
||||
//args is the array of arguments passed in.
|
||||
//on an instance method, this first (args[0]) will almost always
|
||||
//be $this, ie: the object the method is being run on
|
||||
return originalMethod.apply(this, args);
|
||||
}
|
||||
```
|
||||
|
||||
Please note that if you are just calling methods, I recommend attempting to call the method directly on the object. `Eg: ModAPI.world.spawnEntityInWorld(*an entity object*)` or using `ModAPI.reflect.getClassByName("MyClass").methods.methodName.method()`;
|
||||
|
||||
### Property: ModAPI.hooks._teavm
|
||||
`ModAPI.hooks._teavm` is usually only used for internal purposes, but it is basically a collection of every internal TeaVM method. Keep in mind that this only stores references (for performance reasons), so modifying and editing it's contents will not affect the way the game runs.
|
||||
@@ -0,0 +1,185 @@
|
||||
# EaglerForge ModAPI Documentation
|
||||
The EaglerForge ModAPI is housed in a global JavaScript object stored on `globalThis`, called `ModAPI` or `PluginAPI`. (both are identical)
|
||||
|
||||
### Important Notice!
|
||||
From people used to the doc prior to EaglerForgeInjector, now, when you see something like `ModAPI.world`'s type is `World`, that literally means it is identical to an instance of `net.minecraft.world.World` from java. For easier modding, here are some online javadocs, that explain properties from each individual method and proerty of every 1.8 class:
|
||||
|
||||
https://nurmarvin.github.io/Minecraft-1.8-JavaDocs/overview-summary.html - Javadoc for vanilla 1.8
|
||||
https://eaglerreborn.github.io/javadoc/ - EaglerReborn (EF precursor) javadoc, for EaglercraftX u17 (missing serverside classes, this version didn't have singleplayer)
|
||||
An up-to-date javadoc for EaglercraftX is coming soon, in the meanwhile, I recommend modding with a local EaglercraftX workspace, so you can inspect the contents of each class.
|
||||
|
||||
Additionally, when you se that something like `ModAPI.mcinstance` is `Raw<Minecraft>` this means that it has a lot of TeaVM nonsense like '$' prefixes before everything, as well has making it difficult to call the objects methods.
|
||||
|
||||
### Global ModAPI Object:
|
||||
|
||||
The global object has the following properties:
|
||||
- `ModAPI.player: EntityPlayerSP`
|
||||
- Only accessible after `ModAPI.require("player")` is called, this is the local player entity. It is regenerated every time the `update` event is called.
|
||||
- `ModAPI.world: WorldClient`
|
||||
- Only accessible after `ModAPI.require("world")` is called, this is the client-side world. It is regenerated every time the `update` event is called.
|
||||
- `ModAPI.network: NetHandlerPlayClient`
|
||||
- Only accessible after `ModAPI.require("network")` is called, this is the client's networking handler. It is regenerated every time the `update` event is called.
|
||||
- `ModAPI.settings: GameSettings`
|
||||
- This is the Minecraft client's settings. It is generated upon init.
|
||||
- `ModAPI.items: Map<String, Item>`
|
||||
- This is a key-value dictionary of all of the items in the game. It is generated upon init from the static variables of the `Items` class.
|
||||
- For example, to access the item class for `acacia_door`, you can use `ModAPI.items["acacia_door"]`
|
||||
- `ModAPI.blocks: Map<String, Block>`
|
||||
- This is a key-value dictionary of all of the blocks in the game. It is generated upon init from the static variables of the `Blocks` class.
|
||||
- For example, to access the block class for `bedrock`, you can use `ModAPI.blocks["bedrock"]`
|
||||
- `ModAPI.materials: Map<String, Material>`
|
||||
- This is a key-value dictionary of all of the blocks in the game. It is generated upon init from the static variables of the `Material` class.
|
||||
- For example, to access the material class for `portal`, you can use `ModAPI.materials["portal"]`
|
||||
- `ModAPI.enchantments: Map<String, Enchantment|Object>`
|
||||
- This is a key-value dictionary of all of the enchantments in the game. It is generated upon init from the static variables of the `Enchantment` class.
|
||||
- For example, to access the enchantment class for `knockback`, you can use `ModAPI.enchantments["knockback"]`
|
||||
- As the enchantment class has other static variables, `Object.keys` will also return non-enchantment keys such as `enchantmentsBookList`.
|
||||
- `ModAPI.blockSounds: Map<String, SoundType>` (1.12 only)
|
||||
- This is a key-value dictionary of `SoundType`s. Used in `.setSoundType(soundType)` when registering custom blocks in 1.12.
|
||||
- `ModAPI.minecraft: Minecraft`
|
||||
- This is the minecraft instance for the client, generated upon init.
|
||||
- It can also be accessed using `ModAPI.mc`
|
||||
- `ModAPI.mcinstance: Raw<Minecraft>`
|
||||
- This is the raw minecraft instance for the client, generated upon init.
|
||||
- It can also be accessed using `ModAPI.javaClient`
|
||||
- It can also be accessed using `ModAPI.minecraft.getRef()`
|
||||
- It can also be accessed using `Minecraft`
|
||||
- Only here for compatibility
|
||||
- `ModAPI.server: MinecraftServer`
|
||||
- This is the dedicated minecraft server in the service worker, generated when the `serverstart`.
|
||||
- It can only be accessed in the dedicated server's context. (See `ModAPI.dedicatedServer`)
|
||||
- It can also be accessed using `ModAPI.serverInstance`
|
||||
- `ModAPI.rawServer: MinecraftServer`
|
||||
- This is the dedicated minecraft server in the service worker, generated when the `serverstart` event is fired.
|
||||
- It can only be accessed in the dedicated server's context. (See `ModAPI.dedicatedServer`)
|
||||
- It can also be accessed using `ModAPI.server.getRef()`
|
||||
- `ModAPI.hooks`
|
||||
- This is the internal hooking map for ModAPI and can be used to patch, intercept, or rewrite internal functions, and more.
|
||||
- More: [HooksDocumentation](hooks.md)
|
||||
- `ModAPI.util`
|
||||
- This contains utilities for using `ModAPI.hooks`, `ModAPI.reflect`, and more.
|
||||
- More: [UtilDocumentation](utils.md)
|
||||
- `ModAPI.reflect`
|
||||
- This is a wrapper around `ModAPI.hooks`, `ModAPI.hooks._teavm` and `ModAPI.hooks._classMap` that makes accessing and using internal java classes in mods much easier.
|
||||
- More: [ReflectDocumentation](reflect.md)
|
||||
- `ModAPI.dedicatedServer`
|
||||
- This object is used to push code for use in the dedicated server.
|
||||
- Once the dedicated server worker has started, it is unuseable.
|
||||
- More: [DedicatedServerDocumentation](dedicatedserver.md)
|
||||
- `ModAPI.meta`
|
||||
- This module is used to register metadata for mods such as their title, credits, icon and description.
|
||||
- More: [MetaDocumentation](meta.md)
|
||||
- `ModAPI.array`
|
||||
- This module is used to interact and create arrays easily.
|
||||
- More: [ArrayDocumentation](array.md)
|
||||
- `ModAPI.keygen`
|
||||
- This module is used to get IDs for registering blocks and items without hardcoding an ID.
|
||||
- More: [KeygenDocumentation](keygen.md)
|
||||
- `ModAPI.resolution`
|
||||
- This module is used to query information about GUI dimensions, to make drawing to the screen easier, generated when the `frame` event is fired.
|
||||
- Deprecated alias (please do not use): `ModAPI.ScaledResolution`
|
||||
- More: [ArrayDocumentation](array.md)
|
||||
- `ModAPI.version: String`
|
||||
- The version of ModAPI.
|
||||
- `ModAPI.is_1_12: Boolean`
|
||||
- Property defining wether or not ModAPI thinks the current version is 1.12-based.
|
||||
- `ModAPI.isServer: Boolean`
|
||||
- Property defining wether or not ModAPI thinks it is running on the dedicated server.
|
||||
- `ModAPI.flavour: String`
|
||||
- The flavour of ModAPI. Hardcoded to be `"injector"`.
|
||||
|
||||
The ModAPI object has the following methods:
|
||||
- `addEventListener(eventName: String, callback: Function) : void`
|
||||
- More: [EventDocumentation](events.md)
|
||||
- `require(componentName: String) : void`
|
||||
- Import required modules, such as `player` and `network`.
|
||||
- Usage: `ModAPI.require("module")`
|
||||
- `displayToChat(message: String) : void`
|
||||
- Displays client-side message to user's ingame chat gui.
|
||||
- Usage: `ModAPI.displayToChat("Hello World.")`
|
||||
- `clickMouse() : void`
|
||||
- Triggers a left click ingame.
|
||||
- `rightClickMouse() : void`
|
||||
- Triggers a right click ingame.
|
||||
- `getFPS() : int`
|
||||
- Gets the frames per second of the game
|
||||
- `promisify(asyncJavaMethod: Method | Constructor) : PromisifiedJavaRunner`
|
||||
- Allows running java methods that are @Async/@Async dependent.
|
||||
- More: [PromisifyDocumentation](promisify.md)
|
||||
- `addCredit(category: String, contributor: String, contents: String)`
|
||||
- Lets you easily add credits to Eaglercraft's credits.txt
|
||||
- eg: `ModAPI.addCredit("My Cool Mod", "Username", " - Coded the mod\n - Wrote somne credits")`
|
||||
|
||||
|
||||
## Handling strings, numbers and booleans to and from java.
|
||||
Java strings and JavaScript strings are not the same. Calling a method like this: `ModAPI.player.sendChatMessage("hello world")`, will not work, as you are running a Java method with a JavaScript string. To convert a JS string to a Java string, use `ModAPI.util.str(yourString)`. For example, the correct version of the above example is `ModAPI.player.sendChatMessage(ModAPI.util.str("hello world"))`. This problem is automatically mitigated on a few functions, namely `ModAPI.displayToChat()`.
|
||||
|
||||
|
||||
---
|
||||
Java numbers and JavaScript numbers are stored the same way, with no problems with having to cast, like with strings. This is why you can simply do something like `ModAPI.player.motionY = 99999`, without having to do any conversion.
|
||||
|
||||
|
||||
---
|
||||
Booleans in Java are stored as a number, where `1` means `true` and `0` means `false`. There are no functions for converting inbetween these, because it is very easy to do so (unlike strings). To convert a javascript boolean into a java boolean simply multiply you boolean by 1.
|
||||
|
||||
Eg:
|
||||
```javascript
|
||||
var myBool = true;
|
||||
console.log(myBool * 1);
|
||||
// logs '1'
|
||||
|
||||
var myBool = false;
|
||||
console.log(myBool * 1);
|
||||
// logs '0'
|
||||
```
|
||||
|
||||
Better yet, if you need to use booleans very often, just store them as numbers directly in javascript. JavaScript if statements already recognise `0` as false, so something like:
|
||||
```javascript
|
||||
var condition = 0;
|
||||
if (condition) {
|
||||
console.log("yes");
|
||||
} else {
|
||||
console.log("no");
|
||||
}
|
||||
// outputs 'no'
|
||||
```
|
||||
will work out of the box.
|
||||
|
||||
## Accessing raw data
|
||||
In ModAPI's architecture, when you request an object like `ModAPI.player`, instead of giving you `ModAPI.mcinstance.$thePlayer`, it will return a `TeaVM_to_Recursive_BaseData_ProxyConf` proxy. These automatically remove the `$` prefixes, make instance methods run with the actaul object, and a variety other features.
|
||||
|
||||
However, when calling methods via `ModAPI.hooks`, `ModAPI.reflect`, or even just running a method that takes in object arguments on something like `ModAPI.player`, passing in these ModAPI proxies will cause an error.
|
||||
|
||||
To pass in raw java data simply call `getRef()` on the proxy which will return the raw, unmodified version of it.
|
||||
|
||||
For example, take the method `setRenderViewEntity()` on `ModAPI.mcinstance`. Instead of passing an entity from `ModAPI.world.loadedEntityList.get(index)` directly, you need to use `ModAPI.world.loadedEntityList.get(index).getRef()`. Demo code:
|
||||
```javascript
|
||||
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());
|
||||
```
|
||||
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
|
||||
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()`.
|
||||
|
||||
For example:
|
||||
```javascript
|
||||
ModAPI.player.inGround //returns undefined
|
||||
ModAPI.player.inGround0 //returns 1 or 0, the correct value
|
||||
|
||||
ModAPI.player.isCorrective() //returns false
|
||||
|
||||
var correctedPlayer = ModAPI.player.getCorrective();
|
||||
|
||||
correctedPlayer.inGround //returns 1 or 0, the correct value
|
||||
correctedPlayer.inGround0 //returns 1 or 0, the correct value
|
||||
|
||||
correctedPlayer.isCorrective() //returns true
|
||||
```
|
||||
|
||||
You can check if an object is corrective using `<object>.isCorrective()`;
|
||||
|
||||
Accessing children of a corrective object will also make them corrective. `correctedPlayer.fishEntity.isCorrective(); //true`
|
||||
@@ -0,0 +1,14 @@
|
||||
## ModAPI.keygen
|
||||
ModAPI.keygen contains the API for getting numerical item, block and entity IDs from a string. It looks at registries to derive the IDs, so IDs will not be automatically reserved until a block/item is actually registered into the game. Ideally, you'd want to call a keygen method just before registering your block.
|
||||
|
||||
Methods:
|
||||
- `ModAPI.keygen.item(itemId: String) : number`
|
||||
- Example usage is: `var id = ModAPI.keygen.item("my_example_item");`
|
||||
- `ModAPI.keygen.block(blockId: String) : number`
|
||||
- Example usage is: `var id = ModAPI.keygen.block("my_example_block");`
|
||||
- `ModAPI.keygen.entity(entityId: String) : number`
|
||||
- Example usage is: `var id = ModAPI.keygen.entity("my_example_entity");`
|
||||
- `ModAPI.keygen.sound(soundId: String) : number`
|
||||
- Example usage is: `var id = ModAPI.keygen.sound("my.example.sound");`
|
||||
- `ModAPI.keygen.enchantment(enchantmentId: String) : number`
|
||||
- Example usage is: `var id = ModAPI.keygen.enchantment("sharpness_v2");`
|
||||
@@ -0,0 +1,17 @@
|
||||
## ModAPI.meta
|
||||
ModAPI.meta contains the API for registering metadata on mods easily.
|
||||
|
||||
Methods:
|
||||
- `ModAPI.meta.title(title: String)`
|
||||
- Sets the title of the mod. This is mandatory if any metadata is to be displayed. Character limit of 16.
|
||||
- `ModAPI.meta.credits(credits: String)`
|
||||
- Sets the credits of the mod. Character limit of 36.
|
||||
- `ModAPI.meta.description(desc: String)`
|
||||
- Sets the description of the mod. Character limit of 160.
|
||||
- `ModAPI.meta.icon(iconURL: String)`
|
||||
- Sets the icon of the mod.
|
||||
- It can be extremely low res, it will not appear blurry.
|
||||
- `ModAPI.meta.version(versionCode: String)`
|
||||
- Sets the version of the mod. Appended after the title.
|
||||
- `ModAPI.meta.config(configFn: Function)`
|
||||
- Once the client is fully loaded, creates a button in the mod manager GUI that runs the specified function when pressed.
|
||||
@@ -0,0 +1,37 @@
|
||||
## ModAPI.promisify()
|
||||
Some methods in java are asynchronous, meaning that they don't return a value/modify state immediately. Calling them in an event or in a patch to a normal function will cause a stack implosion, characterised by the client/dedicated server hanging without any error messages.
|
||||
|
||||
In order to call them properly from javascript, you need to use the `ModAPI.promisify()` function.
|
||||
|
||||
For example, here we have a simple client-side command that will try to use the `PlatformRuntime` class to download data from a URI:
|
||||
```javascript
|
||||
ModAPI.addEventListener("sendchatmessage", function downloadSomething(e) {
|
||||
if (e.message.toLowerCase().startsWith("/downloadtest")) {
|
||||
var arraybuffer = ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI(ModAPI.util.str("data:text/plain,hi"));
|
||||
console.log(arraybuffer);
|
||||
}
|
||||
});
|
||||
```
|
||||
This will cause the client to hang. The correct way of calling this asynchronous method is like this:
|
||||
```javascript
|
||||
ModAPI.addEventListener("sendchatmessage", function downloadSomething(e) {
|
||||
if (e.message.toLowerCase().startsWith("/downloadtest")) {
|
||||
ModAPI.promisify(ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI)(ModAPI.util.str("data:text/plain,hi")).then(arraybuffer => {
|
||||
console.log(arraybuffer);
|
||||
});
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
The way this promisify method works is by taking in a java method, and (effectively) converting it into a javascript async function.
|
||||
For example, you can do:
|
||||
```javascript
|
||||
var asyncDownloadRemoteURI = ModAPI.promisify(ModAPI.hooks.methods.nlevi_PlatformRuntime_downloadRemoteURI);
|
||||
|
||||
console.log(typeof asyncDownloadRemoteURI); //Logs function
|
||||
```
|
||||
|
||||
When it is called, like any other asyncronous function, it returns a `Promise` object.
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
||||
|
||||
You can replace the argument with any other method or constructor, including non asynchronous ones.
|
||||
@@ -0,0 +1,84 @@
|
||||
## ModAPI.reflect
|
||||
|
||||
ModAPI.reflect supplies a user friendly wrapper for accessing and interacting with java classes from javascript.
|
||||
|
||||
Properties:
|
||||
|
||||
- `classes: ReflectClass[]`
|
||||
- `ModAPI.reflect.classes` is an array of ReflectClasses, representing (almost) every java class.
|
||||
- `classMap: Map<String, ReflectClass>` is a map of every class.
|
||||
|
||||
Methods:
|
||||
|
||||
- `ModAPI.reflect.getClassById(classId: String) : ReflectClass`
|
||||
- This method is used to find a class by its id.
|
||||
- For example, to get the `Minecraft` class, you can use `ModAPI.reflect.getClassById("net.minecraft.client.Minecraft")`
|
||||
- `ModAPI.reflect.getClassByName(className: String) : ReflectClass`
|
||||
- This method is used to find a class by its id.
|
||||
- For example, to get the `Minecraft` class, you can use `ModAPI.reflect.getClassById("Minecraft")`
|
||||
- This runs slower than `getClassById` because it has to filter through all classes. Make sure to cache the result rather than calling it over and over again.
|
||||
- `ModAPI.reflect.getSuper(rClass: ReflectClass, filter: Function?) : Function`
|
||||
- Gets a super function from a reflect class. This is used to extend built in classes, like `Block`.
|
||||
- For an example, see lines [29](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L29) and [33](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L33) in `unlucky_blocks.js`
|
||||
- When called without a filter function, the filter defaults to `(fn)=>fn.length === 1`
|
||||
- `ModAPI.reflect.prototypeStack(rClass: ReflectClass, target: Class/ConstructorFunction) : void`
|
||||
- Copies methods from a reflect class and it's parents onto a target native JavaScript class. This allows TeaVM to use these objects normally, without you having to manually reimplement every method. In other words, this is the equivalent of extending a class.
|
||||
- Also adds some metadata to make the class work with `ModAPI.util.asClass`
|
||||
- [Example usage](https://github.com/eaglerforge/EaglerForgeInjector/blob/6e8598c180f96a65c0c101be72e6d0fa53195404/examplemods/unlucky_blocks.js#L37)
|
||||
- `ModAPI.reflect.implements(target: Class/ConstructorFunction, interface: ReflectClass)`
|
||||
- Marks the provided interface as a supertype of the target class.
|
||||
- JavaScript equivalent of the `implements` keyword
|
||||
### ReflectClass Definition
|
||||
|
||||
Each `ReflectClass` has the following properties:
|
||||
|
||||
- `binaryName: String?`
|
||||
- The binary name of the class in question. Eg: `Lnet.minecraft.client.entity.EntityPlayerSP;`
|
||||
- Will be `null` if `hasMeta` is equal to `false`
|
||||
- `class: Class?`
|
||||
- The actual class. Cannot be used easily with `new` keyword, this is mostly useful for extending using `prototype`.
|
||||
- Will be `null` if `hasMeta` is equal to `false`
|
||||
- `compiledName: String`
|
||||
- The TeaVM compiled name of the class. It is equal to the first letters of the package, an underscore, and the class name. Eg: `nmce_EntityPlayerSP`
|
||||
- `constructors: Function[]`
|
||||
- The constructors for the class.
|
||||
- `hasMeta: Boolean`
|
||||
- Wether or not the class has metadata saved by TeaVM.
|
||||
- `id: String?`
|
||||
- The class id of the class. Eg: `net.minecraft.client.entity.EntityPlayerSP`
|
||||
- Will be `null` if `hasMeta` is equal to `false`
|
||||
- `name: String`
|
||||
- The name of the class. Eg: `EntityPlayerSP`
|
||||
- `methods: Map<String, ReflectMethod>`
|
||||
- `staticMethods: Map<String, ReflectMethod>`
|
||||
- `staticVariableNames: String[]`
|
||||
- List of all the static variable names for the class.
|
||||
- `staticVariables: Map<String, *>`
|
||||
- key-value dictionary of all the static variables in a class.
|
||||
- `superclass: ReflectClass?`
|
||||
- The superclass.
|
||||
|
||||
Each `ReflectClass` has the following methods:
|
||||
|
||||
- `instanceOf(object: Object)`
|
||||
- Checks if the `object` is an instance of the class.
|
||||
- `getConstructorByArgs(...argumentNames) : Function`
|
||||
- Finds a constructor that matches the specified argument names. Eg:
|
||||
- `ModAPI.reflect.getClassByName("ItemStack").getConstructorByArgs("blockIn", "amount")`
|
||||
|
||||
### ReflectMethod Definition
|
||||
|
||||
Each `ReflectMethod` has the following properties:
|
||||
|
||||
- `methodName: String`
|
||||
- The compiled method name of the method. Eg: `nmce_EntityPlayerSP_closeScreen`.
|
||||
- `methodNameShort: String`
|
||||
- The short name of the method. Eg: `closeScreen`.
|
||||
|
||||
Each `ReflectClass` has the following methods:
|
||||
- `method(...)`
|
||||
- This is the java method.
|
||||
- If it is an instance method (accessed from a ReflectClasses' `methods` property), the first argument should be an instance of the class. Eg: `ModAPI.reflect.getClassByName("EntityPlayerSP").methods.closeScreen.method(ModAPI.player.getRef())`
|
||||
- If it is a static method (accessed from a ReflectClasses' `staticMethods` property), call the method as usual. Eg: `ModAPI.reflect.getClassById("net.minecraft.init.Items").staticMethods.getRegisteredItem.method(ModAPI.util.str("apple"))`
|
||||
|
||||
Keep in mind that you need to wrap strings using `ModAPI.util.str("MyString")`, convert booleans into respective numbers (`true`->`1`, `false`->`0`), and get references of ModAPI proxies (`ModAPI.player`->`ModAPI.player.getRef()`);
|
||||
@@ -0,0 +1,87 @@
|
||||
## ModAPI.util
|
||||
|
||||
ModAPI.util provides and exposes a large number of utilities for interacting with ModAPI.
|
||||
|
||||
Properties:
|
||||
|
||||
- `StaticProps_ProxyConf: ProxyConfiguration`
|
||||
- This is the proxy configuration used for exposing `ModAPI.items`, `ModAPI.blocks`, `ModAPI.enchantments` and `ModAPI.materials`
|
||||
- See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy
|
||||
- `TeaVM_to_BaseData_ProxyConf: ProxyConfiguration`
|
||||
- This is a non-recursive proxy config for removing prefixes from java objects.
|
||||
- `TeaVM_to_Recursive_BaseData_ProxyConf: ProxyConfiguration`
|
||||
- This is a recursive proxy config for removing prefixes from java objects. It handles properties (both object and array) as well as function outputs. Used for `ModAPI.player`, `ModAPI.mc`, `ModAPI.world`, `ModAPI.network` and more.
|
||||
- `TeaVMArray_To_Recursive_BaseData_ProxyConf: ProxyConfiguration`
|
||||
- This is a recursive proxy config for handling arrays from `TeaVM_to_Recursive_BaseData_ProxyConf`
|
||||
|
||||
Methods:
|
||||
|
||||
- `ModAPI.util.str(jsString: String) : java.lang.String`
|
||||
- Converts a javascript string to a java string, for use in java methods and constructors.
|
||||
- Alias: `ModAPI.util.string()`
|
||||
- `ModAPI.util.unstr(jclString: java.lang.String) : String`
|
||||
- Converts a java string to a javascript string.
|
||||
- Alias: `ModAPI.util.ustr()`
|
||||
- Alias: `ModAPI.util.unstring()`
|
||||
- Alias: `ModAPI.util.jclStrToJsStr()`
|
||||
- `ModAPI.util.getMethodFromPackage(classId: String, methodName: String) : String`
|
||||
- Takes a class id (eg: `net.minecraft.client.Minecraft`) and a method name (eg: `middleClickMouse`) and returns its key in `ModAPI.hooks.methods`.
|
||||
- `ModAPI.util.stringToUint16Array(string: String) : Uint16Array`
|
||||
- Encodes a string into a uint16array.
|
||||
- `ModAPI.util.setStringContent(jclString: java.lang.String, contents: String) : void`
|
||||
- Writes a new javascript string into the contents of a java string.
|
||||
- `ModAPI.util.getMethodFromPackage(classId: String, methodName: String) : String`
|
||||
- Takes a class id (eg: `net.minecraft.client.Minecraft`) and a method name (eg: `middleClickMouse`) and returns its key in `ModAPI.hooks.methods`.
|
||||
- `ModAPI.util.hashCode(string: String) : String`
|
||||
- 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)
|
||||
- `ModAPI.util.bootstrap() : void`
|
||||
- Regenerate proxies for ModAPI.items, .blocks, .materials, .enchantments
|
||||
- `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.
|
||||
- `ModAPI.util.getNearestProperty(object: Object, property: string) : string`
|
||||
- Finds the nearest property name to the one you specify (suffix based). This is used to mitigate teavm adding random suffixes to properties.
|
||||
- `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.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.
|
||||
- `ModAPI.util.asClass(class: Class) : Class`
|
||||
- Converts a javascript class to a java class.
|
||||
- Equivalent of using `MyClass.class` in java.
|
||||
Reference in New Issue
Block a user