From 0ce441882348df5fbed0b89da1e6b785f644df94 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 16 Jun 2024 15:50:35 +0100 Subject: [PATCH 1/3] feat: port to 1.21 & added mpp --- .github/workflows/build.yml | 3 +- .github/workflows/release.yml | 5 +- build.gradle | 85 ++++++++++- common/build.gradle | 24 +-- .../dev/ftb/mods/ftbguides/FTBGuides.java | 29 ++-- .../ftbguides/client/FTBGuidesClient.java | 2 +- .../mods/ftbguides/client/GuideBookColor.java | 11 +- .../ftbguides/client/gui/FTBGuidesTheme.java | 19 +-- .../ftbguides/client/gui/GuideScreen.java | 45 +++--- .../ftbguides/client/gui/SearchScreen.java | 19 ++- .../client/gui/panel/BlockQuotePanel.java | 5 +- .../client/gui/widgets/CodeBlockWidget.java | 9 +- .../client/gui/widgets/CustomTextField.java | 15 +- .../client/gui/widgets/IconButton.java | 7 +- .../client/gui/widgets/LineBreakWidget.java | 5 +- .../mods/ftbguides/config/ClientConfig.java | 8 +- .../ftb/mods/ftbguides/docs/DocMetadata.java | 4 +- .../ftb/mods/ftbguides/docs/DocRenderer.java | 7 +- .../ftb/mods/ftbguides/docs/DocsLoader.java | 7 +- .../ftb/mods/ftbguides/docs/DocsManager.java | 10 +- .../ftb/mods/ftbguides/docs/GuideIndex.java | 2 +- .../mods/ftbguides/net/OpenGuiMessage.java | 3 +- .../ftbguides/registry/GuideBookData.java | 17 +++ .../ftbguides/registry/GuideBookItem.java | 2 +- .../ftb/mods/ftbguides/registry/ModItems.java | 21 ++- fabric/build.gradle | 53 +------ fabric/src/main/resources/fabric.mod.json | 8 +- forge/build.gradle | 140 ------------------ forge/gradle.properties | 1 - gradle.properties | 27 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- neoforge/build.gradle | 95 ++++++++++++ neoforge/gradle.properties | 1 + .../ftb/mods/ftbguides/forge/ClientSetup.java | 4 +- .../mods/ftbguides/forge/FTBGuidesForge.java | 0 neoforge/src/main/resources/.DS_Store | Bin 0 -> 6148 bytes .../resources/META-INF/neoforge.mods.toml | 12 +- .../src/main/resources/pack.mcmeta | 0 settings.gradle | 6 +- 39 files changed, 368 insertions(+), 345 deletions(-) create mode 100644 common/src/main/java/dev/ftb/mods/ftbguides/registry/GuideBookData.java delete mode 100644 forge/build.gradle delete mode 100644 forge/gradle.properties create mode 100644 neoforge/build.gradle create mode 100644 neoforge/gradle.properties rename {forge => neoforge}/src/main/java/dev/ftb/mods/ftbguides/forge/ClientSetup.java (78%) rename {forge => neoforge}/src/main/java/dev/ftb/mods/ftbguides/forge/FTBGuidesForge.java (100%) create mode 100644 neoforge/src/main/resources/.DS_Store rename forge/src/main/resources/META-INF/mods.toml => neoforge/src/main/resources/META-INF/neoforge.mods.toml (74%) rename {forge => neoforge}/src/main/resources/pack.mcmeta (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ec67c57..eae06a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,7 @@ jobs: with: curse-publish-task: "" maven-snapshots: true + java-version: 21 secrets: ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }} - saps-token: ${{ secrets.SAPS_TOKEN }} \ No newline at end of file + saps-token: ${{ secrets.SAPS_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f875fc..5d42e34 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,8 +10,9 @@ jobs: !contains(github.event.head_commit.message, '[ciskip]') uses: FTBTeam/mods-meta/.github/workflows/standard-release.yml@main with: - curse-publish-task: curseforge + curse-publish-task: publishMods + java-version: 21 secrets: ftb-maven-token: ${{ secrets.FTB_MAVEN_TOKEN }} saps-token: ${{ secrets.SAPS_TOKEN }} - curse-token: ${{ secrets.CURSEFORGE_KEY }} \ No newline at end of file + curse-token: ${{ secrets.CURSEFORGE_KEY }} diff --git a/build.gradle b/build.gradle index 4659861..29069d3 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,7 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" - id "dev.architectury.loom" version "1.2-SNAPSHOT" apply false + id "dev.architectury.loom" version "1.6-SNAPSHOT" apply false + id "me.modmuss50.mod-publish-plugin" version "0.5.1" } architectury { @@ -16,10 +17,7 @@ subprojects { dependencies { minecraft "com.mojang:minecraft:${rootProject.minecraft_version}" - // The following line declares the mojmap mappings, you may use other mappings as well mappings loom.officialMojangMappings() - // The following line declares the yarn mappings you may select this one as well. - // mappings "net.fabricmc:yarn:1.19.2+build.28:v2" } } @@ -42,8 +40,18 @@ allprojects { url "https://maven.architectury.dev/" } + maven { url "https://maven.neoforged.net/" } + maven { - url "https://maven.saps.dev/minecraft" + url "https://maven.saps.dev/releases" + content { + includeGroup "dev.latvian.mods" + includeGroup "dev.ftb.mods" + } + } + + maven { + url "https://maven.saps.dev/snapshots" content { includeGroup "dev.latvian.mods" includeGroup "dev.ftb.mods" @@ -68,12 +76,75 @@ allprojects { tasks.withType(JavaCompile) { options.encoding = "UTF-8" - options.release = 17 + options.release = 21 } java { withSourcesJar() } + + publishing { + repositories { + if (ftbPublishing.ftbToken) { + maven { + url ftbPublishing.ftbURL + credentials { + username = ftbPublishing.ftbUser + password = ftbPublishing.ftbToken + } + } + } + + if (ftbPublishing.sapsToken) { + maven { + url ftbPublishing.sapsURL + credentials { + username = ftbPublishing.sapsUser + password = ftbPublishing.sapsToken + } + } + } + } + } } -task curseforgePublish +publishMods { + dryRun = providers.environmentVariable("CURSEFORGE_KEY").getOrNull() == null + changelog = providers.environmentVariable("CHANGELOG").getOrElse("No changelog provided") + version = "${mod_version}" + + // TODO: Migrate to something else + def tag = providers.environmentVariable("TAG").getOrElse("release") + type = tag == "beta" ? BETA : (tag == "alpha" ? ALPHA : STABLE) + + def createOptions = (String projectName) -> { + publishOptions { + file = project.provider { project(":$projectName").tasks.remapJar }.flatMap { it.archiveFile } + displayName = "[${projectName.toUpperCase()}][${minecraft_version}] ${readable_name} ${mod_version}" + modLoaders.add(projectName.toLowerCase()) + } + } + + def fabricOptions = createOptions("fabric") + def neoForgeOptions = createOptions("neoforge") + + def curseForgeOptions = curseforgeOptions { + accessToken = providers.environmentVariable("CURSEFORGE_KEY") + minecraftVersions.add("${minecraft_version}") + } + + curseforge("curseforgeFabric") { + from(curseForgeOptions, fabricOptions) + projectId = curseforge_id + requires("fabric-api") + requires("architectury-api") + requires('ftb-library-fabric') + } + + curseforge("curseforgeNeoForge") { + from(curseForgeOptions, neoForgeOptions) + projectId = curseforge_id + requires("architectury-api") + requires('ftb-library-forge') + } +} diff --git a/common/build.gradle b/common/build.gradle index cbbfafb..fe40766 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -11,7 +11,7 @@ dependencies { // Do NOT use other classes from fabric loader modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}" // Remove the next line if you don't want to depend on the API - modApi "dev.architectury:architectury:${rootProject.architectury_version}" + modApi "dev.architectury:architectury:${rootProject.architectury_api_version}" modApi("dev.ftb.mods:ftb-library:${rootProject.ftb_library_version}") { transitive false } @@ -27,26 +27,4 @@ publishing { from components.java } } - - repositories { - if (ftbPublishing.ftbToken) { - maven { - url ftbPublishing.ftbURL - credentials { - username = ftbPublishing.ftbUser - password = ftbPublishing.ftbToken - } - } - } - - if (ftbPublishing.sapsToken) { - maven { - url ftbPublishing.sapsURL - credentials { - username = ftbPublishing.sapsUser - password = ftbPublishing.sapsToken - } - } - } - } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java b/common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java index c241343..d3f0772 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/FTBGuides.java @@ -12,11 +12,13 @@ import dev.ftb.mods.ftbguides.commands.OpenGuiCommand; import dev.ftb.mods.ftbguides.docs.DocsLoader; import dev.ftb.mods.ftbguides.net.FTBGuidesNet; +import dev.ftb.mods.ftbguides.registry.GuideBookData; import dev.ftb.mods.ftbguides.registry.ModItems; import net.minecraft.commands.CommandBuildContext; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.packs.PackType; import net.minecraft.world.InteractionHand; @@ -27,15 +29,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.HashMap; + public class FTBGuides { public static final String MOD_ID = "ftbguides"; public static final String MOD_NAME = "FTB Guides"; public static final Logger LOGGER = LogManager.getLogger(MOD_NAME); - public static final CreativeModeTab ITEM_GROUP = CreativeTabRegistry.create( - new ResourceLocation(MOD_ID, MOD_ID), () -> new ItemStack(ModItems.BOOK.get()) - ); - public static void init() { ReloadListenerRegistry.register(PackType.CLIENT_RESOURCES, new DocsLoader()); @@ -50,18 +50,21 @@ public static void init() { } public static ResourceLocation rl(String path) { - return new ResourceLocation(FTBGuides.MOD_ID, path); + return ResourceLocation.fromNamespaceAndPath(FTBGuides.MOD_ID, path); } private static CompoundEventResult rightClickItem(Player player, InteractionHand interactionHand) { - if (player.level.isClientSide) { + if (player.level().isClientSide) { ItemStack stack = player.getItemInHand(interactionHand); - if (stack.hasTag()) { - String target = stack.getTag().getString(MOD_ID + ":page"); - if (!target.isEmpty()) { - FTBGuidesClient.openGui(target); - return CompoundEventResult.interruptTrue(stack); + GuideBookData data = stack.get(ModItems.GUIDE_DATA.get()); + if (data != null) { + String target = data.guide(); + if (target.isEmpty()) { + return CompoundEventResult.pass(); } + + FTBGuidesClient.openGui(target); + return CompoundEventResult.interruptTrue(stack); } } return CompoundEventResult.pass(); @@ -78,9 +81,7 @@ public static ItemStack makeGuideBook(Item item, String page) { } public static ItemStack makeGuideBook(ItemStack stack, String page) { - CompoundTag tag = stack.hasTag() ? stack.getTag() : new CompoundTag(); - tag.putString(MOD_ID + ":page", page); - stack.setTag(tag); + stack.set(ModItems.GUIDE_DATA.get(), new GuideBookData(page)); return stack; } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/FTBGuidesClient.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/FTBGuidesClient.java index 228602f..4febca6 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/FTBGuidesClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/FTBGuidesClient.java @@ -21,6 +21,6 @@ public static void openGui(@Nullable String path) { } public static void displayError(Component error) { - Minecraft.getInstance().getToasts().addToast(new SystemToast(SystemToast.SystemToastIds.TUTORIAL_HINT, Component.translatable("ftbguides.gui.error"), error)); + Minecraft.getInstance().getToasts().addToast(new SystemToast(SystemToast.SystemToastId.WORLD_BACKUP, Component.translatable("ftbguides.gui.error"), error)); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/GuideBookColor.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/GuideBookColor.java index 03c574e..9539a44 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/GuideBookColor.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/GuideBookColor.java @@ -1,6 +1,8 @@ package dev.ftb.mods.ftbguides.client; import dev.ftb.mods.ftbguides.FTBGuides; +import dev.ftb.mods.ftbguides.registry.GuideBookData; +import dev.ftb.mods.ftbguides.registry.ModItems; import dev.ftb.mods.ftblibrary.icon.Color4I; import net.minecraft.Util; import net.minecraft.client.color.item.ItemColor; @@ -26,8 +28,11 @@ public int getColor(ItemStack itemStack, int layer) { } private static String getBookNamespace(ItemStack itemStack) { - //noinspection DataFlowIssue - String s = itemStack.hasTag() ? itemStack.getTag().getString(FTBGuides.MOD_ID + ":page") : ""; - return s.split(":")[0]; + GuideBookData guideBookData = itemStack.get(ModItems.GUIDE_DATA.get()); + if (guideBookData == null || guideBookData.guide().isEmpty()) { + return ""; + } + + return guideBookData.guide().split(":")[0]; } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/FTBGuidesTheme.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/FTBGuidesTheme.java index 78fa5b0..d120a05 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/FTBGuidesTheme.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/FTBGuidesTheme.java @@ -7,6 +7,7 @@ import dev.ftb.mods.ftblibrary.ui.GuiHelper; import dev.ftb.mods.ftblibrary.ui.Theme; import dev.ftb.mods.ftblibrary.ui.WidgetType; +import net.minecraft.client.gui.GuiGraphics; public class FTBGuidesTheme extends Theme { private final GuideScreen screen; @@ -20,20 +21,20 @@ private GuideIndex.GuideTheme getGuideTheme() { } @Override - public void drawContextMenuBackground(PoseStack matrixStack, int x, int y, int w, int h) { - getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h); - GuiHelper.drawRectWithShade(matrixStack, x, y, w, h, getGuideTheme().guiColor(), 16); + public void drawContextMenuBackground(GuiGraphics guiGraphics, int x, int y, int w, int h) { + getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h); + GuiHelper.drawRectWithShade(guiGraphics, x, y, w, h, getGuideTheme().guiColor(), 16); } @Override - public void drawScrollBarBackground(PoseStack matrixStack, int x, int y, int w, int h, WidgetType type) { - getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h); - GuiHelper.drawRectWithShade(matrixStack, x, y, w, h, getGuideTheme().guiColor(), -16); + public void drawScrollBarBackground(GuiGraphics guiGraphics, int x, int y, int w, int h, WidgetType type) { + getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h); + GuiHelper.drawRectWithShade(guiGraphics, x, y, w, h, getGuideTheme().guiColor(), -16); } @Override - public void drawScrollBar(PoseStack matrixStack, int x, int y, int w, int h, WidgetType type, boolean vertical) { - getGuideTheme().guiColor().withAlpha(128).draw(matrixStack, x + 2, y + 1, w - 4, h - 2); - GuiHelper.drawRectWithShade(matrixStack, x + 2, y + 1, w - 4, h - 2, getGuideTheme().guiColor(), 16); + public void drawScrollBar(GuiGraphics guiGraphics, int x, int y, int w, int h, WidgetType type, boolean vertical) { + getGuideTheme().guiColor().withAlpha(128).draw(guiGraphics, x + 2, y + 1, w - 4, h - 2); + GuiHelper.drawRectWithShade(guiGraphics, x + 2, y + 1, w - 4, h - 2, getGuideTheme().guiColor(), 16); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/GuideScreen.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/GuideScreen.java index 5bb496c..380053f 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/GuideScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/GuideScreen.java @@ -17,6 +17,7 @@ import dev.ftb.mods.ftblibrary.ui.input.MouseButton; import dev.ftb.mods.ftblibrary.util.TooltipList; import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; @@ -200,7 +201,7 @@ public void showSearchResults(String searchTerm) { Parser parser = Parser.builder().build(); Node node = parser.parse(markdown.toString()); - ResourceLocation id = new ResourceLocation(activeNode.pageId().getNamespace(), "_search"); + ResourceLocation id = ResourceLocation.fromNamespaceAndPath(activeNode.pageId().getNamespace(), "_search"); setActivePage(new DocsLoader.NodeWithMeta(id, node, DocMetadata.searchResult(searchResults))); } @@ -239,8 +240,8 @@ private void toggleExpanded(String catId) { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { - getGuideTheme().bgColor().draw(matrixStack, x, y, w, h); + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { + getGuideTheme().bgColor().draw(guiGraphics, x, y, w, h); } @Override @@ -278,15 +279,17 @@ public boolean navigateTo(String target, boolean addToHistory) { pageId = pageId.replaceAll("\\.md$", ""); + ResourceLocation location; if (pageId.isEmpty() && !anchor.isEmpty()) { // just jumping to an anchor in the current doc if (scrollToAnchor(anchor)) { if (addToHistory) addToHistory(anchor); } - } else if (ResourceLocation.isValidResourceLocation(pageId)) { + // TODO: I think I ported the parse logic wrong here + } else if ((location = ResourceLocation.tryParse(pageId)) != null) { ResourceLocation newPage = pageId.contains(":") ? - new ResourceLocation(pageId) : - activeNode != null ? new ResourceLocation(activeNode.pageId().getNamespace(), pageId) : rl(pageId); + location : + activeNode != null ? ResourceLocation.fromNamespaceAndPath(activeNode.pageId().getNamespace(), pageId) : rl(pageId); if (setActivePage(newPage) && (anchor.isEmpty() || scrollToAnchor(anchor))) { if (addToHistory) addToHistory(anchor); } else { @@ -324,7 +327,7 @@ public boolean scrollToAnchor(String anchorName) { if (anchorName.isEmpty()) { return false; } - for (Widget w : docsPanel.widgets) { + for (Widget w : docsPanel.getWidgets()) { if (w instanceof Anchorable a && a.getAnchorName().equals(anchorName)) { docsScrollbar.setValue(w.posY); return true; @@ -402,9 +405,9 @@ public int getX() { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { - getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h); - getGuideTheme().guiColor().draw(matrixStack, x + w - 1, y, 1, h); + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { + getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h); + getGuideTheme().guiColor().draw(guiGraphics, x + w - 1, y, 1, h); } private abstract class ListButton extends SimpleTextButton { @@ -414,7 +417,7 @@ public ListButton(Component title, Icon icon) { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { } protected int getIndent() { @@ -437,11 +440,11 @@ public void onClicked(MouseButton button) { } @Override - public void draw(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { + public void draw(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { if (node == activeNode) { - getGuideTheme().linkColor().withAlpha(128).draw(matrixStack, x, y, parent.width - posX - 3, h); + getGuideTheme().linkColor().withAlpha(128).draw(guiGraphics, x, y, parent.width - posX - 3, h); } - super.draw(matrixStack, theme, x, y, w, h); + super.draw(guiGraphics, theme, x, y, w, h); } @Override @@ -487,7 +490,7 @@ public void addWidgets() { public void alignWidgets() { align(new WidgetLayout.Vertical(0, 4, 0)); - docsScrollbar.setMaxValue(getContentHeight()); +// docsScrollbar.setMaxValue(getContentHeight()); docsScrollbar.setValue(lastScrollPos); } @@ -548,8 +551,8 @@ public void alignWidgets() { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { - getGuideTheme().guiColor().draw(matrixStack, x, y + h - 1, w, 1); + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { + getGuideTheme().guiColor().draw(guiGraphics, x, y + h - 1, w, 1); } } @@ -559,11 +562,11 @@ public ExpandIndexButton() { } @Override - public void draw(PoseStack poseStack, Theme theme, int x, int y, int w, int h) { + public void draw(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { if (!indexPanel.expanded) { - getGuideTheme().indexBgColor().draw(poseStack, x, y, w, h); - getGuideTheme().guiColor().draw(poseStack, x + w, y, 1, h); - Icons.RIGHT.draw(poseStack, x + (w - 12) / 2, y + (h - 12) / 2, 12, 12); + getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h); + getGuideTheme().guiColor().draw(guiGraphics, x + w, y, 1, h); + Icons.RIGHT.draw(guiGraphics, x + (w - 12) / 2, y + (h - 12) / 2, 12, 12); } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/SearchScreen.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/SearchScreen.java index 66e0681..37b7ae3 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/SearchScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/SearchScreen.java @@ -3,8 +3,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import dev.ftb.mods.ftbguides.config.ClientConfig; import dev.ftb.mods.ftblibrary.icon.Color4I; +import dev.ftb.mods.ftblibrary.icon.Icon; import dev.ftb.mods.ftblibrary.ui.*; import dev.ftb.mods.ftblibrary.ui.input.MouseButton; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.network.chat.Component; public class SearchScreen extends BaseScreen { @@ -25,7 +27,7 @@ public void onEnterPressed() { textBox.setFocused(true); searchButton = new SimpleButton(this, Component.empty(), GuideScreen.SEARCH_ICON, (btn, mb) -> doSearch()); - scopeButton = new SimpleTextButton(this, Component.empty(), Color4I.EMPTY) { + scopeButton = new SimpleTextButton(this, Component.empty(), Icon.empty()) { @Override public void onClicked(MouseButton button) { ClientConfig.toggleSearchThisOnly(); @@ -53,19 +55,20 @@ public boolean onInit() { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { + var matrixStack = guiGraphics.pose(); matrixStack.translate(0, 0, -800); - guideScreen.draw(matrixStack, theme, x, y, w, h); + guideScreen.draw(guiGraphics, theme, x, y, w, h); matrixStack.translate(0, 0, 800); - Color4I.DARK_GRAY.withAlpha(192).draw(matrixStack, guideScreen.getX(), guideScreen.getY(), guideScreen.width, guideScreen.height); + Color4I.DARK_GRAY.withAlpha(192).draw(guiGraphics, guideScreen.getX(), guideScreen.getY(), guideScreen.width, guideScreen.height); - guideScreen.getGuideTheme().indexBgColor().draw(matrixStack, x, y, w, h); - GuiHelper.drawRectWithShade(matrixStack, x, y, w, h, guideScreen.getGuideTheme().guiColor(), 16); + guideScreen.getGuideTheme().indexBgColor().draw(guiGraphics, x, y, w, h); + GuiHelper.drawRectWithShade(guiGraphics, x, y, w, h, guideScreen.getGuideTheme().guiColor(), 16); } @Override - public void drawForeground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { - getTheme().drawString(matrixStack, Component.translatable("gui.recipebook.search_hint"), posX + 5, posY + 9, + public void drawForeground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { + getTheme().drawString(guiGraphics, Component.translatable("gui.recipebook.search_hint"), posX + 5, posY + 9, guideScreen.getGuideTheme().textColor(), 0); } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/panel/BlockQuotePanel.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/panel/BlockQuotePanel.java index c886370..444777a 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/panel/BlockQuotePanel.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/panel/BlockQuotePanel.java @@ -6,6 +6,7 @@ import dev.ftb.mods.ftblibrary.ui.Theme; import dev.ftb.mods.ftblibrary.ui.Widget; import dev.ftb.mods.ftblibrary.ui.WidgetLayout; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import java.util.ArrayList; @@ -29,9 +30,9 @@ public void addWidgets() { } @Override - public void drawBackground(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { + public void drawBackground(GuiGraphics guiGraphics, Theme theme, int x, int y, int w, int h) { // Draw a line to the left of the panel - Color4I.GRAY.draw(matrixStack, x, y, 2, h); + Color4I.GRAY.draw(guiGraphics, x, y, 2, h); } @Override diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CodeBlockWidget.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CodeBlockWidget.java index 7d4fd21..102341d 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CodeBlockWidget.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CodeBlockWidget.java @@ -9,6 +9,7 @@ import dev.ftb.mods.ftblibrary.ui.Theme; import dev.ftb.mods.ftblibrary.ui.Widget; import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; @@ -28,13 +29,13 @@ public CodeBlockWidget(Panel p, List lines) { } @Override - public void draw(PoseStack matrixStack, Theme theme, int x, int y, int w, int h) { + public void draw(GuiGraphics graphics, Theme theme, int x, int y, int w, int h) { GuideIndex.GuideTheme guideTheme = GuideThemeProvider.getGuideThemeFor(this); - guideTheme.indexBgColor().draw(matrixStack, x, y, w, h); - GuiHelper.drawHollowRect(matrixStack, x, y, w, h, guideTheme.guiColor().withAlpha(128), false); + guideTheme.indexBgColor().draw(graphics, x, y, w, h); + GuiHelper.drawHollowRect(graphics, x, y, w, h, guideTheme.guiColor().withAlpha(128), false); for (int i = 0; i < lines.size(); i++) { - theme.drawString(matrixStack, lines.get(i), x + 2, y + 3 + i * 10, guideTheme.codeColor(), 0); + theme.drawString(graphics, lines.get(i), x + 2, y + 3 + i * 10, guideTheme.codeColor(), 0); } } } diff --git a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CustomTextField.java b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CustomTextField.java index fe9e3cf..39a9691 100644 --- a/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CustomTextField.java +++ b/common/src/main/java/dev/ftb/mods/ftbguides/client/gui/widgets/CustomTextField.java @@ -1,6 +1,5 @@ package dev.ftb.mods.ftbguides.client.gui.widgets; -import dev.ftb.mods.ftbguides.client.FTBGuidesClient; import dev.ftb.mods.ftbguides.client.gui.ClickEventHandler; import dev.ftb.mods.ftbguides.client.gui.GuideThemeProvider; import dev.ftb.mods.ftblibrary.ui.Panel; @@ -13,6 +12,8 @@ import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; +import java.util.Optional; + public class CustomTextField extends TextField implements Anchorable { private String anchorName = ""; @@ -28,9 +29,9 @@ public CustomTextField(Panel panel, Component text) { public boolean mousePressed(MouseButton button) { if (isMouseOver()) { if (button.isLeft() && Minecraft.getInstance().screen != null) { - Style style = getComponentStyleAt(getGui().getTheme(), getMouseX(), getMouseY()); - if (style != null) { - return handleCustomClickEvent(style) || Minecraft.getInstance().screen.handleComponentClicked(style); + Optional