|
@@ -1,36 +1,16 @@
|
|
|
package me.shedaniel.clothconfig2;
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
-import me.shedaniel.clothconfig2.api.*;
|
|
|
-import me.shedaniel.clothconfig2.gui.entries.MultiElementListEntry;
|
|
|
-import me.shedaniel.clothconfig2.gui.entries.NestedListListEntry;
|
|
|
+import me.shedaniel.clothconfig2.api.ScrollingContainer;
|
|
|
import me.shedaniel.clothconfig2.impl.EasingMethod;
|
|
|
import me.shedaniel.clothconfig2.impl.EasingMethod.EasingMethodImpl;
|
|
|
-import me.shedaniel.clothconfig2.impl.builders.DropdownMenuBuilder;
|
|
|
-import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
|
|
|
-import net.fabricmc.api.ClientModInitializer;
|
|
|
import net.fabricmc.api.EnvType;
|
|
|
import net.fabricmc.api.Environment;
|
|
|
-import net.fabricmc.loader.api.FabricLoader;
|
|
|
-import net.minecraft.client.MinecraftClient;
|
|
|
-import net.minecraft.client.util.InputUtil;
|
|
|
-import net.minecraft.item.Item;
|
|
|
-import net.minecraft.item.Items;
|
|
|
-import net.minecraft.text.LiteralText;
|
|
|
-import net.minecraft.text.TranslatableText;
|
|
|
-import net.minecraft.util.Identifier;
|
|
|
-import net.minecraft.util.registry.Registry;
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.jetbrains.annotations.ApiStatus;
|
|
|
|
|
|
-import java.lang.reflect.Method;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
@Environment(EnvType.CLIENT)
|
|
|
-public class ClothConfigInitializer implements ClientModInitializer {
|
|
|
-
|
|
|
+public class ClothConfigInitializer {
|
|
|
public static final Logger LOGGER = LogManager.getFormatterLogger("ClothConfig");
|
|
|
|
|
|
@Deprecated
|
|
@@ -72,137 +52,4 @@ public class ClothConfigInitializer implements ClientModInitializer {
|
|
|
public static double getBounceBackMultiplier() {
|
|
|
return -10;
|
|
|
}
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onInitializeClient() {
|
|
|
- if (FabricLoader.getInstance().isModLoaded("modmenu")) {
|
|
|
- try {
|
|
|
- Class<?> clazz = Class.forName("io.github.prospector.modmenu.api.ModMenuApi");
|
|
|
- Method method = clazz.getMethod("addConfigOverride", String.class, Runnable.class);
|
|
|
- method.invoke(null, "cloth-config2", (Runnable) () -> {
|
|
|
- try {
|
|
|
- MinecraftClient.getInstance().openScreen(getConfigBuilderWithDemo().build());
|
|
|
- } catch (Throwable throwable) {
|
|
|
- throwable.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (Exception e) {
|
|
|
- ClothConfigInitializer.LOGGER.error("[ClothConfig] Failed to add test config override for ModMenu!", e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static ConfigBuilder getConfigBuilderWithDemo() {
|
|
|
- class Pair<T, R> {
|
|
|
- T t;
|
|
|
- R r;
|
|
|
-
|
|
|
- public Pair(T t, R r) {
|
|
|
- this.t = t;
|
|
|
- this.r = r;
|
|
|
- }
|
|
|
-
|
|
|
- public T getLeft() {
|
|
|
- return t;
|
|
|
- }
|
|
|
-
|
|
|
- public R getRight() {
|
|
|
- return r;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean equals(Object o) {
|
|
|
- if (this == o) return true;
|
|
|
- if (o == null || getClass() != o.getClass()) return false;
|
|
|
-
|
|
|
- Pair<?, ?> pair = (Pair<?, ?>) o;
|
|
|
-
|
|
|
- if (!Objects.equals(t, pair.t)) return false;
|
|
|
- return Objects.equals(r, pair.r);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public int hashCode() {
|
|
|
- int result = t != null ? t.hashCode() : 0;
|
|
|
- result = 31 * result + (r != null ? r.hashCode() : 0);
|
|
|
- return result;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ConfigBuilder builder = ConfigBuilder.create().setParentScreen(MinecraftClient.getInstance().currentScreen).setTitle(new TranslatableText("title.cloth-config.config"));
|
|
|
- builder.setDefaultBackgroundTexture(new Identifier("minecraft:textures/block/oak_planks.png"));
|
|
|
- builder.setGlobalized(true);
|
|
|
- ConfigEntryBuilder entryBuilder = builder.entryBuilder();
|
|
|
- ConfigCategory testing = builder.getOrCreateCategory(new TranslatableText("category.cloth-config.testing"));
|
|
|
- testing.addEntry(entryBuilder.startKeyCodeField(new LiteralText("Cool Key"), InputUtil.UNKNOWN_KEYCODE).setDefaultValue(InputUtil.UNKNOWN_KEYCODE).build());
|
|
|
- testing.addEntry(entryBuilder.startModifierKeyCodeField(new LiteralText("Cool Modifier Key"), ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).setDefaultValue(ModifierKeyCode.of(InputUtil.Type.KEYSYM.createFromCode(79), Modifier.of(false, true, false))).build());
|
|
|
- testing.addEntry(entryBuilder.startDoubleList(new LiteralText("A list of Doubles"), Arrays.asList(1d, 2d, 3d)).setDefaultValue(Arrays.asList(1d, 2d, 3d)).build());
|
|
|
- testing.addEntry(entryBuilder.startLongList(new LiteralText("A list of Longs"), Arrays.asList(1L, 2L, 3L)).setDefaultValue(Arrays.asList(1L, 2L, 3L)).build());
|
|
|
- testing.addEntry(entryBuilder.startStrList(new LiteralText("A list of Strings"), Arrays.asList("abc", "xyz")).setDefaultValue(Arrays.asList("abc", "xyz")).build());
|
|
|
- SubCategoryBuilder colors = entryBuilder.startSubCategory(new LiteralText("Colors")).setExpanded(true);
|
|
|
- colors.add(entryBuilder.startColorField(new LiteralText("A color field"), 0x00ffff).setDefaultValue(0x00ffff).build());
|
|
|
- colors.add(entryBuilder.startColorField(new LiteralText("An alpha color field"), 0xff00ffff).setDefaultValue(0xff00ffff).setAlphaMode(true).build());
|
|
|
- colors.add(entryBuilder.startColorField(new LiteralText("An alpha color field"), 0xffffffff).setDefaultValue(0xffff0000).setAlphaMode(true).build());
|
|
|
- colors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- colors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- colors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- colors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- colors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- SubCategoryBuilder innerColors = entryBuilder.startSubCategory(new LiteralText("Inner Colors")).setExpanded(true);
|
|
|
- innerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- innerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- innerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- SubCategoryBuilder innerInnerColors = entryBuilder.startSubCategory(new LiteralText("Inner Inner Colors")).setExpanded(true);
|
|
|
- innerInnerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- innerInnerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- innerInnerColors.add(entryBuilder.startDropdownMenu(new LiteralText("lol apple"), DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(Items.APPLE), DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).setDefaultValue(Items.APPLE).setSelections(Registry.ITEM.stream().sorted(Comparator.comparing(Item::toString)).collect(Collectors.toCollection(LinkedHashSet::new))).setSaveConsumer(item -> System.out.println("save this " + item)).build());
|
|
|
- innerColors.add(innerInnerColors.build());
|
|
|
- colors.add(innerColors.build());
|
|
|
- testing.addEntry(colors.build());
|
|
|
- testing.addEntry(entryBuilder.startDropdownMenu(new LiteralText("Suggestion Random Int"), DropdownMenuBuilder.TopCellElementBuilder.of(10,
|
|
|
- s -> {
|
|
|
- try {
|
|
|
- return Integer.parseInt(s);
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
-
|
|
|
- }
|
|
|
- return null;
|
|
|
- })).setDefaultValue(10).setSelections(Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).build());
|
|
|
- testing.addEntry(entryBuilder.startDropdownMenu(new LiteralText("Selection Random Int"), DropdownMenuBuilder.TopCellElementBuilder.of(10,
|
|
|
- s -> {
|
|
|
- try {
|
|
|
- return Integer.parseInt(s);
|
|
|
- } catch (NumberFormatException ignored) {
|
|
|
-
|
|
|
- }
|
|
|
- return null;
|
|
|
- })).setDefaultValue(5).setSuggestionMode(false).setSelections(Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)).build());
|
|
|
- testing.addEntry(new NestedListListEntry<Pair<Integer, Integer>, MultiElementListEntry<Pair<Integer, Integer>>>(
|
|
|
- new LiteralText("Nice"),
|
|
|
- Lists.newArrayList(new Pair<>(10, 10), new Pair<>(20, 40)),
|
|
|
- false,
|
|
|
- Optional::empty,
|
|
|
- list -> {},
|
|
|
- () -> Lists.newArrayList(new Pair<>(10, 10), new Pair<>(20, 40)),
|
|
|
- entryBuilder.getResetButtonKey(),
|
|
|
- true,
|
|
|
- true,
|
|
|
- (elem, nestedListListEntry) -> {
|
|
|
- if (elem == null) {
|
|
|
- Pair<Integer, Integer> newDefaultElemValue = new Pair<>(10, 10);
|
|
|
- return new MultiElementListEntry<>(new LiteralText("Pair"), newDefaultElemValue,
|
|
|
- Lists.newArrayList(entryBuilder.startIntField(new LiteralText("Left"), newDefaultElemValue.getLeft()).setDefaultValue(10).build(),
|
|
|
- entryBuilder.startIntField(new LiteralText("Right"), newDefaultElemValue.getRight()).setDefaultValue(10).build()),
|
|
|
- true);
|
|
|
- } else {
|
|
|
- return new MultiElementListEntry<>(new LiteralText("Pair"), elem,
|
|
|
- Lists.newArrayList(entryBuilder.startIntField(new LiteralText("Left"), elem.getLeft()).setDefaultValue(10).build(),
|
|
|
- entryBuilder.startIntField(new LiteralText("Right"), elem.getRight()).setDefaultValue(10).build()),
|
|
|
- true);
|
|
|
- }
|
|
|
- }
|
|
|
- ));
|
|
|
- builder.transparentBackground();
|
|
|
- return builder;
|
|
|
- }
|
|
|
}
|