Skip to content

Commit a8aab6c

Browse files
Add Ability to Toggle Fancy UI with Command
- Toggle Fancy UI with `/fwm on` and `/fwm off` - Use `/fwm` to open mod settings - Fix error spam due to InventoryChangeListener not being removed when GuiFancyWarp stops initialization due to an error - Fix version missing warning from Forge on startup - Bump version to v2.0-beta.1
1 parent 6dbb3ae commit a8aab6c

8 files changed

Lines changed: 79 additions & 11 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ tasks.processResources {
104104
inputs.property("mcversion", mcVersion)
105105
inputs.property("modid", modid)
106106

107-
filesMatching("mcmod.info") {
107+
filesMatching(arrayListOf("mcmod.info", "version.properties")) {
108108
expand(inputs.properties)
109109
}
110110

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
33
baseGroup = ca.tirelesstraveler
44
mcVersion = 1.8.9
55
modid = fancywarpmenu
6-
version = 2.0
6+
version = 2.0-beta.1

src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
package ca.tirelesstraveler.fancywarpmenu;
2424

25-
import ca.tirelesstraveler.fancywarpmenu.commands.OpenConfigCommand;
25+
import ca.tirelesstraveler.fancywarpmenu.commands.FancyWarpMenuCommand;
2626
import ca.tirelesstraveler.fancywarpmenu.data.layout.Island;
2727
import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout;
2828
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
@@ -103,7 +103,7 @@ public void init(FMLInitializationEvent event) {
103103
updateCheckResult = ForgeVersion.getResult(modContainer);
104104
keyBindingOpenWarpMenu = new KeyBinding("fancywarpmenu.key.openMenu", Keyboard.KEY_C, "fancywarpmenu.key.categories.fancyWarpMenu");
105105
ClientRegistry.registerKeyBinding(keyBindingOpenWarpMenu);
106-
ClientCommandHandler.instance.registerCommand(new OpenConfigCommand());
106+
ClientCommandHandler.instance.registerCommand(new FancyWarpMenuCommand());
107107

108108
Layout overworldLayout = FancyWarpMenuState.getOverworldLayout();
109109
ProgressManager.ProgressBar bar = ProgressManager.push("Loading Textures",

src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/OpenConfigCommand.java renamed to src/main/java/ca/tirelesstraveler/fancywarpmenu/commands/FancyWarpMenuCommand.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,33 @@
2222

2323
package ca.tirelesstraveler.fancywarpmenu.commands;
2424

25+
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
2526
import ca.tirelesstraveler.fancywarpmenu.state.FancyWarpMenuState;
26-
import net.minecraft.command.CommandBase;
27-
import net.minecraft.command.ICommandSender;
27+
import ca.tirelesstraveler.fancywarpmenu.utils.ChatUtils;
28+
import net.minecraft.command.*;
29+
import net.minecraft.util.ChatComponentTranslation;
30+
import net.minecraft.util.ChatStyle;
31+
import net.minecraft.util.EnumChatFormatting;
2832

2933
import java.util.Collections;
3034
import java.util.List;
3135

32-
public class OpenConfigCommand extends CommandBase {
36+
/**
37+
* This is the main command of the mod.<br>
38+
* <bold>Syntax</bold><br>
39+
* <ul>
40+
* <li>/fancywarpmenu &lt;args&gt;</li>
41+
* <li>/fwm &lt;args&gt;</li>
42+
* </ul>
43+
* <br>
44+
* <bold>Arguments</bold>
45+
* <ul>
46+
* <li>(empty) - Open mod config menu</li>
47+
* <li>"on" or "1" - Enable Fancy Warp Menu</li>
48+
* <li>"off" or "0" - Disable Fancy Warp Menu</li>
49+
* </ul>
50+
*/
51+
public class FancyWarpMenuCommand extends CommandBase {
3352
@Override
3453
public int getRequiredPermissionLevel() {
3554
return 0;
@@ -42,7 +61,7 @@ public List<String> getCommandAliases() {
4261

4362
@Override
4463
public String getCommandName() {
45-
return "fancywarpmenuconfig";
64+
return "fancywarpmenu";
4665
}
4766

4867
@Override
@@ -56,7 +75,28 @@ public String getCommandUsage(ICommandSender sender) {
5675
* The {@link net.minecraftforge.event.CommandEvent} is intercepted instead to prevent the screen from being closed.
5776
*/
5877
@Override
59-
public void processCommand(ICommandSender sender, String[] args) {
60-
FancyWarpMenuState.setOpenConfigMenuRequested(true);
78+
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
79+
if (args.length > 0) {
80+
switch (args[0]) {
81+
case "1":
82+
case "on":
83+
Settings.setWarpMenuEnabled(true);
84+
ChatUtils.sendMessageWithModNamePrefix(
85+
new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuEnabled")
86+
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
87+
break;
88+
case "0":
89+
case "off":
90+
Settings.setWarpMenuEnabled(false);
91+
ChatUtils.sendMessageWithModNamePrefix(
92+
new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuDisabled")
93+
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
94+
break;
95+
default:
96+
throw new SyntaxErrorException();
97+
}
98+
} else {
99+
FancyWarpMenuState.setOpenConfigMenuRequested(true);
100+
}
61101
}
62102
}

src/main/java/ca/tirelesstraveler/fancywarpmenu/gui/GuiFancyWarp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public void initGui() {
126126
inventoryTooSmallMessageTranslationKey, chestInventory.getSizeInventory(), lastSlotIndexToCheck)
127127
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
128128
setCustomUIState(false, false);
129+
chestInventory.removeInventoryChangeListener(inventoryListener);
129130
return;
130131
}
131132

@@ -143,6 +144,7 @@ public void initGui() {
143144
} catch (RuntimeException e) {
144145
guiInitException = e;
145146
buttonList.clear();
147+
chestInventory.removeInventoryChangeListener(inventoryListener);
146148

147149
int lineCount = 2;
148150
int labelX = 0;

src/main/resources/assets/fancywarpmenu/lang/en_US.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fancywarpmenu.key.categories.fancyWarpMenu=Fancy Warp Menu
5252

5353
fancywarpmenu.messages.useWarpMenuInsteadOfCommand=Reminder to use the Fancy Warp Menu instead!
5454
fancywarpmenu.messages.fancyWarpMenuEnabled=Fancy Warp Menu Enabled
55+
fancywarpmenu.messages.fancyWarpMenuDisabled=Fancy Warp Menu Disabled
5556

5657
fancywarpmenu.errors.notUnlocked=Not Unlocked
5758
fancywarpmenu.errors.unknownDestination=Unknown Destination
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# Copyright (c) 2024. TirelessTraveler
3+
#
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all
12+
# copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
20+
# OR OTHER DEALINGS IN THE SOFTWARE.
21+
#
22+
23+
# Forge expects a mod version in the main mod class or in this file, otherwise it logs a warning on startup.
24+
# suppress inspection "UnusedProperty"
25+
fancywarpmenu.version = ${version}

version/update.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"homepage": "https://github.com/ILikePlayingGames/FancyWarpMenu/releases",
33
"promos": {
44
"1.8.9-recommended": "1.0",
5-
"1.8.9-latest": "1.0"
5+
"1.8.9-latest": "2.0-beta.1"
66
},
77
"1.8.9": {
88
"1.0": "New textures and additional language support",

0 commit comments

Comments
 (0)