diff options
| author | shedaniel <daniel@shedaniel.me> | 2019-11-26 20:59:59 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2019-11-26 20:59:59 +0800 |
| commit | 516f882d348cd9535a963f3674597ca680c49909 (patch) | |
| tree | 95048c24b82274d0e7cfcce8143f5a39705937f7 /src/main/java/me/shedaniel/rei/impl | |
| parent | 295dae46f8f3b717c914adacc023e7692b82bfc1 (diff) | |
| download | RoughlyEnoughItems-516f882d348cd9535a963f3674597ca680c49909.tar.gz RoughlyEnoughItems-516f882d348cd9535a963f3674597ca680c49909.tar.bz2 RoughlyEnoughItems-516f882d348cd9535a963f3674597ca680c49909.zip | |
3.2.12
Fixed #29
Diffstat (limited to 'src/main/java/me/shedaniel/rei/impl')
5 files changed, 106 insertions, 4 deletions
diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java index c270166fc..128b414f3 100644 --- a/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ConfigManagerImpl.java @@ -7,7 +7,9 @@ package me.shedaniel.rei.impl; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; import me.sargunvohra.mcmods.autoconfig1u.gui.ConfigScreenProvider; +import me.sargunvohra.mcmods.autoconfig1u.gui.registry.GuiRegistry; import me.sargunvohra.mcmods.autoconfig1u.serializer.JanksonConfigSerializer; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.ConfigObject; @@ -17,8 +19,12 @@ import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resource.language.I18n; import net.minecraft.text.LiteralText; +import java.util.Collections; import java.util.List; +import static me.sargunvohra.mcmods.autoconfig1u.util.Utils.getUnsafely; +import static me.sargunvohra.mcmods.autoconfig1u.util.Utils.setUnsafely; + @Deprecated @Internal public class ConfigManagerImpl implements ConfigManager { @@ -28,6 +34,14 @@ public class ConfigManagerImpl implements ConfigManager { public ConfigManagerImpl() { this.craftableOnly = false; AutoConfig.register(ConfigObjectImpl.class, JanksonConfigSerializer::new); + GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ConfigObjectImpl.class); + //noinspection rawtypes + guiRegistry.registerAnnotationProvider((i13n, field, config, defaults, guiProvider) -> Collections.singletonList( + ConfigEntryBuilder.create().startEnumSelector(i13n, (Class) field.getType(), getUnsafely(field, config, null)) + .setDefaultValue(() -> getUnsafely(field, defaults)) + .setSaveConsumer(newValue -> setUnsafely(field, config, newValue)) + .build() + ), field -> field.getType().isEnum(), ConfigObject.UseEnumSelectorInstead.class); RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded."); } diff --git a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java index a4d89f58d..bcb60b331 100644 --- a/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java @@ -203,14 +203,17 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { public static class Appearance { @Comment("The ordering of the items on the item panel.") + @UseEnumSelectorInstead private ItemListOrderingConfig itemListOrdering = ItemListOrderingConfig.REGISTRY_ASCENDING; @Comment("Declares the appearance of REI windows.") private boolean darkTheme = false; @Comment("Whether REI should render entry's overlay.\nExample: Enchantment Glint") private boolean renderEntryExtraOverlay = true; @Comment("The ordering of the items on the item panel.") + @UseEnumSelectorInstead private RecipeScreenType recipeScreenType = RecipeScreenType.UNSET; @Comment("Declares the position of the search field.") + @UseEnumSelectorInstead private SearchFieldLocation searchFieldLocation = SearchFieldLocation.CENTER; @Comment("Declares the position of the item list panel.") private boolean mirrorItemPanel = false; @@ -220,6 +223,7 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares whether REI should lighten the button if hovered.") private boolean lighterButtonHover = true; private boolean clickableRecipeArrows = true; + @UseEnumSelectorInstead private ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; @Comment("Declares the appearance of recipe's border.") private boolean lightGrayRecipeBorder = false; diff --git a/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java b/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java index a6f65e1b3..a6f0558b7 100644 --- a/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java +++ b/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java @@ -10,7 +10,6 @@ import me.shedaniel.math.api.Rectangle; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.gui.widget.EntryListWidget; import me.shedaniel.rei.gui.widget.QueuedTooltip; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; @@ -152,7 +151,7 @@ public class FluidEntryStack extends AbstractEntryStack { public QueuedTooltip getTooltip(int mouseX, int mouseY) { if (!getSetting(Settings.TOOLTIP_ENABLED).value().get() || isEmpty()) return null; - List<String> toolTip = Lists.newArrayList(EntryListWidget.tryGetEntryStackName(this)); + List<String> toolTip = Lists.newArrayList(SearchArgument.tryGetEntryStackName(this)); if (amount >= 0) { String amountTooltip = getSetting(Settings.Fluid.AMOUNT_TOOLTIP).value().apply(this); if (amountTooltip != null) for (String s : amountTooltip.split("\n")) toolTip.add(s); diff --git a/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java b/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java index 3814fa69a..af0103d58 100644 --- a/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java +++ b/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java @@ -12,7 +12,6 @@ import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.ItemStackRenderOverlayHook; -import me.shedaniel.rei.gui.widget.EntryListWidget; import me.shedaniel.rei.gui.widget.QueuedTooltip; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.item.ItemRenderer; @@ -122,7 +121,7 @@ public class ItemEntryStack extends AbstractEntryStack { public QueuedTooltip getTooltip(int mouseX, int mouseY) { if (!getSetting(Settings.TOOLTIP_ENABLED).value().get() || isEmpty()) return null; - List<String> toolTip = Lists.newArrayList(EntryListWidget.tryGetItemStackToolTip(getItemStack(), true)); + List<String> toolTip = Lists.newArrayList(SearchArgument.tryGetItemStackToolTip(getItemStack(), true)); toolTip.addAll(getSetting(Settings.TOOLTIP_APPEND_EXTRA).value().apply(this)); if (getSetting(Settings.TOOLTIP_APPEND_MOD).value().get() && ConfigManager.getInstance().getConfig().shouldAppendModNames()) { final String modString = ClientHelper.getInstance().getFormattedModFromItem(getItem()); diff --git a/src/main/java/me/shedaniel/rei/impl/SearchArgument.java b/src/main/java/me/shedaniel/rei/impl/SearchArgument.java index 7771ad8e4..74d4bf8fc 100644 --- a/src/main/java/me/shedaniel/rei/impl/SearchArgument.java +++ b/src/main/java/me/shedaniel/rei/impl/SearchArgument.java @@ -5,8 +5,24 @@ package me.shedaniel.rei.impl; +import com.google.common.collect.Lists; +import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.annotations.Internal; +import me.shedaniel.rei.gui.widget.QueuedTooltip; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.fluid.Fluid; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; +import org.apache.commons.lang3.StringUtils; +import java.util.Collections; +import java.util.List; import java.util.Locale; import java.util.function.Function; @@ -15,6 +31,8 @@ import java.util.function.Function; public class SearchArgument { public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true); + @Deprecated + private static List<Item> searchBlacklisted = Lists.newArrayList(); private ArgumentType argumentType; private String text; public final Function<String, Boolean> INCLUDE = s -> s.contains(text); @@ -31,6 +49,59 @@ public class SearchArgument { this.include = include; } + @Deprecated + public static String tryGetEntryStackName(EntryStack stack) { + if (stack.getType() == EntryStack.Type.ITEM) + return tryGetItemStackName(stack.getItemStack()); + else if (stack.getType() == EntryStack.Type.FLUID) + return tryGetFluidName(stack.getFluid()); + return ""; + } + + @Deprecated + public static String tryGetEntryStackTooltip(EntryStack stack) { + QueuedTooltip tooltip = stack.getTooltip(0, 0); + if (tooltip != null) return CollectionUtils.joinToString(tooltip.getText(), "\n"); + return ""; + } + + @Deprecated + public static String tryGetFluidName(Fluid fluid) { + Identifier id = Registry.FLUID.getId(fluid); + if (I18n.hasTranslation("block." + id.toString().replaceFirst(":", "."))) + return I18n.translate("block." + id.toString().replaceFirst(":", ".")); + return CollectionUtils.mapAndJoinToString(id.getPath().split("_"), StringUtils::capitalize, " "); + } + + @Deprecated + public static List<String> tryGetItemStackToolTip(ItemStack itemStack, boolean careAboutAdvanced) { + if (!searchBlacklisted.contains(itemStack.getItem())) + try { + return CollectionUtils.map(itemStack.getTooltip(MinecraftClient.getInstance().player, MinecraftClient.getInstance().options.advancedItemTooltips && careAboutAdvanced ? TooltipContext.Default.ADVANCED : TooltipContext.Default.NORMAL), Text::asFormattedString); + } catch (Throwable e) { + e.printStackTrace(); + searchBlacklisted.add(itemStack.getItem()); + } + return Collections.singletonList(tryGetItemStackName(itemStack)); + } + + @Deprecated + public static String tryGetItemStackName(ItemStack stack) { + if (!searchBlacklisted.contains(stack.getItem())) + try { + return stack.getName().asFormattedString(); + } catch (Throwable e) { + e.printStackTrace(); + searchBlacklisted.add(stack.getItem()); + } + try { + return I18n.translate("item." + Registry.ITEM.getId(stack.getItem()).toString().replace(":", ".")); + } catch (Throwable e) { + e.printStackTrace(); + } + return "ERROR"; + } + public Function<String, Boolean> getFunction(boolean include) { return include ? INCLUDE : NOT_INCLUDE; } @@ -59,4 +130,19 @@ public class SearchArgument { ALWAYS } + @Deprecated + @Internal + public static class SearchArguments { + public static final SearchArguments ALWAYS = new SearchArguments(new SearchArgument[]{SearchArgument.ALWAYS}); + private SearchArgument[] arguments; + + public SearchArguments(SearchArgument[] arguments) { + this.arguments = arguments; + } + + public SearchArgument[] getArguments() { + return arguments; + } + } + } |
