diff --git a/common/build.gradle b/common/build.gradle index e4cf9bb..6d81433 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,6 +1,6 @@ repositories { maven { url "https://maven.terraformersmc.com/" } - maven { url = "https://api.modrinth.com/maven" } + maven { url "https://api.modrinth.com/maven" } } dependencies { diff --git a/common/src/main/java/moe/caramel/chat/Main.java b/common/src/main/java/moe/caramel/chat/Main.java index 9e9ced8..645414d 100644 --- a/common/src/main/java/moe/caramel/chat/Main.java +++ b/common/src/main/java/moe/caramel/chat/Main.java @@ -18,9 +18,7 @@ */ public final class Main { - public static final String MOD_ID = "caramelchat"; static { Main.instance = new Main(); } - public static final boolean DEBUG = false; private static Main instance; diff --git a/common/src/main/java/moe/caramel/chat/PlatformProvider.java b/common/src/main/java/moe/caramel/chat/PlatformProvider.java new file mode 100644 index 0000000..9ef8b7c --- /dev/null +++ b/common/src/main/java/moe/caramel/chat/PlatformProvider.java @@ -0,0 +1,77 @@ +package moe.caramel.chat; + +import moe.caramel.chat.util.ModLogger; + +/** + * Platform Provider Interface + */ +public abstract class PlatformProvider { + + /** + * Mod id. + */ + public static final String MOD_ID = "caramelchat"; + + /** + * Default Provider. + */ + public static final PlatformProvider DEFAULT = new PlatformProvider() { + @Override + public String getVersion() { + return "UNKNOWN"; + } + + @Override + public String getPlatformName() { + return "UNKNOWN"; + } + }; + + // ================================ + + private static PlatformProvider provider = PlatformProvider.DEFAULT; + + /** + * Gets the Platform provider. + * + * @return provider + */ + public static PlatformProvider getProvider() { + return provider; + } + + /** + * Sets the Platform provider. + * + * @param provider provider + */ + public static void setProvider(final PlatformProvider provider) { + if (PlatformProvider.provider == PlatformProvider.DEFAULT) { + PlatformProvider.provider = provider; + ModLogger.log("The platform provider has been loaded: {}", provider); + } else { + throw new UnsupportedOperationException(); + } + } + + // ================================ + + /** + * Gets the current mod version. + * + * @return mod version + */ + public abstract String getVersion(); + + /** + * Gets the current platform name. + * + * @return platform name + */ + public abstract String getPlatformName(); + + @Override + public String toString() { + return "(" + getPlatformName() + " / " + getVersion() + ")"; + } +} diff --git a/common/src/main/java/moe/caramel/chat/driver/IController.java b/common/src/main/java/moe/caramel/chat/driver/IController.java index 1056217..05c926b 100644 --- a/common/src/main/java/moe/caramel/chat/driver/IController.java +++ b/common/src/main/java/moe/caramel/chat/driver/IController.java @@ -7,6 +7,7 @@ import moe.caramel.chat.util.ModLogger; import moe.caramel.chat.wrapper.AbstractIMEWrapper; import net.minecraft.client.gui.screens.Screen; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; /** @@ -36,6 +37,16 @@ public interface IController { */ void setFocus(final boolean focus); + /** + * Gets the current keyboard status. + * + * @return keyboard status (if {@code null}, OS isn't supported) + */ + @Nullable + default KeyboardStatus getKeyboardStatus() { + return null; + } + /** * Gets the controller. * @@ -58,6 +69,6 @@ static IController getController() { } catch (final Exception exception) { ModLogger.error("Error while loading the CocoaInput Driver.", exception); } - return new UnknownController(); + return UnknownController.INSTANCE; } } diff --git a/common/src/main/java/moe/caramel/chat/driver/IOperator.java b/common/src/main/java/moe/caramel/chat/driver/IOperator.java index 189ee07..c4f2101 100644 --- a/common/src/main/java/moe/caramel/chat/driver/IOperator.java +++ b/common/src/main/java/moe/caramel/chat/driver/IOperator.java @@ -5,6 +5,13 @@ */ public interface IOperator { + /** + * Gets the IME controller. + * + * @return controller + */ + IController getController(); + /** * Set whether to focus or not. (Wrapper) * diff --git a/common/src/main/java/moe/caramel/chat/driver/KeyboardStatus.java b/common/src/main/java/moe/caramel/chat/driver/KeyboardStatus.java new file mode 100644 index 0000000..77753b1 --- /dev/null +++ b/common/src/main/java/moe/caramel/chat/driver/KeyboardStatus.java @@ -0,0 +1,54 @@ +package moe.caramel.chat.driver; + +/** + * Gets the current keyboard status. + * + * @param language current ime language + * @param useNative whether to using the native language + */ +public record KeyboardStatus(Language language, boolean useNative) { + + @Override + public Language language() { + return useNative() ? language : Language.ENGLISH; + } + + /** + * Gets the display to use for language change notifications. + * + * @return display + */ + public String display() { + return language().display; + } + + /** + * Gets the indicator X offset. + * + * @return X offset + */ + public float offset() { + return language().offset; + } + + /** + * Display List + */ + public enum Language { + + ENGLISH("ENG", 0.5f), + KOREAN("한", 0.0f), + JAPANESE("あ", 0.5f), + CHINESE_SIMPLIFIED("中", 0.5f), + CHINESE_TRADITIONAL("中", 0.5f), + OTHER("Native", 0.5f); + + private final String display; + private final float offset; + + Language(final String display, final float offset) { + this.display = display; + this.offset = offset; + } + } +} diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/darwin/DarwinOperator.java b/common/src/main/java/moe/caramel/chat/driver/arch/darwin/DarwinOperator.java index 9411ea8..b102e02 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/darwin/DarwinOperator.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/darwin/DarwinOperator.java @@ -1,6 +1,7 @@ package moe.caramel.chat.driver.arch.darwin; import com.mojang.blaze3d.platform.Window; +import moe.caramel.chat.driver.IController; import moe.caramel.chat.driver.IOperator; import moe.caramel.chat.util.ModLogger; import moe.caramel.chat.wrapper.AbstractIMEWrapper; @@ -55,6 +56,11 @@ public DarwinOperator(final DarwinController controller, final AbstractIMEWrappe ); } + @Override + public IController getController() { + return controller; + } + @Override public void setFocused(final boolean focus) { if (focus != this.nowFocused) { diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownController.java b/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownController.java index fc141de..d42f3fb 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownController.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownController.java @@ -11,7 +11,9 @@ */ public final class UnknownController implements IController { - public UnknownController() { + public static final IController INSTANCE = new UnknownController(); + + private UnknownController() { ModLogger.log("[Native] Load the Unknown Controller."); } diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownOperator.java b/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownOperator.java index fd3a5b8..98096b8 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownOperator.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/unknown/UnknownOperator.java @@ -1,5 +1,6 @@ package moe.caramel.chat.driver.arch.unknown; +import moe.caramel.chat.driver.IController; import moe.caramel.chat.driver.IOperator; /** @@ -7,6 +8,11 @@ */ public final class UnknownOperator implements IOperator { + @Override + public IController getController() { + return UnknownController.INSTANCE; + } + @Override public void setFocused(final boolean focus) { } diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/win/Driver_Win.java b/common/src/main/java/moe/caramel/chat/driver/arch/win/Driver_Win.java index 122242b..1f3dfb5 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/win/Driver_Win.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/win/Driver_Win.java @@ -4,12 +4,28 @@ import com.sun.jna.Library; import com.sun.jna.Pointer; import com.sun.jna.WString; +import moe.caramel.chat.driver.KeyboardStatus.Language; +import java.util.Map; /** * CocoaInput Windows Driver */ public interface Driver_Win extends Library { + int LAYOUT_CHINESE_TRADITIONAL = 0x0404; + int LAYOUT_JAPANESE = 0x0411; + int LAYOUT_KOREAN = 0x0412; + int LAYOUT_CHINESE_SIMPLIFIED = 0x0804; + + Map LAYOUT_MAP = Map.of( + LAYOUT_KOREAN, Language.KOREAN, + LAYOUT_JAPANESE, Language.JAPANESE, + LAYOUT_CHINESE_SIMPLIFIED, Language.CHINESE_SIMPLIFIED, + LAYOUT_CHINESE_TRADITIONAL, Language.CHINESE_TRADITIONAL + ); + + // ================================ + /** * Initialize CocoaInput Windows Driver. * @@ -38,6 +54,20 @@ void initialize( */ void set_focus(final int flag); + /** + * Gets the current keyboard layout. + * + * @return current keyboard layout + */ + int getKeyboardLayout(); + + /** + * Gets the current IME status. + * + * @return IME status. (Native if 1) + */ + int getStatus(); + // ================================ interface PreeditCallback extends Callback { diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/win/WinController.java b/common/src/main/java/moe/caramel/chat/driver/arch/win/WinController.java index 4e67d65..4ea9234 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/win/WinController.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/win/WinController.java @@ -1,10 +1,13 @@ package moe.caramel.chat.driver.arch.win; +import static moe.caramel.chat.driver.arch.win.Driver_Win.LAYOUT_MAP; import com.sun.jna.Native; import moe.caramel.chat.Main; import moe.caramel.chat.controller.ScreenController; import moe.caramel.chat.driver.IController; import moe.caramel.chat.driver.IOperator; +import moe.caramel.chat.driver.KeyboardStatus; +import moe.caramel.chat.driver.KeyboardStatus.Language; import moe.caramel.chat.util.ModLogger; import moe.caramel.chat.wrapper.AbstractIMEWrapper; import net.minecraft.client.Minecraft; @@ -89,4 +92,12 @@ public void changeFocusedScreen(final Screen screen) { public void setFocus(final boolean focus) { this.driver.set_focus(focus ? 1 : 0); } + + @Override + public KeyboardStatus getKeyboardStatus() { + return new KeyboardStatus( + LAYOUT_MAP.getOrDefault(driver.getKeyboardLayout(), Language.OTHER), + (driver.getStatus() != 0) + ); + } } diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/win/WinOperator.java b/common/src/main/java/moe/caramel/chat/driver/arch/win/WinOperator.java index d164a7a..411acde 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/win/WinOperator.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/win/WinOperator.java @@ -1,5 +1,6 @@ package moe.caramel.chat.driver.arch.win; +import moe.caramel.chat.driver.IController; import moe.caramel.chat.driver.IOperator; import moe.caramel.chat.util.ModLogger; import moe.caramel.chat.wrapper.AbstractIMEWrapper; @@ -27,6 +28,11 @@ public AbstractIMEWrapper getWrapper() { return wrapper; } + @Override + public IController getController() { + return controller; + } + @Override public void setFocused(final boolean focus) { if (focus == this.nowFocused) { diff --git a/common/src/main/java/moe/caramel/chat/driver/arch/x11/X11Operator.java b/common/src/main/java/moe/caramel/chat/driver/arch/x11/X11Operator.java index 46654c8..8bff4e0 100644 --- a/common/src/main/java/moe/caramel/chat/driver/arch/x11/X11Operator.java +++ b/common/src/main/java/moe/caramel/chat/driver/arch/x11/X11Operator.java @@ -1,5 +1,6 @@ package moe.caramel.chat.driver.arch.x11; +import moe.caramel.chat.driver.IController; import moe.caramel.chat.driver.IOperator; import moe.caramel.chat.util.ModLogger; import moe.caramel.chat.wrapper.AbstractIMEWrapper; @@ -27,6 +28,11 @@ public AbstractIMEWrapper getWrapper() { return wrapper; } + @Override + public IController getController() { + return controller; + } + @Override public void setFocused(final boolean focus) { if (focus == this.nowFocused) { diff --git a/common/src/main/java/moe/caramel/chat/mixin/MixinChatScreen.java b/common/src/main/java/moe/caramel/chat/mixin/MixinChatScreen.java new file mode 100644 index 0000000..f6fc1a5 --- /dev/null +++ b/common/src/main/java/moe/caramel/chat/mixin/MixinChatScreen.java @@ -0,0 +1,137 @@ +package moe.caramel.chat.mixin; + +import static net.minecraft.client.Minecraft.UNIFORM_FONT; +import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; +import moe.caramel.chat.Main; +import moe.caramel.chat.PlatformProvider; +import moe.caramel.chat.controller.EditBoxController; +import moe.caramel.chat.driver.KeyboardStatus; +import moe.caramel.chat.wrapper.WrapperEditBox; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.gui.components.CommandSuggestions; +import net.minecraft.client.gui.components.EditBox; +import net.minecraft.client.gui.screens.ChatScreen; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.util.Mth; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +/** + * Chat screen Mixin + */ +@Mixin(ChatScreen.class) +public abstract class MixinChatScreen { + + @Shadow protected EditBox input; + @Shadow CommandSuggestions commandSuggestions; + + @Unique private static final int TOOLTIP_TIME = 500; + @Unique private static final int FADE_TIME = 250; + @Unique private static final Component MARK_VERSION = Component + .translatable("caramelChat v%s", PlatformProvider.getProvider().getVersion()) + .setStyle(Style.EMPTY.withHoverEvent(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + Component.translatable("caramel.chat.redistribution_warn") + ))); + + @Unique KeyboardStatus.Language caramelChat$lastLanguage; + @Unique long caramelChat$changeTime; + + @Inject(method = "render", at = @At("HEAD")) + private void render(final PoseStack stack, final int mouseX, final int mouseY, final float tickDelta, final CallbackInfo ci) { + final Screen screen = ((Screen) (Object) this); + RenderSystem.enableBlend(); + this.caramelChat$renderMark(screen, stack, mouseX, mouseY, tickDelta); + this.caramelChat$renderImeStatus(screen, stack, mouseX, mouseY, tickDelta); + RenderSystem.disableBlend(); + } + + @Unique + private void caramelChat$renderMark(final Screen screen, final PoseStack stack, final int mouseX, final int mouseY, final float tickDelta) { + final int markStartY = 10; + final int markEndY = (markStartY + screen.font.lineHeight); + final int markEndX = (screen.width - 10); + final int markStartX = (markEndX - screen.font.width(MARK_VERSION)); + + screen.font.draw(stack, MARK_VERSION, markStartX, markStartY, 0x33FFFFFF); + if ( (markStartX <= mouseX && mouseX <= markEndX) && (markStartY <= mouseY && mouseY <= markEndY) ) { + screen.renderComponentHoverEffect(stack, MARK_VERSION.getStyle(), mouseX, mouseY); + } + } + + @Unique + private void caramelChat$renderImeStatus(final Screen screen, final PoseStack stack, final int mouseX, final int mouseY, final float tickDelta) { + final WrapperEditBox wrapper = EditBoxController.getWrapper(this.input); + final KeyboardStatus status = wrapper.getIme().getController().getKeyboardStatus(); + if (status == null) { + return; // Unsupported OS + } + + /* Render Debug information */ + if (Main.DEBUG) { + GuiComponent.drawString(stack, screen.font, status.toString(), 10, 10, 0xFFFFFFFF); + } + + /* Check Render condition */ + final long currentTime = System.currentTimeMillis(); + if (this.caramelChat$lastLanguage != status.language()) { + this.caramelChat$lastLanguage = status.language(); + this.caramelChat$changeTime = currentTime; + } + + final int elapsed = (int) (currentTime - this.caramelChat$changeTime); + if (elapsed > TOOLTIP_TIME) { + return; + } + + /* Calculate Position */ + final CommandSuggestions suggestions = this.commandSuggestions; + final Component display = Component.literal(status.display()).withStyle(style -> style.withFont(UNIFORM_FONT)); + + int borderStartX = 2; + int borderEndX = (borderStartX + Mth.floor(screen.font.getSplitter().stringWidth(display) - status.offset()) + 4); + final int suggestionWidth = (suggestions.suggestions != null) ? suggestions.suggestions.rect.getX() : Integer.MAX_VALUE; + if (suggestionWidth <= borderEndX) { + final int safeRange = (suggestionWidth - borderEndX - 2); + borderStartX += safeRange; + borderEndX += safeRange; + } + + final int usageHeight = (suggestions.suggestions == null && suggestions.commandUsagePosition == 0) ? (12 * suggestions.commandUsage.size()) : 0; + final int borderEndY = (screen.height - 14 - usageHeight - 2); + final int borderStartY = (borderEndY - screen.font.lineHeight - 2); + + /* Render */ + final int backColor = this.caramelChat$color(Minecraft.getInstance().options.getBackgroundColor(Integer.MIN_VALUE), elapsed); + final int textColor = this.caramelChat$color(0xFFFFFFFF, elapsed); + GuiComponent.fill(stack, borderStartX, borderStartY, borderEndX, borderEndY, backColor); + screen.font.draw(stack, display, (borderStartX + 2), (borderStartY + 1), textColor); + } + + @Unique + private int caramelChat$color(final int color, final int elapsed) { + // Fade time hasn't started yet. + if (elapsed < FADE_TIME) { + return color; + } + + // Calculate alpha value + final int initialAlpha = ( (color >> 24) & 0xFF ); + final float progress = ((float) (TOOLTIP_TIME - elapsed) / FADE_TIME); + final int alpha = (int) (progress * initialAlpha); + if (alpha < 5) { + return 0; + } + + return (alpha << 24) | (color & 0x00FFFFFF); + } +} diff --git a/common/src/main/java/moe/caramel/chat/mixin/xaeromap/MixinPluginXaeroMapWayPoint.java b/common/src/main/java/moe/caramel/chat/mixin/xaeromap/MixinPluginXaeroMapWayPoint.java index ac76880..92d4e9c 100644 --- a/common/src/main/java/moe/caramel/chat/mixin/xaeromap/MixinPluginXaeroMapWayPoint.java +++ b/common/src/main/java/moe/caramel/chat/mixin/xaeromap/MixinPluginXaeroMapWayPoint.java @@ -14,7 +14,7 @@ import xaero.common.gui.GuiAddWaypoint; /** - * (Xaero's Minimap Mixin) ???. + * (Xaero's Minimap Mixin) Fix IME. */ @Mixin(GuiAddWaypoint.class) public abstract class MixinPluginXaeroMapWayPoint { @@ -22,7 +22,7 @@ public abstract class MixinPluginXaeroMapWayPoint { @Shadow private EditBox nameTextField; @Shadow private EditBox initialTextField; @Shadow(remap = false) private boolean ignoreEditBoxChanges; - @Shadow(remap = false) protected abstract void postType(GuiEventListener focused); + @Shadow(remap = false) protected abstract void postType(final GuiEventListener focused); @Inject(method = "init", at = @At("TAIL")) private void init(final CallbackInfo ci) { diff --git a/common/src/main/resources/assets/caramelchat/lang/en_us.json b/common/src/main/resources/assets/caramelchat/lang/en_us.json index ec1922a..a3faf37 100644 --- a/common/src/main/resources/assets/caramelchat/lang/en_us.json +++ b/common/src/main/resources/assets/caramelchat/lang/en_us.json @@ -1,3 +1,5 @@ { - "modmenu.descriptionTranslation.caramelchat": "Provides an enhanced IME input experience in Minecraft." + "modmenu.descriptionTranslation.caramelchat": "Provides an enhanced IME input experience in Minecraft.", + + "caramel.chat.redistribution_warn": "caramelChat is exclusively distributed on Modrinth. Please refrain from redistributing it." } diff --git a/common/src/main/resources/assets/caramelchat/lang/ko_kr.json b/common/src/main/resources/assets/caramelchat/lang/ko_kr.json index a6553d2..ea6cc71 100644 --- a/common/src/main/resources/assets/caramelchat/lang/ko_kr.json +++ b/common/src/main/resources/assets/caramelchat/lang/ko_kr.json @@ -1,3 +1,5 @@ { - "modmenu.descriptionTranslation.caramelchat": "Minecraft에서 향상된 IME 입력 경험을 제공합니다." + "modmenu.descriptionTranslation.caramelchat": "Minecraft에서 향상된 IME 입력 경험을 제공합니다.", + + "caramel.chat.redistribution_warn": "caramelChat은 오직 Modrinth에서만 배포합니다. 재배포는 하지 말아주세요." } diff --git a/common/src/main/resources/caramelchat.accesswidener b/common/src/main/resources/caramelchat.accesswidener index 30c0c4a..d78a089 100644 --- a/common/src/main/resources/caramelchat.accesswidener +++ b/common/src/main/resources/caramelchat.accesswidener @@ -9,6 +9,11 @@ accessible field net/minecraft/client/gui/components/EditBox cursorPos I accessible field net/minecraft/client/gui/components/EditBox highlightPos I accessible field net/minecraft/client/gui/components/EditBox responder Ljava/util/function/Consumer; +accessible field net/minecraft/client/gui/components/CommandSuggestions commandUsage Ljava/util/List; +accessible field net/minecraft/client/gui/components/CommandSuggestions commandUsagePosition I +accessible field net/minecraft/client/gui/components/CommandSuggestions suggestions Lnet/minecraft/client/gui/components/CommandSuggestions$SuggestionsList; +accessible field net/minecraft/client/gui/components/CommandSuggestions$SuggestionsList rect Lnet/minecraft/client/renderer/Rect2i; + accessible field net/minecraft/client/gui/font/TextFieldHelper setMessageFn Ljava/util/function/Consumer; mutable field net/minecraft/client/gui/font/TextFieldHelper setMessageFn Ljava/util/function/Consumer; accessible field net/minecraft/client/gui/font/TextFieldHelper stringValidator Ljava/util/function/Predicate; @@ -41,5 +46,6 @@ accessible class net/minecraft/client/gui/screens/inventory/BookEditScreen$Pos2i accessible method net/minecraft/client/gui/screens/inventory/CreativeModeInventoryScreen refreshSearchResults ()V accessible field net/minecraft/client/gui/screens/Screen font Lnet/minecraft/client/gui/Font; +accessible method net/minecraft/client/gui/screens/Screen renderComponentHoverEffect (Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/network/chat/Style;II)V accessible method net/minecraft/client/KeyboardHandler charTyped (JII)V diff --git a/common/src/main/resources/caramelchat.mixins.json b/common/src/main/resources/caramelchat.mixins.json index 180f17b..02dce1a 100644 --- a/common/src/main/resources/caramelchat.mixins.json +++ b/common/src/main/resources/caramelchat.mixins.json @@ -7,6 +7,7 @@ "required": true, "client": [ "MixinBookEditScreen", + "MixinChatScreen", "MixinCreativeModeInventoryScreen", "MixinEditBox", "MixinMinecraft", diff --git a/common/src/main/resources/native/libwincocoainput.dll b/common/src/main/resources/native/libwincocoainput.dll index 42a6234..616187f 100644 Binary files a/common/src/main/resources/native/libwincocoainput.dll and b/common/src/main/resources/native/libwincocoainput.dll differ diff --git a/fabric/src/main/java/moe/caramel/chat/fabric/FabricProvider.java b/fabric/src/main/java/moe/caramel/chat/fabric/FabricProvider.java new file mode 100644 index 0000000..0659318 --- /dev/null +++ b/fabric/src/main/java/moe/caramel/chat/fabric/FabricProvider.java @@ -0,0 +1,26 @@ +package moe.caramel.chat.fabric; + +import moe.caramel.chat.PlatformProvider; +import net.fabricmc.loader.api.Version; + +/** + * Fabric Provider + */ +public final class FabricProvider extends PlatformProvider { + + private final String version; + + public FabricProvider(final Version version) { + this.version = version.getFriendlyString(); + } + + @Override + public String getVersion() { + return version; + } + + @Override + public String getPlatformName() { + return "Fabric"; + } +} diff --git a/fabric/src/main/java/moe/caramel/chat/fabric/MainFabric.java b/fabric/src/main/java/moe/caramel/chat/fabric/MainFabric.java new file mode 100644 index 0000000..aba3c4e --- /dev/null +++ b/fabric/src/main/java/moe/caramel/chat/fabric/MainFabric.java @@ -0,0 +1,19 @@ +package moe.caramel.chat.fabric; + +import static moe.caramel.chat.PlatformProvider.MOD_ID; +import moe.caramel.chat.PlatformProvider; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; + +/** + * Fabric platform initializer + */ +public final class MainFabric implements ClientModInitializer { + + @Override + public void onInitializeClient() { + final ModContainer container = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(); + PlatformProvider.setProvider(new FabricProvider(container.getMetadata().getVersion())); + } +} diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index a64c034..05ea6d1 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -21,6 +21,9 @@ "icon": "icon.png", "environment": "client", + "entrypoints": { + "client": [ "moe.caramel.chat.fabric.MainFabric" ] + }, "accessWidener": "caramelchat.accesswidener", "mixins": [ "caramelchat.mixins.json" ], "depends": { diff --git a/forge/src/main/java/moe/caramel/chat/forge/ForgeProvider.java b/forge/src/main/java/moe/caramel/chat/forge/ForgeProvider.java new file mode 100644 index 0000000..4027129 --- /dev/null +++ b/forge/src/main/java/moe/caramel/chat/forge/ForgeProvider.java @@ -0,0 +1,25 @@ +package moe.caramel.chat.forge; + +import moe.caramel.chat.PlatformProvider; + +/** + * Forge Provider + */ +public final class ForgeProvider extends PlatformProvider { + + private final String version; + + public ForgeProvider(final String version) { + this.version = version; + } + + @Override + public String getVersion() { + return version; + } + + @Override + public String getPlatformName() { + return "Forge"; + } +} diff --git a/forge/src/main/java/moe/caramel/chat/forge/MainForge.java b/forge/src/main/java/moe/caramel/chat/forge/MainForge.java index 1841eaf..95aaa37 100644 --- a/forge/src/main/java/moe/caramel/chat/forge/MainForge.java +++ b/forge/src/main/java/moe/caramel/chat/forge/MainForge.java @@ -1,10 +1,15 @@ package moe.caramel.chat.forge; -import moe.caramel.chat.Main; +import static moe.caramel.chat.PlatformProvider.MOD_ID; +import moe.caramel.chat.PlatformProvider; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.loading.FMLLoader; -@Mod(Main.MOD_ID) +@Mod(MOD_ID) public final class MainForge { - public MainForge() { } + public MainForge() { + final String version = FMLLoader.getLoadingModList().getModFileById(MOD_ID).versionString(); + PlatformProvider.setProvider(new ForgeProvider(version)); + } } diff --git a/gradle.properties b/gradle.properties index 8fdf0dd..bbf7674 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.jvmargs=-Xmx2G archives_base_name=caramelChat -mod_version=1.1.2-SNAPSHOT +mod_version=1.2.0-SNAPSHOT maven_group=moe.caramel minecraft_version=1.19.4