Skip to content

Commit

Permalink
Migrade slots
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHell228 committed Sep 15, 2024
1 parent 06778f4 commit 68d2ef7
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public interface Container extends Inventory {
*/
List<Inventory> viewed();

/**
* @deprecated Use {@link #setCursor(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean setCursor(ItemStack item) {
return this.setCursor((ItemStackLike) item);
}

/**
* Sets the viewing players cursor item.
* <p>Returns false when the container is no longer open.</p>
Expand All @@ -67,7 +75,7 @@ public interface Container extends Inventory {
*
* @return true if the cursor was set.
*/
boolean setCursor(ItemStack item);
boolean setCursor(ItemStackLike item);

/**
* Gets the viewing players cursor item.
Expand Down
68 changes: 58 additions & 10 deletions src/main/java/org/spongepowered/api/item/inventory/Inventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ static Builder builder() {
*/
ItemStack peek();

/**
* @deprecated Use {@link #offer(ItemStackLike...)} instead.
*/
@Deprecated(forRemoval = true)
default InventoryTransactionResult offer(ItemStack... stacks) {
return this.offer((ItemStackLike[]) stacks);
}

/**
* Adds one or more ItemStacks to this inventory.
*
Expand All @@ -150,18 +158,26 @@ static Builder builder() {
* @return A SUCCESS transaction-result if all stacks were added and
* FAILURE when at least one stack was not or only partially added to the inventory.
*/
InventoryTransactionResult offer(ItemStack... stacks);
InventoryTransactionResult offer(ItemStackLike... stacks);

/**
* @deprecated Use {@link #canFit(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean canFit(ItemStack stack) {
return this.canFit((ItemStackLike) stack);
}

/**
* Returns true if the entire stack can fit in this inventory.
*
* <p>If this returns {@code true} {@link #offer(ItemStack...)} should always succeed.</p>
* <p>If this returns {@code true} {@link #offer(ItemStackLike...)} should always succeed.</p>
*
* @param stack The stack of items to check if it can fit in this inventory.
*
* @return true if the entire stack can fit in this inventory.
*/
boolean canFit(ItemStack stack);
boolean canFit(ItemStackLike stack);

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

/**
* @deprecated Use {@link #offer(int, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default InventoryTransactionResult offer(int index, ItemStack stack) {
return this.offer(index, (ItemStackLike) stack);
}

/**
* Adds an ItemStack to the slot at given index.
* Returns a {@link InventoryTransactionResult.Type#SUCCESS} only if the entire {@link ItemStack} fits the slot.
* Returns a {@link InventoryTransactionResult.Type#SUCCESS} only if the entire {@link ItemStackLike} fits the slot.
*
* @param index The slot index
* @param stack The stack to add to this inventory.
*
* @return A SUCCESS transaction-result if the entire stack was added and
* FAILURE when the stack was not or only partially added to the inventory.
*/
InventoryTransactionResult offer(int index, ItemStack stack);
InventoryTransactionResult offer(int index, ItemStackLike stack);

/**
* @deprecated Use {@link #set(int, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default InventoryTransactionResult set(int index, ItemStack stack) {
return this.set(index, (ItemStackLike) stack);
}

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

/**
* Gets the {@link Slot} at the given index.
Expand Down Expand Up @@ -260,15 +292,23 @@ static Builder builder() {
*/
int capacity();

/**
* @deprecated Use {@link #contains(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean contains(ItemStack stack) {
return this.contains((ItemStackLike) stack);
}

/**
* Checks whether the stacks quantity or more of given stack is contained in this Inventory.
* To check if an inventory contains any amount use {@link #containsAny(ItemStack)}.
* To check if an inventory contains any amount use {@link #containsAny(ItemStackLike)}.
*
* @param stack The stack to check for
*
* @return True if there are at least the given stack's amount of items present in this inventory.
*/
boolean contains(ItemStack stack);
boolean contains(ItemStackLike stack);

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

/**
* @deprecated Use {@link #containsAny(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean containsAny(ItemStack stack) {
return this.containsAny((ItemStackLike) stack);
}

/**
* Checks whether the given stack is contained in this Inventory.
* The stack size is ignored.
*
* <p>Note this will return true if any amount of the supplied stack is found.
* To check if an inventory contains at least a given quantity use {@link #contains(ItemStack)}.</p>
* To check if an inventory contains at least a given quantity use {@link #contains(ItemStackLike)}.</p>
*
* @param stack The stack to check for
*
* @return True if the stack is present in this inventory
*/
boolean containsAny(ItemStack stack);
boolean containsAny(ItemStackLike stack);

// TODO remove from API? do we need to get a property relative to another parent in API?
/**
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/spongepowered/api/item/inventory/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public interface Slot extends Inventory {
*/
Slot viewedSlot();

/**
* @deprecated Use {@link #set(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default InventoryTransactionResult set(ItemStack stack) {
return this.set((ItemStackLike) stack);
}

/**
* Adds the ItemStack to this slot overwriting the existing item.
*
Expand All @@ -48,5 +56,5 @@ public interface Slot extends Inventory {
* @return A SUCCESS transaction-result if the entire stack was added and
* FAILURE when the stack was not or only partially added to the inventory.
*/
InventoryTransactionResult set(ItemStack stack);
InventoryTransactionResult set(ItemStackLike stack);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,31 @@

import org.spongepowered.api.item.ItemType;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.item.inventory.Slot;

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

/**
* @deprecated Use {@link #isValidItem(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean isValidItem(ItemStack stack) {
return this.isValidItem((ItemStackLike) stack);
}

/**
* Check whether the supplied item can be inserted into this slot. Returning
* false from this method implies that {@link #offer} <b>would always return
* false</b> for this item.
*
* @param stack ItemStack to check
* @param stack ItemStackLike to check
* @return true if the stack is valid for this slot
*/
boolean isValidItem(ItemStack stack);
boolean isValidItem(ItemStackLike stack);

/**
* Check whether the supplied item can be inserted into this slot. Returning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.util.Direction;

Expand All @@ -34,6 +35,14 @@
*/
public interface SidedSlot extends Slot {

/**
* @deprecated Use {@link #canAccept(ItemStackLike, Direction)} instead.
*/
@Deprecated(forRemoval = true)
default boolean canAccept(ItemStack stack, Direction from) {
return this.canAccept((ItemStackLike) stack, from);
}

/**
* Gets whether this slot can accept the specified item from the specified
* direction.
Expand All @@ -43,19 +52,35 @@ public interface SidedSlot extends Slot {
* @return true if this inventory can accept the supplied stack from the
* specified direction
*/
boolean canAccept(ItemStack stack, Direction from);
boolean canAccept(ItemStackLike stack, Direction from);

/**
* @deprecated Use {@link #offer(ItemStackLike, Direction)} instead.
*/
@Deprecated(forRemoval = true)
default boolean offer(ItemStack stack, Direction from) {
return this.offer((ItemStackLike) stack, from);
}

/**
* Attempts to insert the supplied stack into this inventory from the
* specified direction.
*
* @see Inventory#offer(ItemStack...)
* @see Inventory#offer(ItemStackLike...)
* @param stack Stack to insert
* @param from Direction to check for insertion from
* @return true if this inventory can accept the supplied stack from the
* specified direction
*/
boolean offer(ItemStack stack, Direction from);
boolean offer(ItemStackLike stack, Direction from);

/**
* @deprecated Use {@link #canGet(ItemStackLike, Direction)} instead.
*/
@Deprecated(forRemoval = true)
default boolean canGet(ItemStack stack, Direction from) {
return this.canGet((ItemStackLike) stack, from);
}

/**
* Gets whether automation can extract the specified item from the specified
Expand All @@ -66,6 +91,6 @@ public interface SidedSlot extends Slot {
* @return true if automation can retrieve the supplied stack from the
* specified direction
*/
boolean canGet(ItemStack stack, Direction from);
boolean canGet(ItemStackLike stack, Direction from);

}

0 comments on commit 68d2ef7

Please sign in to comment.