Skip to content

Commit

Permalink
Fixed the config button not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFrydae committed Feb 19, 2021
1 parent 98de875 commit 1be9af0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 42 deletions.
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ dependencies {
testImplementation 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'

modApi("me.shedaniel.cloth:cloth-config-fabric:4.10.13") {
// Mod Menu, to add the hook for a config screen
modImplementation "io.github.prospector:modmenu:${project.modmenu_version}"

// Easy config screen setup library
modApi("me.shedaniel.cloth:config-2:${project.cloth_version}") {
exclude(group: "net.fabricmc.fabric-api")
}

modImplementation "io.github.prospector:modmenu:1.14.9+build.14"
include "me.shedaniel.cloth:config-2:${project.cloth_version}"
}

processResources {
Expand Down
18 changes: 10 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.4
loader_version=0.11.1
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.16.5
yarn_mappings=1.16.5+build.4
loader_version=0.11.1
fabric_version=0.29.3+1.16

# Mod Properties
mod_version = 1.3.0
maven_group = coffee.waffle
archives_base_name = empire-minecraft-utilities
mod_version = 1.3.0
maven_group = coffee.waffle
archives_base_name = empire-minecraft-utilities

# Dependencies
fabric_version=0.29.3+1.16
modmenu_version = 1.14.13+build.19
cloth_version = 5.0.0
75 changes: 47 additions & 28 deletions src/main/java/coffee/waffle/emcutils/utils/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import lombok.Getter;
import lombok.Setter;
import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.TranslatableText;

import java.io.FileReader;
Expand Down Expand Up @@ -41,42 +42,60 @@ public static class ConfigValues {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return parent -> {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(new TranslatableText("emc_utils.config"));

ConfigCategory tabList = builder.getOrCreateCategory(new TranslatableText("emc_utils.config.tablist.category"));
return Config::genConfig;
}

tabList.addEntry(builder.entryBuilder()
.startBooleanToggle(new TranslatableText("emc_utils.config.tablist.showAllServers"), configValues.isTabListShowAllServers())
private static Screen genConfig(Screen parent) {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setTitle(new TranslatableText("emc_utils.config"))
.setSavingRunnable(Config::save);
ConfigEntryBuilder entryBuilder = builder.entryBuilder();

builder.getOrCreateCategory(new TranslatableText("emc_utils.config.tablist.category"))
.addEntry(entryBuilder
.startBooleanToggle(
new TranslatableText("emc_utils.config.tablist.showAllServers"),
configValues.isTabListShowAllServers()
)
.setDefaultValue(true)
.setSaveConsumer(configValues::setTabListShowAllServers).build());

tabList.addEntry(builder.entryBuilder()
.startEnumSelector(new TranslatableText("emc_utils.config.tablist.sort.type"), TabListSortType.class, configValues.getTabListSortType())
.setSaveConsumer(configValues::setTabListShowAllServers)
.build()
)
.addEntry(entryBuilder
.startEnumSelector(
new TranslatableText("emc_utils.config.tablist.sort.type"),
TabListSortType.class,
configValues.getTabListSortType()
)
.setDefaultValue(TabListSortType.NAME_ASCENDING)
.setEnumNameProvider(type -> ((TabListSortType) type).getDescription())
.setSaveConsumer(configValues::setTabListSortType).build());

tabList.addEntry(builder.entryBuilder()
.startEnumSelector(new TranslatableText("emc_utils.config.tablist.placement"), TabListCurrentServerPlacement.class, configValues.getTabListCurrentServerPlacement())
.setSaveConsumer(configValues::setTabListSortType)
.build()
)
.addEntry(entryBuilder
.startEnumSelector(
new TranslatableText("emc_utils.config.tablist.placement"),
TabListCurrentServerPlacement.class,
configValues.getTabListCurrentServerPlacement()
)
.setDefaultValue(TabListCurrentServerPlacement.TOP)
.setEnumNameProvider(placement -> ((TabListCurrentServerPlacement) placement).getDescription())
.setSaveConsumer(configValues::setTabListCurrentServerPlacement).build());
.setSaveConsumer(configValues::setTabListCurrentServerPlacement)
.build()
);

builder.setSavingRunnable(() -> {
try (FileWriter writer = new FileWriter("config/emc_utils.json")) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();
return builder.build();
}

gson.toJson(configValues, writer);
} catch (IOException e) {
Log.exception(e);
}
});
private static void save() {
try (FileWriter writer = new FileWriter("config/emc_utils.json")) {
Gson gson = new GsonBuilder().setPrettyPrinting().create();

return builder.build();
};
gson.toJson(configValues, writer);
} catch (IOException e) {
Log.exception(e);
}
}

@AllArgsConstructor
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/coffee/waffle/emcutils/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Formatting;

import java.io.IOException;
Expand All @@ -28,6 +29,12 @@ public static ClientPlayerEntity getPlayer() {
return MinecraftClient.getInstance().player;
}

public static void sendPlayerMessage(String message) {
for (String line : message.split("\n")) {
MinecraftClient.getInstance().player.sendMessage(new LiteralText(line), false);
}
}

public static int getUserGroup(String name) {
try {
URL url = new URL("https://empireminecraft.com/api/pinfo.php?name=" + name);
Expand Down
File renamed without changes
8 changes: 5 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
],
"contact": {
"homepage": "",
"sources": "https://github.com/MrFrydae/Empire-Minecraft-Utilities"
"sources": "https://github.com/MrFrydae/Empire-Minecraft-Utilities",
"issues": "https://github.com/MrFrydae/Empire-Minecraft-Utilities/issues"
},

"license": "MIT",
"icon": "icon.png",
"icon": "assets/emc_utils/icon.png",

"environment": "*",
"entrypoints": {
Expand All @@ -32,6 +33,7 @@
"depends": {
"fabricloader": ">=0.7.4",
"fabric": "*",
"minecraft": "1.16.x"
"minecraft": "1.16.x",
"cloth-config2": ">=4.10.13"
}
}

0 comments on commit 1be9af0

Please sign in to comment.