package io.gitlab.jfronny.libjf.config.impl.client.gui; import io.gitlab.jfronny.commons.tuple.Tuple; import io.gitlab.jfronny.libjf.config.api.EntryInfo; import io.gitlab.jfronny.libjf.config.api.WidgetFactory; import io.gitlab.jfronny.libjf.unsafe.SafeLog; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.text.Text; import java.util.List; public class WidgetState { public EntryInfo entry; public List> knownStates; public Tuple error; public boolean inLimits = true; public String tempValue; public T cachedValue; public WidgetFactory factory; public void initialize(EntryInfo entry, List> knownStates, WidgetFactory factory) { this.entry = entry; this.knownStates = knownStates; this.factory = factory; try { updateCache(entry.getValue()); } catch (IllegalAccessException e) { SafeLog.error("Could not create initial widget state cache", e); } } public void updateCache(T newValue) { cachedValue = newValue; tempValue = newValue == null ? null : newValue.toString(); } public void writeToEntry() throws IllegalAccessException { entry.setValue(cachedValue); } public void reset() { cachedValue = entry.getDefault(); } }