Skip to content

Commit

Permalink
feat: merge ItemStackLike
Browse files Browse the repository at this point in the history
Merges #2563

Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
  • Loading branch information
gabizou committed Sep 28, 2024
2 parents dee177d + 47299e1 commit c8b38af
Show file tree
Hide file tree
Showing 34 changed files with 871 additions and 300 deletions.
24 changes: 15 additions & 9 deletions src/main/java/org/spongepowered/api/advancement/DisplayInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.spongepowered.api.Sponge;
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.ItemStackSnapshot;
import org.spongepowered.api.util.CopyableBuilder;

Expand Down Expand Up @@ -164,24 +165,29 @@ default Builder icon(ItemType itemType) {
}

/**
* Sets the icon of the advancement with the
* specified {@link ItemStack}.
*
* @param itemStack The item stack
* @return This builder, for chaining
* @deprecated Use {@link #icon(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default Builder icon(ItemStack itemStack) {
return this.icon(itemStack.createSnapshot());
return this.icon((ItemStackLike) itemStack);
}

/**
* @deprecated Use {@link #icon(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default Builder icon(ItemStackSnapshot itemStackSnapshot) {
return this.icon((ItemStackLike) itemStackSnapshot);
}

/**
* Sets the icon of the advancement with the
* specified {@link ItemStackSnapshot}.
* specified {@link ItemStackLike}.
*
* @param itemStackSnapshot The item stack snapshot
* @param itemStack The item stack snapshot
* @return This builder, for chaining
*/
Builder icon(ItemStackSnapshot itemStackSnapshot);
Builder icon(ItemStackLike itemStack);

/**
* Sets whether a toast should be shown. This is the notification
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/spongepowered/api/block/entity/Jukebox.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.data.value.Value;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;

/**
Expand Down Expand Up @@ -59,10 +60,18 @@ default Value.Mutable<ItemStackSnapshot> item() {
*/
void eject();

/**
* @deprecated Use {@link #insert(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void insert(ItemStack disc) {
this.insert((ItemStackLike) disc);
}

/**
* Ejects the current music disc item in this Jukebox and inserts the given one.
*
* @param disc The music disc item to insert
*/
void insert(ItemStack disc);
void insert(ItemStackLike disc);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.spongepowered.api.item.ItemTypes;
import org.spongepowered.api.item.enchantment.Enchantment;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.api.util.CopyableBuilder;

Expand Down Expand Up @@ -162,13 +163,24 @@ public Builder group(final String group) {
return this;
}

/**
* @deprecated Use {@link #item(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
public Builder item(final ItemStack itemStack) {
this.item(java.util.Objects.requireNonNull(itemStack, "ItemStack").createSnapshot());
return this;
return this.item((ItemStackLike) itemStack);
}

/**
* @deprecated Use {@link #item(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
public Builder item(final ItemStackSnapshot snapshot) {
this.snapshot = java.util.Objects.requireNonNull(snapshot, "ItemStackSnapshot");
return this.item((ItemStackLike) snapshot);
}

public Builder item(final ItemStackLike item) {
this.snapshot = java.util.Objects.requireNonNull(item, "item").asImmutable();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public interface AffectItemStackEvent extends Event, Cancellable {
*/
default List<? extends Transaction<ItemStackSnapshot>> filter(Predicate<ItemStack> predicate) {
final List<Transaction<ItemStackSnapshot>> invalidatedTransactions = new ArrayList<>();
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().createStack())).forEach(transaction -> {
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().asMutable())).forEach(transaction -> {
transaction.setValid(false);
invalidatedTransactions.add(transaction);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface AffectSlotEvent extends AffectItemStackEvent {
@Override
default List<SlotTransaction> filter(Predicate<ItemStack> predicate) {
final List<SlotTransaction> invalidatedTransactions = new ArrayList<>();
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().createStack())).forEach(transaction -> {
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().asMutable())).forEach(transaction -> {
transaction.setValid(false);
invalidatedTransactions.add(transaction);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.kyori.adventure.text.ComponentLike;
import org.spongepowered.api.block.entity.EnchantmentTable;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.registry.DefaultedRegistryValue;
import org.spongepowered.api.tag.EnchantmenTypeTags;
import org.spongepowered.api.tag.Taggable;
Expand Down Expand Up @@ -82,22 +83,38 @@ public interface EnchantmentType extends DefaultedRegistryValue, ComponentLike,
int maximumEnchantabilityForLevel(int level);

/**
* Test if this enchantment type can be applied to an {@link ItemStack}.
* @deprecated Use {@link #canBeAppliedToStack(ItemStackLike)} instead,
*/
@Deprecated(forRemoval = true)
default boolean canBeAppliedToStack(ItemStack stack) {
return this.canBeAppliedToStack((ItemStackLike) stack);
}

/**
* Test if this enchantment type can be applied to an {@link ItemStackLike}.
*
* @param stack The item stack to check
* @return Whether this enchantment type can be applied
*/
boolean canBeAppliedToStack(ItemStack stack);
boolean canBeAppliedToStack(ItemStackLike stack);

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

/**
* Test if this enchantment type can be applied to an {@link ItemStack} by
* Test if this enchantment type can be applied to an {@link ItemStackLike} by
* the {@link EnchantmentTable}.
*
* @param stack Te item stack to check
* @return Whether this enchantment type can be applied by the
* enchantment table
*/
boolean canBeAppliedByTable(ItemStack stack);
boolean canBeAppliedByTable(ItemStackLike stack);

/**
* Test if this enchantment type can be applied along with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ public interface ArmorEquipable extends Equipable {
*/
ItemStack head();

/**
* @deprecated Use {@link #setHead(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setHead(ItemStack head) {
this.setHead((ItemStackLike) head);
}

/**
* Sets the head.
*
* @param head The head
*/
void setHead(ItemStack head);
void setHead(ItemStackLike head);

/**
* Gets the chest.
Expand All @@ -60,12 +68,20 @@ public interface ArmorEquipable extends Equipable {
*/
ItemStack chest();

/**
* @deprecated Use {@link #setChest(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setChest(ItemStack chest) {
this.setChest((ItemStackLike) chest);
}

/**
* Sets the chest.
*
* @param chest The chest
*/
void setChest(ItemStack chest);
void setChest(ItemStackLike chest);

/**
* Gets the legs.
Expand All @@ -74,12 +90,20 @@ public interface ArmorEquipable extends Equipable {
*/
ItemStack legs();

/**
* @deprecated Use {@link #setLegs(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setLegs(ItemStack legs) {
this.setLegs((ItemStackLike) legs);
}

/**
* Sets the legs.
*
* @param legs The legs
*/
void setLegs(ItemStack legs);
void setLegs(ItemStackLike legs);

/**
* Gets the feet.
Expand All @@ -88,12 +112,20 @@ public interface ArmorEquipable extends Equipable {
*/
ItemStack feet();

/**
* @deprecated Use {@link #setFeet(ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setFeet(ItemStack feet) {
this.setFeet((ItemStackLike) feet);
}

/**
* Sets the feet.
*
* @param feet The feet
*/
void setFeet(ItemStack feet);
void setFeet(ItemStackLike feet);

/**
* Gets the equipped item in hand.
Expand All @@ -113,21 +145,37 @@ default ItemStack itemInHand(Supplier<? extends HandType> handType) {
*/
ItemStack itemInHand(HandType handType);

/**
* @deprecated Use {@link #setItemInHand(Supplier, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setItemInHand(Supplier<? extends HandType> handType, ItemStack itemInHand) {
this.setItemInHand(handType, (ItemStackLike) itemInHand);
}

/**
* Sets the equipped item in hand.
*
* @param handType The hand type to set to
* @param itemInHand The item in hand
*/
default void setItemInHand(Supplier<? extends HandType> handType, ItemStack itemInHand) {
default void setItemInHand(Supplier<? extends HandType> handType, ItemStackLike itemInHand) {
this.setItemInHand(handType.get(), itemInHand);
}

/**
* @deprecated Use {@link #setItemInHand(HandType, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default void setItemInHand(HandType handType, ItemStack itemInHand) {
this.setItemInHand(handType, (ItemStackLike) itemInHand);
}

/**
* Sets the equipped item in hand.
*
* @param handType The hand type to set to
* @param itemInHand The item in hand
*/
void setItemInHand(HandType handType, ItemStack itemInHand);
void setItemInHand(HandType handType, ItemStackLike itemInHand);
}
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
36 changes: 34 additions & 2 deletions src/main/java/org/spongepowered/api/item/inventory/Equipable.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ default boolean canEquip(final Supplier<? extends EquipmentType> type) {
return this.canEquip(type.get());
}

/**
* @deprecated Use {@link #canEquip(EquipmentType, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean canEquip(EquipmentType type, ItemStack equipment) {
return this.canEquip(type, (ItemStackLike) equipment);
}

/**
* Gets whether this {@link Equipable} can equip the supplied equipment in its slot of
* the specified type (eg. whether calling {@link #equip} with the specified
Expand All @@ -65,9 +73,17 @@ default boolean canEquip(final Supplier<? extends EquipmentType> type) {
* @param equipment The equipment to check for
* @return true if can equip the supplied equipment
*/
boolean canEquip(EquipmentType type, ItemStack equipment);
boolean canEquip(EquipmentType type, ItemStackLike equipment);

/**
* @deprecated Use {@link #canEquip(Supplier, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean canEquip(final Supplier<? extends EquipmentType> type, final ItemStack equipment) {
return this.canEquip(type, (ItemStackLike) equipment);
}

default boolean canEquip(final Supplier<? extends EquipmentType> type, final ItemStackLike equipment) {
return this.canEquip(type.get(), equipment);
}

Expand All @@ -84,6 +100,14 @@ default Optional<ItemStack> equipped(final Supplier<? extends EquipmentType> typ
return this.equipped(type.get());
}

/**
* @deprecated Use {@link #equip(EquipmentType, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean equip(EquipmentType type, ItemStack equipment) {
return this.equip(type, (ItemStackLike) equipment);
}

/**
* Sets the item currently equipped by the {@link Equipable} in the specified slot, if
* the equipable has such a slot.
Expand All @@ -95,9 +119,17 @@ default Optional<ItemStack> equipped(final Supplier<? extends EquipmentType> typ
* specified equipment type or because the item was incompatible with
* the specified slot.
*/
boolean equip(EquipmentType type, ItemStack equipment);
boolean equip(EquipmentType type, ItemStackLike equipment);

/**
* @deprecated Use {@link #equip(Supplier, ItemStackLike)} instead.
*/
@Deprecated(forRemoval = true)
default boolean equip(final Supplier<? extends EquipmentType> type, final ItemStack equipment) {
return this.equip(type, (ItemStackLike) equipment);
}

default boolean equip(final Supplier<? extends EquipmentType> type, final ItemStackLike equipment) {
return this.equip(type.get(), equipment);
}
}
Loading

0 comments on commit c8b38af

Please sign in to comment.