Skip to content

Commit

Permalink
Added integration with Mod Menu (#56)
Browse files Browse the repository at this point in the history
* Added integration with Mod Menu

feat: added integration with Mod Menu

+ Created an entrypoint for ModMenu and added it to fabric.mod.json
+ Added ModMenu as a recommended mod in fabric.mod.json
+ Added ModMenu to gradle.build and gradle.properties
- Removed Fn+7 keybind for accessing the ModeSwitcherScreen

* Renamed some parameters for consistency

Renamed the parameters of the render() function in SettingsScreen.java to match those of the render() function in ModeSwitcherScreen.java

* Revert "Renamed some parameters for consistency"

This reverts commit 2ff665b.

* Restored F7 keybind

+ Restored the original constructor
+ Added a second constructor for ModMenu integration

* Fixed "Done" button functionality

The settings screen's "Done" button now returns to the previous screen, either in-game or the mod menu, depending on how it was opened
+ Overrides onClose() to set the screen to the parent screen

* Changed default screen for Lighty settings

Changed the default settings screen from "ModeSwitcherScreen" to "SettingsScreen" to match the changes made in the latest Lighty version and to allow for easier porting to it

* Restored a call to Compute.clear()

* Confirmed compatibility with MC 1.20.4

Confirmed compatibility with MC 1.20.4 after updating the gradle and loom versions

* Added missing whitespace

* Revert "Confirmed compatibility with MC 1.20.4"

This reverts commit 562bb73.

* Remapped F7 keybind to open the original Screen
  • Loading branch information
poqbox authored May 10, 2024
1 parent c864013 commit 2a1212a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,17 @@
import java.util.function.Supplier;

public class ModeSwitcherScreen extends Screen {
private Screen parent;
private static final List<ButtonHolder> BUTTONS = Lists.newArrayList();
public ModeSwitcherScreen() {
super(Component.translatable("modeSwitcher.lighty.title"));
}

public ModeSwitcherScreen(Screen parent) {
super(Component.translatable("modeSwitcher.lighty.title"));
this.parent = parent;
}

@Override
protected void init() {
GridLayout gridWidget = new GridLayout();
Expand All @@ -48,7 +54,8 @@ protected void init() {
adder.addChild(btn.get());
}

adder.addChild(Button.builder(Component.translatable("modeSwitcher.lighty.settings"), button -> Minecraft.getInstance().setScreen(new SettingsScreen())).build(), adder.newCellSettings().paddingTop(6));
assert this.minecraft != null;
adder.addChild(Button.builder(Component.translatable("modeSwitcher.lighty.settings"), button -> Minecraft.getInstance().setScreen(new SettingsScreen(this.minecraft.screen))).build(), adder.newCellSettings().paddingTop(6));
adder.addChild(Button.builder(CommonComponents.GUI_DONE, button -> this.onClose()).build());
gridWidget.arrangeElements();
FrameLayout.alignInRectangle(gridWidget, 0, this.height/6 - 12, this.width, this.height, 0.5f, 0f);
Expand All @@ -62,6 +69,11 @@ public void render(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, flo
super.render(guiGraphics, mouseX, mouseY, delta);
}

@Override
public void onClose() {
assert this.minecraft != null;
this.minecraft.setScreen(parent);
}

@Override
public boolean isPauseScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
import org.jetbrains.annotations.NotNull;

public class SettingsScreen extends Screen {
private Screen parent;
public SettingsScreen() {
super(Component.translatable("settings.lighty.title"));
}

public SettingsScreen(Screen parent) {
super(Component.translatable("settings.lighty.title"));
this.parent = parent;
}

OptionsList list;

@Override
Expand Down Expand Up @@ -122,7 +128,8 @@ public void render(@NotNull GuiGraphics guiGraphics, int i, int j, float f) {
@Override
public void onClose() {
Compute.clear();
super.onClose();
assert this.minecraft != null;
this.minecraft.setScreen(parent);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repositories {
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven {url = "https://maven.terraformersmc.com/releases/"} // Mod Menu repository
}

loom {
Expand All @@ -35,6 +36,11 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${rootProject.findProperty("fabric_api_version")}"

// Mod Menu
modImplementation "com.terraformersmc:modmenu:${rootProject.findProperty("modmenu_version")}", {
exclude module: 'fabric-api'
}

compileOnly project(":common")

// Uncomment the following line to enable the deprecated Fabric API modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.schmarrn.lighty.fabric;

import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import dev.schmarrn.lighty.ui.SettingsScreen;

public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return SettingsScreen::new;
}
}
6 changes: 6 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"entrypoints": {
"client": [
"dev.schmarrn.lighty.fabric.LightyFabric"
],
"modmenu": [
"dev.schmarrn.lighty.fabric.ModMenuIntegration"
]
},
"mixins": [
Expand All @@ -30,5 +33,8 @@
"fabricloader": ">=0.14.21",
"minecraft": ">=1.20.3",
"fabric": "*"
},
"recommends": {
"modmenu": ">=9.0.0"
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ mod_name=lighty
fabric_loader_version=0.14.23
fabric_api_version=0.91.1+1.20.3

neo_version=20.3.8-beta
modmenu_version = 9.0.0

# neo stuff
neo_version=20.3.8-beta
minecraft_version_range=[1.20.3,1.21)
neo_version_range=[20.3,)
loader_version_range=[1,)
Expand Down

0 comments on commit 2a1212a

Please sign in to comment.