From 814104e75897b504d267b5f753bff667bf3fa5b8 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Mon, 23 Sep 2024 12:33:38 +0800 Subject: [PATCH 1/2] Minor documentation fix --- docs/apidoc/events.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/apidoc/events.md b/docs/apidoc/events.md index 32bd6ee..f06d52a 100644 --- a/docs/apidoc/events.md +++ b/docs/apidoc/events.md @@ -42,6 +42,8 @@ Events broadcast data for use in mods. - `frame`: - Called just when a frame is rendered on the client. - Event object is blank. + + ### Server Side Events Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md) - `serverstart`: From d872980fc4a80bd342f86dd313b6293af5dd85d9 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Mon, 23 Sep 2024 18:32:20 +0800 Subject: [PATCH 2/2] u37 fixes --- docs/apidoc/utils.md | 4 ++- docs/quirks.md | 2 +- examplemods/grapplehook.js | 2 +- examplemods/lib.customitems.js | 5 ++-- index.html | 6 ++-- injector.js | 31 +++++++++++++++++---- injector.stepAsync.js => injector.minify.js | 4 +-- postinit.js | 19 +++++++++++-- 8 files changed, 56 insertions(+), 17 deletions(-) rename injector.stepAsync.js => injector.minify.js (96%) diff --git a/docs/apidoc/utils.md b/docs/apidoc/utils.md index 734e950..8446a71 100644 --- a/docs/apidoc/utils.md +++ b/docs/apidoc/utils.md @@ -41,4 +41,6 @@ Methods: - 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. \ No newline at end of file + - 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. \ No newline at end of file diff --git a/docs/quirks.md b/docs/quirks.md index d2cff39..92e3643 100644 --- a/docs/quirks.md +++ b/docs/quirks.md @@ -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`. +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`. #### 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. diff --git a/examplemods/grapplehook.js b/examplemods/grapplehook.js index cee1577..2595f04 100644 --- a/examplemods/grapplehook.js +++ b/examplemods/grapplehook.js @@ -29,7 +29,7 @@ PluginAPI.addEventListener("update", () => { //Every client tick if ( PluginAPI.player.fishEntity !== undefined && //If the fish hook exists GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air - PluginAPI.player.fishEntity.inGround2 //And the hook is in the ground + PluginAPI.player.fishEntity[PluginAPI.util.getNearestProperty(ModAPI.player.fishEntity, "inGround")] //And the hook is in the ground (the inGround property is botched with random suffixes sometimes) ) { GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position PluginAPI.player.fishEntity.posX, diff --git a/examplemods/lib.customitems.js b/examplemods/lib.customitems.js index 8afbb3a..8e12501 100644 --- a/examplemods/lib.customitems.js +++ b/examplemods/lib.customitems.js @@ -59,9 +59,10 @@ if (!globalThis.LCI_LMBEVENTS[cid]) { return oldDig.apply(this, [$this, packet]); } - var statusTag = Object.keys(packet.$status).find(x => { return x.startsWith("$name") }); + var $status = ModAPI.util.getNearestProperty(packet, "$status"); + var statusTag = Object.keys(packet[$status]).find(x => { return x.startsWith("$name") }); var positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0]; - var stat = ModAPI.util.unstr(packet.$status[statusTag]); + var stat = ModAPI.util.unstr(packet[$status][statusTag]); if (stat === "START_DESTROY_BLOCK") { sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag])); } diff --git a/index.html b/index.html index 7affca3..dd3c385 100644 --- a/index.html +++ b/index.html @@ -90,7 +90,9 @@
>Choose .html file...
- Awaiting input... +     + +      Awaiting input...