mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-26 23:39:25 -09:00
Docs for corrective, and patches stuff
This commit is contained in:
parent
8539ca74fe
commit
9fcac52d28
@ -142,3 +142,25 @@ 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());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 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`
|
@ -2,7 +2,7 @@
|
|||||||
When TeaVM compiles code, it sometimes does strange things.
|
When TeaVM compiles code, it sometimes does strange things.
|
||||||
|
|
||||||
#### Property Suffixes
|
#### Property Suffixes
|
||||||
TeaVM will add suffixes to some variables, seemingly randomly. An example is the property `inGround` of any entity. When accessing this on the `ModAPI.player.fishEntity` object, TeaVM has renamed it to `inGround2`. Can be mitigated with `ModAPI.util.getNearestProperty`.
|
TeaVM will add suffixes to some variables, seemingly randomly. An example is the property `inGround` of any entity. When accessing this on the `ModAPI.player.fishEntity` object, TeaVM has renamed it to `inGround2`. Can be mitigated with `ModAPI.util.getNearestProperty`, or, even better, using a corrective version of ModAPI.player.
|
||||||
|
|
||||||
#### Collapsing Methods
|
#### Collapsing Methods
|
||||||
When I was trying to hook into the server-side processing of chat messages, I found that chat packets were handled by the method `processChatMessage` in `NetHandlerPlayServer`. However, in the compiled JavaScript, this method no longer exists. This is because it is only used once, in the `processPacket` method of `C01PacketChatMessage`. TeaVM automatically saw this, and collapsed one method into the other.
|
When I was trying to hook into the server-side processing of chat messages, I found that chat packets were handled by the method `processChatMessage` in `NetHandlerPlayServer`. However, in the compiled JavaScript, this method no longer exists. This is because it is only used once, in the `processPacket` method of `C01PacketChatMessage`. TeaVM automatically saw this, and collapsed one method into the other.
|
||||||
|
12
patches.js
12
patches.js
@ -1,11 +1,17 @@
|
|||||||
class PatchesRegistry {
|
class PatchesRegistry {
|
||||||
static patchedEventNames = []
|
static patchFns = []
|
||||||
static patchedEventNames = []
|
static patchedEventNames = []
|
||||||
static getEventInjectorCode() {
|
static getEventInjectorCode() {
|
||||||
return globalThis.modapi_specialevents = "[" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "]"
|
return "globalThis.modapi_specialevents = [" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "]"
|
||||||
|
}
|
||||||
|
static addPatch(fn) {
|
||||||
|
patchFns.push(fn);
|
||||||
|
}
|
||||||
|
static addSpecialEvent(x) {
|
||||||
|
PatchesRegistry.patchedEventNames.push(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function addPatch(params) {
|
function addPatch() {
|
||||||
|
|
||||||
}
|
}
|
||||||
function addSpecialEvent(eventName) {
|
function addSpecialEvent(eventName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user