Clear encoder cache when configuration finishes & on disconnect
Credit to @XFactHD for the suggestion
This commit is contained in:
parent
97c4b35c82
commit
7a8beea66e
|
|
@ -0,0 +1,21 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.encoder_cache_leak;
|
||||
|
||||
import net.minecraft.client.multiplayer.ClientConfigurationPacketListenerImpl;
|
||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||
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.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ClientConfigurationPacketListenerImpl.class)
|
||||
@ClientOnlyMixin
|
||||
public class ClientConfigurationPacketListenerImplMixin {
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason Reset the encoder cache after configuration finishes as the registries are now changing.
|
||||
*/
|
||||
@Inject(method = "handleConfigurationFinished", at = @At("RETURN"))
|
||||
private void resetEncoderCache(CallbackInfo ci) {
|
||||
((EncoderCacheAccessor)DataComponentsAccessor.mfix$getCache()).mfix$getCache().invalidateAll();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.embeddedt.modernfix.common.mixin.perf.encoder_cache_leak;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||
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.callback.CallbackInfo;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
@ClientOnlyMixin
|
||||
public class MinecraftMixin {
|
||||
/**
|
||||
* @author embeddedt
|
||||
* @reason Make sure the encoder cache is cleared when the client disconnects, as it retains strong references
|
||||
* to registries.
|
||||
*/
|
||||
@Inject(method = {
|
||||
"disconnect(Lnet/minecraft/client/gui/screens/Screen;Z)V",
|
||||
"clearClientLevel(Lnet/minecraft/client/gui/screens/Screen;)V"
|
||||
}, at = @At("RETURN"))
|
||||
private void clearEncoderCache(CallbackInfo ci) {
|
||||
((EncoderCacheAccessor)DataComponentsAccessor.mfix$getCache()).mfix$getCache().invalidateAll();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user