|
| 1 | +package sunsetsatellite.catalyst.core.util; |
| 2 | + |
| 3 | +import com.mojang.nbt.CompoundTag; |
| 4 | +import net.minecraft.core.item.Item; |
| 5 | +import net.minecraft.core.item.ItemStack; |
| 6 | +import net.minecraft.core.world.World; |
| 7 | +import org.jetbrains.annotations.UnmodifiableView; |
| 8 | + |
| 9 | +import java.util.ArrayList; |
| 10 | +import java.util.List; |
| 11 | + |
| 12 | +public interface IItemStackList { |
| 13 | + |
| 14 | + /** |
| 15 | + * @param stack The stack to add |
| 16 | + * @return The remaining amount that couldn't be stored or <code>null</code> if there was no overflow or <code>stack</code> itself was <code>null</code>. |
| 17 | + */ |
| 18 | + ItemStack add(ItemStack stack); |
| 19 | + |
| 20 | + /** |
| 21 | + * @param index Index to insert the item at |
| 22 | + * @param stack The stack to add. |
| 23 | + * @return The remaining amount that couldn't be stored or <code>null</code> if there was no overflow or <code>stack</code> itself was <code>null</code>. |
| 24 | + */ |
| 25 | + ItemStack add(int index, ItemStack stack); |
| 26 | + |
| 27 | + /** |
| 28 | + * @param stacks The stacks to be added |
| 29 | + * @return List of stacks that couldn't be added. |
| 30 | + */ |
| 31 | + @UnmodifiableView List<ItemStack> addAll(ItemStackList stacks); |
| 32 | + |
| 33 | + /** |
| 34 | + * @param stacks The stacks to be added |
| 35 | + * @return List of stacks that couldn't be added. |
| 36 | + */ |
| 37 | + @UnmodifiableView List<ItemStack> addAll(List<ItemStack> stacks); |
| 38 | + |
| 39 | + /** |
| 40 | + * @return Maximum items that can be stored in this list. |
| 41 | + */ |
| 42 | + long getItemCapacity(); |
| 43 | + |
| 44 | + /** |
| 45 | + * @return Maximum amount of stacks that can be stored in this list. |
| 46 | + * <br> Usually <code>{@link IItemStackList#getAmount()} / 64</code>. |
| 47 | + */ |
| 48 | + long getStackCapacity(); |
| 49 | + |
| 50 | + /** |
| 51 | + * @return Amount of stacks currently in the list. |
| 52 | + * <br> Usually <code>{@link IItemStackList#getAmount()} / 64</code>. |
| 53 | + */ |
| 54 | + long getStackAmount(); |
| 55 | + |
| 56 | + /** |
| 57 | + * @return Amounts of items currently in the list. |
| 58 | + */ |
| 59 | + long getAmount(); |
| 60 | + |
| 61 | + /** |
| 62 | + * @param slot Slot ID to remove from |
| 63 | + * @param amount Amount to remove |
| 64 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly <code>amount</code> |
| 65 | + * @param unlimited If <code>false</code>, amount will be limited to {@link Item#getItemStackLimit()} |
| 66 | + * @return The removed item stack. |
| 67 | + */ |
| 68 | + ItemStack remove(int slot, long amount, boolean strict, boolean unlimited); |
| 69 | + |
| 70 | + /** |
| 71 | + * @param slot Slot ID to remove from |
| 72 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} |
| 73 | + * @param unlimited If <code>false</code>, amount will be limited to {@link Item#getItemStackLimit()} |
| 74 | + * @return The removed item stack. |
| 75 | + */ |
| 76 | + ItemStack remove(int slot, boolean strict, boolean unlimited); |
| 77 | + |
| 78 | + /** |
| 79 | + * @param id The item ID to remove |
| 80 | + * @param meta The item metadata to remove |
| 81 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} |
| 82 | + * @param unlimited If <code>false</code>, amount will be limited to {@link Item#getItemStackLimit()} |
| 83 | + * @return The removed item stack. |
| 84 | + */ |
| 85 | + ItemStack remove(int id, int meta, long amount, CompoundTag data, boolean strict, boolean unlimited); |
| 86 | + |
| 87 | + /** |
| 88 | + * @param stacks List of stacks to remove |
| 89 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} for each stack |
| 90 | + * @param unlimited If <code>false</code>, amount will be limited to {@link Item#getItemStackLimit()} for each stack |
| 91 | + * @return <code>true</code> if operation was successful, false otherwise. |
| 92 | + */ |
| 93 | + boolean removeAll(List<ItemStack> stacks, boolean strict, boolean unlimited); |
| 94 | + |
| 95 | + /** |
| 96 | + * @param what List of stacks to move |
| 97 | + * @param where List to move stacks to |
| 98 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} for each stack |
| 99 | + * @return The list of stacks that couldn't be moved. |
| 100 | + */ |
| 101 | + @UnmodifiableView List<ItemStack> move(List<ItemStack> what, ItemStackList where, boolean strict); |
| 102 | + |
| 103 | + /** |
| 104 | + * @param what List of stacks to move |
| 105 | + * @param where List to move stacks to |
| 106 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} for each stack |
| 107 | + * @return The list of stacks that couldn't be moved. |
| 108 | + */ |
| 109 | + @UnmodifiableView List<ItemStack> move(ItemStackList what, ItemStackList where, boolean strict); |
| 110 | + |
| 111 | + /** |
| 112 | + * @param stacks List of stacks to move |
| 113 | + * @param strict If <code>true</code>, method fails if amount in list is not strictly {@link Item#getItemStackLimit()} for each stack |
| 114 | + * @param unlimited If <code>false</code>, amount will be limited to {@link Item#getItemStackLimit()} for each stack |
| 115 | + * @return List of the moved items. |
| 116 | + */ |
| 117 | + List<ItemStack> exportAll(List<ItemStack> stacks, boolean strict, boolean unlimited); |
| 118 | + |
| 119 | + /** |
| 120 | + * Drops item stack at the specified slot id into the world. |
| 121 | + */ |
| 122 | + boolean eject(World world, int x, int y, int z, int slot, long amount, boolean strict); |
| 123 | + |
| 124 | + /** |
| 125 | + * Drops item stack at the specified item id and metadata into the world. |
| 126 | + */ |
| 127 | + boolean eject(World world, int x, int y, int z, int id, int meta, CompoundTag data, long amount, boolean strict); |
| 128 | + |
| 129 | + /** |
| 130 | + * Drops contents of this list into the world. |
| 131 | + */ |
| 132 | + void ejectAll(World world, int x, int y, int z); |
| 133 | + |
| 134 | + /** |
| 135 | + * @param id The item ID to search for |
| 136 | + * @param meta The item metadata to search for |
| 137 | + * @return <code>true</code> if list contains any of specified item, false otherwise. |
| 138 | + */ |
| 139 | + boolean contains(int id, int meta, CompoundTag data); |
| 140 | + |
| 141 | + /** |
| 142 | + * @param id The item ID to search for |
| 143 | + * @param meta The item metadata to search for |
| 144 | + * @param amount The amount to check |
| 145 | + * @return <code>true</code> if list contains at least <code>amount</code> of specified item, false otherwise. |
| 146 | + */ |
| 147 | + boolean containsAtLeast(int id, int meta, CompoundTag data, long amount); |
| 148 | + |
| 149 | + /** |
| 150 | + * @param stacks List of stacks to check |
| 151 | + * @return <code>true</code> if list contains all the items of <code>stacks</code>, false otherwise. |
| 152 | + */ |
| 153 | + boolean containsAtLeast(List<ItemStack> stacks); |
| 154 | + |
| 155 | + /** |
| 156 | + * @param stacks List of stacks to check |
| 157 | + * @return <code>true</code> if list contains all the items of <code>stacks</code>, false otherwise. |
| 158 | + */ |
| 159 | + boolean containsAtLeast(ItemStackList stacks); |
| 160 | + |
| 161 | + /** |
| 162 | + * @param stacks List of stacks to check against |
| 163 | + * @return List of stacks that this list either doesn't contain at all or doesn't contain a sufficient quantity of. |
| 164 | + */ |
| 165 | + ArrayList<ItemStack> returnMissing(ArrayList<ItemStack> stacks); |
| 166 | + |
| 167 | + /** |
| 168 | + * @param id The item ID to search for |
| 169 | + * @param meta The item metadata to search for |
| 170 | + * @return Amounts of the specified item in the list. |
| 171 | + */ |
| 172 | + long count(int id, int meta, CompoundTag data); |
| 173 | + |
| 174 | + /** |
| 175 | + * @param id The item ID to search for |
| 176 | + * @return Amounts of the specified item in the list. |
| 177 | + */ |
| 178 | + long count(int id); |
| 179 | + |
| 180 | + /** |
| 181 | + * @param id The item ID to search for |
| 182 | + * @param meta The item metadata to search for |
| 183 | + * @return Position in the list or <code>-1</code> if item couldn't be found. |
| 184 | + */ |
| 185 | + int find(int id, int meta, CompoundTag data); |
| 186 | + |
| 187 | + /** |
| 188 | + * @param index The slot ID to get the stack from |
| 189 | + * @return The found stack or <code>null</code>. |
| 190 | + */ |
| 191 | + ItemStack get(int index); |
| 192 | + |
| 193 | + /** |
| 194 | + * @param id The item ID to search for |
| 195 | + * @param meta The item metadata to search for |
| 196 | + * @return The found stack or <code>null</code>. |
| 197 | + */ |
| 198 | + ItemStack get(int id, int meta, CompoundTag data); |
| 199 | + |
| 200 | + /** |
| 201 | + * @return Last stack of the list. |
| 202 | + */ |
| 203 | + ItemStack getLast(); |
| 204 | + |
| 205 | + /** |
| 206 | + * Called when the list changes. |
| 207 | + */ |
| 208 | + void inventoryChanged(); |
| 209 | + |
| 210 | + /** |
| 211 | + * Deletes all items from this list. |
| 212 | + */ |
| 213 | + void clear(); |
| 214 | + |
| 215 | + /** |
| 216 | + * @return Copy of this list. |
| 217 | + */ |
| 218 | + IItemStackList copy(); |
| 219 | + |
| 220 | + /** |
| 221 | + * @return Standard unmodifiable java list made from the contents of this list. |
| 222 | + */ |
| 223 | + @UnmodifiableView List<ItemStack> getStacks(); |
| 224 | + |
| 225 | + /** |
| 226 | + * @return <code>true</code> if list is empty, false otherwise. |
| 227 | + */ |
| 228 | + boolean isEmpty(); |
| 229 | +} |
0 commit comments