undo changes from other pr

This reverts commits 7e4a084e and 65c30ccb
This commit is contained in:
rhysdh540 2023-07-18 10:23:24 -04:00
parent fdb41a0411
commit 57a8c23eff
3 changed files with 7 additions and 20 deletions

View file

@ -22,8 +22,6 @@ public abstract class ConfigBase {
protected List<ConfigBase> children;
public void registerAll(final ForgeConfigSpec.Builder builder) {
if(allValues == null) // avoid null pointer exception if config class is empty
allValues = new ArrayList<>();
for (CValue<?, ?> cValue : allValues)
cValue.register(builder);
}

View file

@ -34,40 +34,29 @@ public class BaseConfigScreen extends ConfigScreen {
private static final Map<String, UnaryOperator<BaseConfigScreen>> DEFAULTS = new HashMap<>();
static {
setDefaultActionFor(Create.ID, base -> base
setDefaultActionFor(Create.ID, (base) -> base
.withTitles("Client Settings", "World Generation Settings", "Gameplay Settings")
.withSpecs(AllConfigs.client().specification, AllConfigs.common().specification, AllConfigs.server().specification)
);
// also set titles for jei and computercraft
setDefaultActionFor("jei", base -> base.withTitle("Just Enough Items"));
setDefaultActionFor("computercraft", base -> base.withTitle("ComputerCraft"));
}
/**
* If you are a Create Addon dev and want to change the config labels or title, add a default action here.
* <p>
* If you are a Create Addon dev and want to change the config labels,
* add a default action here.
*
* Make sure you call either {@link #withSpecs(ForgeConfigSpec, ForgeConfigSpec, ForgeConfigSpec)}
* or {@link #searchForSpecsInModContainer()}
*
* @param modID the modID of your addon/mod
*/
public static void setDefaultActionFor(String modID, UnaryOperator<BaseConfigScreen> transform) {
if (DEFAULTS.containsKey(modID)) {
if (!DEFAULTS.containsKey(modID)) {
Create.LOGGER.error("Somebody tried to set default action for mod {}, but it was already set!", modID);
return;
// or throw an exception
}
DEFAULTS.put(modID, transform);
}
public static String getCustomTitleIfExists(String modID) {
for(Map.Entry<String, UnaryOperator<BaseConfigScreen>> entry : DEFAULTS.entrySet()) {
if(entry.getKey().equals(modID))
return entry.getValue().apply(new BaseConfigScreen(null, modID)).titleString;
}
return modID;
}
public static BaseConfigScreen forCreate(Screen parent) {
return new BaseConfigScreen(parent, Create.ID);
}

View file

@ -99,7 +99,7 @@ public class ConfigModListScreen extends ConfigScreen {
protected String id;
public ModEntry(String id, Screen parent) {
super(BaseConfigScreen.getCustomTitleIfExists(id).equals(id) ? toHumanReadable(id) : BaseConfigScreen.getCustomTitleIfExists(id));
super(toHumanReadable(id));
this.id = id;
button = new BoxWidget(0, 0, 35, 16)
@ -112,7 +112,7 @@ public class ConfigModListScreen extends ConfigScreen {
button.active = false;
button.updateColorsFromState();
button.modifyElement(e -> ((DelegatedStencilElement) e).withElementRenderer(BaseConfigScreen.DISABLED_RENDERER));
labelTooltip.add(Components.literal(BaseConfigScreen.getCustomTitleIfExists(id).equals(id) ? toHumanReadable(id) : BaseConfigScreen.getCustomTitleIfExists(id)));
labelTooltip.add(Components.literal(toHumanReadable(id)));
labelTooltip.addAll(TooltipHelper.cutStringTextComponent("This Mod does not have any configs registered or is not using Forge's config system", Palette.ALL_GRAY));
}