This commit is contained in:
ZXMushroom63 2024-12-03 20:01:40 +08:00
commit f6742d0c59
5 changed files with 115 additions and 4 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Eagler Forge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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