-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add WIP config api with IMS' redesign of the options page and contari…
…a's forge mod entrypoint loader code
- Loading branch information
Showing
66 changed files
with
2,455 additions
and
1,006 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
common/src/api/java/net/caffeinemc/mods/sodium/api/config/ConfigEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.caffeinemc.mods.sodium.api.config; | ||
|
||
import net.caffeinemc.mods.sodium.api.config.structure.ConfigBuilder; | ||
|
||
public interface ConfigEntryPoint { | ||
void registerConfigEarly(ConfigBuilder builder); | ||
|
||
void registerConfigLate(ConfigBuilder builder); | ||
} |
11 changes: 11 additions & 0 deletions
11
common/src/api/java/net/caffeinemc/mods/sodium/api/config/ConfigState.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package net.caffeinemc.mods.sodium.api.config; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public interface ConfigState { | ||
boolean readBooleanOption(ResourceLocation id); | ||
|
||
int readIntOption(ResourceLocation id); | ||
|
||
<E extends Enum<E>> E readEnumOption(ResourceLocation id, Class<E> enumClass); | ||
} |
6 changes: 6 additions & 0 deletions
6
common/src/api/java/net/caffeinemc/mods/sodium/api/config/StorageEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package net.caffeinemc.mods.sodium.api.config; | ||
|
||
@FunctionalInterface | ||
public interface StorageEventHandler { | ||
void afterSave(); | ||
} |
7 changes: 7 additions & 0 deletions
7
common/src/api/java/net/caffeinemc/mods/sodium/api/config/option/ControlValueFormatter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.caffeinemc.mods.sodium.api.config.option; | ||
|
||
import net.minecraft.network.chat.Component; | ||
|
||
public interface ControlValueFormatter { | ||
Component format(int value); | ||
} |
7 changes: 7 additions & 0 deletions
7
common/src/api/java/net/caffeinemc/mods/sodium/api/config/option/NameProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.caffeinemc.mods.sodium.api.config.option; | ||
|
||
import net.minecraft.network.chat.Component; | ||
|
||
public interface NameProvider { | ||
Component getName(); | ||
} |
9 changes: 9 additions & 0 deletions
9
common/src/api/java/net/caffeinemc/mods/sodium/api/config/option/OptionBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.caffeinemc.mods.sodium.api.config.option; | ||
|
||
public interface OptionBinding<V> { | ||
void save(V value); | ||
|
||
V load(); | ||
|
||
// TODO: add shortcuts to generate for vanilla option bindings | ||
} |
2 changes: 1 addition & 1 deletion
2
...sodium/client/gui/options/OptionFlag.java → .../sodium/api/config/option/OptionFlag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
common/src/api/java/net/caffeinemc/mods/sodium/api/config/option/Range.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.caffeinemc.mods.sodium.api.config.option; | ||
|
||
public record Range(int min, int max, int step) { | ||
public boolean isValueValid(int value) { | ||
return value >= this.min && value <= this.max && (value - this.min) % this.step == 0; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...on/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/BooleanOptionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.caffeinemc.mods.sodium.api.config.*; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionBinding; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionFlag; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionImpact; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public interface BooleanOptionBuilder extends OptionBuilder<Boolean> { | ||
@Override | ||
BooleanOptionBuilder setName(Component name); | ||
|
||
@Override | ||
BooleanOptionBuilder setStorageHandler(StorageEventHandler storage); | ||
|
||
@Override | ||
BooleanOptionBuilder setTooltip(Component tooltip); | ||
|
||
@Override | ||
BooleanOptionBuilder setTooltip(Function<Boolean, Component> tooltip); | ||
|
||
@Override | ||
BooleanOptionBuilder setImpact(OptionImpact impact); | ||
|
||
@Override | ||
BooleanOptionBuilder setFlags(OptionFlag... flags); | ||
|
||
@Override | ||
BooleanOptionBuilder setDefaultValue(Boolean value); | ||
|
||
@Override | ||
BooleanOptionBuilder setDefaultProvider(Function<ConfigState, Boolean> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
BooleanOptionBuilder setEnabled(boolean available); | ||
|
||
@Override | ||
BooleanOptionBuilder setEnabledProvider(Function<ConfigState, Boolean> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
BooleanOptionBuilder setBinding(Consumer<Boolean> save, Supplier<Boolean> load); | ||
|
||
@Override | ||
BooleanOptionBuilder setBinding(OptionBinding<Boolean> binding); | ||
} |
19 changes: 19 additions & 0 deletions
19
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/ConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public interface ConfigBuilder { | ||
ModOptionsBuilder registerModConfig(String namespace, String name, String version); | ||
|
||
ModOptionsBuilder registerOwnModConfig(); | ||
|
||
OptionPageBuilder createOptionPage(); | ||
|
||
OptionGroupBuilder createOptionGroup(); | ||
|
||
BooleanOptionBuilder createBooleanOption(ResourceLocation id); | ||
|
||
IntegerOptionBuilder createIntegerOption(ResourceLocation id); | ||
|
||
<E extends Enum<E>> EnumOptionBuilder<E> createEnumOption(ResourceLocation id, Class<E> enumClass); | ||
} |
61 changes: 61 additions & 0 deletions
61
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/EnumOptionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.caffeinemc.mods.sodium.api.config.*; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionBinding; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionFlag; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionImpact; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public interface EnumOptionBuilder<E extends Enum<E>> extends OptionBuilder<E> { | ||
@Override | ||
EnumOptionBuilder<E> setName(Component name); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setStorageHandler(StorageEventHandler storage); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setTooltip(Component tooltip); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setTooltip(Function<E, Component> tooltip); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setImpact(OptionImpact impact); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setFlags(OptionFlag... flags); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setDefaultValue(E value); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setDefaultProvider(Function<ConfigState, E> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setEnabled(boolean available); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setEnabledProvider(Function<ConfigState, Boolean> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setBinding(Consumer<E> save, Supplier<E> load); | ||
|
||
@Override | ||
EnumOptionBuilder<E> setBinding(OptionBinding<E> binding); | ||
|
||
EnumOptionBuilder<E> setAllowedValues(Set<E> allowedValues); | ||
|
||
EnumOptionBuilder<E> setAllowedValuesProvider(Function<ConfigState, Set<E>> provider, ResourceLocation... dependencies); | ||
|
||
EnumOptionBuilder<E> setElementNameProvider(Function<E, Component> provider); | ||
|
||
static <E extends Enum<E>> Function<E, Component> nameProviderFrom(Component... names) { | ||
return e -> names[e.ordinal()]; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...on/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/IntegerOptionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.caffeinemc.mods.sodium.api.config.*; | ||
import net.caffeinemc.mods.sodium.api.config.option.*; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public interface IntegerOptionBuilder extends OptionBuilder<Integer> { | ||
@Override | ||
IntegerOptionBuilder setName(Component name); | ||
|
||
@Override | ||
IntegerOptionBuilder setStorageHandler(StorageEventHandler storage); | ||
|
||
@Override | ||
IntegerOptionBuilder setTooltip(Component tooltip); | ||
|
||
@Override | ||
IntegerOptionBuilder setTooltip(Function<Integer, Component> tooltip); | ||
|
||
@Override | ||
IntegerOptionBuilder setImpact(OptionImpact impact); | ||
|
||
@Override | ||
IntegerOptionBuilder setFlags(OptionFlag... flags); | ||
|
||
@Override | ||
IntegerOptionBuilder setDefaultValue(Integer value); | ||
|
||
@Override | ||
IntegerOptionBuilder setDefaultProvider(Function<ConfigState, Integer> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
IntegerOptionBuilder setEnabled(boolean available); | ||
|
||
@Override | ||
IntegerOptionBuilder setEnabledProvider(Function<ConfigState, Boolean> provider, ResourceLocation... dependencies); | ||
|
||
@Override | ||
IntegerOptionBuilder setBinding(Consumer<Integer> save, Supplier<Integer> load); | ||
|
||
@Override | ||
IntegerOptionBuilder setBinding(OptionBinding<Integer> binding); | ||
|
||
IntegerOptionBuilder setRange(int min, int max, int step); | ||
|
||
IntegerOptionBuilder setRange(Range range); | ||
|
||
IntegerOptionBuilder setRangeProvider(Function<ConfigState, Range> provider, ResourceLocation... dependencies); | ||
|
||
IntegerOptionBuilder setValueFormatter(ControlValueFormatter formatter); | ||
} |
9 changes: 9 additions & 0 deletions
9
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/ModOptionsBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
public interface ModOptionsBuilder { | ||
ModOptionsBuilder setName(String name); | ||
|
||
ModOptionsBuilder setVersion(String version); | ||
|
||
ModOptionsBuilder addPage(OptionPageBuilder page); | ||
} |
38 changes: 38 additions & 0 deletions
38
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/OptionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.caffeinemc.mods.sodium.api.config.*; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionBinding; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionFlag; | ||
import net.caffeinemc.mods.sodium.api.config.option.OptionImpact; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public interface OptionBuilder<V> { | ||
OptionBuilder<V> setName(Component name); | ||
|
||
OptionBuilder<V> setStorageHandler(StorageEventHandler storage); | ||
|
||
OptionBuilder<V> setTooltip(Component tooltip); | ||
|
||
OptionBuilder<V> setTooltip(Function<V, Component> tooltip); | ||
|
||
OptionBuilder<V> setImpact(OptionImpact impact); | ||
|
||
OptionBuilder<V> setFlags(OptionFlag... flags); | ||
|
||
OptionBuilder<V> setDefaultValue(V value); | ||
|
||
OptionBuilder<V> setDefaultProvider(Function<ConfigState, V> provider, ResourceLocation... dependencies); | ||
|
||
OptionBuilder<V> setEnabled(boolean available); | ||
|
||
OptionBuilder<V> setEnabledProvider(Function<ConfigState, Boolean> provider, ResourceLocation... dependencies); | ||
|
||
OptionBuilder<V> setBinding(Consumer<V> save, Supplier<V> load); | ||
|
||
OptionBuilder<V> setBinding(OptionBinding<V> binding); | ||
} |
9 changes: 9 additions & 0 deletions
9
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/OptionGroupBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.minecraft.network.chat.Component; | ||
|
||
public interface OptionGroupBuilder { | ||
OptionGroupBuilder setName(Component name); | ||
|
||
OptionGroupBuilder addOption(OptionBuilder<?> option); | ||
} |
9 changes: 9 additions & 0 deletions
9
common/src/api/java/net/caffeinemc/mods/sodium/api/config/structure/OptionPageBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.caffeinemc.mods.sodium.api.config.structure; | ||
|
||
import net.minecraft.network.chat.Component; | ||
|
||
public interface OptionPageBuilder { | ||
OptionPageBuilder setName(Component name); | ||
|
||
OptionPageBuilder addOptionGroup(OptionGroupBuilder group); | ||
} |
Oops, something went wrong.