disable all particles doc

This commit is contained in:
ZXMushroom63 2024-12-03 15:31:10 +08:00
parent ea4b568b31
commit 18af63692c
4 changed files with 94 additions and 4 deletions

View File

@ -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 <developer name>");
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 <developer name>");
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 <developer name>");
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.
})();
```

View File

@ -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)

View File

@ -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

View File

@ -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")] = ()=>{};
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.particle.EffectRenderer", "hasParticlesInAlphaLayer")] = ()=>{return 0};