aboutsummaryrefslogtreecommitdiff
path: root/RoughlyEnoughItems-api/src/main/java
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-09-07 23:02:24 +0800
committershedaniel <daniel@shedaniel.me>2020-09-07 23:02:24 +0800
commitafe32352abcef8d501acf7985d2e9b1f3fcb673e (patch)
tree53c671ccbc3b58fb9dc7ef1f968a1c3e958820a3 /RoughlyEnoughItems-api/src/main/java
parent973978aa763f8fa4d5e5b6991a5032cbb246594d (diff)
downloadRoughlyEnoughItems-afe32352abcef8d501acf7985d2e9b1f3fcb673e.tar.gz
RoughlyEnoughItems-afe32352abcef8d501acf7985d2e9b1f3fcb673e.tar.bz2
RoughlyEnoughItems-afe32352abcef8d501acf7985d2e9b1f3fcb673e.zip
Made FluidSupportProvider capable in returning more than 1 fluid and fix hwyla double modid tooltip
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-api/src/main/java')
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java7
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java46
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java2
3 files changed, 48 insertions, 7 deletions
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
index 0b1431a35..e1ff44c24 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
@@ -51,6 +51,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
+import java.util.stream.Stream;
@Environment(EnvType.CLIENT)
public interface EntryStack extends TextRepresentable {
@@ -207,10 +208,16 @@ public interface EntryStack extends TextRepresentable {
return copyItemToFluid(stack);
}
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
static EntryStack copyItemToFluid(EntryStack stack) {
return FluidSupportProvider.getInstance().itemToFluid(stack);
}
+ static Stream<EntryStack> copyItemToFluids(EntryStack stack) {
+ return FluidSupportProvider.getInstance().itemToFluids(stack);
+ }
+
Optional<ResourceLocation> getIdentifier();
EntryStack.Type getType();
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java
index 414b80171..76d964965 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/fluid/FluidSupportProvider.java
@@ -27,8 +27,13 @@ import me.shedaniel.rei.api.EntryStack;
import me.shedaniel.rei.impl.Internals;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.world.InteractionResultHolder;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Objects;
+import java.util.stream.Stream;
/**
* Experimental library, scheduled to change if needed.
@@ -40,13 +45,13 @@ public interface FluidSupportProvider {
@ApiStatus.ScheduledForRemoval
FluidSupportProvider INSTANCE = new FluidSupportProvider() {
@Override
- public void registerFluidProvider(@NotNull FluidProvider provider) {
- getInstance().registerFluidProvider(provider);
+ public void registerProvider(@NotNull Provider provider) {
+ getInstance().registerProvider(provider);
}
@Override
- public @NotNull EntryStack itemToFluid(@NotNull EntryStack itemStack) {
- return getInstance().itemToFluid(itemStack);
+ public @NotNull Stream<EntryStack> itemToFluids(@NotNull EntryStack itemStack) {
+ return getInstance().itemToFluids(itemStack);
}
};
@@ -54,7 +59,21 @@ public interface FluidSupportProvider {
return Internals.getFluidSupportProvider();
}
- void registerFluidProvider(@NotNull FluidProvider provider);
+ /**
+ * @deprecated Please switch to {@link FluidSupportProvider#registerProvider(Provider)}
+ */
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
+ default void registerFluidProvider(@NotNull FluidProvider provider) {
+ registerProvider(itemStack -> {
+ EntryStack stack = Objects.requireNonNull(provider.itemToFluid(itemStack));
+ if (!stack.isEmpty())
+ return InteractionResultHolder.success(Stream.of(stack));
+ return InteractionResultHolder.pass(null);
+ });
+ }
+
+ void registerProvider(@NotNull Provider provider);
@Deprecated
@ApiStatus.ScheduledForRemoval
@@ -64,8 +83,15 @@ public interface FluidSupportProvider {
}
@NotNull
- EntryStack itemToFluid(@NotNull EntryStack itemStack);
+ default EntryStack itemToFluid(@NotNull EntryStack itemStack) {
+ return itemToFluids(itemStack).findFirst().orElse(EntryStack.empty());
+ }
+
+ @NotNull
+ Stream<EntryStack> itemToFluids(@NotNull EntryStack itemStack);
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
interface FluidProvider {
@Deprecated
@ApiStatus.ScheduledForRemoval
@@ -74,9 +100,17 @@ public interface FluidSupportProvider {
return EntryStack.empty();
}
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
@NotNull
default EntryStack itemToFluid(@NotNull EntryStack itemStack) {
return EntryStack.empty();
}
}
+
+ @FunctionalInterface
+ interface Provider {
+ @NotNull
+ InteractionResultHolder<@Nullable Stream<@NotNull EntryStack>> itemToFluid(@NotNull EntryStack itemStack);
+ }
}
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java
index 411518b37..5d1b3f5c8 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/utils/FormattingUtils.java
@@ -30,7 +30,7 @@ public final class FormattingUtils {
for (char c : string.toCharArray()) {
if (lastSpecial) {
lastSpecial = false;
- if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 'r' || (c >= 'A' && c <= 'F') || c == 'R')) {
+ if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'k' && c <= 'o') || c == 'r' || (c >= 'A' && c <= 'F') || (c >= 'K' && c <= 'O') || c == 'R')) {
builder.append('ยง');
builder.append(c);
}