Class ConfigurationScreen.ConfigurationSectionScreen
java.lang.Object
net.minecraft.client.gui.components.events.AbstractContainerEventHandler
net.minecraft.client.gui.screens.Screen
net.minecraft.client.gui.screens.options.OptionsSubScreen
net.neoforged.neoforge.client.gui.ConfigurationScreen.ConfigurationSectionScreen
- All Implemented Interfaces:
ContainerEventHandler,GuiEventListener,Renderable,TabOrderedElement
- Direct Known Subclasses:
ConfigurationScreen.ConfigurationListScreen
- Enclosing class:
ConfigurationScreen
A UI screen that presents a single section of configuration values and allows the user to edit them, including an unlimited undo system and reset to default.
This class is automatically used if you use NeoForge's generic configuration UI, see ConfigurationScreen.
If you have special needs, you can subclass this class to achieve the desired behaviour. For example:
- To filter out values that should not be displayed, override the matching
create*Value()method and return null when the key matches. - To use another UI element, override the matching
create*Value()method and return your new UI element wrapped in aConfigurationScreen.ConfigurationSectionScreen.Element. - To change the way lists work, override
createList(String, ListValueSpec, ConfigValue)and return a subclassedConfigurationScreen.ConfigurationListScreen. - To add additional (synthetic) config values, override
createSyntheticValues(). - To be notified on each changed value instead of getting one
ModConfigEventat the end, overrideonChanged(String). Note thatonChanged(String)will be called on every change (e.g. each typed character for Strings) if the new value is valid and different. - To re-arrange your config values, declare them in the appropriate order.
- To change which values a config value can accept, supply the
ModConfigSpec.Builderwith a validator and/or a range. - To have your config values display with readable names, add their translations to your language file. When running in a development environment, missing
translations are printed out to the log by default. However, you need to visit every configuration screen manually for those to be collected.
Tooltips are also taken from the language file, but if there's no translation, the comment will be used instead.
OptionsSubScreen and inherits some behaviour that is not needed. For example, we need to pass the vanilla
options to our superclass' constructor.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordA custom variant of OptionsInstance.Enum that doesn't show the key on the button, just the valuestatic final recordstatic interfaceA filter callback to suppress certain elements from being shown in the configuration UI.Nested classes/interfaces inherited from class net.minecraft.client.gui.screens.Screen
Screen.NarratableSearchResult -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected final ConfigurationScreen.ConfigurationSectionScreen.Contextprotected final Buttonprotected static final longprotected ModConfigSpec.RestartTypeprotected @Nullable Buttonprotected final Map<String, ConfigurationScreen.ConfigurationSectionScreen> protected @Nullable Buttonprotected final ConfigurationScreen.UndoManagerFields inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
lastScreen, layout, list, optionsFields inherited from class net.minecraft.client.gui.screens.Screen
FADE_IN_TIME, font, FOOTER_SEPARATOR, HEADER_SEPARATOR, height, INWORLD_FOOTER_SEPARATOR, INWORLD_HEADER_SEPARATOR, MENU_BACKGROUND, minecraft, narratorButton, renderables, screenExecutor, title, width -
Constructor Summary
ConstructorsModifierConstructorDescriptionConfigurationSectionScreen(Screen parent, ModConfig.Type type, ModConfig modConfig, Component title) Constructs a new section screen for the top-most section in aModConfig.ConfigurationSectionScreen(Screen parent, ModConfig.Type type, ModConfig modConfig, Component title, ConfigurationScreen.ConfigurationSectionScreen.Filter filter) Constructs a new section screen for the top-most section in aModConfig.ConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context parentContext, Screen parent, Map<String, Object> valueSpecs, String key, Set<? extends com.electronwill.nightconfig.core.UnmodifiableConfig.Entry> entrySet, Component title) Constructs a new section screen for a sub-section of a config.protectedConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context context, Component title) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidprotected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateBooleanValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Boolean> source, Consumer<Boolean> target) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateDoubleValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Double> source, Consumer<Double> target) protected <T extends Enum<T>>
@Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateEnumValue(String key, ModConfigSpec.ValueSpec spec, Supplier<T> source, Consumer<T> target) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateIntegerValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Integer> source, Consumer<Integer> target) protected <T> @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateList(String key, ModConfigSpec.ListValueSpec spec, ModConfigSpec.ConfigValue<List<T>> list) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateLongValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Long> source, Consumer<Long> target) protected <T extends Number & Comparable<? super T>>
@Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateNumberBox(String key, ModConfigSpec.ValueSpec spec, Supplier<T> source, Consumer<T> target, @Nullable Predicate<T> tester, Function<String, T> parser, T zero) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateOtherSection(String key, Object value) Called when an entry is encountered that is neither aModConfigSpec.ConfigValuenor a section.protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateOtherValue(String key, ModConfigSpec.ConfigValue<?> value) Called when aModConfigSpec.ConfigValueis found that has an unknown data type.protected voidprotected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateSection(String key, com.electronwill.nightconfig.core.UnmodifiableConfig subconfig, com.electronwill.nightconfig.core.UnmodifiableConfig subsection) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateSlider(String key, Supplier<Integer> source, Consumer<Integer> target, @Nullable ModConfigSpec.Range<Integer> range) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.ElementcreateStringValue(String key, Predicate<String> tester, Supplier<String> source, Consumer<String> target) protected Collection<? extends ConfigurationScreen.ConfigurationSectionScreen.Element> Override this to add additional configuration elements to the list.protected voidprotected StringgetComment(String key) protected <T> OptionInstance.TooltipSupplier<T> getTooltip(String key, @Nullable ModConfigSpec.Range<?> range) protected ComponentgetTooltipComponent(String key, @Nullable ModConfigSpec.Range<?> range) protected MutableComponentprotected StringgetTranslationKey(String key) protected @Nullable ModConfigSpec.ValueSpecgetValueSpec(String key) protected booleanprotected booleanprotected booleanisPartialNumber(String value, boolean allowNegative) protected voidThis is called whenever a value is changed and the change is submitted to the appropriateConfigSpec.voidonClose()rebuild()voidrender(GuiGraphics graphics, int p_281550_, int p_282878_, float p_282465_) Renders the graphical user interface (GUI) element.protected voidsetResetButtonstate(boolean state) protected voidsetUndoButtonstate(boolean state) Methods inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
addContents, addTitle, init, removed, repositionElementsMethods inherited from class net.minecraft.client.gui.screens.Screen
added, addRenderableOnly, addRenderableWidget, addWidget, afterKeyboardAction, afterMouseAction, afterMouseMove, canInterruptWithAnotherScreen, changeFocus, children, clearFocus, clearWidgets, clickCommandAction, clickUrlAction, defaultHandleClickEvent, defaultHandleGameClickEvent, fadeWidgets, fillCrashDetails, findNarratableWidget, getBackgroundMusic, getFont, getMinecraft, getNarrationMessage, getRectangle, getTitle, getTooltipFromItem, getUsageNarration, handleClickEvent, handleComponentClicked, handleDelayedNarration, init, insertText, isAllowedInPortal, isInGameUi, isMouseOver, isPauseScreen, isValidCharacterForName, keyPressed, onFilesDrop, panoramaShouldSpin, rebuildWidgets, removeWidget, renderBackground, renderBlurredBackground, renderMenuBackground, renderMenuBackground, renderMenuBackgroundTexture, renderPanorama, renderTransparentBackground, renderWithTooltipAndSubtitles, resize, setInitialFocus, setInitialFocus, shouldCloseOnEsc, shouldNarrateNavigation, showsActiveEffects, tick, triggerImmediateNarration, updateNarratedWidget, updateNarrationState, updateNarratorStatusMethods inherited from class net.minecraft.client.gui.components.events.AbstractContainerEventHandler
getFocused, isDragging, setDragging, setFocusedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.client.gui.components.events.ContainerEventHandler
charTyped, getChildAt, getCurrentFocusPath, isFocused, keyReleased, mouseClicked, mouseDragged, mouseReleased, mouseScrolled, nextFocusPath, setFocusedMethods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
getBorderForArrowNavigation, mouseMoved, shouldTakeFocusAfterInteractionMethods inherited from interface net.minecraft.client.gui.components.TabOrderedElement
getTabOrderGroup
-
Field Details
-
MAX_SLIDER_SIZE
protected static final long MAX_SLIDER_SIZE- See Also:
-
context
-
changed
protected boolean changed -
needsRestart
-
sectionCache
-
undoButton
-
resetButton
-
doneButton
-
undoManager
-
-
Constructor Details
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(Screen parent, ModConfig.Type type, ModConfig modConfig, Component title) Constructs a new section screen for the top-most section in aModConfig.- Parameters:
parent- The screen to return to when the user presses escape or the "Done" button. If this is aConfigurationScreen, additional information is passed before closing.type- TheModConfig.Typethis configuration is for. Only used to generate the title of the screen.modConfig- The actual config to show and edit.
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(Screen parent, ModConfig.Type type, ModConfig modConfig, Component title, ConfigurationScreen.ConfigurationSectionScreen.Filter filter) Constructs a new section screen for the top-most section in aModConfig.- Parameters:
parent- The screen to return to when the user presses escape or the "Done" button. If this is aConfigurationScreen, additional information is passed before closing.type- TheModConfig.Typethis configuration is for. Only used to generate the title of the screen.modConfig- The actual config to show and edit.filter- TheConfigurationScreen.ConfigurationSectionScreen.Filterto use.
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context parentContext, Screen parent, Map<String, Object> valueSpecs, String key, Set<? extends com.electronwill.nightconfig.core.UnmodifiableConfig.Entry> entrySet, Component title) Constructs a new section screen for a sub-section of a config.- Parameters:
parentContext- TheConfigurationScreen.ConfigurationSectionScreen.Contextobject of the parent.parent- The screen to return to when the user presses escape or the "Done" button. If this is aConfigurationScreen.ConfigurationSectionScreen, additional information is passed before closing.valueSpecs- The source for theModConfigSpec.ValueSpecobjects for this section.key- The key of the section.entrySet- The source for theModConfigSpec.ConfigValueobjects for this section.
-
ConfigurationSectionScreen
protected ConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context context, Component title)
-
-
Method Details
-
getValueSpec
-
getTranslationKey
-
getTranslationComponent
-
getComment
-
getTooltip
protected <T> OptionInstance.TooltipSupplier<T> getTooltip(String key, @Nullable @Nullable ModConfigSpec.Range<?> range) -
getTooltipComponent
protected Component getTooltipComponent(String key, @Nullable @Nullable ModConfigSpec.Range<?> range) -
onChanged
This is called whenever a value is changed and the change is submitted to the appropriateConfigSpec.- Parameters:
key- The key of the changed configuration. To get an absolute key, useConfigurationScreen.ConfigurationSectionScreen.Context.makeKeyList(String).
-
addOptions
protected void addOptions()- Specified by:
addOptionsin classOptionsSubScreen
-
rebuild
-
createSyntheticValues
protected Collection<? extends ConfigurationScreen.ConfigurationSectionScreen.Element> createSyntheticValues()Override this to add additional configuration elements to the list.- Returns:
- A collection of
ConfigurationScreen.ConfigurationSectionScreen.Element.
-
isNonDefault
-
isAnyNondefault
protected boolean isAnyNondefault() -
createStringValue
-
createOtherSection
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createOtherSection(String key, Object value) Called when an entry is encountered that is neither aModConfigSpec.ConfigValuenor a section. Override this to produce whatever UI elements are appropriate for this object.Note that this case is unusual and shouldn't happen unless someone injected something into the config system.
- Parameters:
key- The key of the entry.value- The entry itself.- Returns:
- null if no UI element should be added or an
ConfigurationScreen.ConfigurationSectionScreen.Elementto be added to the UI.
-
createOtherValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createOtherValue(String key, ModConfigSpec.ConfigValue<?> value) Called when aModConfigSpec.ConfigValueis found that has an unknown data type. Override this to produce whatever UI elements are appropriate for this object.- Parameters:
key- The key of the entry.value- The entry itself.- Returns:
- null if no UI element should be added or an
ConfigurationScreen.ConfigurationSectionScreen.Elementto be added to the UI.
-
createBooleanValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createBooleanValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Boolean> source, Consumer<Boolean> target) -
createEnumValue
@Nullable protected <T extends Enum<T>> @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createEnumValue(String key, ModConfigSpec.ValueSpec spec, Supplier<T> source, Consumer<T> target) -
createIntegerValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createIntegerValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Integer> source, Consumer<Integer> target) -
createSlider
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createSlider(String key, Supplier<Integer> source, Consumer<Integer> target, @Nullable @Nullable ModConfigSpec.Range<Integer> range) -
createLongValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createLongValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Long> source, Consumer<Long> target) -
createNumberBox
@Nullable protected <T extends Number & Comparable<? super T>> @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createNumberBox(String key, ModConfigSpec.ValueSpec spec, Supplier<T> source, Consumer<T> target, @Nullable @Nullable Predicate<T> tester, Function<String, T> parser, T zero) -
isPartialNumber
-
createDoubleValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createDoubleValue(String key, ModConfigSpec.ValueSpec spec, Supplier<Double> source, Consumer<Double> target) -
createSection
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createSection(String key, com.electronwill.nightconfig.core.UnmodifiableConfig subconfig, com.electronwill.nightconfig.core.UnmodifiableConfig subsection) -
createList
@Nullable protected <T> @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createList(String key, ModConfigSpec.ListValueSpec spec, ModConfigSpec.ConfigValue<List<T>> list) -
render
Description copied from interface:RenderableRenders the graphical user interface (GUI) element.- Specified by:
renderin interfaceRenderable- Overrides:
renderin classScreen- Parameters:
graphics- the GuiGraphics object used for rendering.p_281550_- the x-coordinate of the mouse cursor.p_282878_- the y-coordinate of the mouse cursor.p_282465_- the partial tick time.
-
createUndoButton
protected void createUndoButton() -
setUndoButtonstate
protected void setUndoButtonstate(boolean state) -
createResetButton
protected void createResetButton() -
setResetButtonstate
protected void setResetButtonstate(boolean state) -
onClose
public void onClose()- Overrides:
onClosein classOptionsSubScreen
-