Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ItemStackLike #4130

Merged
merged 13 commits into from
Sep 28, 2024
2 changes: 1 addition & 1 deletion SpongeAPI
Submodule SpongeAPI updated 34 files
+15 −9 src/main/java/org/spongepowered/api/advancement/DisplayInfo.java
+10 −1 src/main/java/org/spongepowered/api/block/entity/Jukebox.java
+15 −3 src/main/java/org/spongepowered/api/event/cause/entity/damage/DamageModifier.java
+1 −1 src/main/java/org/spongepowered/api/event/item/inventory/AffectItemStackEvent.java
+1 −1 src/main/java/org/spongepowered/api/event/item/inventory/AffectSlotEvent.java
+21 −4 src/main/java/org/spongepowered/api/item/enchantment/EnchantmentType.java
+54 −6 src/main/java/org/spongepowered/api/item/inventory/ArmorEquipable.java
+9 −1 src/main/java/org/spongepowered/api/item/inventory/Container.java
+34 −2 src/main/java/org/spongepowered/api/item/inventory/Equipable.java
+58 −10 src/main/java/org/spongepowered/api/item/inventory/Inventory.java
+9 −106 src/main/java/org/spongepowered/api/item/inventory/ItemStack.java
+172 −0 src/main/java/org/spongepowered/api/item/inventory/ItemStackLike.java
+6 −33 src/main/java/org/spongepowered/api/item/inventory/ItemStackSnapshot.java
+9 −1 src/main/java/org/spongepowered/api/item/inventory/Slot.java
+19 −2 src/main/java/org/spongepowered/api/item/inventory/equipment/EquipmentInventory.java
+11 −2 src/main/java/org/spongepowered/api/item/inventory/slot/FilteringSlot.java
+29 −4 src/main/java/org/spongepowered/api/item/inventory/slot/SidedSlot.java
+23 −6 src/main/java/org/spongepowered/api/item/inventory/transaction/InventoryTransactionResult.java
+12 −3 src/main/java/org/spongepowered/api/item/inventory/transaction/SlotTransaction.java
+11 −2 src/main/java/org/spongepowered/api/item/inventory/type/GridInventory.java
+11 −2 src/main/java/org/spongepowered/api/item/inventory/type/Inventory2D.java
+10 −1 src/main/java/org/spongepowered/api/item/inventory/type/ViewableInventory.java
+28 −3 src/main/java/org/spongepowered/api/item/merchant/TradeOffer.java
+37 −4 src/main/java/org/spongepowered/api/item/recipe/RecipeManager.java
+47 −16 src/main/java/org/spongepowered/api/item/recipe/cooking/CookingRecipe.java
+12 −3 src/main/java/org/spongepowered/api/item/recipe/cooking/CookingResult.java
+58 −22 src/main/java/org/spongepowered/api/item/recipe/crafting/Ingredient.java
+19 −2 src/main/java/org/spongepowered/api/item/recipe/crafting/RecipeInput.java
+12 −3 src/main/java/org/spongepowered/api/item/recipe/crafting/RecipeResult.java
+28 −11 src/main/java/org/spongepowered/api/item/recipe/crafting/ShapedCraftingRecipe.java
+26 −11 src/main/java/org/spongepowered/api/item/recipe/crafting/ShapelessCraftingRecipe.java
+12 −3 src/main/java/org/spongepowered/api/item/recipe/crafting/SpecialCraftingRecipe.java
+26 −11 src/main/java/org/spongepowered/api/item/recipe/single/StoneCutterRecipe.java
+26 −11 src/main/java/org/spongepowered/api/item/recipe/smithing/SmithingRecipe.java
46 changes: 40 additions & 6 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,14 @@
<sha256 value="d2b115634f5c085db4b9c9ffc2658e89e231fdbfbe2242121a1cd95d4d948dd7" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.code.gson" name="gson" version="2.11.0">
<artifact name="gson-2.11.0.jar">
<sha256 value="57928d6e5a6edeb2abd3770a8f95ba44dce45f3b23b7a9dc2b309c581552a78b" origin="Generated by Gradle"/>
</artifact>
<artifact name="gson-2.11.0.pom">
<sha256 value="c0e547bea998888e6e25c5886a90e762272bc88b5275343dd2c05ded6ca2e360" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.code.gson" name="gson" version="2.2.4">
<artifact name="gson-2.2.4.pom">
<sha256 value="ae984d5d19894ce6dc4689866eaa12f8fc31409113e60ee3b44853b8ac4fd380" origin="Generated by Gradle"/>
Expand All @@ -524,6 +532,11 @@
<sha256 value="4248e0882426c615182385d6086c3ef3262e769957189e29306280b85482b833" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.code.gson" name="gson-parent" version="2.11.0">
<artifact name="gson-parent-2.11.0.pom">
<sha256 value="8acb1f3b72a6f026916ac0735bad9aab0293d527edb7b365327def13a9367b7a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.code.gson" name="gson-parent" version="2.8.0">
<artifact name="gson-parent-2.8.0.pom">
<sha256 value="0f1d8369b1e9f1bc4b467c8dcfdd8b59733aad5b5c8419c3a59b2f9abaf04cd2" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -603,6 +616,14 @@
<sha256 value="aea7e991e2dfdcb47f5fbd508587535f7802bcb9e2fc2d4ebb50be41b684da9f" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.errorprone" name="error_prone_annotations" version="2.27.0">
<artifact name="error_prone_annotations-2.27.0.jar">
<sha256 value="24c923372c58e35d0b9f16a028929bb9aedc77521867c274f2bd0735df5ba1f5" origin="Generated by Gradle"/>
</artifact>
<artifact name="error_prone_annotations-2.27.0.pom">
<sha256 value="4ca5a35d61235e16549ac346d1e34551cdf0fe27e84aa57e03cbeb255ea4e5da" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.errorprone" name="error_prone_annotations" version="2.3.4">
<artifact name="error_prone_annotations-2.3.4.jar">
<sha256 value="baf7d6ea97ce606c53e11b6854ba5f2ce7ef5c24dddf0afa18d1260bd25b002c" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -681,6 +702,11 @@
<sha256 value="4a6ad00d31b0a5adcd9a4f605065d5b445fae4a04cbf827e5d1ac1077e2f814d" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.errorprone" name="error_prone_parent" version="2.27.0">
<artifact name="error_prone_parent-2.27.0.pom">
<sha256 value="fa81829d049559df6927f9c9a6fd6bbd09f8b50e6d4736ae72c8300b6c3d7654" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.google.errorprone" name="error_prone_parent" version="2.3.4">
<artifact name="error_prone_parent-2.3.4.pom">
<sha256 value="40495b437a60d2398f0fdfc054b89d9c394a82347a274a0721c2e950a4302186" origin="Generated by Gradle"/>
Expand Down Expand Up @@ -1876,12 +1902,12 @@
</artifact>
</component>
<component group="net.fabricmc" name="intermediary" version="1.21.1">
<artifact name="intermediary-1.21.1-v2.jar">
<sha256 value="e8bd6a4c39e235ee2dc73063558610775c72a2572fa0c6b32915b149074012a6" origin="Generated by Gradle"/>
</artifact>
<artifact name="intermediary-1.21.1.pom">
<sha256 value="b6ec5f03e95bea232b6960ed077dd0a765a3aabfd74732ee600eb77d2651adf4" origin="Generated by Gradle"/>
</artifact>
<artifact name="intermediary-1.21.1-v2.jar">
<sha256 value="e8bd6a4c39e235ee2dc73063558610775c72a2572fa0c6b32915b149074012a6" origin="Generated by Gradle"/>
</artifact>
<artifact name="intermediary-1.21.1.pom">
<sha256 value="b6ec5f03e95bea232b6960ed077dd0a765a3aabfd74732ee600eb77d2651adf4" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.fabricmc" name="lorenz-tiny" version="4.0.2">
<artifact name="lorenz-tiny-4.0.2.jar">
Expand Down Expand Up @@ -2322,6 +2348,14 @@
<sha256 value="b4bd71c336e4f8265aac276c6519c6e1793c5ce55f583c26896a7bca48658f2a" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.kyori" name="mammoth" version="1.4.0">
<artifact name="mammoth-1.4.0.jar">
<sha256 value="b04abb96b666f763d2d7467b0308f23fe8d8b753f8ad89143814cb5ea9901eb3" origin="Generated by Gradle"/>
</artifact>
<artifact name="mammoth-1.4.0.module">
<sha256 value="c204766a8f14ce4e1a124a5302a9839101fcda118de2aba6b76cc62865264aae" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="net.kyori" name="option" version="1.0.0">
<artifact name="option-1.0.0-javadoc.jar">
<sha256 value="97772ea0fa34365c2a44590a18c80a580874d9cdac44dba012f9e73304ab3c8a" origin="Generated by Gradle"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.spongepowered.api.advancement.AdvancementType;
import org.spongepowered.api.advancement.AdvancementTypes;
import org.spongepowered.api.advancement.DisplayInfo;
import org.spongepowered.api.item.inventory.ItemStackLike;
import org.spongepowered.api.item.inventory.ItemStackSnapshot;
import org.spongepowered.common.adventure.SpongeAdventure;
import org.spongepowered.common.util.Preconditions;
Expand Down Expand Up @@ -72,9 +73,9 @@ public DisplayInfo.Builder title(final Component title) {
}

@Override
public DisplayInfo.Builder icon(final ItemStackSnapshot itemStackSnapshot) {
Objects.requireNonNull(itemStackSnapshot, "itemStackSnapshot");
this.icon = itemStackSnapshot;
public DisplayInfo.Builder icon(final ItemStackLike itemStack) {
Objects.requireNonNull(itemStack, "itemStackSnapshot");
this.icon = itemStack.asImmutable();
return this;
}

Expand Down Expand Up @@ -104,7 +105,7 @@ public DisplayInfo build() {
final net.minecraft.network.chat.Component title = SpongeAdventure.asVanilla(this.title);
final net.minecraft.network.chat.Component description = SpongeAdventure.asVanilla(this.description);
final net.minecraft.advancements.AdvancementType frameType = (net.minecraft.advancements.AdvancementType) (Object) this.advancementType;
final ItemStack icon = (ItemStack) (Object) this.icon.createStack();
final ItemStack icon = (ItemStack) (Object) this.icon.asMutable();
return (DisplayInfo) new net.minecraft.advancements.DisplayInfo(icon, title, description, null,
frameType, this.showToast, this.announceToChat, this.hidden);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private Command.Parameterized infoSubcommand() {
.content("Block Info: ")
.color(TextColor.color(SpongeCommand.GREEN))
.append(Component.text(serverLocation.blockPosition().toString())
.hoverEvent(ItemStack.builder().fromBlockState(serverLocation.block()).build().createSnapshot())
.hoverEvent(ItemStack.builder().fromBlockState(serverLocation.block()).build().asImmutable())
)
.append(Component.newline())
.append(Component.text("Creator: ", TextColor.color(SpongeCommand.MINT)))
Expand Down Expand Up @@ -324,7 +324,7 @@ private Command.Parameterized infoSubcommand() {
.content("Block Info: ")
.color(TextColor.color(SpongeCommand.GREEN))
.append(Component.text(locatableBlock.blockPosition().toString())
.hoverEvent(ItemStack.builder().fromBlockState(locatableBlock.blockState()).build().createSnapshot())
.hoverEvent(ItemStack.builder().fromBlockState(locatableBlock.blockState()).build().asImmutable())
)
.append(Component.newline())
.append(Component.text("Creator: ", TextColor.color(SpongeCommand.MINT)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public SpongeItemStackSnapshotDataBuilder() {

@Override
protected Optional<ItemStackSnapshot> buildContent(DataView container) throws InvalidDataException {
return SpongeItemStack.createItemStack(container).map(ItemStack::createSnapshot);
return SpongeItemStack.createItemStack(container).map(ItemStack::asImmutable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
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.entity.UserInventory;
import org.spongepowered.api.item.inventory.equipment.EquipmentInventory;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
Expand Down Expand Up @@ -285,7 +286,7 @@ public boolean canEquip(final EquipmentType type) {
}

@Override
public boolean canEquip(final EquipmentType type, final @Nullable ItemStack equipment) {
public boolean canEquip(final EquipmentType type, final @Nullable ItemStackLike equipment) {
return true;
}

Expand All @@ -295,7 +296,7 @@ public Optional<ItemStack> equipped(final EquipmentType type) {
}

@Override
public boolean equip(final EquipmentType type, final @Nullable ItemStack equipment) {
public boolean equip(final EquipmentType type, final @Nullable ItemStackLike equipment) {
if (this.canEquip(type, equipment)) {
this.loadInventory();
this.setEquippedItem(type, equipment);
Expand Down Expand Up @@ -330,7 +331,7 @@ public ItemStack head() {
}

@Override
public void setHead(final ItemStack helmet) {
public void setHead(final ItemStackLike helmet) {
this.equip(EquipmentTypes.HEAD.get(), helmet);
}

Expand All @@ -340,7 +341,7 @@ public ItemStack chest() {
}

@Override
public void setChest(final ItemStack chestplate) {
public void setChest(final ItemStackLike chestplate) {
this.equip(EquipmentTypes.CHEST.get(), chestplate);
}

Expand All @@ -350,7 +351,7 @@ public ItemStack legs() {
}

@Override
public void setLegs(final ItemStack leggings) {
public void setLegs(final ItemStackLike leggings) {
this.equip(EquipmentTypes.LEGS.get(), leggings);
}

Expand All @@ -360,12 +361,12 @@ public ItemStack feet() {
}

@Override
public void setFeet(final ItemStack boots) {
public void setFeet(final ItemStackLike boots) {
this.equip(EquipmentTypes.FEET.get(), boots);
}

@Override
public void setItemInHand(final HandType handType, final @Nullable ItemStack itemInHand) {
public void setItemInHand(final HandType handType, final @Nullable ItemStackLike itemInHand) {
if (handType == HandTypes.MAIN_HAND.get()) {
this.setEquippedItem(EquipmentTypes.MAINHAND, itemInHand);
} else if (handType == HandTypes.OFF_HAND.get()) {
Expand Down Expand Up @@ -439,11 +440,11 @@ public void save() throws IOException {

// Helpers for Equipment:

private void setEquippedItem(final Supplier<? extends EquipmentType> type, final @Nullable ItemStack item) {
private void setEquippedItem(final Supplier<? extends EquipmentType> type, final @Nullable ItemStackLike item) {
this.setEquippedItem(type.get(), item);
}

private void setEquippedItem(final EquipmentType type, final @Nullable ItemStack item) {
private void setEquippedItem(final EquipmentType type, final @Nullable ItemStackLike item) {
throw new MissingImplementationException("SpongeUser", "setEquippedItem");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.spongepowered.api.item.inventory.Equipable;
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.equipment.EquipmentInventory;
import org.spongepowered.api.item.inventory.equipment.EquipmentType;
import org.spongepowered.api.item.inventory.type.CarriedInventory;
Expand Down Expand Up @@ -267,7 +268,7 @@ public ItemStack head() {
}

@Override
public void setHead(final ItemStack head) {
public void setHead(final ItemStackLike head) {
this.backingObjectConsumer(player -> player.setHead(head), user -> user.setHead(head));
}

Expand All @@ -277,7 +278,7 @@ public ItemStack chest() {
}

@Override
public void setChest(final ItemStack chest) {
public void setChest(final ItemStackLike chest) {
this.backingObjectConsumer(player -> player.setChest(chest), user -> user.setChest(chest));
}

Expand All @@ -287,7 +288,7 @@ public ItemStack legs() {
}

@Override
public void setLegs(final ItemStack legs) {
public void setLegs(final ItemStackLike legs) {
this.backingObjectConsumer(player -> player.setLegs(legs), user -> user.setLegs(legs));
}

Expand All @@ -297,7 +298,7 @@ public ItemStack feet() {
}

@Override
public void setFeet(final ItemStack feet) {
public void setFeet(final ItemStackLike feet) {
this.backingObjectConsumer(player -> player.setFeet(feet), user -> user.setFeet(feet));
}

Expand All @@ -307,7 +308,7 @@ public ItemStack itemInHand(final HandType handType) {
}

@Override
public void setItemInHand(final HandType handType, final ItemStack itemInHand) {
public void setItemInHand(final HandType handType, final ItemStackLike itemInHand) {
this.backingObjectConsumer(player -> player.setItemInHand(handType, itemInHand), user -> user.setItemInHand(handType, itemInHand));
}

Expand All @@ -322,7 +323,7 @@ public boolean canEquip(final EquipmentType type) {
}

@Override
public boolean canEquip(final EquipmentType type, final ItemStack equipment) {
public boolean canEquip(final EquipmentType type, final ItemStackLike equipment) {
return this.backingObject(player -> player.canEquip(type, equipment), user -> user.canEquip(type, equipment));
}

Expand All @@ -332,7 +333,7 @@ public Optional<ItemStack> equipped(final EquipmentType type) {
}

@Override
public boolean equip(final EquipmentType type, final ItemStack equipment) {
public boolean equip(final EquipmentType type, final ItemStackLike equipment) {
return this.backingObject(player -> player.equip(type, equipment), user -> user.equip(type, equipment));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static boolean callPlayerInventoryPickupEvent(final Player player, final
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.PICKUP)) {
for (final ItemStackSnapshot item : list) {
final org.spongepowered.api.item.inventory.ItemStack itemStack = item.createStack();
final org.spongepowered.api.item.inventory.ItemStack itemStack = item.asMutable();
player.getInventory().add(ItemStackUtil.toNative(itemStack));
if (!itemStack.isEmpty()) {
// Modified pickup items do not fit inventory - pre-cancel ChangeInventoryEvent.Pickup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Optional<ClickContainerEvent> createInventoryEvent(
) {
if (slotTransactions.isEmpty() && this.slotNum >= 0 && this.slot != null) {
// No SlotTransaction was captured. So we add the clicked slot as a transaction with the creative stack
final ItemStackSnapshot item = this.slot.peek().createSnapshot();
final ItemStackSnapshot item = this.slot.peek().asImmutable();
slotTransactions.add(new SlotTransaction(this.slot, item, this.creativeStack));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public <K extends Packet<?>> K getPacket() {

public P itemUsed(final ItemStack stack) {
this.itemUsed = stack;
this.itemUsedSnapshot = this.itemUsed.createSnapshot();
this.itemUsedSnapshot = this.itemUsed.asImmutable();
return (P) this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ public static void handleSlotRestore(@Nullable final Player player, final @Nulla
final org.spongepowered.api.item.inventory.Slot slot = slotTransaction.slot();
final ItemStackSnapshot snapshot = eventCancelled || !slotTransaction.isValid() ? slotTransaction.original() : slotTransaction.custom().get();
if (containerMenu == null || slot.viewedSlot() instanceof Slot) {
slot.set(snapshot.createStack());
slot.set(snapshot);
} else if (player instanceof ServerPlayer serverPlayer
&& containerMenu != player.inventoryMenu && serverPlayer.inventory().containsInventory(slot)) {
final org.spongepowered.api.item.inventory.ItemStack stack = snapshot.createStack();
final org.spongepowered.api.item.inventory.ItemStack stack = snapshot.asMutable();
slot.set(stack);
((net.minecraft.server.level.ServerPlayer) player).connection.send(
new ClientboundContainerSetSlotPacket(-2, player.inventoryMenu.getStateId(), ((SlotAdapter) slot).getOrdinal(), ItemStackUtil.toNative(stack)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.spongepowered.api.item.inventory.EmptyInventory;
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.ItemStackSnapshot;
import org.spongepowered.api.item.inventory.Slot;
import org.spongepowered.api.item.inventory.query.Query;
Expand Down Expand Up @@ -105,12 +106,12 @@ public boolean hasChildren() {
}

@Override
public boolean contains(ItemStack stack) {
public boolean contains(ItemStackLike stack) {
return false;
}

@Override
public boolean containsAny(ItemStack stack) {
public boolean containsAny(ItemStackLike stack) {
return false;
}

Expand Down Expand Up @@ -193,7 +194,7 @@ public Inventory root() {
}

@Override
public InventoryTransactionResult offer(ItemStack... stacks) {
public InventoryTransactionResult offer(ItemStackLike... stacks) {
return InventoryTransactionResult.builder().type(Type.FAILURE).reject(stacks).build();
}

Expand All @@ -209,16 +210,16 @@ public Optional<ItemStack> peekAt(int index) {
return Optional.empty();
}

public InventoryTransactionResult offer(int index, ItemStack stack) {
public InventoryTransactionResult offer(int index, ItemStackLike stack) {
return InventoryTransactionResult.builder().type(Type.NO_SLOT).reject(stack).build();
}

public InventoryTransactionResult set(int index, ItemStack stack) {
public InventoryTransactionResult set(int index, ItemStackLike stack) {
return InventoryTransactionResult.builder().type(Type.NO_SLOT).reject(stack).build();
}

@Override
public boolean canFit(ItemStack stack) {
public boolean canFit(ItemStackLike stack) {
return false;
}

Expand Down
Loading