diff options
Diffstat (limited to 'api/src/main/java/me/shedaniel')
10 files changed, 17 insertions, 334 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java index d9f0eae23..706a5c7eb 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/ClientHelper.java @@ -35,7 +35,6 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.gui.chat.NarratorChatListener; import net.minecraft.core.Registry; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; @@ -101,7 +100,7 @@ public interface ClientHelper { String mod = getModFromItem(item); if (mod.isEmpty()) return NarratorChatListener.NO_TITLE; - return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + return Component.literal(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); } /** @@ -114,7 +113,7 @@ public interface ClientHelper { String mod = getModFromIdentifier(identifier); if (mod.isEmpty()) return NarratorChatListener.NO_TITLE; - return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + return Component.literal(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); } /** @@ -127,7 +126,7 @@ public interface ClientHelper { String mod = getModFromModId(modid); if (mod.isEmpty()) return NarratorChatListener.NO_TITLE; - return new TextComponent(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); + return Component.literal(mod).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC); } default List<Component> appendModIdToTooltips(List<Component> components, String modId) { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java index 0533988d2..b1d3c0bd9 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Label.java @@ -28,7 +28,6 @@ import me.shedaniel.math.Point; import me.shedaniel.rei.api.client.REIRuntime; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.FormattedText; -import net.minecraft.network.chat.TextComponent; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -147,53 +146,17 @@ public abstract class Label extends WidgetWithBounds { /** * @return the tooltip from the current tooltip function, null if no tooltip. - * @deprecated use {@link #getTooltipLines} - */ - @Nullable - @Deprecated - @ApiStatus.ScheduledForRemoval - public String getTooltip() { - Component[] lines = getTooltipLines(); - String tooltip = null; - if(lines != null) { - StringBuilder tooltipBuilder = new StringBuilder(); - for (Component line:lines) { - tooltipBuilder.append(line.getContents()).append("\n"); - } - tooltip = tooltipBuilder.toString(); - } - return tooltip; - } - - /** - * @return the tooltip from the current tooltip function, null if no tooltip. */ @Nullable public abstract Component[] getTooltipLines(); - - /** - * Sets the tooltip function used to get the tooltip. - * - * @param tooltip the tooltip function used to get the tooltip. - * @deprecated use {@link #setTooltipFunction(Function)} - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - public void setTooltip(@Nullable Function<Label, @Nullable String> tooltip) { - if(tooltip != null) setTooltipFunction((label) -> { - String text = tooltip.apply(label); - if(text != null) return Stream.of(text.split("\n")).map(TextComponent::new).toArray(Component[]::new); - return null; - }); - } - + /** * Sets the tooltip function used to get the tooltip. * * @param tooltip the tooltip function used to get the tooltip. */ public abstract void setTooltipFunction(@Nullable Function<Label, @Nullable Component[]> tooltip); - + /** * Sets the tooltip. * @@ -202,76 +165,17 @@ public abstract class Label extends WidgetWithBounds { public void setTooltip(Component... tooltip) { setTooltipFunction((label) -> tooltip); } - - /** - * Sets the tooltip. - * - * @param tooltip the tooltip. - */ - public void setTooltip(String... tooltip) { - setTooltipFunction((label) -> Stream.of(tooltip).map(TextComponent::new).toArray(Component[]::new)); - } /** * Sets the tooltip. * * @param tooltip the lines of tooltip. * @return the label itself. - * @deprecated use {@link #tooltip(String...)} - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - public final Label tooltipLines(String... tooltip) { - return tooltip(tooltip); - } - - /** - * Sets the tooltip. - * - * @param tooltip the line of tooltip. - * @return the label itself. - * @deprecated use {@link #tooltip(String...)} - */ - @Deprecated - @ApiStatus.ScheduledForRemoval - public final Label tooltipLine(String tooltip) { - return tooltip(tooltip); - } - - /** - * Sets the tooltip. - * - * @param tooltip the lines of tooltip. - * @return the label itself. - */ - public final Label tooltip(String... tooltip) { - return tooltipFunction(label -> Stream.of(tooltip).map(TextComponent::new).toArray(Component[]::new)); - } - - /** - * Sets the tooltip. - * - * @param tooltip the lines of tooltip. - * @return the label itself. */ public final Label tooltip(Component... tooltip) { return tooltipFunction(label -> tooltip); } - - /** - * Sets the tooltip function. - * - * @param tooltip the tooltip function used to get the tooltip. - * @return the label itself. - * @deprecated use {@link #tooltipFunction} - */ - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "8.0.0") - public final Label tooltipSupplier(@Nullable Function<Label, @Nullable String> tooltip) { - setTooltip(tooltip); - return this; - } - + /** * Sets the tooltip function. * diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index 0a5c1062d..a9caf9577 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -48,14 +48,6 @@ public interface Tooltip { return ClientInternals.createTooltipEntry(text); } - @Deprecated - @ApiStatus.ScheduledForRemoval - static Tooltip.Entry entry(ClientTooltipComponent text) { - return ClientInternals.createTooltipEntry(text); - } - - @Deprecated - @ApiStatus.ScheduledForRemoval static Tooltip.Entry entry(TooltipComponent text) { return ClientInternals.createTooltipEntry(text); } @@ -98,14 +90,6 @@ public interface Tooltip { List<Entry> entries(); - @Deprecated - @ApiStatus.ScheduledForRemoval - List<TooltipComponent> components(); - - @Deprecated - @ApiStatus.ScheduledForRemoval - Tooltip add(ClientTooltipComponent component); - Tooltip add(Component text); Tooltip add(TooltipComponent component); @@ -117,15 +101,6 @@ public interface Tooltip { return this; } - @Deprecated - @ApiStatus.ScheduledForRemoval - default Tooltip addAll(ClientTooltipComponent... components) { - for (ClientTooltipComponent component : components) { - add(component); - } - return this; - } - default Tooltip addAll(Component... text) { for (Component component : text) { add(component); @@ -140,15 +115,6 @@ public interface Tooltip { return this; } - @Deprecated - @ApiStatus.ScheduledForRemoval - default Tooltip addAllComponents(Iterable<ClientTooltipComponent> text) { - for (ClientTooltipComponent component : text) { - add(component); - } - return this; - } - default Tooltip addAllTexts(Iterable<Component> text) { for (Component component : text) { add(component); @@ -175,9 +141,5 @@ public interface Tooltip { Component getAsText(); TooltipComponent getAsTooltipComponent(); - - @Deprecated - @ApiStatus.ScheduledForRemoval - ClientTooltipComponent getAsComponent(); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java index ad79d1d92..bfb63808d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandler.java @@ -65,14 +65,6 @@ public interface TransferHandler extends Comparable<TransferHandler> { return Double.compare(getPriority(), o.getPriority()); } - @Deprecated - @Environment(EnvType.CLIENT) - @Nullable - @ApiStatus.ScheduledForRemoval - default TransferHandlerErrorRenderer provideErrorRenderer(Context context, Object data) { - return null; - } - @ApiStatus.NonExtendable interface Result { /** @@ -132,12 +124,6 @@ public interface TransferHandler extends Comparable<TransferHandler> { */ Result color(int color); - /** - * Sets the error data, to be passed to {@link TransferHandler#provideErrorRenderer(Context, Object)}. - */ - @Deprecated - Result errorRenderer(Object data); - Result renderer(TransferHandlerRenderer renderer); @ApiStatus.Experimental @@ -191,12 +177,6 @@ public interface TransferHandler extends Comparable<TransferHandler> { @ApiStatus.NonExtendable interface Context { - @Deprecated - @ApiStatus.ScheduledForRemoval - static Context create(boolean actuallyCrafting, @Nullable AbstractContainerScreen<?> containerScreen, Display display) { - return create(actuallyCrafting, Screen.hasShiftDown(), containerScreen, display); - } - static Context create(boolean actuallyCrafting, boolean stackedCrafting, @Nullable AbstractContainerScreen<?> containerScreen, Display display) { return new ContextImpl(actuallyCrafting, stackedCrafting, containerScreen, () -> display); } @@ -229,7 +209,7 @@ public interface TransferHandler extends Comparable<TransferHandler> { final class ResultImpl implements Result { private boolean successful, applicable, returningToScreen, blocking; private Component error; - private Object errorRenderer; + private TransferHandlerRenderer renderer; private BiConsumer<Point, TooltipSink> tooltipRenderer; private int color; @@ -272,14 +252,8 @@ public interface TransferHandler extends Comparable<TransferHandler> { } @Override - public Result errorRenderer(Object data) { - this.errorRenderer = data; - return this; - } - - @Override public Result renderer(TransferHandlerRenderer renderer) { - this.errorRenderer = renderer; + this.renderer = renderer; return this; } @@ -316,11 +290,7 @@ public interface TransferHandler extends Comparable<TransferHandler> { @Override public TransferHandlerRenderer getRenderer(TransferHandler handler, Context context) { - if (errorRenderer == null) return null; - if (errorRenderer instanceof TransferHandlerRenderer) return (TransferHandlerRenderer) errorRenderer; - if (isSuccessful()) return null; - TransferHandlerErrorRenderer renderer = handler.provideErrorRenderer(context, this.errorRenderer); - return renderer == null ? null : renderer.asNew(); + return renderer; } @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java deleted file mode 100644 index 6c890f8fc..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/transfer/TransferHandlerErrorRenderer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.api.client.registry.transfer; - -import com.mojang.blaze3d.vertex.PoseStack; -import me.shedaniel.math.Rectangle; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.common.display.Display; -import org.jetbrains.annotations.ApiStatus; - -import java.util.List; - -@ApiStatus.Experimental -@FunctionalInterface -@Deprecated -@ApiStatus.ScheduledForRemoval -public interface TransferHandlerErrorRenderer { - void render(PoseStack matrices, int mouseX, int mouseY, float delta, List<Widget> widgets, Rectangle bounds, Display display); - - default TransferHandlerRenderer asNew() { - return this::render; - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java index a3cf46f2b..d2219af7e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuTransferException.java @@ -24,7 +24,6 @@ package me.shedaniel.rei.api.common.transfer.info; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; public class MenuTransferException extends Exception { private final Component component; @@ -40,7 +39,7 @@ public class MenuTransferException extends Exception { } public MenuTransferException(String message) { - this(new TranslatableComponent(message)); + this(Component.translatable(message)); } public static MenuTransferException createNotApplicable() { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleGridMenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleGridMenuInfo.java index bd6a7e671..84ea33e09 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleGridMenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleGridMenuInfo.java @@ -28,7 +28,7 @@ import me.shedaniel.rei.api.common.transfer.info.MenuInfo; import me.shedaniel.rei.api.common.transfer.info.MenuInfoContext; import me.shedaniel.rei.api.common.transfer.info.MenuTransferException; import me.shedaniel.rei.api.common.transfer.info.stack.SlotAccessor; -import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.AbstractContainerMenu; import java.util.stream.Collectors; @@ -68,7 +68,7 @@ public interface SimpleGridMenuInfo<T extends AbstractContainerMenu, D extends S int height = getCraftingHeight(context.getMenu()); SimpleGridMenuDisplay display = context.getDisplay(); if (display != null && (display.getWidth() > width || display.getHeight() > height)) { - throw new MenuTransferException(new TranslatableComponent("error.rei.transfer.too_small", width, height)); + throw new MenuTransferException(Component.translatable("error.rei.transfer.too_small", width, height)); } } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java index a478ee693..f00f400c3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/CollectionUtils.java @@ -30,7 +30,7 @@ import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.rei.api.common.entry.EntryStack; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.MutableComponent; import net.minecraft.util.Mth; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Ingredient; @@ -249,7 +249,7 @@ public class CollectionUtils { } public static <T> Component mapAndJoinToComponent(Iterable<T> list, Function<T, Component> function, Component separator) { - TextComponent joiner = new TextComponent(""); + MutableComponent joiner = Component.literal(""); boolean first = true; for (T t : list) { if (first) { @@ -263,7 +263,7 @@ public class CollectionUtils { } public static <T> Component mapAndJoinToComponent(T[] list, Function<T, Component> function, Component separator) { - TextComponent joiner = new TextComponent(""); + MutableComponent joiner = Component.literal(""); boolean first = true; for (T t : list) { if (first) { diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/ImmutableTextComponent.java b/api/src/main/java/me/shedaniel/rei/api/common/util/ImmutableTextComponent.java deleted file mode 100644 index 8a621d332..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/ImmutableTextComponent.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.api.common.util; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.locale.Language; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; -import net.minecraft.network.chat.TextComponent; -import net.minecraft.util.FormattedCharSequence; - -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -/** - * A simple lightweight implementation of {@link Component} that holds a style-less text. - */ -public final class ImmutableTextComponent implements MutableComponent { - public static final ImmutableTextComponent EMPTY = new ImmutableTextComponent(""); - private final String content; - @Environment(EnvType.CLIENT) - private FormattedCharSequence visualOrderText; - - public ImmutableTextComponent(String content) { - this.content = content; - } - - @Override - public Style getStyle() { - return Style.EMPTY; - } - - @Override - public String getContents() { - return content; - } - - @Override - public List<Component> getSiblings() { - return Collections.emptyList(); - } - - @Override - public MutableComponent plainCopy() { - return this; - } - - @Override - public MutableComponent copy() { - return plainCopy(); - } - - @Override - @Environment(EnvType.CLIENT) - public <T> Optional<T> visit(ContentConsumer<T> visitor) { - return visitSelf(visitor); - } - - @Override - @Environment(EnvType.CLIENT) - public <T> Optional<T> visit(StyledContentConsumer<T> styledVisitor, Style style) { - return visitSelf(styledVisitor, style); - } - - @Override - @Environment(EnvType.CLIENT) - public FormattedCharSequence getVisualOrderText() { - if (visualOrderText == null) { - visualOrderText = Language.getInstance().getVisualOrder(this); - } - return visualOrderText; - } - - @Override - public MutableComponent setStyle(Style style) { - return new TextComponent(content).withStyle(style); - } - - @Override - public MutableComponent append(Component component) { - return new TextComponent(content).append(component); - } -} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java b/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java index 2638805e6..23f96182e 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/TextRepresentable.java @@ -30,10 +30,10 @@ import net.minecraft.network.chat.Component; */ public interface TextRepresentable { default Component asFormattedText() { - return ImmutableTextComponent.EMPTY; + return Component.empty(); } default Component asFormatStrippedText() { - return new ImmutableTextComponent(FormattingUtils.stripFormatting(asFormattedText().getString())); + return Component.literal(FormattingUtils.stripFormatting(asFormattedText().getString())); } } |
