|
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; |
@@ -233,7 +235,7 @@ protected void init() { |
233 | 235 | this.descriptionListWidget.setX(this.rightPaneX); |
234 | 236 |
|
235 | 237 | // Mods folder button |
236 | | - 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(); |
| 238 | + 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(); |
237 | 239 |
|
238 | 240 | // Done button |
239 | 241 | ClickableWidget doneButton = ButtonWidget.builder(ScreenTexts.DONE, button -> client.setScreen(previousScreen)).position(this.width / 2 + 4, this.height - 28).size(150, 20).build(); |
@@ -611,6 +613,21 @@ private static boolean isValidMod(Path mod) { |
611 | 613 | } |
612 | 614 | } |
613 | 615 |
|
| 616 | + private static Path getModsFolder() { |
| 617 | + ModContainer container = FabricLoader.getInstance().getModContainer(ModMenu.MOD_ID).orElseThrow(); |
| 618 | + |
| 619 | + while (container.getContainingMod().isPresent()) { |
| 620 | + container = container.getContainingMod().get(); |
| 621 | + } |
| 622 | + |
| 623 | + if (container.getOrigin().getKind() == ModOrigin.Kind.PATH) { |
| 624 | + return container.getOrigin().getPaths().getFirst().getParent(); |
| 625 | + } else { |
| 626 | + // Fall back on the old behavior |
| 627 | + return FabricLoader.getInstance().getGameDir().resolve("mods"); |
| 628 | + } |
| 629 | + } |
| 630 | + |
614 | 631 | public boolean getModHasConfigScreen(String modId) { |
615 | 632 | if (this.modScreenErrors.containsKey(modId)) { |
616 | 633 | return false; |
|
0 commit comments