From 18af63692cbc60e2f4efc8e4031d8d02be4deaaa Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Tue, 3 Dec 2024 15:31:10 +0800 Subject: [PATCH] disable all particles doc --- docs/tutorials/disable_all_particles.md | 90 +++++++++++++++++++++++++ docs/tutorials/index.md | 2 +- docs/tutorials/vclip.md | 2 +- examplemods/no_particles.js | 4 +- 4 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 docs/tutorials/disable_all_particles.md diff --git a/docs/tutorials/disable_all_particles.md b/docs/tutorials/disable_all_particles.md new file mode 100644 index 0000000..99526ff --- /dev/null +++ b/docs/tutorials/disable_all_particles.md @@ -0,0 +1,90 @@ +## Disable All Particles +Particles in minecraft are really laggy, and there's a large chance you may want to disable them to boost your FPS when breaking blocks. + +Let's look through the Eaglercraft 1.8 source code to find where particles are rendered. We can do this with a global search for `particle`. You'll find a lot of hits in the `EffectRenderer` class in the `net.minecraft.client.particle` package. We methods we'll want to patch are: +- `renderParticles` +- `addEffect` +- `addBlockDestroyEffects` +- `hasParticlesInAlphaLayer` + +For the first 3 methods, you can see that they are defined something like: +```java + public void renderParticles() { + // render particles code. + } +``` +The `void` in `public void` means that it does not expect a return value. +Using [`ModAPI.util.getMethodFromPackage`](../apidoc/utils.md) we can find the compiled method name, and look for it in [`ModAPI.hooks.methods`](../apidoc/hooks.md#property-modapihooksmethods). + +```javascript +(function NoParticles() { + //Basic, boilerplate code + ModAPI.meta.title("No Particles"); + ModAPI.meta.description("Disables all particles in game"); + ModAPI.meta.credits("By "); + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles") + ] = function () {}; //Override renderParticles in EffectRenderer to an empty function that does nothing. +})(); +``` + +We can also do this for `addEffect` and `addBlockDestroyEffects`. + +```javascript +(function NoParticles() { + //Basic, boilerplate code + ModAPI.meta.title("No Particles"); + ModAPI.meta.description("Disables all particles in game"); + ModAPI.meta.credits("By "); + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles") + ] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing. + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect") + ] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing. + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects") + ] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing. +})(); +``` + +For `hasParticlesInAlphaLayer`, it doesn't use `void`, but instead a `boolean`. +```java + public boolean hasParticlesInAlphaLayer() { + // hasParticlesInAlphaLayer code. + } +``` +When TeaVM translates booleans, it converts booleans to integers: +- `false` turns into `0` +- `true` turns into `1` + +So when we override `hasParticlesInAlphaLayer`, we'll need to return a `0` or a `1`. Since we want the game to thing that there aren't any particles in the alpha layer, we'll return `0` (false). + +```javascript +(function NoParticles() { + //Basic, boilerplate code + ModAPI.meta.title("No Particles"); + ModAPI.meta.description("Disables all particles in game"); + ModAPI.meta.credits("By "); + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles") + ] = function () {}; //Override renderParticles in EffectRenderer with an empty function that does nothing. + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect") + ] = function () {}; //Override addEffect in EffectRenderer with an empty function that does nothing. + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects") + ] = function () {}; //Override addBlockDestroyEffects in EffectRenderer with an empty function that does nothing. + + ModAPI.hooks.methods[ + ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer") + ] = function () {return 0}; //Override hasParticlesInAlphaLayer in EffectRenderer with a function that returns 0. +})(); +``` \ No newline at end of file diff --git a/docs/tutorials/index.md b/docs/tutorials/index.md index 91665ad..42e5e16 100644 --- a/docs/tutorials/index.md +++ b/docs/tutorials/index.md @@ -20,7 +20,7 @@ Prerequisites: - A copy of the eaglercraft workspace (optional, get it at: https://git.eaglercraft.rip/eaglercraft/eaglercraft-1.8-workspace) Tutorials: -- [Disable All Particles](comingsoon) +- [Disable All Particles](disable_all_particles.md) - [/hat mod](comingsoon) - [/spawnxp command](comingsoon) - [Slippery Mod](comingsoon) diff --git a/docs/tutorials/vclip.md b/docs/tutorials/vclip.md index b6f0d14..7afb570 100644 --- a/docs/tutorials/vclip.md +++ b/docs/tutorials/vclip.md @@ -15,7 +15,7 @@ Example of the issue: if mod A and mod B both use `var myVariable = 0`, the valu This allows us to use variables without worrying about mod compatibility, as variables are scoped to the function. \ -Then, we'll add some basic metadata for the mod loader (note that this is optional, but makes the mod look a lot better in the GUI once the game is loaded.)\ +Then, we'll add some basic [metadata](../apidoc/meta.md) for the mod loader (note that this is optional, but makes the mod look a lot better in the GUI once the game is loaded.)\ We'll also require the player, so the `ModAPI.player` global is generated. ```javascript diff --git a/examplemods/no_particles.js b/examplemods/no_particles.js index cd202de..997d619 100644 --- a/examplemods/no_particles.js +++ b/examplemods/no_particles.js @@ -1,4 +1,4 @@ ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "renderParticles")] = ()=>{}; -ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")] = ()=>{return 0}; ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addEffect")] = ()=>{}; -ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")] = ()=>{}; \ No newline at end of file +ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "addBlockDestroyEffects")] = ()=>{}; +ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")] = ()=>{return 0}; \ No newline at end of file