001package net.tnemc.item.providers;
002/*
003 * The New Item Library
004 * Copyright (C) 2022 - 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020
021import net.tnemc.item.AbstractItemStack;
022import net.tnemc.item.platform.Identifiable;
023
024/**
025 * An ItemProvider represents a provider used to give the Locale stack, and provide various item stack
026 * comparisons. This could be used for something such as ItemsAdder, etc.
027 *
028 * @param <T> The implementation-specific type of this item stack.
029 * @author creatorfromhell
030 * @since 0.2.0.0
031 */
032public interface ItemProvider<T> extends Identifiable {
033
034  /**
035   * Checks if the given serialized item stack applies to the specified item.
036   *
037   * @param serialized The serialized item stack to check against the item.
038   * @param item The item to check against.
039   * @return True if the serialized item stack applies to the item, false otherwise.
040   * @since 0.2.0.0
041   */
042  boolean appliesTo(final AbstractItemStack<? extends T> serialized, final T item);
043
044  /**
045   * Checks if the provided item stack is similar to the original item stack.
046   *
047   * @param original The original item stack to compare against.
048   * @param compare The item stack to compare.
049   * @return True if the two item stacks are similar, otherwise false.
050   * @since 0.2.0.0
051   */
052  boolean similar(final AbstractItemStack<? extends T> original, final T compare);
053
054  /**
055   * Returns true if the provided item is similar to this. An item is similar if the basic
056   * information is the same, except for the amount. What this includes: - material - display -
057   * modelData - flags - lore - attributes - enchantments
058   * What this does not include: - Item Data/components.
059   *
060   * @param compare The stack to compare.
061   *
062   * @return True if the two are similar, otherwise false.
063   * @since 0.2.0.0
064   * @author creatorfromhell
065   * @since 0.2.0.0
066   */
067  default boolean similar(final AbstractItemStack<? extends T> original, final AbstractItemStack<? extends T> compare) {
068
069    return original.itemProvider().equalsIgnoreCase(compare.itemProvider())
070           && original.providerItemID().equalsIgnoreCase(compare.providerItemID());
071  }
072
073  /**
074   * Checks if the components of two items are equal.
075   *
076   * @param original The original item to compare.
077   * @param compare The item to compare against the original.
078   * @return true if the components of the two items are equal, otherwise false.
079   * @since 0.2.0.0
080   */
081  default boolean componentsEqual(final AbstractItemStack<? extends T> original, final AbstractItemStack<? extends T> compare) {
082
083    //We don't need to check this since the item providers are direct copies.
084    return true;
085  }
086
087  /**
088   * Checks if the components of two items are equal.
089   *
090   * @param original The original item to compare.
091   * @param compare The item to compare against the original.
092   * @return true if the components of the two items are equal, otherwise false.
093   * @since 0.2.0.0
094   */
095  default boolean componentsEqual(final AbstractItemStack<? extends T> original, final T compare) {
096
097    //We don't need to check this since the item providers are direct copies.
098    return true;
099  }
100
101  /**
102   * Checks if the components of two items are equal.
103   *
104   * @param original The original item to compare.
105   * @param compare The item to compare against the original.
106   * @return true if the components of the two items are equal, otherwise false.
107   * @since 0.2.0.0
108   */
109  default boolean componentsEqual(final T original, final T compare) {
110
111    //We don't need to check this since the item providers are direct copies.
112    return true;
113  }
114
115  /**
116   * Creates a copy of the original item stack with a specified amount.
117   *
118   * @param original The original item stack to copy.
119   * @param amount The amount for the new item stack.
120   * @return A new item stack with the specified amount.
121   * @since 0.2.0.0
122   */
123  T locale(final AbstractItemStack<? extends T> original, final int amount);
124
125  /**
126   * @return An instance of the implementation's locale version of AbstractItemStack.
127   * @since 0.2.0.0
128   * @author creatorfromhell
129   * @since 0.2.0.0
130   * @since 0.2.0.0
131   */
132  default T locale(final AbstractItemStack<? extends T> original) {
133
134    return locale(original, original.amount());
135  }
136}