Docs for corrective, and patches stuff

This commit is contained in:
ZXMushroom63 2024-10-02 14:49:17 +08:00
parent 8539ca74fe
commit 9fcac52d28
3 changed files with 33 additions and 5 deletions

View File

@ -141,4 +141,26 @@ For example, take the method `setRenderViewEntity()` on `ModAPI.mcinstance`. Ins
```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());
```
```
## 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`

View File

@ -2,7 +2,7 @@
When TeaVM compiles code, it sometimes does strange things.
#### 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
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.

View File

@ -1,11 +1,17 @@
class PatchesRegistry {
static patchedEventNames = []
static patchFns = []
static patchedEventNames = []
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) {