aboutsummaryrefslogtreecommitdiff
path: root/shared-internals/src/main/java/me
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2022-08-05 01:30:08 +0800
committershedaniel <daniel@shedaniel.me>2022-08-26 10:53:55 +0900
commit8c13c015031a0de865d2e767cd8e879754f803e2 (patch)
tree2bb6fa6578b63d1c216b863a6c4206295c044b36 /shared-internals/src/main/java/me
parent8f5d3ef632f3d1a733c98ce5607c9fd5a0fd7567 (diff)
downloadRoughlyEnoughItems-8c13c015031a0de865d2e767cd8e879754f803e2.tar.gz
RoughlyEnoughItems-8c13c015031a0de865d2e767cd8e879754f803e2.tar.bz2
RoughlyEnoughItems-8c13c015031a0de865d2e767cd8e879754f803e2.zip
More work
Diffstat (limited to 'shared-internals/src/main/java/me')
-rw-r--r--shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java8
-rw-r--r--shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java2
-rw-r--r--shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/TextTransformations.java99
3 files changed, 108 insertions, 1 deletions
diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java
index 16863185c..7a60c7692 100644
--- a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java
+++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java
@@ -25,9 +25,13 @@ package me.shedaniel.rei.impl.client.config;
import me.shedaniel.autoconfig.gui.registry.GuiRegistry;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Jankson;
+import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.rei.api.client.config.ConfigManager;
import org.jetbrains.annotations.ApiStatus;
+import java.util.Collection;
+import java.util.Collections;
+
@ApiStatus.Internal
public interface ConfigManagerInternal extends ConfigManager {
/**
@@ -45,5 +49,9 @@ public interface ConfigManagerInternal extends ConfigManager {
default void setup(Jankson.Builder builder) {}
default void setup(GuiRegistry registry) {}
+
+ default Collection<? extends AbstractConfigListEntry<?>> collectAdvanced() {
+ return Collections.emptyList();
+ }
}
}
diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java
index eab3a1c87..96c4fd177 100644
--- a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java
+++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java
@@ -24,7 +24,7 @@
package me.shedaniel.rei.impl.client.util;
import me.shedaniel.rei.api.client.gui.Renderer;
-import me.shedaniel.rei.impl.ClientInternals;
+import me.shedaniel.rei.impl.client.ClientInternals;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/TextTransformations.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/TextTransformations.java
new file mode 100644
index 000000000..44f621722
--- /dev/null
+++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/TextTransformations.java
@@ -0,0 +1,99 @@
+/*
+ * This file is licensed under the MIT License, part of Roughly Enough Items.
+ * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.shedaniel.rei.impl.client.util;
+
+import me.shedaniel.math.Color;
+import net.minecraft.Util;
+import net.minecraft.client.Minecraft;
+import net.minecraft.network.chat.Style;
+import net.minecraft.network.chat.TextColor;
+import net.minecraft.util.FormattedCharSequence;
+import org.jetbrains.annotations.ApiStatus;
+
+@ApiStatus.Internal
+public class TextTransformations {
+ public static FormattedCharSequence applyRainbow(FormattedCharSequence sequence, int x, int y) {
+ int[] combinedX = {x};
+ return sink -> sequence.accept((charIndex, style, codePoint) -> {
+ if (charIndex == 0) combinedX[0] = x;
+ int rgb = Color.HSBtoRGB(((Util.getMillis() - combinedX[0] * 10 - y * 10) % 2000) / 2000F, 0.8F, 0.95F);
+ combinedX[0] += Minecraft.getInstance().font.getSplitter().widthProvider.getWidth(codePoint, style);
+ return sink.accept(charIndex, style.withColor(TextColor.fromRgb(rgb)), codePoint);
+ });
+ }
+
+ public static FormattedCharSequence forwardWithTransformation(String text, CharSequenceTransformer transformer) {
+ if (text.isEmpty()) {
+ return FormattedCharSequence.EMPTY;
+ }
+ return sink -> {
+ int length = text.length();
+
+ for (int charIndex = 0; charIndex < length; ++charIndex) {
+ char c = text.charAt(charIndex);
+
+ if (Character.isHighSurrogate(c)) {
+ if (charIndex + 1 >= length) {
+ // Broken?
+ if (!sink.accept(charIndex, Style.EMPTY, 65533)) {
+ return false;
+ }
+ break;
+ }
+
+ char forward = text.charAt(charIndex + 1);
+ if (Character.isLowSurrogate(forward)) {
+ // Combine them together
+ if (!sink.accept(charIndex, Style.EMPTY, Character.toCodePoint(c, forward))) {
+ return false;
+ }
+
+ charIndex++;
+ } else {
+ // Broken?
+ if (!sink.accept(charIndex, Style.EMPTY, 65533)) {
+ return false;
+ }
+ }
+ } else if (Character.isSurrogate(c)) {
+ // This is weird, broken?
+ if (!sink.accept(charIndex, Style.EMPTY, 65533)) {
+ return false;
+ }
+ } else {
+ if (!sink.accept(charIndex, transformer.apply(text, charIndex, c), c)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ };
+ }
+
+ @FunctionalInterface
+ public interface CharSequenceTransformer {
+ Style apply(String text, int charIndex, char c);
+ }
+}