-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathModMenuIntegration.java
More file actions
74 lines (66 loc) · 2.7 KB
/
ModMenuIntegration.java
File metadata and controls
74 lines (66 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Wildfire's Female Gender Mod is a female gender mod created for Minecraft.
* Copyright (C) 2023-present WildfireRomeo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.wildfire.compat;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
import com.wildfire.gui.screen.WardrobeBrowserScreen;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.layouts.LinearLayout;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import java.util.Objects;
public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> {
var client = Minecraft.getInstance();
var player = client.player;
if(player == null) {
return new NotInWorldScreen(client, screen);
}
return WardrobeBrowserScreen.create(player, screen);
};
}
// TODO it'd be nice to support opening the proper mod ui outside a world (like what show me your skin does),
// but doing so requires implementing a fake player entity, which in turn requires bodge implementations
// of basic classes like the registry.
// so, for now, just make a screen that says this isn't supported.
private static class NotInWorldScreen extends ConfirmScreen {
private final Screen parent;
public NotInWorldScreen(Minecraft client, Screen parent) {
super(
_ -> client.setScreen(parent),
Component.translatable("wildfire_gender.not_in_world.title").withStyle(ChatFormatting.RED),
Component.translatable("wildfire_gender.not_in_world")
);
this.parent = parent;
}
@Override
protected void addButtons(LinearLayout layout) {
layout.addChild(Button.builder(CommonComponents.GUI_OK, (button) -> onClose()).build());
}
@Override
public void onClose() {
Objects.requireNonNull(minecraft, "client").setScreen(parent);
}
}
}