Skip to content

Commit

Permalink
LEGACY: Forge Mixin Improvement (CCBlueX#2786)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclipsesDev committed Apr 13, 2024
1 parent 4880c4a commit 2326dee
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
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;
}
}
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());
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/liquidbounce.forge.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@
"render.MixinVisGraph",
"resources.MixinSkinManager",
"tweaks.MixinAnvilChunkLoader",
"tweaks.MixinMinecraftServer",
"world.MixinChunk",
"world.MixinWorld",
"world.MixinWorldClient"
],
"client": [
"gui.MixinGuiAchievement"
"gui.MixinGuiAchievement",
"tweaks.MixinEntityFX"
]
}

0 comments on commit 2326dee

Please sign in to comment.