Upload files to "src/openonyx/history/internal"

This commit is contained in:
winterflyt committed 2026-11-30 06:00:57 +02:00
1 parent e781057f68
commit 8d3ce6856e
4 files changed
+379

No files matched your search

@@ -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();
}
}
@@ -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<Set<Block>> {
public static final Comparator<Block> 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 <O> BlockSetSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
super.visibleWhen(settingValue, predicate);
return this;
}
protected Set<Block> L(Set<Block> set) {
return L((Iterable<Block>)set);
}
public static String L(Block block) {
return String.valueOf(Block.blockRegistry.getNameForObject(block));
}
public BlockSetSetting onChange(Consumer<Set<Block>> consumer) {
super.onChange(consumer);
return this;
}
public BlockSetSetting visibleWhen(SettingValue<Boolean> settingValue) {
super.visibleWhen(settingValue);
return this;
}
public static Set<Block> L(Iterable<Block> 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);
}
}
@@ -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<Boolean> {
public BooleanSetting visibleWhen(SettingValue<Boolean> 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<Boolean> consumer) {
super.onChange(consumer);
return this;
}
public BooleanSetting describe(String string) {
super.describe(string);
return this;
}
public boolean isEnabled() {
return this.getValue();
}
public <O> BooleanSetting visibleWhen(SettingValue<O> settingValue, Predicate<O> predicate) {
super.visibleWhen(settingValue, predicate);
return this;
}
}
@@ -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<E extends Enum<E>> extends SettingValue<E> {
private final List<E> 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 <O> EnumSetting<E> visibleWhen(SettingValue<O> settingValue, Predicate<O> 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<E> 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<E> onChange(Consumer<E> consumer) {
super.onChange(consumer);
return this;
}
public List<E> getValues() {
return this.values;
}
public EnumSetting<E> 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<E> visibleWhen(SettingValue<Boolean> settingValue) {
super.visibleWhen(settingValue);
return this;
}
}