diff options
Diffstat (limited to 'src')
16 files changed, 413 insertions, 12 deletions
diff --git a/src/main/java/dev/isxander/fabricmodtemplate/.gitkeep b/src/main/java/dev/isxander/fabricmodtemplate/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/src/main/java/dev/isxander/fabricmodtemplate/.gitkeep +++ /dev/null diff --git a/src/main/java/dev/isxander/fabricmodtemplate/mixins/.gitkeep b/src/main/java/dev/isxander/fabricmodtemplate/mixins/.gitkeep deleted file mode 100644 index e69de29..0000000 --- a/src/main/java/dev/isxander/fabricmodtemplate/mixins/.gitkeep +++ /dev/null diff --git a/src/main/java/dev/isxander/yacl/api/Binding.java b/src/main/java/dev/isxander/yacl/api/Binding.java new file mode 100644 index 0000000..67ff822 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/Binding.java @@ -0,0 +1,18 @@ +package dev.isxander.yacl.api; + +import dev.isxander.yacl.impl.GenericBindingImpl; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface Binding<T> { + void setValue(T value); + + T getValue(); + + void resetValue(); + + static <T> Binding<T> of(T def, Supplier<T> getter, Consumer<T> setter) { + return new GenericBindingImpl<>(def, getter, setter); + } +} diff --git a/src/main/java/dev/isxander/yacl/api/ConfigCategory.java b/src/main/java/dev/isxander/yacl/api/ConfigCategory.java new file mode 100644 index 0000000..ee2fbc7 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/ConfigCategory.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.impl.ConfigCategoryImpl; +import net.minecraft.text.Text; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface ConfigCategory { + @NotNull Text name(); + + @NotNull ImmutableList<Option<?>> options(); + + static Builder createBuilder() { + return new Builder(); + } + + class Builder { + private Text name; + private final List<Option<?>> options = new ArrayList<>(); + + private Builder() { + + } + + public Builder setName(@NotNull Text name) { + Validate.notNull(name, "`name` cannot be null"); + + this.name = name; + return this; + } + + public Builder addOption(@NotNull Option<?> option) { + Validate.notNull(option, "`option` must not be null"); + + this.options.add(option); + return this; + } + + public ConfigCategory build() { + Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); + Validate.notEmpty(options, "`at least one option must be added to build `ConfigCategory`"); + + return new ConfigCategoryImpl(name, ImmutableList.copyOf(options)); + } + } +} diff --git a/src/main/java/dev/isxander/yacl/api/Control.java b/src/main/java/dev/isxander/yacl/api/Control.java new file mode 100644 index 0000000..0733c4f --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/Control.java @@ -0,0 +1,10 @@ +package dev.isxander.yacl.api; + +import dev.isxander.yacl.api.utils.Dimension; +import dev.isxander.yacl.gui.AbstractWidget; + +public interface Control<T> { + Option<T> option(); + + AbstractWidget provideWidget(Dimension<Integer> widgetDimension); +} diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java new file mode 100644 index 0000000..1c7a8a1 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -0,0 +1,101 @@ +package dev.isxander.yacl.api; + +import dev.isxander.yacl.impl.OptionImpl; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface Option<T> { + @NotNull Text name(); + + @Nullable Text tooltip(); + + @NotNull Control<T> control(); + + @NotNull Binding<T> binding(); + + boolean changed(); + + void requestSet(T value); + + void applyValue(); + + static <T> Builder<T> createBuilder() { + return new Builder<>(); + } + + class Builder<T> { + private Text name; + + private final List<Text> tooltipLines = new ArrayList<>(); + + private Control<T> control; + + private Binding<T> binding; + + private Builder() { + + } + + public Builder<T> name(@NotNull Text name) { + Validate.notNull(name, "`name` cannot be null"); + + this.name = name; + return this; + } + + public Builder<T> tooltip(@NotNull Text... tooltips) { + Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); + + tooltipLines.addAll(List.of(tooltips)); + return this; + } + + public Builder<T> controller(@NotNull Control<T> control) { + Validate.notNull(control, "`control` cannot be null"); + + this.control = control; + return this; + } + + public Builder<T> binding(@NotNull Binding<T> binding) { + Validate.notNull(binding, "`binding` cannot be null"); + + this.binding = binding; + return this; + } + + public Builder<T> binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter) { + Validate.notNull(def, "`default` must not be null"); + Validate.notNull(getter, "`getter` must not be null"); + Validate.notNull(setter, "`setter` must not be null"); + + this.binding = Binding.of(def, getter, setter); + return this; + } + + public Option<T> build() { + Validate.notNull(name, "`name` must not be null when building `Option`"); + Validate.notNull(control, "`control` must not be null when building `Option`"); + Validate.notNull(binding, "`binding` must not be null when building `Option`"); + + MutableText concatenatedTooltip = Text.empty(); + boolean first = true; + for (Text line : tooltipLines) { + if (!first) concatenatedTooltip.append("\n"); + first = false; + + concatenatedTooltip.append(line); + } + + return new OptionImpl<>(name, concatenatedTooltip, control, binding); + } + } +} diff --git a/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java new file mode 100644 index 0000000..d7f8416 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/YetAnotherConfigLib.java @@ -0,0 +1,55 @@ +package dev.isxander.yacl.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.impl.YetAnotherConfigLibImpl; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; +import org.apache.commons.lang3.Validate; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public interface YetAnotherConfigLib { + + Text title(); + + ImmutableList<ConfigCategory> categories(); + + Screen generateScreen(); + + static Builder createBuilder(Text title) { + return new Builder(title); + } + + class Builder { + private Text title; + private final List<ConfigCategory> categories = new ArrayList<>(); + + private Builder(@NotNull Text title) { + Validate.notNull(title, "`title` cannot be null"); + this.title = title; + } + + public Builder setTitle(@NotNull Text title) { + Validate.notNull(title, "`title` cannot be null"); + + this.title = title; + return this; + } + + public Builder addCategory(@NotNull ConfigCategory category) { + Validate.notNull(category, "`category` cannot be null"); + + this.categories.add(category); + return this; + } + + public YetAnotherConfigLib build() { + Validate.notNull(title, "`title must not be null to build `YetAnotherConfigLib`"); + Validate.notEmpty(categories, "`categories` must not be empty to build `YetAnotherConfigLib`"); + + return new YetAnotherConfigLibImpl(title, ImmutableList.copyOf(categories)); + } + } +} diff --git a/src/main/java/dev/isxander/yacl/api/utils/Dimension.java b/src/main/java/dev/isxander/yacl/api/utils/Dimension.java new file mode 100644 index 0000000..cf7127a --- /dev/null +++ b/src/main/java/dev/isxander/yacl/api/utils/Dimension.java @@ -0,0 +1,20 @@ +package dev.isxander.yacl.api.utils; + +import dev.isxander.yacl.impl.utils.DimensionIntegerImpl; + +public interface Dimension<T extends Number> { + T x(); + T y(); + + T width(); + T height(); + + T xLimit(); + T yLimit(); + + boolean isPointInside(T x, T y); + + static Dimension<Integer> ofInt(int x, int y, int width, int height) { + return new DimensionIntegerImpl(x, y, width, height); + } +} diff --git a/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java new file mode 100644 index 0000000..2a8a519 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/gui/AbstractWidget.java @@ -0,0 +1,8 @@ +package dev.isxander.yacl.gui; + +import net.minecraft.client.gui.Drawable; +import net.minecraft.client.gui.Element; +import net.minecraft.client.gui.Selectable; + +public abstract class AbstractWidget implements Element, Drawable, Selectable { +} diff --git a/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java new file mode 100644 index 0000000..0f6f33b --- /dev/null +++ b/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -0,0 +1,12 @@ +package dev.isxander.yacl.impl; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.api.ConfigCategory; +import dev.isxander.yacl.api.Option; +import net.minecraft.text.Text; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public record ConfigCategoryImpl(Text name, ImmutableList<Option<?>> options) implements ConfigCategory { + +} diff --git a/src/main/java/dev/isxander/yacl/impl/GenericBindingImpl.java b/src/main/java/dev/isxander/yacl/impl/GenericBindingImpl.java new file mode 100644 index 0000000..f2321c7 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/impl/GenericBindingImpl.java @@ -0,0 +1,36 @@ +package dev.isxander.yacl.impl; + +import dev.isxander.yacl.api.Binding; +import org.jetbrains.annotations.ApiStatus; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +@ApiStatus.Internal +public class GenericBindingImpl<T> implements Binding<T> { + private final T def; + private final Supplier<T> getter; + private final Consumer<T> setter; + + public GenericBindingImpl(T def, Supplier<T> getter, Consumer<T> setting) { + this.def = def; + this.getter = getter; + this.setter = setting; + } + + + @Override + public void setValue(T value) { + setter.accept(value); + } + + @Override + public T getValue() { + return getter.get(); + } + + @Override + public void resetValue() { + setValue(def); + } +} diff --git a/src/main/java/dev/isxander/yacl/impl/OptionImpl.java b/src/main/java/dev/isxander/yacl/impl/OptionImpl.java new file mode 100644 index 0000000..3f6e5c2 --- /dev/null +++ b/src/main/java/dev/isxander/yacl/impl/OptionImpl.java @@ -0,0 +1,65 @@ +package dev.isxander.yacl.impl; + +import dev.isxander.yacl.api.Binding; +import dev.isxander.yacl.api.Control; +import dev.isxander.yacl.api.Option; +import net.minecraft.text.Text; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@ApiStatus.Internal +public class OptionImpl<T> implements Option<T> { + private final Text name; + private final Text tooltip; + private final Control<T> control; + private final Binding<T> binding; + + private @Nullable T changedValue = null; + + public OptionImpl(@NotNull Text name, + @Nullable Text tooltip, + @NotNull Control<T> control, + @NotNull Binding<T> binding) { + this.name = name; + this.tooltip = tooltip; + this.control = control; + this.binding = binding; + } + + @Override + public @NotNull Text name() { + return name; + } + + @Override + public @Nullable Text tooltip() { + return tooltip; + } + + @Override + public @NotNull Control<T> control() { + return control; + } + + @Override + public @NotNull Binding<T> binding() { + return binding; + } + + @Override + public boolean changed() { + return !binding().getValue().equals(changedValue); + } + + @Override + public void requestSet(T value) { + this.changedValue = value; + } + + @Override + public void applyValue() { + if (changedValue != null) + binding().setValue(changedValue); + } +} diff --git a/src/main/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java b/src/main/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java new file mode 100644 index 0000000..0cef49f --- /dev/null +++ b/src/main/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java @@ -0,0 +1,16 @@ +package dev.isxander.yacl.impl; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.api.ConfigCategory; +import dev.isxander.yacl.api.YetAnotherConfigLib; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public record YetAnotherConfigLibImpl(Text title, ImmutableList<ConfigCategory> categories) implements YetAnotherConfigLib { + @Override + public Screen generateScreen() { + return null; + } +} diff --git a/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java b/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java new file mode 100644 index 0000000..908157d --- /dev/null +++ b/src/main/java/dev/isxander/yacl/impl/utils/DimensionIntegerImpl.java @@ -0,0 +1,22 @@ +package dev.isxander.yacl.impl.utils; + +import dev.isxander.yacl.api.utils.Dimension; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public record DimensionIntegerImpl(Integer x, Integer y, Integer width, Integer height) implements Dimension<Integer> { + @Override + public Integer xLimit() { + return x + width; + } + + @Override + public Integer yLimit() { + return y + height; + } + + @Override + public boolean isPointInside(Integer x, Integer y) { + return x >= x() && x <= xLimit() && y >= y() && y <= yLimit(); + } +} diff --git a/src/main/resources/fabric-mod-template.mixins.json b/src/main/resources/fabric-mod-template.mixins.json deleted file mode 100644 index 9ac6462..0000000 --- a/src/main/resources/fabric-mod-template.mixins.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "package": "dev.isxander.fabricmodtemplate.mixins", - "required": true, - "minVersion": "0.8", - "compatibilityLevel": "JAVA_17", - "mixins": [ - - ] -}
\ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 95b5d16..708c30e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -17,9 +17,6 @@ "entrypoints": { }, - "mixins": [ - "fabric-mod-template.mixins.json" - ], "depends": { "fabricloader": ">=0.14.0", "minecraft": "1.19.x", |