Skip to content

Commit

Permalink
Add emoji context mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldexun committed Aug 21, 2024
1 parent e01453e commit 0b34a06
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ final def mod_dependencies = [
'curse.maven:effortlessbuilding-302113:2847346' : [debug_effortless_building],
'curse.maven:elementary-staffs-346007:2995593' : [debug_elementary_staffs],
'curse.maven:elenaidodge2-442962:3343308' : [debug_elenai_dodge_2],
'curse.maven:emojicord-349107:4000684' : [debug_emojicord],
'curse.maven:enderstorage-245174:2755787' : [debug_enderstorage],
'curse.maven:epic-siege-mod-229449:3356157' : [debug_epic_siege_mod],
'curse.maven:extrautilities-225561:2678374' : [debug_extra_utilities_2],
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ debug_crafttweaker = false
debug_effortless_building = false
debug_elementary_staffs = false
debug_elenai_dodge_2 = false
debug_emojicord = false
debug_enderio = false
debug_enderstorage = false
debug_epic_siege_mod = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public class UTConfigMods
@Config.Name("Elenai Dodge 2")
public static final ElenaiDodge2Category ELENAI_DODGE_2 = new ElenaiDodge2Category();

@Config.LangKey("cfg.universaltweaks.modintegration.emojicord")
@Config.Name("Emojicord")
public static final EmojicordCategory EMOJICORD = new EmojicordCategory();

@Config.LangKey("cfg.universaltweaks.modintegration.enderstorage")
@Config.Name("Ender Storage")
public static final EnderStorageCategory ENDER_STORAGE = new EnderStorageCategory();
Expand Down Expand Up @@ -443,6 +447,14 @@ public static class ElenaiDodge2Category
public int utED2SprintingFeatherRequirement = 6;
}

public static class EmojicordCategory
{
@Config.RequiresMcRestart
@Config.Name("Emoji Context")
@Config.Comment("Improves emoji context calculation to improve fps when rendering a lot of text")
public boolean utEmojiContextToggle = true;
}

public static class EnderStorageCategory
{
@Config.RequiresMcRestart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import mod.acgaming.universaltweaks.UniversalTweaks;
import mod.acgaming.universaltweaks.config.UTConfigBugfixes;
import mod.acgaming.universaltweaks.config.UTConfigGeneral;
import mod.acgaming.universaltweaks.config.UTConfigMods;
import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import mod.acgaming.universaltweaks.util.UTReflectionUtil;
import zone.rong.mixinbooter.IEarlyMixinLoader;
Expand Down Expand Up @@ -152,6 +153,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.world.village.json", () -> UTConfigTweaks.WORLD.utVillageDistance != 32);
}
});
public static boolean emojicordLoaded;
public static boolean openModsLoaded;
public static boolean surgeLoaded;
private static final Map<String, Supplier<Boolean>> clientsideMixinConfigs = ImmutableMap.copyOf(new HashMap<String, Supplier<Boolean>>()
Expand All @@ -171,6 +173,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.bugfixes.misc.spectatormenu.json", () -> UTConfigBugfixes.MISC.utSpectatorMenuToggle);
put("mixins.bugfixes.misc.startup.json", () -> UTConfigTweaks.PERFORMANCE.utFasterBackgroundStartupToggle);
put("mixins.bugfixes.world.frustumculling.json", () -> UTConfigBugfixes.WORLD.utFrustumCullingToggle);
put("mixins.mods.emojicord.emojicontext.json", () -> UTConfigMods.EMOJICORD.utEmojiContextToggle && emojicordLoaded);
put("mixins.tweaks.blocks.betterplacement.json", () -> UTConfigTweaks.BLOCKS.BETTER_PLACEMENT.utBetterPlacementToggle);
put("mixins.tweaks.blocks.hitdelay.json", () -> UTConfigTweaks.BLOCKS.utBlockHitDelay != 5);
put("mixins.tweaks.entities.autojump.json", () -> UTConfigTweaks.ENTITIES.utAutoJumpToggle);
Expand Down Expand Up @@ -232,6 +235,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
Locale.setDefault(Locale.ENGLISH);
}

emojicordLoaded = UTReflectionUtil.isClassLoaded("net.teamfruit.emojicord.asm.EmojicordCorePlugin");
openModsLoaded = UTReflectionUtil.isClassLoaded("openmods.core.OpenModsClassTransformer");
randomPatchesLoaded = UTReflectionUtil.isClassLoaded("com.therandomlabs.randompatches.core.RPCore");
renderLibLoaded = UTReflectionUtil.isClassLoaded("meldexun.renderlib.RenderLib");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package mod.acgaming.universaltweaks.mods.emojicord.emojicontext;

public class EmojiFontRendererContext
{

public static boolean isChatInput;
public static boolean isChatMessage;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package mod.acgaming.universaltweaks.mods.emojicord.emojicontext.mixin;

import java.util.EnumSet;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

import mod.acgaming.universaltweaks.mods.emojicord.emojicontext.EmojiFontRendererContext;
import net.teamfruit.emojicord.EmojicordConfig;
import net.teamfruit.emojicord.emoji.EmojiContext;
import net.teamfruit.emojicord.emoji.EmojiContext.EmojiContextAttribute;
import net.teamfruit.emojicord.emoji.EmojiFontRenderer;

@Mixin(value = EmojiFontRenderer.class, remap = false)
public class UTEmojiFontRendererMixin
{

@Shadow(remap = false)
private static EmojiContext CurrentContext;

@Overwrite(remap = false)
public static String updateEmojiContext(final String text)
{
if (EmojicordConfig.spec.isAvailable() && EmojicordConfig.RENDER.renderEnabled.get())
{
final EnumSet<EmojiContextAttribute> attributes = EnumSet.noneOf(EmojiContextAttribute.class);
if (EmojiFontRendererContext.isChatInput)
attributes.add(EmojiContextAttribute.CHAT_INPUT);
if (EmojiFontRendererContext.isChatMessage)
attributes.add(EmojiContextAttribute.CHAT_MESSAGE);
CurrentContext = EmojiContext.EmojiContextCache.instance.getContext(text, attributes);
return CurrentContext.text;
}
CurrentContext = null;
return text;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mod.acgaming.universaltweaks.mods.emojicord.emojicontext.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import mod.acgaming.universaltweaks.mods.emojicord.emojicontext.EmojiFontRendererContext;
import net.minecraft.client.gui.GuiChat;

@Mixin(GuiChat.class)
public class UTGuiChatMixin
{

@ModifyVariable(method = "drawScreen", at = @At("HEAD"), index = 3, ordinal = 0, name = "partialTicks")
private float pre_drawScreen(float partialTicks)
{
EmojiFontRendererContext.isChatInput = true;
return partialTicks;
}

@ModifyVariable(method = "drawScreen", at = @At("RETURN"), index = 3, ordinal = 0, name = "partialTicks")
private float post_drawScreen(float partialTicks)
{
EmojiFontRendererContext.isChatInput = false;
return partialTicks;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package mod.acgaming.universaltweaks.mods.emojicord.emojicontext.mixin;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import mod.acgaming.universaltweaks.mods.emojicord.emojicontext.EmojiFontRendererContext;
import net.minecraft.client.gui.GuiNewChat;

@Mixin(GuiNewChat.class)
public class UTGuiNewChatMixin
{

@ModifyVariable(method = "drawChat", at = @At("HEAD"), index = 1, ordinal = 0, name = "updateCounter")
private int pre_drawChat(int updateCounter)
{
EmojiFontRendererContext.isChatMessage = true;
return updateCounter;
}

@ModifyVariable(method = "drawChat", at = @At("RETURN"), index = 1, ordinal = 0, name = "updateCounter")
private int post_drawChat(int updateCounter)
{
EmojiFontRendererContext.isChatMessage = false;
return updateCounter;
}

}
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cfg.universaltweaks.modintegration.cqrepoured=Chocolate Quest Repoured
cfg.universaltweaks.modintegration.effortlessbuilding=Effortless Building
cfg.universaltweaks.modintegration.elementarystaffs=Elementary Staffs
cfg.universaltweaks.modintegration.elenaidodge2=Elenai Dodge 2
cfg.universaltweaks.modintegration.emojicord=Emojicord
cfg.universaltweaks.modintegration.enderstorage=Ender Storage
cfg.universaltweaks.modintegration.erebus=The Erebus
cfg.universaltweaks.modintegration.esm=Epic Siege Mod
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.mods.emojicord.emojicontext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.mods.emojicord.emojicontext.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTEmojiFontRendererMixin", "UTGuiChatMixin", "UTGuiNewChatMixin"]
}

0 comments on commit 0b34a06

Please sign in to comment.