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:
net.minecraft.client.gui.components.events.ContainerEventHandler
,net.minecraft.client.gui.components.events.GuiEventListener
,net.minecraft.client.gui.components.Renderable
,net.minecraft.client.gui.components.TabOrderedElement
- Direct Known Subclasses:
ConfigurationScreen.ConfigurationListScreen
- Enclosing class:
ConfigurationScreen
public static class ConfigurationScreen.ConfigurationSectionScreen
extends net.minecraft.client.gui.screens.options.OptionsSubScreen
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
ModConfigEvent
at 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.Builder
with 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 record
static final record
A custom variant of OptionsInstance.Enum that doesn't show the key on the button, just the valuestatic final record
static interface
A 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
net.minecraft.client.gui.screens.Screen.NarratableSearchResult
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected final ConfigurationScreen.ConfigurationSectionScreen.Context
protected final net.minecraft.client.gui.components.Button
protected static final long
protected ModConfigSpec.RestartType
protected @Nullable net.minecraft.client.gui.components.Button
protected final Map
<String, ConfigurationScreen.ConfigurationSectionScreen> protected @Nullable net.minecraft.client.gui.components.Button
protected final ConfigurationScreen.UndoManager
Fields inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
lastScreen, layout, list, options
Fields inherited from class net.minecraft.client.gui.screens.Screen
CUBE_MAP, font, FOOTER_SEPARATOR, HEADER_SEPARATOR, height, INWORLD_FOOTER_SEPARATOR, INWORLD_HEADER_SEPARATOR, MENU_BACKGROUND, minecraft, narratorButton, PANORAMA, renderables, screenExecutor, title, width
Fields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionConfigurationSectionScreen
(net.minecraft.client.gui.screens.Screen parent, net.neoforged.fml.config.ModConfig.Type type, net.neoforged.fml.config.ModConfig modConfig, net.minecraft.network.chat.Component title) Constructs a new section screen for the top-most section in aModConfig
.ConfigurationSectionScreen
(net.minecraft.client.gui.screens.Screen parent, net.neoforged.fml.config.ModConfig.Type type, net.neoforged.fml.config.ModConfig modConfig, net.minecraft.network.chat.Component title, ConfigurationScreen.ConfigurationSectionScreen.Filter filter) Constructs a new section screen for the top-most section in aModConfig
.ConfigurationSectionScreen
(ConfigurationScreen.ConfigurationSectionScreen.Context parentContext, net.minecraft.client.gui.screens.Screen parent, Map<String, Object> valueSpecs, String key, Set<? extends com.electronwill.nightconfig.core.UnmodifiableConfig.Entry> entrySet, net.minecraft.network.chat.Component title) Constructs a new section screen for a sub-section of a config.protected
ConfigurationSectionScreen
(ConfigurationScreen.ConfigurationSectionScreen.Context context, net.minecraft.network.chat.Component title) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createBooleanValue
(String key, ModConfigSpec.ValueSpec spec, Supplier<Boolean> source, Consumer<Boolean> target) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createDoubleValue
(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.Element
createIntegerValue
(String key, ModConfigSpec.ValueSpec spec, Supplier<Integer> source, Consumer<Integer> target) protected <T> @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createList
(String key, ModConfigSpec.ListValueSpec spec, ModConfigSpec.ConfigValue<List<T>> list) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createLongValue
(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.Element
createOtherSection
(String key, Object value) Called when an entry is encountered that is neither aModConfigSpec.ConfigValue
nor a section.protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createOtherValue
(String key, ModConfigSpec.ConfigValue<?> value) Called when aModConfigSpec.ConfigValue
is found that has an unknown data type.protected void
protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createSection
(String key, com.electronwill.nightconfig.core.UnmodifiableConfig subconfig, com.electronwill.nightconfig.core.UnmodifiableConfig subsection) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createSlider
(String key, Supplier<Integer> source, Consumer<Integer> target, @Nullable ModConfigSpec.Range<Integer> range) protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element
createStringValue
(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 void
protected String
getComment
(String key) protected <T> net.minecraft.client.OptionInstance.TooltipSupplier
<T> getTooltip
(String key, @Nullable ModConfigSpec.Range<?> range) protected net.minecraft.network.chat.Component
getTooltipComponent
(String key, @Nullable ModConfigSpec.Range<?> range) protected net.minecraft.network.chat.MutableComponent
protected String
getTranslationKey
(String key) protected @Nullable ModConfigSpec.ValueSpec
getValueSpec
(String key) protected boolean
protected boolean
protected boolean
isPartialNumber
(String value, boolean allowNegative) protected void
This is called whenever a value is changed and the change is submitted to the appropriateConfigSpec
.void
onClose()
rebuild()
void
render
(net.minecraft.client.gui.GuiGraphics graphics, int p_281550_, int p_282878_, float p_282465_) protected void
setResetButtonstate
(boolean state) protected void
setUndoButtonstate
(boolean state) Methods inherited from class net.minecraft.client.gui.screens.options.OptionsSubScreen
addContents, addTitle, init, removed, repositionElements
Methods inherited from class net.minecraft.client.gui.screens.Screen
added, addRenderableOnly, addRenderableWidget, addWidget, afterKeyboardAction, afterMouseAction, afterMouseMove, changeFocus, children, clearFocus, clearTooltipForNextRenderPass, clearWidgets, fillCrashDetails, findNarratableWidget, getBackgroundMusic, getFont, getMinecraft, getNarrationMessage, getRectangle, getTitle, getTooltipFromItem, getUsageNarration, handleComponentClicked, handleDelayedNarration, hasAltDown, hasControlDown, hasShiftDown, init, insertText, isCopy, isCut, isMouseOver, isPaste, isPauseScreen, isSelectAll, isValidCharacterForName, keyPressed, onFilesDrop, rebuildWidgets, removeWidget, renderBackground, renderBlurredBackground, renderMenuBackground, renderMenuBackground, renderMenuBackgroundTexture, renderPanorama, renderTransparentBackground, renderWithTooltip, resize, setInitialFocus, setInitialFocus, setTooltipForNextRenderPass, setTooltipForNextRenderPass, setTooltipForNextRenderPass, setTooltipForNextRenderPass, shouldCloseOnEsc, shouldNarrateNavigation, showsActiveEffects, tick, triggerImmediateNarration, updateNarratedWidget, updateNarrationState, updateNarratorStatus
Methods inherited from class net.minecraft.client.gui.components.events.AbstractContainerEventHandler
getFocused, isDragging, setDragging, setFocused
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.minecraft.client.gui.components.events.ContainerEventHandler
charTyped, getChildAt, getCurrentFocusPath, isFocused, keyReleased, mouseClicked, mouseDragged, mouseReleased, mouseScrolled, nextFocusPath, setFocused
Methods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
getBorderForArrowNavigation, mouseMoved
Methods 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
@Nullable protected @Nullable net.minecraft.client.gui.components.Button undoButton -
resetButton
@Nullable protected @Nullable net.minecraft.client.gui.components.Button resetButton -
doneButton
protected final net.minecraft.client.gui.components.Button doneButton -
undoManager
-
-
Constructor Details
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(net.minecraft.client.gui.screens.Screen parent, net.neoforged.fml.config.ModConfig.Type type, net.neoforged.fml.config.ModConfig modConfig, net.minecraft.network.chat.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.Type
this configuration is for. Only used to generate the title of the screen.modConfig
- The actual config to show and edit.
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(net.minecraft.client.gui.screens.Screen parent, net.neoforged.fml.config.ModConfig.Type type, net.neoforged.fml.config.ModConfig modConfig, net.minecraft.network.chat.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.Type
this configuration is for. Only used to generate the title of the screen.modConfig
- The actual config to show and edit.filter
- TheConfigurationScreen.ConfigurationSectionScreen.Filter
to use.
-
ConfigurationSectionScreen
public ConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context parentContext, net.minecraft.client.gui.screens.Screen parent, Map<String, Object> valueSpecs, String key, Set<? extends com.electronwill.nightconfig.core.UnmodifiableConfig.Entry> entrySet, net.minecraft.network.chat.Component title) Constructs a new section screen for a sub-section of a config.- Parameters:
parentContext
- TheConfigurationScreen.ConfigurationSectionScreen.Context
object 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.ValueSpec
objects for this section.key
- The key of the section.entrySet
- The source for theModConfigSpec.ConfigValue
objects for this section.
-
ConfigurationSectionScreen
protected ConfigurationSectionScreen(ConfigurationScreen.ConfigurationSectionScreen.Context context, net.minecraft.network.chat.Component title)
-
-
Method Details
-
getValueSpec
-
getTranslationKey
-
getTranslationComponent
-
getComment
-
getTooltip
protected <T> net.minecraft.client.OptionInstance.TooltipSupplier<T> getTooltip(String key, @Nullable @Nullable ModConfigSpec.Range<?> range) -
getTooltipComponent
protected net.minecraft.network.chat.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:
addOptions
in classnet.minecraft.client.gui.screens.options.OptionsSubScreen
-
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.ConfigValue
nor 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.Element
to be added to the UI.
-
createOtherValue
@Nullable protected @Nullable ConfigurationScreen.ConfigurationSectionScreen.Element createOtherValue(String key, ModConfigSpec.ConfigValue<?> value) Called when aModConfigSpec.ConfigValue
is 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.Element
to 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
public void render(net.minecraft.client.gui.GuiGraphics graphics, int p_281550_, int p_282878_, float p_282465_) - Specified by:
render
in interfacenet.minecraft.client.gui.components.Renderable
- Overrides:
render
in classnet.minecraft.client.gui.screens.Screen
-
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:
onClose
in classnet.minecraft.client.gui.screens.options.OptionsSubScreen
-