diff --git a/src/openonyx/history/internal/ActionSetting.java b/src/openonyx/history/internal/ActionSetting.java new file mode 100644 index 0000000..116ce13 --- /dev/null +++ b/src/openonyx/history/internal/ActionSetting.java @@ -0,0 +1,49 @@ +package openonyx.history.internal; + +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import java.util.function.BooleanSupplier; +import openonyx.history.Setting; + +public class ActionSetting extends Setting { + private final Runnable runnable; + private String buttonLabel; + + public ActionSetting withButtonLabel(String string) { + this.buttonLabel = string; + return this; + } + + @Override + public JsonElement toJson() { + return JsonNull.INSTANCE; + } + + public ActionSetting describe(String string) { + super.describe(string); + return this; + } + + public ActionSetting visibleWhen(BooleanSupplier booleanSupplier) { + super.visibleWhen(booleanSupplier); + return this; + } + + public String getButtonLabel() { + return this.buttonLabel; + } + + public ActionSetting(String string, Runnable runnable) { + super(string); + this.runnable = runnablex; + this.buttonLabel = string; + } + + @Override + public void fromJson(JsonElement jsonElement) { + } + + public void run() { + this.runnable.run(); + } +} diff --git a/src/openonyx/history/internal/BlockSetSetting.java b/src/openonyx/history/internal/BlockSetSetting.java new file mode 100644 index 0000000..8c32baa --- /dev/null +++ b/src/openonyx/history/internal/BlockSetSetting.java @@ -0,0 +1,151 @@ +package openonyx.history.internal; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; +import java.util.function.Predicate; +import net.minecraft.block.Block; +import net.minecraft.util.ResourceLocation; +import openonyx.history.SettingValue; + +public class BlockSetSetting extends SettingValue> { + public static final Comparator COMPARATOR = Comparator.comparing(BlockSetSetting::L); + + @Override + public void fromJson(JsonElement jsonElement) { + if (jsonElement.isJsonArray()) { + TreeSet treeSet = new TreeSet<>(COMPARATOR); + Iterator iterator = jsonElement.getAsJsonArray().iterator(); + + label27: + while (true) { + Iterator iterator1 = iterator; + + while (iterator1.hasNext()) { + JsonElement jsonElement1; + if (!(jsonElement1 = (JsonElement)iterator.next()).isJsonPrimitive()) { + continue label27; + } + + if (!jsonElement1.getAsJsonPrimitive().isString()) { + iterator1 = iterator; + } else { + ResourceLocation resourceLocation = new ResourceLocation(jsonElement1.getAsString()); + if (!Block.blockRegistry.containsKey(resourceLocation)) { + iterator1 = iterator; + } else { + treeSet.add(Block.blockRegistry.getObject(resourceLocation)); + iterator1 = iterator; + } + } + } + + this.setValue(treeSet); + return; + } + } + } + + public void D(Block block) { + if (this.L(block)) { + this.d(block); + } else { + this.L(block); + } + } + + @Override + public JsonElement toJson() { + BlockSetSetting blockSetSetting1 = this; + JsonArray jsonArray = new JsonArray(); + Iterator iterator; + Iterator iterator1 = iterator = blockSetSetting1.getValue().iterator(); + + while (iterator1.hasNext()) { + Block block = (Block)iterator.next(); + iterator1 = iterator; + jsonArray.add(new JsonPrimitive(L(block))); + } + + return jsonArray; + } + + public boolean L(Block block) { + return this.getValue().contains(block); + } + + public BlockSetSetting describe(String string) { + super.describe(string); + return this; + } + + public BlockSetSetting visibleWhen(SettingValue settingValue, Predicate predicate) { + super.visibleWhen(settingValue, predicate); + return this; + } + + protected Set L(Set set) { + return L((Iterable)set); + } + + public static String L(Block block) { + return String.valueOf(Block.blockRegistry.getNameForObject(block)); + } + + public BlockSetSetting onChange(Consumer> consumer) { + super.onChange(consumer); + return this; + } + + public BlockSetSetting visibleWhen(SettingValue settingValue) { + super.visibleWhen(settingValue); + return this; + } + + public static Set L(Iterable iterable) { + Iterable iterable1 = iterable; + TreeSet treeSet = new TreeSet<>(COMPARATOR); + Iterator iterator = iterable1.iterator(); + + while (iterator.hasNext()) { + Block block; + if ((block = (Block)iterator.next()) != null) { + treeSet.add(block); + } + } + + return treeSet; + } + + public void d(Block block) { + BlockSetSetting blockSetSetting1 = this; + TreeSet treeSet; + (treeSet = new TreeSet<>(COMPARATOR)).addAll(blockSetSetting1.getValue()); + treeSet.remove(block); + blockSetSetting1.setValue(treeSet); + } + + public BlockSetSetting(String string, Block... blocks) { + super(string, L(List.of(blocks))); + } + + public BlockSetSetting visibleWhen(BooleanSupplier booleanSupplier) { + super.visibleWhen(booleanSupplier); + return this; + } + + public void L(Block block) { + BlockSetSetting blockSetSetting1 = this; + TreeSet treeSet; + (treeSet = new TreeSet<>(COMPARATOR)).addAll(blockSetSetting1.getValue()); + treeSet.add(block); + blockSetSetting1.setValue(treeSet); + } +} diff --git a/src/openonyx/history/internal/BooleanSetting.java b/src/openonyx/history/internal/BooleanSetting.java new file mode 100644 index 0000000..6f0b479 --- /dev/null +++ b/src/openonyx/history/internal/BooleanSetting.java @@ -0,0 +1,59 @@ +package openonyx.history.internal; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; +import java.util.function.Predicate; +import openonyx.history.SettingValue; + +public class BooleanSetting extends SettingValue { + public BooleanSetting visibleWhen(SettingValue settingValue) { + super.visibleWhen(settingValue); + return this; + } + + public BooleanSetting(String string, boolean bl) { + super(string, bl); + } + + public void toggle() { + this.setValue(!this.getValue()); + } + + @Override + public void fromJson(JsonElement jsonElement) { + if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isBoolean()) { + this.setValue(jsonElement.getAsBoolean()); + } + } + + @Override + public JsonElement toJson() { + return new JsonPrimitive(this.getValue()); + } + + public BooleanSetting visibleWhen(BooleanSupplier booleanSupplier) { + super.visibleWhen(booleanSupplier); + return this; + } + + public BooleanSetting onChange(Consumer consumer) { + super.onChange(consumer); + return this; + } + + public BooleanSetting describe(String string) { + super.describe(string); + return this; + } + + public boolean isEnabled() { + return this.getValue(); + } + + public BooleanSetting visibleWhen(SettingValue settingValue, Predicate predicate) { + super.visibleWhen(settingValue, predicate); + return this; + } +} diff --git a/src/openonyx/history/internal/EnumSetting.java b/src/openonyx/history/internal/EnumSetting.java new file mode 100644 index 0000000..f6a59f2 --- /dev/null +++ b/src/openonyx/history/internal/EnumSetting.java @@ -0,0 +1,120 @@ +package openonyx.history.internal; + +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import java.util.Iterator; +import java.util.List; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; +import java.util.function.Predicate; +import openonyx.history.DisplayNamed; +import openonyx.history.SettingValue; + +public class EnumSetting> extends SettingValue { + private final List values; + + @SafeVarargs + public EnumSetting(String string, E enum_, E... enums) { + super(string, (E)enum_); + this.values = List.of((E[])enums); + if (!this.values.contains(enum_)) { + throw new IllegalArgumentException( + new StringBuilder().insert(0, "Default '").append(enum_).append("' is not offered by '").append(string).append("'").toString() + ); + } + } + + public EnumSetting visibleWhen(SettingValue settingValue, Predicate predicate) { + super.visibleWhen(settingValue, predicate); + return this; + } + + public static String displayName(Enum enum_) { + Enum enum_x = enum_; + if (enum_x instanceof DisplayNamed) { + DisplayNamed displayNamed; + return (displayNamed = (DisplayNamed)enum_x).getDisplayName(); + } + + StringBuilder stringBuilder = new StringBuilder(enum_x.name().length()); + String[] strings; + int j = (strings = enum_x.name().toLowerCase().split("_")).length; + + int i; + for (int k = i = 0; k < j; k = ++i) { + String string; + if (!(string = strings[i]).isEmpty()) { + StringBuilder stringBuilder1; + if (stringBuilder.isEmpty()) { + stringBuilder.append(Character.toUpperCase(string.charAt(0))); + stringBuilder1 = stringBuilder; + } else { + stringBuilder.append(' ').append(string.charAt(0)); + stringBuilder1 = stringBuilder; + } + + stringBuilder1.append(string, 1, string.length()); + } + } + + return stringBuilder.toString(); + } + + @Override + public JsonElement toJson() { + return new JsonPrimitive(this.getValue().name()); + } + + public EnumSetting(String string, E enum_) { + super(string, (E)enum_); + this.values = List.of((E[])enum_.getDeclaringClass().getEnumConstants()); + } + + public EnumSetting describe(String string) { + super.describe(string); + return this; + } + + @Override + public void fromJson(JsonElement jsonElement) { + if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) { + String string = jsonElement.getAsString(); + Iterator iterator = this.values.iterator(); + + while (iterator.hasNext()) { + Enum enum_; + if ((enum_ = (Enum)iterator.next()).name().equals(string)) { + this.setValue((E)enum_); + return; + } + } + } + } + + public EnumSetting onChange(Consumer consumer) { + super.onChange(consumer); + return this; + } + + public List getValues() { + return this.values; + } + + public EnumSetting visibleWhen(BooleanSupplier booleanSupplier) { + super.visibleWhen(booleanSupplier); + return this; + } + + public boolean is(E enum_) { + return this.getValue() == enum_; + } + + public void cycle() { + this.setValue(this.values.get((this.values.indexOf(this.getValue()) + 1) % this.values.size())); + } + + public EnumSetting visibleWhen(SettingValue settingValue) { + super.visibleWhen(settingValue); + return this; + } +}