Skip to content

Commit c8b38af

Browse files
committed
feat: merge ItemStackLike
Merges #2563 Signed-off-by: Gabriel Harris-Rouquette <gabizou@me.com>
2 parents dee177d + 47299e1 commit c8b38af

34 files changed

+871
-300
lines changed

src/main/java/org/spongepowered/api/advancement/DisplayInfo.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.spongepowered.api.Sponge;
2929
import org.spongepowered.api.item.ItemType;
3030
import org.spongepowered.api.item.inventory.ItemStack;
31+
import org.spongepowered.api.item.inventory.ItemStackLike;
3132
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3233
import org.spongepowered.api.util.CopyableBuilder;
3334

@@ -164,24 +165,29 @@ default Builder icon(ItemType itemType) {
164165
}
165166

166167
/**
167-
* Sets the icon of the advancement with the
168-
* specified {@link ItemStack}.
169-
*
170-
* @param itemStack The item stack
171-
* @return This builder, for chaining
168+
* @deprecated Use {@link #icon(ItemStackLike)} instead.
172169
*/
170+
@Deprecated(forRemoval = true)
173171
default Builder icon(ItemStack itemStack) {
174-
return this.icon(itemStack.createSnapshot());
172+
return this.icon((ItemStackLike) itemStack);
173+
}
174+
175+
/**
176+
* @deprecated Use {@link #icon(ItemStackLike)} instead.
177+
*/
178+
@Deprecated(forRemoval = true)
179+
default Builder icon(ItemStackSnapshot itemStackSnapshot) {
180+
return this.icon((ItemStackLike) itemStackSnapshot);
175181
}
176182

177183
/**
178184
* Sets the icon of the advancement with the
179-
* specified {@link ItemStackSnapshot}.
185+
* specified {@link ItemStackLike}.
180186
*
181-
* @param itemStackSnapshot The item stack snapshot
187+
* @param itemStack The item stack snapshot
182188
* @return This builder, for chaining
183189
*/
184-
Builder icon(ItemStackSnapshot itemStackSnapshot);
190+
Builder icon(ItemStackLike itemStack);
185191

186192
/**
187193
* Sets whether a toast should be shown. This is the notification

src/main/java/org/spongepowered/api/block/entity/Jukebox.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.spongepowered.api.data.Keys;
2828
import org.spongepowered.api.data.value.Value;
2929
import org.spongepowered.api.item.inventory.ItemStack;
30+
import org.spongepowered.api.item.inventory.ItemStackLike;
3031
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3132

3233
/**
@@ -59,10 +60,18 @@ default Value.Mutable<ItemStackSnapshot> item() {
5960
*/
6061
void eject();
6162

63+
/**
64+
* @deprecated Use {@link #insert(ItemStackLike)} instead.
65+
*/
66+
@Deprecated(forRemoval = true)
67+
default void insert(ItemStack disc) {
68+
this.insert((ItemStackLike) disc);
69+
}
70+
6271
/**
6372
* Ejects the current music disc item in this Jukebox and inserts the given one.
6473
*
6574
* @param disc The music disc item to insert
6675
*/
67-
void insert(ItemStack disc);
76+
void insert(ItemStackLike disc);
6877
}

src/main/java/org/spongepowered/api/event/cause/entity/damage/DamageModifier.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.spongepowered.api.item.ItemTypes;
3131
import org.spongepowered.api.item.enchantment.Enchantment;
3232
import org.spongepowered.api.item.inventory.ItemStack;
33+
import org.spongepowered.api.item.inventory.ItemStackLike;
3334
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
3435
import org.spongepowered.api.util.CopyableBuilder;
3536

@@ -162,13 +163,24 @@ public Builder group(final String group) {
162163
return this;
163164
}
164165

166+
/**
167+
* @deprecated Use {@link #item(ItemStackLike)} instead.
168+
*/
169+
@Deprecated(forRemoval = true)
165170
public Builder item(final ItemStack itemStack) {
166-
this.item(java.util.Objects.requireNonNull(itemStack, "ItemStack").createSnapshot());
167-
return this;
171+
return this.item((ItemStackLike) itemStack);
168172
}
169173

174+
/**
175+
* @deprecated Use {@link #item(ItemStackLike)} instead.
176+
*/
177+
@Deprecated(forRemoval = true)
170178
public Builder item(final ItemStackSnapshot snapshot) {
171-
this.snapshot = java.util.Objects.requireNonNull(snapshot, "ItemStackSnapshot");
179+
return this.item((ItemStackLike) snapshot);
180+
}
181+
182+
public Builder item(final ItemStackLike item) {
183+
this.snapshot = java.util.Objects.requireNonNull(item, "item").asImmutable();
172184
return this;
173185
}
174186

src/main/java/org/spongepowered/api/event/item/inventory/AffectItemStackEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public interface AffectItemStackEvent extends Event, Cancellable {
6767
*/
6868
default List<? extends Transaction<ItemStackSnapshot>> filter(Predicate<ItemStack> predicate) {
6969
final List<Transaction<ItemStackSnapshot>> invalidatedTransactions = new ArrayList<>();
70-
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().createStack())).forEach(transaction -> {
70+
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().asMutable())).forEach(transaction -> {
7171
transaction.setValid(false);
7272
invalidatedTransactions.add(transaction);
7373
});

src/main/java/org/spongepowered/api/event/item/inventory/AffectSlotEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface AffectSlotEvent extends AffectItemStackEvent {
4040
@Override
4141
default List<SlotTransaction> filter(Predicate<ItemStack> predicate) {
4242
final List<SlotTransaction> invalidatedTransactions = new ArrayList<>();
43-
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().createStack())).forEach(transaction -> {
43+
this.transactions().stream().filter(transaction -> !predicate.test(transaction.finalReplacement().asMutable())).forEach(transaction -> {
4444
transaction.setValid(false);
4545
invalidatedTransactions.add(transaction);
4646
});

src/main/java/org/spongepowered/api/item/enchantment/EnchantmentType.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.kyori.adventure.text.ComponentLike;
2828
import org.spongepowered.api.block.entity.EnchantmentTable;
2929
import org.spongepowered.api.item.inventory.ItemStack;
30+
import org.spongepowered.api.item.inventory.ItemStackLike;
3031
import org.spongepowered.api.registry.DefaultedRegistryValue;
3132
import org.spongepowered.api.tag.EnchantmenTypeTags;
3233
import org.spongepowered.api.tag.Taggable;
@@ -82,22 +83,38 @@ public interface EnchantmentType extends DefaultedRegistryValue, ComponentLike,
8283
int maximumEnchantabilityForLevel(int level);
8384

8485
/**
85-
* Test if this enchantment type can be applied to an {@link ItemStack}.
86+
* @deprecated Use {@link #canBeAppliedToStack(ItemStackLike)} instead,
87+
*/
88+
@Deprecated(forRemoval = true)
89+
default boolean canBeAppliedToStack(ItemStack stack) {
90+
return this.canBeAppliedToStack((ItemStackLike) stack);
91+
}
92+
93+
/**
94+
* Test if this enchantment type can be applied to an {@link ItemStackLike}.
8695
*
8796
* @param stack The item stack to check
8897
* @return Whether this enchantment type can be applied
8998
*/
90-
boolean canBeAppliedToStack(ItemStack stack);
99+
boolean canBeAppliedToStack(ItemStackLike stack);
100+
101+
/**
102+
* @deprecated Use {@link #canBeAppliedToStack(ItemStackLike)} instead,
103+
*/
104+
@Deprecated(forRemoval = true)
105+
default boolean canBeAppliedByTable(ItemStack stack) {
106+
return this.canBeAppliedByTable((ItemStackLike) stack);
107+
}
91108

92109
/**
93-
* Test if this enchantment type can be applied to an {@link ItemStack} by
110+
* Test if this enchantment type can be applied to an {@link ItemStackLike} by
94111
* the {@link EnchantmentTable}.
95112
*
96113
* @param stack Te item stack to check
97114
* @return Whether this enchantment type can be applied by the
98115
* enchantment table
99116
*/
100-
boolean canBeAppliedByTable(ItemStack stack);
117+
boolean canBeAppliedByTable(ItemStackLike stack);
101118

102119
/**
103120
* Test if this enchantment type can be applied along with

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ public interface ArmorEquipable extends Equipable {
4646
*/
4747
ItemStack head();
4848

49+
/**
50+
* @deprecated Use {@link #setHead(ItemStackLike)} instead.
51+
*/
52+
@Deprecated(forRemoval = true)
53+
default void setHead(ItemStack head) {
54+
this.setHead((ItemStackLike) head);
55+
}
56+
4957
/**
5058
* Sets the head.
5159
*
5260
* @param head The head
5361
*/
54-
void setHead(ItemStack head);
62+
void setHead(ItemStackLike head);
5563

5664
/**
5765
* Gets the chest.
@@ -60,12 +68,20 @@ public interface ArmorEquipable extends Equipable {
6068
*/
6169
ItemStack chest();
6270

71+
/**
72+
* @deprecated Use {@link #setChest(ItemStackLike)} instead.
73+
*/
74+
@Deprecated(forRemoval = true)
75+
default void setChest(ItemStack chest) {
76+
this.setChest((ItemStackLike) chest);
77+
}
78+
6379
/**
6480
* Sets the chest.
6581
*
6682
* @param chest The chest
6783
*/
68-
void setChest(ItemStack chest);
84+
void setChest(ItemStackLike chest);
6985

7086
/**
7187
* Gets the legs.
@@ -74,12 +90,20 @@ public interface ArmorEquipable extends Equipable {
7490
*/
7591
ItemStack legs();
7692

93+
/**
94+
* @deprecated Use {@link #setLegs(ItemStackLike)} instead.
95+
*/
96+
@Deprecated(forRemoval = true)
97+
default void setLegs(ItemStack legs) {
98+
this.setLegs((ItemStackLike) legs);
99+
}
100+
77101
/**
78102
* Sets the legs.
79103
*
80104
* @param legs The legs
81105
*/
82-
void setLegs(ItemStack legs);
106+
void setLegs(ItemStackLike legs);
83107

84108
/**
85109
* Gets the feet.
@@ -88,12 +112,20 @@ public interface ArmorEquipable extends Equipable {
88112
*/
89113
ItemStack feet();
90114

115+
/**
116+
* @deprecated Use {@link #setFeet(ItemStackLike)} instead.
117+
*/
118+
@Deprecated(forRemoval = true)
119+
default void setFeet(ItemStack feet) {
120+
this.setFeet((ItemStackLike) feet);
121+
}
122+
91123
/**
92124
* Sets the feet.
93125
*
94126
* @param feet The feet
95127
*/
96-
void setFeet(ItemStack feet);
128+
void setFeet(ItemStackLike feet);
97129

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

148+
/**
149+
* @deprecated Use {@link #setItemInHand(Supplier, ItemStackLike)} instead.
150+
*/
151+
@Deprecated(forRemoval = true)
152+
default void setItemInHand(Supplier<? extends HandType> handType, ItemStack itemInHand) {
153+
this.setItemInHand(handType, (ItemStackLike) itemInHand);
154+
}
155+
116156
/**
117157
* Sets the equipped item in hand.
118158
*
119159
* @param handType The hand type to set to
120160
* @param itemInHand The item in hand
121161
*/
122-
default void setItemInHand(Supplier<? extends HandType> handType, ItemStack itemInHand) {
162+
default void setItemInHand(Supplier<? extends HandType> handType, ItemStackLike itemInHand) {
123163
this.setItemInHand(handType.get(), itemInHand);
124164
}
125165

166+
/**
167+
* @deprecated Use {@link #setItemInHand(HandType, ItemStackLike)} instead.
168+
*/
169+
@Deprecated(forRemoval = true)
170+
default void setItemInHand(HandType handType, ItemStack itemInHand) {
171+
this.setItemInHand(handType, (ItemStackLike) itemInHand);
172+
}
173+
126174
/**
127175
* Sets the equipped item in hand.
128176
*
129177
* @param handType The hand type to set to
130178
* @param itemInHand The item in hand
131179
*/
132-
void setItemInHand(HandType handType, ItemStack itemInHand);
180+
void setItemInHand(HandType handType, ItemStackLike itemInHand);
133181
}

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/Equipable.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ default boolean canEquip(final Supplier<? extends EquipmentType> type) {
5656
return this.canEquip(type.get());
5757
}
5858

59+
/**
60+
* @deprecated Use {@link #canEquip(EquipmentType, ItemStackLike)} instead.
61+
*/
62+
@Deprecated(forRemoval = true)
63+
default boolean canEquip(EquipmentType type, ItemStack equipment) {
64+
return this.canEquip(type, (ItemStackLike) equipment);
65+
}
66+
5967
/**
6068
* Gets whether this {@link Equipable} can equip the supplied equipment in its slot of
6169
* the specified type (eg. whether calling {@link #equip} with the specified
@@ -65,9 +73,17 @@ default boolean canEquip(final Supplier<? extends EquipmentType> type) {
6573
* @param equipment The equipment to check for
6674
* @return true if can equip the supplied equipment
6775
*/
68-
boolean canEquip(EquipmentType type, ItemStack equipment);
76+
boolean canEquip(EquipmentType type, ItemStackLike equipment);
6977

78+
/**
79+
* @deprecated Use {@link #canEquip(Supplier, ItemStackLike)} instead.
80+
*/
81+
@Deprecated(forRemoval = true)
7082
default boolean canEquip(final Supplier<? extends EquipmentType> type, final ItemStack equipment) {
83+
return this.canEquip(type, (ItemStackLike) equipment);
84+
}
85+
86+
default boolean canEquip(final Supplier<? extends EquipmentType> type, final ItemStackLike equipment) {
7187
return this.canEquip(type.get(), equipment);
7288
}
7389

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

103+
/**
104+
* @deprecated Use {@link #equip(EquipmentType, ItemStackLike)} instead.
105+
*/
106+
@Deprecated(forRemoval = true)
107+
default boolean equip(EquipmentType type, ItemStack equipment) {
108+
return this.equip(type, (ItemStackLike) equipment);
109+
}
110+
87111
/**
88112
* Sets the item currently equipped by the {@link Equipable} in the specified slot, if
89113
* the equipable has such a slot.
@@ -95,9 +119,17 @@ default Optional<ItemStack> equipped(final Supplier<? extends EquipmentType> typ
95119
* specified equipment type or because the item was incompatible with
96120
* the specified slot.
97121
*/
98-
boolean equip(EquipmentType type, ItemStack equipment);
122+
boolean equip(EquipmentType type, ItemStackLike equipment);
99123

124+
/**
125+
* @deprecated Use {@link #equip(Supplier, ItemStackLike)} instead.
126+
*/
127+
@Deprecated(forRemoval = true)
100128
default boolean equip(final Supplier<? extends EquipmentType> type, final ItemStack equipment) {
129+
return this.equip(type, (ItemStackLike) equipment);
130+
}
131+
132+
default boolean equip(final Supplier<? extends EquipmentType> type, final ItemStackLike equipment) {
101133
return this.equip(type.get(), equipment);
102134
}
103135
}

0 commit comments

Comments
 (0)