forked from CCBlueX/LiquidBounce
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LEGACY: Forge Mixin Improvement (CCBlueX#2786)
- Loading branch information
1 parent
4880c4a
commit 2326dee
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/net/ccbluex/liquidbounce/injection/forge/mixins/tweaks/MixinEntityFX.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.ccbluex.liquidbounce.injection.forge.mixins.tweaks; | ||
|
||
import net.minecraft.client.particle.EntityFX; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(EntityFX.class) | ||
public class MixinEntityFX { | ||
// Cache the brightness value | ||
@Unique | ||
private static final int BRIGHTNESS_VALUE = 0xF000F0; | ||
|
||
@Redirect(method={"renderParticle"}, at=@At(value="INVOKE", target="Lnet/minecraft/client/particle/EntityFX;getBrightnessForRender(F)I")) | ||
private int renderParticle(EntityFX entityFX, float f) { | ||
return BRIGHTNESS_VALUE; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...ain/java/net/ccbluex/liquidbounce/injection/forge/mixins/tweaks/MixinMinecraftServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.ccbluex.liquidbounce.injection.forge.mixins.tweaks; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import net.ccbluex.liquidbounce.utils.ClientUtils; | ||
import net.minecraft.server.MinecraftServer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyVariable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(MinecraftServer.class) | ||
public class MixinMinecraftServer { | ||
|
||
/** | ||
* Ensures proper resource release for the favicon in the status response. | ||
* This optimization releases the ByteBuf object to prevent resource leaks. | ||
* | ||
* @param byteBuf The ByteBuf object to be released. | ||
* @return The ByteBuf object after release. | ||
*/ | ||
@ModifyVariable( | ||
method = "addFaviconToStatusResponse", | ||
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerStatusResponse;setFavicon(Ljava/lang/String;)V", shift = At.Shift.AFTER), | ||
ordinal = 1 | ||
) | ||
private ByteBuf releaseFaviconByteBuf(ByteBuf byteBuf) { | ||
try { | ||
ClientUtils.INSTANCE.getLOGGER().info("Releasing favicon ByteBuf: {}", byteBuf); | ||
} catch (Exception e) { | ||
ClientUtils.INSTANCE.getLOGGER().error("Error occurred during favicon ByteBuf release", e); | ||
} finally { | ||
if (byteBuf != null) { | ||
byteBuf.release(); | ||
} | ||
} | ||
return byteBuf; | ||
} | ||
|
||
@Inject(method = "<init>*", at = @At("RETURN")) | ||
private void onInit(CallbackInfo ci) { | ||
try { | ||
ClientUtils.INSTANCE.getLOGGER().info("{} mixin successfully loaded!", getClass().getSimpleName()); | ||
} catch (Exception e) { | ||
ClientUtils.INSTANCE.getLOGGER().error("Failed to load {} mixin: {}", getClass().getSimpleName(), e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters