|
14 | 14 | import com.terraformersmc.modmenu.util.mod.Mod; |
15 | 15 | import com.terraformersmc.modmenu.util.mod.ModBadgeRenderer; |
16 | 16 | import net.fabricmc.loader.api.FabricLoader; |
| 17 | +import net.fabricmc.loader.api.ModContainer; |
| 18 | +import net.fabricmc.loader.api.metadata.ModOrigin; |
17 | 19 | import net.minecraft.SharedConstants; |
18 | 20 | import net.minecraft.client.gl.RenderPipelines; |
19 | 21 | import net.minecraft.client.gui.DrawContext; |
@@ -246,7 +248,7 @@ protected void init() { |
246 | 248 | this.descriptionListWidget.setX(this.rightPaneX); |
247 | 249 |
|
248 | 250 | // Mods folder button |
249 | | - ClickableWidget modsFolderButton = ButtonWidget.builder(ModMenuScreenTexts.MODS_FOLDER, button -> Util.getOperatingSystem().open(FabricLoader.getInstance().getGameDir().resolve("mods").toUri())).position(this.width / 2 - 154, this.height - 28).size(150, 20).build(); |
| 251 | + ClickableWidget modsFolderButton = ButtonWidget.builder(ModMenuScreenTexts.MODS_FOLDER, button -> Util.getOperatingSystem().open(getModsFolder().toUri())).position(this.width / 2 - 154, this.height - 28).size(150, 20).build(); |
250 | 252 |
|
251 | 253 | // Done button |
252 | 254 | ClickableWidget doneButton = ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(previousScreen)).position(this.width / 2 + 4, this.height - 28).size(150, 20).build(); |
@@ -624,6 +626,21 @@ private static boolean isValidMod(Path mod) { |
624 | 626 | } |
625 | 627 | } |
626 | 628 |
|
| 629 | + private static Path getModsFolder() { |
| 630 | + ModContainer container = FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(); |
| 631 | + |
| 632 | + while (container.getContainingMod().isPresent()) { |
| 633 | + container = container.getContainingMod().get(); |
| 634 | + } |
| 635 | + |
| 636 | + if (container.getOrigin().getKind() == ModOrigin.Kind.PATH) { |
| 637 | + return container.getOrigin().getPaths().getFirst().getParent(); |
| 638 | + } else { |
| 639 | + // Fall back on the old behavior |
| 640 | + return FabricLoader.getInstance().getGameDir().resolve("mods"); |
| 641 | + } |
| 642 | + } |
| 643 | + |
627 | 644 | public boolean getModHasConfigScreen(String modId) { |
628 | 645 | if (this.modScreenErrors.containsKey(modId)) { |
629 | 646 | return false; |
|
0 commit comments