aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
Diffstat (limited to 'api')
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java2
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java2
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java61
-rw-r--r--api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java75
4 files changed, 128 insertions, 12 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
index 81bb56d15..03503919a 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRenderer.java
@@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
/**
* A renderer to render a {@link EntryStack}.
- * Use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setRenderer} to change the {@link EntryRenderer} for a {@link EntryStack}.
+ * Use {@link EntryStack#withRenderer} to change the {@link EntryRenderer} for a {@link EntryStack}.
*
* @param <T> the entry type
* @see BatchedEntryRenderer
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java
index f1dbe8d7b..0f3f18c6f 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/renderer/EntryRendererRegistry.java
@@ -36,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Registry to transform {@link EntryRenderer} for stacks at a global level.
- * For specific stacks, you can use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setRenderer}
+ * For specific stacks, you can use {@link EntryStack#withRenderer}
*/
@ApiStatus.Experimental
public interface EntryRendererRegistry extends Reloadable<REIClientPlugin> {
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java
index 5fa855549..48ce5985a 100644
--- a/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java
+++ b/api/src/main/java/me/shedaniel/rei/api/client/util/ClientEntryStacks.java
@@ -25,10 +25,16 @@ package me.shedaniel.rei.api.client.util;
import dev.architectury.fluid.FluidStack;
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererProvider;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry;
import me.shedaniel.rei.api.client.entry.type.BuiltinClientEntryTypes;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
+import me.shedaniel.rei.api.client.gui.widgets.TooltipContext;
import me.shedaniel.rei.api.common.entry.EntryStack;
+import me.shedaniel.rei.api.common.entry.type.EntryDefinition;
+import me.shedaniel.rei.api.common.entry.type.EntryType;
+import net.minecraft.network.chat.Component;
import java.util.function.BiFunction;
import java.util.function.Function;
@@ -44,22 +50,75 @@ public final class ClientEntryStacks {
return EntryStack.of(BuiltinClientEntryTypes.RENDERING, renderer);
}
+ /**
+ * Sets a renderer for the {@link EntryStack}. This will override the default renderer from the {@link EntryDefinition}.
+ * <p>
+ * You can transform the renderer on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#register(EntryType, EntryRendererProvider)}.
+ *
+ * @return the {@link EntryStack}
+ * @see EntryStack#getRenderer() for how the tooltip is resolved
+ * @see EntryRenderer#empty() for an empty renderer
+ * @deprecated use {@link EntryStack#withRenderer(EntryRenderer)} with {@link EntryRenderer#empty()} instead
+ */
+ @Deprecated(forRemoval = true)
public static <T> EntryStack<T> setNotRenderer(EntryStack<? extends T> stack) {
return setRenderer(stack, EntryRenderer.empty());
}
+ /**
+ * Sets a renderer for the {@link EntryStack}. This will override the default renderer from the {@link EntryDefinition}.
+ * <p>
+ * You can transform the renderer on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#register(EntryType, EntryRendererProvider)}.
+ *
+ * @param renderer the new renderer to use
+ * @return the {@link EntryStack}
+ * @see EntryStack#getRenderer() for how the tooltip is resolved
+ * @see EntryRenderer#empty() for an empty renderer
+ * @deprecated use {@link EntryStack#withRenderer(EntryRenderer)} instead
+ */
+ @Deprecated(forRemoval = true)
public static <T> EntryStack<T> setRenderer(EntryStack<? extends T> stack, EntryRenderer<? extends T> renderer) {
return stack.setting(EntryStack.Settings.RENDERER, s -> renderer).cast();
}
+ /**
+ * Sets a renderer for the {@link EntryStack}. This will override the default renderer from the {@link EntryDefinition}.
+ * <p>
+ * You can transform the renderer on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#register(EntryType, EntryRendererProvider)}.
+ *
+ * @param rendererProvider the new renderer to use
+ * @return the {@link EntryStack}
+ * @see EntryStack#getRenderer() for how the tooltip is resolved
+ * @see EntryRenderer#empty() for an empty renderer
+ * @deprecated use {@link EntryStack#withRenderer(Function)} instead
+ */
+ @Deprecated(forRemoval = true)
@SuppressWarnings("rawtypes")
public static <T> EntryStack<T> setRenderer(EntryStack<? extends T> stack, Function<EntryStack<T>, EntryRenderer<? extends T>> rendererProvider) {
return stack.setting(EntryStack.Settings.RENDERER, (Function) rendererProvider).cast();
}
+ /**
+ * Sets a tooltip processor to the {@link EntryStack}. The processor will be used to modify the tooltip.
+ * <p>
+ * You can transform the tooltip on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
+ * <p>
+ * To append to the tooltip, use {@link EntryStack#tooltip(Component...)} instead.
+ *
+ * @param stack the stack to set the tooltip processor to
+ * @param processor the processor to modify the tooltips
+ * @return the {@link EntryStack}
+ * @see EntryStack#getTooltip(TooltipContext, boolean) for how the tooltip is resolved
+ * @deprecated use {@link EntryStack#tooltipProcessor(BiFunction)} instead
+ */
@SuppressWarnings("rawtypes")
+ @Deprecated(forRemoval = true)
public static <T> EntryStack<T> setTooltipProcessor(EntryStack<? extends T> stack, BiFunction<EntryStack<T>, Tooltip, Tooltip> processor) {
- return stack.setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (BiFunction) processor).cast();
+ return stack.tooltipProcessor((BiFunction) processor);
}
public static EntryStack<FluidStack> setFluidRenderRatio(EntryStack<FluidStack> stack, float ratio) {
diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
index 9acf0c8ee..4b79fce3f 100644
--- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
+++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java
@@ -27,6 +27,7 @@ import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
import me.shedaniel.rei.api.client.config.ConfigObject;
import me.shedaniel.rei.api.client.entry.renderer.EntryRenderer;
+import me.shedaniel.rei.api.client.entry.renderer.EntryRendererProvider;
import me.shedaniel.rei.api.client.entry.renderer.EntryRendererRegistry;
import me.shedaniel.rei.api.client.gui.Renderer;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
@@ -194,7 +195,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
* <p>
* This tooltip can be appended by {@link EntryStack#tooltip(Component...)},
- * and further processed by {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setTooltipProcessor(EntryStack, BiFunction)}.
+ * and further processed by {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param context the tooltip context
* @param appendModName whether to append the mod name
@@ -214,7 +215,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
* <p>
* This tooltip can be appended by {@link EntryStack#tooltip(Component...)},
- * and further processed by {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setTooltipProcessor(EntryStack, BiFunction)}.
+ * and further processed by {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param context the tooltip context
* @return the tooltip, can be {@code null}
@@ -257,7 +258,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* then is processed by {@link EntryRendererRegistry}.
* <p>
* To modify the renderer at a per stack level,
- * use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setRenderer(EntryStack, EntryRenderer)}.
+ * use {@link EntryStack#withRenderer(EntryRenderer)} instead.
*
* @return the {@link EntryRenderer} of this {@link EntryStack}
*/
@@ -405,7 +406,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* <p>
* It is generally not recommended to use this method, but to instead use the helper
* methods such as {@link EntryStack#tooltip(Component...)} and
- * the methods in {@link me.shedaniel.rei.api.client.util.ClientEntryStacks}.
+ * the methods in {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param settings the setting to apply
* @param value the value of the setting to apply
@@ -459,7 +460,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* You can transform the tooltip on a {@link EntryType} level
* using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
* <p>
- * To modify the tooltip, use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setTooltipProcessor(EntryStack, BiFunction)} instead.
+ * To modify the tooltip, use {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param tooltips the tooltips to append
* @return this {@link EntryStack}
@@ -476,7 +477,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* You can transform the tooltip on a {@link EntryType} level
* using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
* <p>
- * To modify the tooltip, use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setTooltipProcessor(EntryStack, BiFunction)} instead.
+ * To modify the tooltip, use {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param tooltips the tooltips to append
* @return this {@link EntryStack}
@@ -493,7 +494,7 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
* You can transform the tooltip on a {@link EntryType} level
* using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
* <p>
- * To modify the tooltip, use {@link me.shedaniel.rei.api.client.util.ClientEntryStacks#setTooltipProcessor(EntryStack, BiFunction)} instead.
+ * To modify the tooltip, use {@link EntryStack#tooltipProcessor(BiFunction)} instead.
*
* @param tooltipProvider the provider for the tooltips to append
* @return this {@link EntryStack}
@@ -505,6 +506,56 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
}
/**
+ * Sets a tooltip processor to this {@link EntryStack}. The processor will be used to modify the tooltip.
+ * <p>
+ * You can transform the tooltip on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#transformTooltip(EntryType, EntryRendererRegistry.TooltipTransformer)}.
+ * <p>
+ * To append to the tooltip, use {@link EntryStack#tooltip(Component...)} instead.
+ *
+ * @param tooltipProcessor the processor to modify the tooltips
+ * @return this {@link EntryStack}
+ * @see EntryStack#getTooltip(TooltipContext, boolean) for how the tooltip is resolved
+ */
+ @SuppressWarnings("rawtypes")
+ @Environment(EnvType.CLIENT)
+ default EntryStack<T> tooltipProcessor(BiFunction<EntryStack<T>, Tooltip, Tooltip> tooltipProcessor) {
+ return setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (BiFunction) tooltipProcessor).cast();
+ }
+
+ /**
+ * Sets a renderer for this {@link EntryStack}. This will override the default renderer from the {@link EntryDefinition}.
+ * <p>
+ * You can transform the renderer on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#register(EntryType, EntryRendererProvider)}.
+ *
+ * @param renderer the new renderer to use
+ * @return this {@link EntryStack}
+ * @see EntryStack#getRenderer() for how the tooltip is resolved
+ * @see EntryRenderer#empty() for an empty renderer
+ */
+ @Environment(EnvType.CLIENT)
+ default EntryStack<T> withRenderer(EntryRenderer<? super T> renderer) {
+ return setting(Settings.RENDERER, $ -> renderer).cast();
+ }
+
+ /**
+ * Sets a renderer for this {@link EntryStack}. This will override the default renderer from the {@link EntryDefinition}.
+ * <p>
+ * You can transform the renderer on a {@link EntryType} level
+ * using {@link EntryRendererRegistry#register(EntryType, EntryRendererProvider)}.
+ *
+ * @param renderer the new renderer to use
+ * @return this {@link EntryStack}
+ * @see EntryStack#getRenderer() for how the tooltip is resolved
+ */
+ @SuppressWarnings("rawtypes")
+ @Environment(EnvType.CLIENT)
+ default EntryStack<T> withRenderer(Function<EntryStack<T>, EntryRenderer<? super T>> renderer) {
+ return setting(Settings.RENDERER, (Function) renderer).cast();
+ }
+
+ /**
* Returns the cheated stack of this {@link EntryStack}.
*
* @return the cheated stack of this {@link EntryStack}
@@ -512,6 +563,12 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
*/
EntryStack<ItemStack> cheatsAs();
+ /**
+ * Settings for {@link EntryStack}s.
+ * Please consider using the utility methods in {@link EntryStack} instead of using this class directly.
+ *
+ * @param <R> the type of the setting
+ */
@Deprecated
class Settings<R> {
@ApiStatus.Internal
@@ -543,8 +600,8 @@ public interface EntryStack<T> extends TextRepresentable, Renderer {
});
}
- private R defaultValue;
- private short id;
+ private final R defaultValue;
+ private final short id;
@ApiStatus.Internal
public Settings(R defaultValue) {