Skip to content

Commit 68d2ef7

Browse files
committed
Migrade slots
1 parent 06778f4 commit 68d2ef7

File tree

5 files changed

+116
-18
lines changed

5 files changed

+116
-18
lines changed

src/main/java/org/spongepowered/api/item/inventory/Container.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public interface Container extends Inventory {
5959
*/
6060
List<Inventory> viewed();
6161

62+
/**
63+
* @deprecated Use {@link #setCursor(ItemStackLike)} instead.
64+
*/
65+
@Deprecated(forRemoval = true)
66+
default boolean setCursor(ItemStack item) {
67+
return this.setCursor((ItemStackLike) item);
68+
}
69+
6270
/**
6371
* Sets the viewing players cursor item.
6472
* <p>Returns false when the container is no longer open.</p>
@@ -67,7 +75,7 @@ public interface Container extends Inventory {
6775
*
6876
* @return true if the cursor was set.
6977
*/
70-
boolean setCursor(ItemStack item);
78+
boolean setCursor(ItemStackLike item);
7179

7280
/**
7381
* Gets the viewing players cursor item.

src/main/java/org/spongepowered/api/item/inventory/Inventory.java

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ static Builder builder() {
142142
*/
143143
ItemStack peek();
144144

145+
/**
146+
* @deprecated Use {@link #offer(ItemStackLike...)} instead.
147+
*/
148+
@Deprecated(forRemoval = true)
149+
default InventoryTransactionResult offer(ItemStack... stacks) {
150+
return this.offer((ItemStackLike[]) stacks);
151+
}
152+
145153
/**
146154
* Adds one or more ItemStacks to this inventory.
147155
*
@@ -150,18 +158,26 @@ static Builder builder() {
150158
* @return A SUCCESS transaction-result if all stacks were added and
151159
* FAILURE when at least one stack was not or only partially added to the inventory.
152160
*/
153-
InventoryTransactionResult offer(ItemStack... stacks);
161+
InventoryTransactionResult offer(ItemStackLike... stacks);
162+
163+
/**
164+
* @deprecated Use {@link #canFit(ItemStackLike)} instead.
165+
*/
166+
@Deprecated(forRemoval = true)
167+
default boolean canFit(ItemStack stack) {
168+
return this.canFit((ItemStackLike) stack);
169+
}
154170

155171
/**
156172
* Returns true if the entire stack can fit in this inventory.
157173
*
158-
* <p>If this returns {@code true} {@link #offer(ItemStack...)} should always succeed.</p>
174+
* <p>If this returns {@code true} {@link #offer(ItemStackLike...)} should always succeed.</p>
159175
*
160176
* @param stack The stack of items to check if it can fit in this inventory.
161177
*
162178
* @return true if the entire stack can fit in this inventory.
163179
*/
164-
boolean canFit(ItemStack stack);
180+
boolean canFit(ItemStackLike stack);
165181

166182
/**
167183
* Gets and removes the stack at the supplied index in this Inventory.
@@ -198,17 +214,33 @@ static Builder builder() {
198214
*/
199215
Optional<ItemStack> peekAt(int index);
200216

217+
/**
218+
* @deprecated Use {@link #offer(int, ItemStackLike)} instead.
219+
*/
220+
@Deprecated(forRemoval = true)
221+
default InventoryTransactionResult offer(int index, ItemStack stack) {
222+
return this.offer(index, (ItemStackLike) stack);
223+
}
224+
201225
/**
202226
* Adds an ItemStack to the slot at given index.
203-
* Returns a {@link InventoryTransactionResult.Type#SUCCESS} only if the entire {@link ItemStack} fits the slot.
227+
* Returns a {@link InventoryTransactionResult.Type#SUCCESS} only if the entire {@link ItemStackLike} fits the slot.
204228
*
205229
* @param index The slot index
206230
* @param stack The stack to add to this inventory.
207231
*
208232
* @return A SUCCESS transaction-result if the entire stack was added and
209233
* FAILURE when the stack was not or only partially added to the inventory.
210234
*/
211-
InventoryTransactionResult offer(int index, ItemStack stack);
235+
InventoryTransactionResult offer(int index, ItemStackLike stack);
236+
237+
/**
238+
* @deprecated Use {@link #set(int, ItemStackLike)} instead.
239+
*/
240+
@Deprecated(forRemoval = true)
241+
default InventoryTransactionResult set(int index, ItemStack stack) {
242+
return this.set(index, (ItemStackLike) stack);
243+
}
212244

213245
/**
214246
* Adds the ItemStack to the slot at given index overwriting the existing item.
@@ -223,7 +255,7 @@ static Builder builder() {
223255
* @return A SUCCESS transaction-result if the entire stack was added and
224256
* FAILURE when the stack was not or only partially added to the inventory.
225257
*/
226-
InventoryTransactionResult set(int index, ItemStack stack);
258+
InventoryTransactionResult set(int index, ItemStackLike stack);
227259

228260
/**
229261
* Gets the {@link Slot} at the given index.
@@ -260,15 +292,23 @@ static Builder builder() {
260292
*/
261293
int capacity();
262294

295+
/**
296+
* @deprecated Use {@link #contains(ItemStackLike)} instead.
297+
*/
298+
@Deprecated(forRemoval = true)
299+
default boolean contains(ItemStack stack) {
300+
return this.contains((ItemStackLike) stack);
301+
}
302+
263303
/**
264304
* Checks whether the stacks quantity or more of given stack is contained in this Inventory.
265-
* To check if an inventory contains any amount use {@link #containsAny(ItemStack)}.
305+
* To check if an inventory contains any amount use {@link #containsAny(ItemStackLike)}.
266306
*
267307
* @param stack The stack to check for
268308
*
269309
* @return True if there are at least the given stack's amount of items present in this inventory.
270310
*/
271-
boolean contains(ItemStack stack);
311+
boolean contains(ItemStackLike stack);
272312

273313
/**
274314
* Checks whether the given ItemType is contained in this Inventory
@@ -279,18 +319,26 @@ static Builder builder() {
279319
*/
280320
boolean contains(ItemType type);
281321

322+
/**
323+
* @deprecated Use {@link #containsAny(ItemStackLike)} instead.
324+
*/
325+
@Deprecated(forRemoval = true)
326+
default boolean containsAny(ItemStack stack) {
327+
return this.containsAny((ItemStackLike) stack);
328+
}
329+
282330
/**
283331
* Checks whether the given stack is contained in this Inventory.
284332
* The stack size is ignored.
285333
*
286334
* <p>Note this will return true if any amount of the supplied stack is found.
287-
* To check if an inventory contains at least a given quantity use {@link #contains(ItemStack)}.</p>
335+
* To check if an inventory contains at least a given quantity use {@link #contains(ItemStackLike)}.</p>
288336
*
289337
* @param stack The stack to check for
290338
*
291339
* @return True if the stack is present in this inventory
292340
*/
293-
boolean containsAny(ItemStack stack);
341+
boolean containsAny(ItemStackLike stack);
294342

295343
// TODO remove from API? do we need to get a property relative to another parent in API?
296344
/**

src/main/java/org/spongepowered/api/item/inventory/Slot.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ public interface Slot extends Inventory {
3838
*/
3939
Slot viewedSlot();
4040

41+
/**
42+
* @deprecated Use {@link #set(ItemStackLike)} instead.
43+
*/
44+
@Deprecated(forRemoval = true)
45+
default InventoryTransactionResult set(ItemStack stack) {
46+
return this.set((ItemStackLike) stack);
47+
}
48+
4149
/**
4250
* Adds the ItemStack to this slot overwriting the existing item.
4351
*
@@ -48,5 +56,5 @@ public interface Slot extends Inventory {
4856
* @return A SUCCESS transaction-result if the entire stack was added and
4957
* FAILURE when the stack was not or only partially added to the inventory.
5058
*/
51-
InventoryTransactionResult set(ItemStack stack);
59+
InventoryTransactionResult set(ItemStackLike stack);
5260
}

src/main/java/org/spongepowered/api/item/inventory/slot/FilteringSlot.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,31 @@
2626

2727
import org.spongepowered.api.item.ItemType;
2828
import org.spongepowered.api.item.inventory.ItemStack;
29+
import org.spongepowered.api.item.inventory.ItemStackLike;
2930
import org.spongepowered.api.item.inventory.Slot;
3031

3132
/**
3233
* An inventory slot which can only accept certain types of item.
3334
*/
3435
public interface FilteringSlot extends Slot {
3536

37+
/**
38+
* @deprecated Use {@link #isValidItem(ItemStackLike)} instead.
39+
*/
40+
@Deprecated(forRemoval = true)
41+
default boolean isValidItem(ItemStack stack) {
42+
return this.isValidItem((ItemStackLike) stack);
43+
}
44+
3645
/**
3746
* Check whether the supplied item can be inserted into this slot. Returning
3847
* false from this method implies that {@link #offer} <b>would always return
3948
* false</b> for this item.
4049
*
41-
* @param stack ItemStack to check
50+
* @param stack ItemStackLike to check
4251
* @return true if the stack is valid for this slot
4352
*/
44-
boolean isValidItem(ItemStack stack);
53+
boolean isValidItem(ItemStackLike stack);
4554

4655
/**
4756
* Check whether the supplied item can be inserted into this slot. Returning

src/main/java/org/spongepowered/api/item/inventory/slot/SidedSlot.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.spongepowered.api.item.inventory.Inventory;
2828
import org.spongepowered.api.item.inventory.ItemStack;
29+
import org.spongepowered.api.item.inventory.ItemStackLike;
2930
import org.spongepowered.api.item.inventory.Slot;
3031
import org.spongepowered.api.util.Direction;
3132

@@ -34,6 +35,14 @@
3435
*/
3536
public interface SidedSlot extends Slot {
3637

38+
/**
39+
* @deprecated Use {@link #canAccept(ItemStackLike, Direction)} instead.
40+
*/
41+
@Deprecated(forRemoval = true)
42+
default boolean canAccept(ItemStack stack, Direction from) {
43+
return this.canAccept((ItemStackLike) stack, from);
44+
}
45+
3746
/**
3847
* Gets whether this slot can accept the specified item from the specified
3948
* direction.
@@ -43,19 +52,35 @@ public interface SidedSlot extends Slot {
4352
* @return true if this inventory can accept the supplied stack from the
4453
* specified direction
4554
*/
46-
boolean canAccept(ItemStack stack, Direction from);
55+
boolean canAccept(ItemStackLike stack, Direction from);
56+
57+
/**
58+
* @deprecated Use {@link #offer(ItemStackLike, Direction)} instead.
59+
*/
60+
@Deprecated(forRemoval = true)
61+
default boolean offer(ItemStack stack, Direction from) {
62+
return this.offer((ItemStackLike) stack, from);
63+
}
4764

4865
/**
4966
* Attempts to insert the supplied stack into this inventory from the
5067
* specified direction.
5168
*
52-
* @see Inventory#offer(ItemStack...)
69+
* @see Inventory#offer(ItemStackLike...)
5370
* @param stack Stack to insert
5471
* @param from Direction to check for insertion from
5572
* @return true if this inventory can accept the supplied stack from the
5673
* specified direction
5774
*/
58-
boolean offer(ItemStack stack, Direction from);
75+
boolean offer(ItemStackLike stack, Direction from);
76+
77+
/**
78+
* @deprecated Use {@link #canGet(ItemStackLike, Direction)} instead.
79+
*/
80+
@Deprecated(forRemoval = true)
81+
default boolean canGet(ItemStack stack, Direction from) {
82+
return this.canGet((ItemStackLike) stack, from);
83+
}
5984

6085
/**
6186
* Gets whether automation can extract the specified item from the specified
@@ -66,6 +91,6 @@ public interface SidedSlot extends Slot {
6691
* @return true if automation can retrieve the supplied stack from the
6792
* specified direction
6893
*/
69-
boolean canGet(ItemStack stack, Direction from);
94+
boolean canGet(ItemStackLike stack, Direction from);
7095

7196
}

0 commit comments

Comments
 (0)