diff --git a/SpongeAPI b/SpongeAPI index 42dc372340a..47299e1628f 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 42dc372340aa68a7ea28a5ffa90b68c25af09661 +Subproject commit 47299e1628fb02b1a980435aaf6043845337c7d7 diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 9f191f07979..71a029b3f74 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -501,6 +501,14 @@ + + + + + + + + @@ -524,6 +532,11 @@ + + + + + @@ -603,6 +616,14 @@ + + + + + + + + @@ -681,6 +702,11 @@ + + + + + @@ -1876,12 +1902,12 @@ - - - - - - + + + + + + @@ -2322,6 +2348,14 @@ + + + + + + + + diff --git a/src/main/java/org/spongepowered/common/advancement/SpongeDisplayInfoBuilder.java b/src/main/java/org/spongepowered/common/advancement/SpongeDisplayInfoBuilder.java index 51e7890f6ad..0f38a02050e 100644 --- a/src/main/java/org/spongepowered/common/advancement/SpongeDisplayInfoBuilder.java +++ b/src/main/java/org/spongepowered/common/advancement/SpongeDisplayInfoBuilder.java @@ -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; @@ -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; } @@ -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); } diff --git a/src/main/java/org/spongepowered/common/command/sponge/SpongeCommand.java b/src/main/java/org/spongepowered/common/command/sponge/SpongeCommand.java index fc787c07789..18627faedec 100644 --- a/src/main/java/org/spongepowered/common/command/sponge/SpongeCommand.java +++ b/src/main/java/org/spongepowered/common/command/sponge/SpongeCommand.java @@ -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))) @@ -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))) diff --git a/src/main/java/org/spongepowered/common/data/builder/item/SpongeItemStackSnapshotDataBuilder.java b/src/main/java/org/spongepowered/common/data/builder/item/SpongeItemStackSnapshotDataBuilder.java index d9bae61a122..3f69d6d43be 100644 --- a/src/main/java/org/spongepowered/common/data/builder/item/SpongeItemStackSnapshotDataBuilder.java +++ b/src/main/java/org/spongepowered/common/data/builder/item/SpongeItemStackSnapshotDataBuilder.java @@ -43,6 +43,6 @@ public SpongeItemStackSnapshotDataBuilder() { @Override protected Optional buildContent(DataView container) throws InvalidDataException { - return SpongeItemStack.createItemStack(container).map(ItemStack::createSnapshot); + return SpongeItemStack.createItemStack(container).map(ItemStack::asImmutable); } } diff --git a/src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java b/src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java index 4b24f5ddcda..6fe79650820 100644 --- a/src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java +++ b/src/main/java/org/spongepowered/common/entity/player/SpongeUserData.java @@ -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; @@ -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; } @@ -295,7 +296,7 @@ public Optional 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); @@ -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); } @@ -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); } @@ -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); } @@ -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()) { @@ -439,11 +440,11 @@ public void save() throws IOException { // Helpers for Equipment: - private void setEquippedItem(final Supplier type, final @Nullable ItemStack item) { + private void setEquippedItem(final Supplier 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"); } diff --git a/src/main/java/org/spongepowered/common/entity/player/SpongeUserView.java b/src/main/java/org/spongepowered/common/entity/player/SpongeUserView.java index 03bc5deb54f..421ff485aba 100644 --- a/src/main/java/org/spongepowered/common/entity/player/SpongeUserView.java +++ b/src/main/java/org/spongepowered/common/entity/player/SpongeUserView.java @@ -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; @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -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)); } @@ -332,7 +333,7 @@ public Optional 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)); } diff --git a/src/main/java/org/spongepowered/common/event/inventory/InventoryEventFactory.java b/src/main/java/org/spongepowered/common/event/inventory/InventoryEventFactory.java index 07c6de04c64..8bbf9b9fd43 100644 --- a/src/main/java/org/spongepowered/common/event/inventory/InventoryEventFactory.java +++ b/src/main/java/org/spongepowered/common/event/inventory/InventoryEventFactory.java @@ -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 diff --git a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/ClickCreativeMenuTransaction.java b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/ClickCreativeMenuTransaction.java index b8f7fcc5b66..281f3025672 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/ClickCreativeMenuTransaction.java +++ b/src/main/java/org/spongepowered/common/event/tracking/context/transaction/inventory/ClickCreativeMenuTransaction.java @@ -74,7 +74,7 @@ Optional 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)); } diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketContext.java b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketContext.java index 136d919fb31..578068f5a90 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketContext.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketContext.java @@ -77,7 +77,7 @@ public > K getPacket() { public P itemUsed(final ItemStack stack) { this.itemUsed = stack; - this.itemUsedSnapshot = this.itemUsed.createSnapshot(); + this.itemUsedSnapshot = this.itemUsed.asImmutable(); return (P) this; } diff --git a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java index 3e6f610aaa2..db98191c158 100644 --- a/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java +++ b/src/main/java/org/spongepowered/common/event/tracking/phase/packet/PacketPhaseUtil.java @@ -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))); diff --git a/src/main/java/org/spongepowered/common/inventory/EmptyInventoryImpl.java b/src/main/java/org/spongepowered/common/inventory/EmptyInventoryImpl.java index 5bd4a343b21..29724972bd8 100644 --- a/src/main/java/org/spongepowered/common/inventory/EmptyInventoryImpl.java +++ b/src/main/java/org/spongepowered/common/inventory/EmptyInventoryImpl.java @@ -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; @@ -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; } @@ -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(); } @@ -209,16 +210,16 @@ public Optional 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; } diff --git a/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java b/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java index faff14a5820..38317b9c96f 100644 --- a/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java +++ b/src/main/java/org/spongepowered/common/inventory/InventoryTransactionResultImpl.java @@ -28,7 +28,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.checkerframework.checker.nullness.qual.Nullable; -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.transaction.InventoryTransactionResult; import org.spongepowered.api.item.inventory.transaction.SlotTransaction; @@ -75,7 +75,7 @@ public InventoryTransactionResult and(InventoryTransactionResult other) { @Override public void revert() { for (SlotTransaction transaction : Lists.reverse(this.slotTransactions)) { - transaction.slot().set(transaction.original().createStack()); + transaction.slot().set(transaction.original()); } } @@ -127,35 +127,35 @@ public InventoryTransactionResult.Builder type(final InventoryTransactionResult. } @Override - public PollBuilder poll(ItemStackSnapshot itemStack) { + public PollBuilder poll(ItemStackLike itemStack) { if (this.polled == null) { this.polled = new ArrayList<>(); } - this.polled.add(itemStack); + this.polled.add(itemStack.asImmutable()); return this; } @Override - public InventoryTransactionResult.Builder reject(ItemStack... itemStacks) { + public InventoryTransactionResult.Builder reject(ItemStackLike... itemStacks) { if (this.rejected == null) { this.rejected = new ArrayList<>(); } - for (ItemStack itemStack1 : itemStacks) { + for (ItemStackLike itemStack1 : itemStacks) { if (!itemStack1.isEmpty()) { - this.rejected.add(itemStack1.createSnapshot()); + this.rejected.add(itemStack1.asImmutable()); } } return this; } @Override - public InventoryTransactionResult.Builder reject(Iterable itemStacks) { + public InventoryTransactionResult.Builder reject(Iterable itemStacks) { if (this.rejected == null) { this.rejected = new ArrayList<>(); } - for (ItemStackSnapshot itemStack1 : itemStacks) { + for (ItemStackLike itemStack1 : itemStacks) { if (!itemStack1.isEmpty()) { - this.rejected.add(itemStack1); + this.rejected.add(itemStack1.asImmutable()); } } return this; diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/AdapterLogic.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/AdapterLogic.java index cbf15b4aa19..dedae4cc143 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/AdapterLogic.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/AdapterLogic.java @@ -109,7 +109,7 @@ public static InventoryTransactionResult.Poll pollSequential(Fabric fabric, @Nul removedType.setQuantity(totalPolled); } - return result.poll(removedType.createSnapshot()).build(); + return result.poll(removedType).build(); } public static Optional peekSequential(Fabric fabric, @Nullable Lens lens) { diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/DefaultImplementedAdapterInventory.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/DefaultImplementedAdapterInventory.java index b173dd8b3b7..5715c7e4927 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/DefaultImplementedAdapterInventory.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/DefaultImplementedAdapterInventory.java @@ -28,6 +28,7 @@ import org.spongepowered.api.item.ItemType; 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.item.inventory.query.Query; import org.spongepowered.api.item.inventory.query.QueryTypes; @@ -97,17 +98,17 @@ default ItemStack peek() { } @Override - default InventoryTransactionResult offer(ItemStack... stacks) { + default InventoryTransactionResult offer(ItemStackLike... stacks) { InventoryTransactionResult result = InventoryTransactionResult.successNoTransactions(); - for (ItemStack stack : stacks) { - result = result.and(AdapterLogic.appendSequential(this.impl$getFabric(), this.impl$getLens(), stack)); + for (ItemStackLike stack : stacks) { + result = result.and(AdapterLogic.appendSequential(this.impl$getFabric(), this.impl$getLens(), stack.asMutable())); } return result; } @Override - default boolean canFit(ItemStack stack) { - return AdapterLogic.canFit(this.impl$getFabric(), this.impl$getLens(), stack); + default boolean canFit(ItemStackLike stack) { + return AdapterLogic.canFit(this.impl$getFabric(), this.impl$getLens(), stack.asMutable()); } @Override @@ -131,13 +132,13 @@ default boolean hasChildren() { } @Override - default boolean contains(ItemStack stack) { - return AdapterLogic.contains(((InventoryBridge) this).bridge$getAdapter(), stack); + default boolean contains(ItemStackLike stack) { + return AdapterLogic.contains(((InventoryBridge) this).bridge$getAdapter(), stack.asMutable()); } @Override - default boolean containsAny(ItemStack stack) { - return AdapterLogic.contains(((InventoryBridge) this).bridge$getAdapter(), stack, 1); + default boolean containsAny(ItemStackLike stack) { + return AdapterLogic.contains(((InventoryBridge) this).bridge$getAdapter(), stack.asMutable(), 1); } @Override @@ -208,13 +209,13 @@ default Optional peekAt(int index) { } @Override - default InventoryTransactionResult set(int index, ItemStack stack) { - return AdapterLogic.insertSequential(this.impl$getFabric(), this.impl$getLens().getSlotLens(this.impl$getFabric(), index), stack); + default InventoryTransactionResult set(int index, ItemStackLike stack) { + return AdapterLogic.insertSequential(this.impl$getFabric(), this.impl$getLens().getSlotLens(this.impl$getFabric(), index), stack.asMutable()); } @Override - default InventoryTransactionResult offer(int index, ItemStack stack) { - return AdapterLogic.appendSequential(this.impl$getFabric(), this.impl$getLens().getSlotLens(this.impl$getFabric(), index), stack); + default InventoryTransactionResult offer(int index, ItemStackLike stack) { + return AdapterLogic.appendSequential(this.impl$getFabric(), this.impl$getLens().getSlotLens(this.impl$getFabric(), index), stack.asMutable()); } @Override diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/EquipmentInventoryAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/EquipmentInventoryAdapter.java index 90f1d32060c..ec6d65c208a 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/EquipmentInventoryAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/EquipmentInventoryAdapter.java @@ -29,6 +29,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.Slot; import org.spongepowered.api.item.inventory.equipment.EquipmentInventory; import org.spongepowered.api.item.inventory.equipment.EquipmentType; @@ -79,7 +80,7 @@ public Optional peek(EquipmentType equipmentType) { } @Override - public InventoryTransactionResult set(EquipmentType equipmentType, ItemStack stack) { + public InventoryTransactionResult set(EquipmentType equipmentType, ItemStackLike stack) { Inventory query = this.queryForType(equipmentType); if (query.capacity() == 0) { return InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.NO_SLOT).build(); diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/GridInventoryAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/GridInventoryAdapter.java index 5e9b6f45c1d..56fc8e6a6a8 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/GridInventoryAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/GridInventoryAdapter.java @@ -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.item.inventory.transaction.InventoryTransactionResult; import org.spongepowered.api.item.inventory.type.GridInventory; @@ -110,8 +111,8 @@ public Optional peek(int x, int y) { } @Override - public InventoryTransactionResult set(int x, int y, ItemStack stack) { - return AdapterLogic.insertSequential(this.inventoryAdapter$getFabric(), this.getSlotLens(x, y), stack); + public InventoryTransactionResult set(int x, int y, ItemStackLike stack) { + return AdapterLogic.insertSequential(this.inventoryAdapter$getFabric(), this.getSlotLens(x, y), stack.asMutable()); } } diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/Inventory2DAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/Inventory2DAdapter.java index 3bc74c369c5..43c7330af0d 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/Inventory2DAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/comp/Inventory2DAdapter.java @@ -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.item.inventory.transaction.InventoryTransactionResult; import org.spongepowered.api.item.inventory.type.Inventory2D; @@ -76,8 +77,8 @@ public Optional peek(Vector2i pos) { } @Override - public InventoryTransactionResult set(Vector2i pos, ItemStack stack) { - return AdapterLogic.insertSequential(this.inventoryAdapter$getFabric(), this.getSlotLens(pos), stack); + public InventoryTransactionResult set(Vector2i pos, ItemStackLike stack) { + return AdapterLogic.insertSequential(this.inventoryAdapter$getFabric(), this.getSlotLens(pos), stack.asMutable()); } } diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/FilteringSlotAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/FilteringSlotAdapter.java index 9a6d2634194..55bc5c8e004 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/FilteringSlotAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/FilteringSlotAdapter.java @@ -27,11 +27,11 @@ import org.spongepowered.api.item.ItemType; 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.FilteringSlot; import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; import org.spongepowered.common.inventory.fabric.Fabric; import org.spongepowered.common.inventory.lens.impl.slot.FilteringSlotLens; -import org.spongepowered.common.item.util.ItemStackUtil; public class FilteringSlotAdapter extends SlotAdapter implements FilteringSlot { @@ -43,7 +43,7 @@ public FilteringSlotAdapter(Fabric fabric, FilteringSlotLens lens, Inventory par } @Override - public boolean isValidItem(ItemStack stack) { + public boolean isValidItem(ItemStackLike stack) { FilteringSlotLens.ItemStackFilter filter = this.filteringSlot.getItemStackFilter(); return filter == null || filter.test(this.impl$getFabric(), stack); } @@ -68,11 +68,11 @@ public InventoryTransactionResult offer(ItemStack stack) { */ @Override - public InventoryTransactionResult set(ItemStack stack) { + public InventoryTransactionResult set(ItemStackLike stack) { final boolean canSet = this.isValidItem(stack); if (!canSet) { final InventoryTransactionResult.Builder result = InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.FAILURE); - result.reject(ItemStackUtil.cloneDefensive(stack)); + result.reject(stack); return result.build(); } diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/HeldSlotAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/HeldSlotAdapter.java index 9db3afc51ea..03cb0814e44 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/HeldSlotAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/HeldSlotAdapter.java @@ -26,13 +26,12 @@ import org.spongepowered.api.item.ItemType; 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.EquipmentType; import org.spongepowered.api.item.inventory.slot.EquipmentSlot; import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; import org.spongepowered.common.inventory.fabric.Fabric; import org.spongepowered.common.inventory.lens.impl.slot.HeldHandSlotLens; -import org.spongepowered.common.item.util.ItemStackUtil; import java.util.function.Predicate; @@ -52,8 +51,8 @@ public boolean isValidItem(EquipmentType type) { } @Override - public boolean isValidItem(ItemStack stack) { - Predicate filter = this.equipmentSlot.getItemStackFilter(); + public boolean isValidItem(ItemStackLike stack) { + Predicate filter = this.equipmentSlot.getItemStackFilter(); return filter == null || filter.test(stack); } @@ -64,11 +63,11 @@ public boolean isValidItem(ItemType type) { } @Override - public InventoryTransactionResult set(ItemStack stack) { + public InventoryTransactionResult set(ItemStackLike stack) { final boolean canSet = this.isValidItem(stack); if (!canSet) { final InventoryTransactionResult.Builder result = InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.FAILURE); - result.reject(ItemStackUtil.cloneDefensive(stack)); + result.reject(stack); return result.build(); } diff --git a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/SlotAdapter.java b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/SlotAdapter.java index 5627c398cf3..569c5c30bb2 100644 --- a/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/SlotAdapter.java +++ b/src/main/java/org/spongepowered/common/inventory/adapter/impl/slots/SlotAdapter.java @@ -30,6 +30,7 @@ import org.spongepowered.api.item.ItemTypes; 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.transaction.InventoryTransactionResult; @@ -89,11 +90,11 @@ public ItemStack peek() { } @Override - public InventoryTransactionResult offer(final ItemStack... stacks) { + public InventoryTransactionResult offer(final ItemStackLike... stacks) { final InventoryTransactionResult.Builder result = InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.SUCCESS); - for (ItemStack stack : stacks) { - final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.toNative(stack); + for (ItemStackLike stack : stacks) { + final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.fromLikeToNative(stack); final int maxStackSize = this.slot.getMaxStackSize(this.inventoryAdapter$getFabric()); int remaining = stack.quantity(); @@ -105,7 +106,7 @@ public InventoryTransactionResult offer(final ItemStack... stacks) { if (old.isEmpty() && this.slot.setStack(this.inventoryAdapter$getFabric(), ItemStackUtil.cloneDefensiveNative(nativeStack, push))) { remaining -= push; newStack = ItemStackUtil.snapshotOf(stack); - } else if (!old.isEmpty() && ItemStackUtil.compareIgnoreQuantity(old, stack) && maxStackSize > old.getCount()) { + } else if (!old.isEmpty() && ItemStackUtil.compareIgnoreQuantity(old, nativeStack) && maxStackSize > old.getCount()) { this.inventoryAdapter$getFabric().fabric$markDirty(); push = Math.max(Math.min(maxStackSize - old.getCount(), remaining), 0); // max() accounts for oversized stacks old.setCount(old.getCount() + push); @@ -124,7 +125,7 @@ public InventoryTransactionResult offer(final ItemStack... stacks) { } @Override - public boolean canFit(final ItemStack stack) { + public boolean canFit(final ItemStackLike stack) { if (stack.isEmpty()) { return true; } @@ -133,13 +134,13 @@ public boolean canFit(final ItemStack stack) { if (old.isEmpty()) { return maxStackSize >= stack.quantity(); } - return ItemStackUtil.compareIgnoreQuantity(old, stack) && maxStackSize - old.getCount() >= stack.quantity(); + return ItemStackUtil.compareIgnoreQuantity(old, stack.asMutable()) && maxStackSize - old.getCount() >= stack.quantity(); } @Override - public InventoryTransactionResult set(final ItemStack stack) { + public InventoryTransactionResult set(final ItemStackLike stack) { final InventoryTransactionResult.Builder result = InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.SUCCESS); - final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.toNative(stack); + final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.fromLikeToNative(stack); final net.minecraft.world.item.ItemStack old = this.slot.getStack(this.inventoryAdapter$getFabric()); ItemStackSnapshot oldSnap = ItemStackUtil.snapshotOf(old); @@ -189,16 +190,16 @@ public boolean hasChildren() { } @Override - public boolean contains(final ItemStack stack) { + public boolean contains(final ItemStackLike stack) { final net.minecraft.world.item.ItemStack slotStack = this.slot.getStack(this.inventoryAdapter$getFabric()); - return slotStack.isEmpty() ? ItemStackUtil.toNative(stack).isEmpty() : - ItemStackUtil.compareIgnoreQuantity(slotStack, stack) && slotStack.getCount() >= stack.quantity(); + return slotStack.isEmpty() ? ItemStackUtil.fromLikeToNative(stack).isEmpty() : + ItemStackUtil.compareIgnoreQuantity(slotStack, stack.asMutable()) && slotStack.getCount() >= stack.quantity(); } @Override - public boolean containsAny(final ItemStack stack) { + public boolean containsAny(final ItemStackLike stack) { final net.minecraft.world.item.ItemStack slotStack = this.slot.getStack(this.inventoryAdapter$getFabric()); - return slotStack.isEmpty() ? ItemStackUtil.toNative(stack).isEmpty() : ItemStackUtil.compareIgnoreQuantity(slotStack, stack); + return slotStack.isEmpty() ? ItemStackUtil.fromLikeToNative(stack).isEmpty() : ItemStackUtil.compareIgnoreQuantity(slotStack, stack.asMutable()); } @Override diff --git a/src/main/java/org/spongepowered/common/inventory/custom/SpongeViewableInventoryBuilder.java b/src/main/java/org/spongepowered/common/inventory/custom/SpongeViewableInventoryBuilder.java index 4d04c948206..c37c4dd9a56 100644 --- a/src/main/java/org/spongepowered/common/inventory/custom/SpongeViewableInventoryBuilder.java +++ b/src/main/java/org/spongepowered/common/inventory/custom/SpongeViewableInventoryBuilder.java @@ -58,7 +58,7 @@ import org.spongepowered.api.item.inventory.ContainerType; import org.spongepowered.api.item.inventory.ContainerTypes; import org.spongepowered.api.item.inventory.Inventory; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.inventory.Slot; import org.spongepowered.api.item.inventory.type.ViewableInventory; import org.spongepowered.api.registry.DefaultedRegistryReference; @@ -214,8 +214,8 @@ public BuildingStep grid(List source, Vector2i size, int offset) { } // dummy @Override - public BuildingStep item(ItemStackSnapshot item) { - this.lastSlot.set(item.createStack()); + public BuildingStep item(ItemStackLike item) { + this.lastSlot.set(item); return this; } diff --git a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/EquipmentSlotLens.java b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/EquipmentSlotLens.java index 0af32460cec..e63fe04826a 100644 --- a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/EquipmentSlotLens.java +++ b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/EquipmentSlotLens.java @@ -52,7 +52,7 @@ private static FilteringSlotLens.ItemStackFilter equipmentTypeFilter(EquipmentTy if (item.isEmpty()) { return true; } - final var equipable = Equipable.get(ItemStackUtil.toNative(item)); + final var equipable = Equipable.get(ItemStackUtil.fromLikeToNative(item)); final var itemSlotType = equipable != null ? equipable.getEquipmentSlot() : EquipmentSlot.MAINHAND; return itemSlotType == (Object) type; }; diff --git a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/FilteringSlotLens.java b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/FilteringSlotLens.java index 0938f34361d..cb1e0731a35 100644 --- a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/FilteringSlotLens.java +++ b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/FilteringSlotLens.java @@ -26,7 +26,7 @@ import net.minecraft.world.Container; 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.common.bridge.world.inventory.InventoryBridge; import org.spongepowered.common.inventory.adapter.impl.slots.FilteringSlotAdapter; @@ -59,7 +59,7 @@ public Slot getAdapter(Fabric fabric, Inventory parent) { @FunctionalInterface public interface ItemStackFilter { - boolean test(Fabric fabric, ItemStack itemStack); + boolean test(Fabric fabric, ItemStackLike itemStack); static ItemStackFilter filterNone() { return (f, i) -> true; @@ -69,7 +69,7 @@ static ItemStackFilter filterIInventory(int slot) { return (fabric, item) -> { InventoryBridge inventory = fabric.fabric$get(slot); if (inventory instanceof Container) { - return ((Container) inventory).canPlaceItem(slot, ItemStackUtil.toNative(item)); + return ((Container) inventory).canPlaceItem(slot, ItemStackUtil.fromLikeToNative(item)); } return true; }; diff --git a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/HeldHandSlotLens.java b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/HeldHandSlotLens.java index 17e5e74d0cc..92e0b4ec5eb 100644 --- a/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/HeldHandSlotLens.java +++ b/src/main/java/org/spongepowered/common/inventory/lens/impl/slot/HeldHandSlotLens.java @@ -28,6 +28,7 @@ import org.spongepowered.api.data.Key; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.Inventory; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.inventory.Slot; import org.spongepowered.api.item.inventory.equipment.EquipmentType; import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; @@ -151,7 +152,7 @@ public Predicate getEquipmentTypeFilter() { return (e) -> e == EquipmentTypes.MAINHAND.get(); } - public Predicate getItemStackFilter() { + public Predicate getItemStackFilter() { return (i) -> true; } diff --git a/src/main/java/org/spongepowered/common/item/SpongeItemStackSnapshot.java b/src/main/java/org/spongepowered/common/item/SpongeItemStackSnapshot.java index abd9ecd8a4b..989ec9f0261 100644 --- a/src/main/java/org/spongepowered/common/item/SpongeItemStackSnapshot.java +++ b/src/main/java/org/spongepowered/common/item/SpongeItemStackSnapshot.java @@ -27,6 +27,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import net.minecraft.core.component.DataComponentPatch; import org.checkerframework.checker.nullness.qual.Nullable; @@ -40,15 +41,19 @@ import org.spongepowered.api.data.persistence.InvalidDataException; import org.spongepowered.api.data.value.MergeFunction; import org.spongepowered.api.data.value.Value; +import org.spongepowered.api.entity.attribute.AttributeModifier; +import org.spongepowered.api.entity.attribute.type.AttributeType; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.equipment.EquipmentType; import org.spongepowered.api.registry.RegistryTypes; import org.spongepowered.common.adventure.SpongeAdventure; import org.spongepowered.common.bridge.data.SpongeDataHolderBridge; import org.spongepowered.common.item.util.ItemStackUtil; import org.spongepowered.common.util.Constants; +import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -119,20 +124,13 @@ public boolean isEmpty() { return this.privateStack.isEmpty(); } - public boolean isNone() { - throw new UnsupportedOperationException("Implement is empty"); + @Override + public Collection attributeModifiers(AttributeType attributeType, EquipmentType equipmentType) { + return this.privateStack.attributeModifiers(attributeType, equipmentType); } - @Override - public ItemStack createStack() { - final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.cloneDefensiveNative(ItemStackUtil.toNative(this.privateStack.copy())); - if(this.components != null) { - nativeStack.applyComponents(this.components); - } - for (final DataManipulator.Immutable manipulator : this.manipulators) { - ((ItemStack) (Object) nativeStack).copyFrom(manipulator); - } - return ItemStackUtil.fromNative(nativeStack); + public boolean isNone() { + throw new UnsupportedOperationException("Implement is empty"); } @Override @@ -142,7 +140,7 @@ public int contentVersion() { @Override public DataContainer toContainer() { - return SpongeItemStack.getDataContainer((net.minecraft.world.item.ItemStack) (Object) this.createStack()); + return SpongeItemStack.getDataContainer((net.minecraft.world.item.ItemStack) (Object) this.asMutable()); } @Override @@ -152,7 +150,7 @@ public Optional transform(final Key> k if (result.type() != DataTransactionResult.Type.SUCCESS) { return Optional.empty(); } - return Optional.of(copy.createSnapshot()); + return Optional.of(copy.asImmutable()); } @Override @@ -162,7 +160,7 @@ public Optional with(final Key> key, f if (result.type() != DataTransactionResult.Type.SUCCESS) { return Optional.empty(); } - return Optional.of(copy.createSnapshot()); + return Optional.of(copy.asImmutable()); } @Override @@ -186,6 +184,28 @@ public boolean supports(final Key key) { return this.privateStack.supports(key); } + @Override + public ItemStack asMutable() { + final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.cloneDefensiveNative(ItemStackUtil.toNative(this.privateStack.copy())); + if (this.components != null) { + nativeStack.applyComponents(this.components); + } + for (final DataManipulator.Immutable manipulator : this.manipulators) { + ((ItemStack) (Object) nativeStack).copyFrom(manipulator); + } + return ItemStackUtil.fromNative(nativeStack); + } + + @Override + public ItemStack asMutableCopy() { + return this.asMutable(); + } + + @Override + public ItemStackSnapshot asImmutable() { + return this; + } + @Override public ItemStackSnapshot copy() { return this; @@ -233,7 +253,7 @@ public void setCreator(final @Nullable UUID uuid) { public ItemStackSnapshot withRawData(DataView container) throws InvalidDataException { final ItemStack copy = this.privateStack.copy(); copy.setRawData(container); - return copy.createSnapshot(); + return copy.asImmutable(); } @Override @@ -243,14 +263,14 @@ public Optional without(Key key) { if (result.type() != DataTransactionResult.Type.SUCCESS) { return Optional.empty(); } - return Optional.of(copy.createSnapshot()); + return Optional.of(copy.asImmutable()); } @Override public ItemStackSnapshot mergeWith(ItemStackSnapshot that, MergeFunction function) { final ItemStack copy = this.privateStack.copy(); copy.copyFrom(that, function); - return copy.createSnapshot(); + return copy.asImmutable(); } @Override @@ -280,6 +300,11 @@ public int hashCode() { return Objects.hash(this.itemType, this.quantity, this.damageValue, this.components, this.creatorUniqueId); } + @Override + public Component asComponent() { + return this.privateStack.asComponent(); + } + @Override public HoverEvent asHoverEvent(final UnaryOperator op) { final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.ITEM_TYPE).valueKey(this.itemType); diff --git a/src/main/java/org/spongepowered/common/item/merchant/SpongeTradeOfferBuilder.java b/src/main/java/org/spongepowered/common/item/merchant/SpongeTradeOfferBuilder.java index 69dd24557da..c189fd8f13d 100644 --- a/src/main/java/org/spongepowered/common/item/merchant/SpongeTradeOfferBuilder.java +++ b/src/main/java/org/spongepowered/common/item/merchant/SpongeTradeOfferBuilder.java @@ -36,6 +36,7 @@ import org.spongepowered.api.data.persistence.DataView; import org.spongepowered.api.data.persistence.InvalidDataException; 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.merchant.TradeOffer; import org.spongepowered.common.accessor.world.item.trading.MerchantOfferAccessor; @@ -64,22 +65,22 @@ public SpongeTradeOfferBuilder() { } @Override - public TradeOffer.Builder firstBuyingItem(final ItemStack item) { + public TradeOffer.Builder firstBuyingItem(final ItemStackLike item) { Objects.requireNonNull(item, "Buying item cannot be null"); - this.firstItem = item.createSnapshot(); + this.firstItem = item.asImmutable(); return this; } @SuppressWarnings("ConstantConditions") @Override - public TradeOffer.Builder secondBuyingItem(final ItemStack item) { - this.secondItem = item != null ? item.createSnapshot() : ItemStackSnapshot.empty(); + public TradeOffer.Builder secondBuyingItem(final ItemStackLike item) { + this.secondItem = item != null ? item.asImmutable() : ItemStackSnapshot.empty(); return this; } @Override - public TradeOffer.Builder sellingItem(final ItemStack item) { - this.sellingItem = item.createSnapshot(); + public TradeOffer.Builder sellingItem(final ItemStackLike item) { + this.sellingItem = item.asImmutable(); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/SpongeRecipeInputFactory.java b/src/main/java/org/spongepowered/common/item/recipe/SpongeRecipeInputFactory.java index 0f591977d30..487cb57c392 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/SpongeRecipeInputFactory.java +++ b/src/main/java/org/spongepowered/common/item/recipe/SpongeRecipeInputFactory.java @@ -27,7 +27,7 @@ import net.minecraft.world.item.crafting.CraftingInput; import net.minecraft.world.item.crafting.SingleRecipeInput; import net.minecraft.world.item.crafting.SmithingRecipeInput; -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.item.inventory.type.GridInventory; import org.spongepowered.api.item.recipe.crafting.RecipeInput; @@ -36,13 +36,13 @@ public final class SpongeRecipeInputFactory implements RecipeInput.Factory { @Override - public RecipeInput.Single single(final ItemStack stack) { - return (RecipeInput.Single) (Object) new SingleRecipeInput(ItemStackUtil.toNative(stack)); + public RecipeInput.Single single(final ItemStackLike stack) { + return (RecipeInput.Single) (Object) new SingleRecipeInput(ItemStackUtil.fromLikeToNative(stack)); } @Override - public RecipeInput.Smithing smithing(final ItemStack template, final ItemStack base, final ItemStack addtion) { - return (RecipeInput.Smithing) (Object) new SmithingRecipeInput(ItemStackUtil.toNative(template), ItemStackUtil.toNative(base), ItemStackUtil.toNative(addtion)); + public RecipeInput.Smithing smithing(final ItemStackLike template, final ItemStackLike base, final ItemStackLike addtion) { + return (RecipeInput.Smithing) (Object) new SmithingRecipeInput(ItemStackUtil.fromLikeToNative(template), ItemStackUtil.fromLikeToNative(base), ItemStackUtil.fromLikeToNative(addtion)); } @Override diff --git a/src/main/java/org/spongepowered/common/item/recipe/cooking/SpongeCookingRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/cooking/SpongeCookingRecipeBuilder.java index ba328b162e8..d173ba4a708 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/cooking/SpongeCookingRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/cooking/SpongeCookingRecipeBuilder.java @@ -35,7 +35,7 @@ import org.spongepowered.api.datapack.DataPack; import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.ItemType; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.RecipeType; import org.spongepowered.api.item.recipe.cooking.CookingRecipe; @@ -92,21 +92,16 @@ public EndStep result(final ItemType result) { } @Override - public EndStep result(final org.spongepowered.api.item.inventory.ItemStack result) { - this.result = ItemStackUtil.toNative(result); + public EndStep result(final ItemStackLike result) { + this.result = ItemStackUtil.fromLikeToNative(result); this.resultFunction = null; return this; } - @Override - public EndStep result(final ItemStackSnapshot result) { - return this.result(result.createStack()); - } - // currently unused - public EndStep result(final Function resultFunction, final org.spongepowered.api.item.inventory.ItemStack exemplaryResult) { - this.result = ItemStackUtil.toNative(exemplaryResult); - this.resultFunction = (inv) -> ItemStackUtil.toNative(resultFunction.apply(InventoryUtil.toSponge(inv))); + public EndStep result(final Function resultFunction, final ItemStackLike exemplaryResult) { + this.result = ItemStackUtil.fromLikeToNative(exemplaryResult); + this.resultFunction = (inv) -> ItemStackUtil.fromLikeToNative(resultFunction.apply(InventoryUtil.toSponge(inv))); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/crafting/custom/SpongeSpecialCraftingRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/crafting/custom/SpongeSpecialCraftingRecipeBuilder.java index 0fc65ff976c..358ecafd86e 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/crafting/custom/SpongeSpecialCraftingRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/crafting/custom/SpongeSpecialCraftingRecipeBuilder.java @@ -30,6 +30,7 @@ import org.spongepowered.api.datapack.DataPack; import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.crafting.RecipeInput; import org.spongepowered.api.item.recipe.crafting.SpecialCraftingRecipe; @@ -57,20 +58,20 @@ public ResultStep matching(BiPredicate biPred } @Override - public ResultStep remainingItems(Function> remainingItemsFunction) { - this.remainingItemsFunction = remainingItemsFunction; + public ResultStep remainingItems(Function> remainingItemsFunction) { + this.remainingItemsFunction = inv -> remainingItemsFunction.apply(inv).stream().map(ItemStackLike::asMutable).toList(); return this; } @Override - public EndStep result(Function resultFunction) { - this.resultFunction = resultFunction; + public EndStep result(Function resultFunction) { + this.resultFunction = inv -> resultFunction.apply(inv).asMutable(); return this; } @Override - public EndStep result(ItemStack result) { - final ItemStack copy = result.copy(); + public EndStep result(ItemStackLike result) { + final ItemStack copy = result.asMutableCopy(); this.resultFunction = inv -> copy.copy(); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/crafting/shaped/SpongeShapedCraftingRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/crafting/shaped/SpongeShapedCraftingRecipeBuilder.java index cbc3331d1d2..58022355737 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/crafting/shaped/SpongeShapedCraftingRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/crafting/shaped/SpongeShapedCraftingRecipeBuilder.java @@ -37,7 +37,7 @@ import org.spongepowered.api.datapack.DataPack; import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.crafting.Ingredient; import org.spongepowered.api.item.recipe.crafting.RecipeInput; @@ -138,33 +138,27 @@ public RowsStep.ResultStep row(final int skip, final Ingredient... ingredients) } @Override - public ShapedCraftingRecipe.Builder.ResultStep remainingItems(Function> remainingItemsFunction) { + public ShapedCraftingRecipe.Builder.ResultStep remainingItems(Function> remainingItemsFunction) { this.remainingItemsFunction = grid -> { final NonNullList mcList = NonNullList.create(); - remainingItemsFunction.apply(InventoryUtil.toSponge(grid)).forEach(stack -> mcList.add(ItemStackUtil.toNative(stack))); + remainingItemsFunction.apply(InventoryUtil.toSponge(grid)).forEach(stack -> mcList.add(ItemStackUtil.fromLikeToNative(stack))); return mcList; }; return this; } @Override - public EndStep result(ItemStackSnapshot result) { + public EndStep result(final ItemStackLike result) { Objects.requireNonNull(result, "result"); - return this.result(result.createStack()); - } - - @Override - public EndStep result(final ItemStack result) { - Objects.requireNonNull(result, "result"); - this.result = result.copy(); + this.result = result.asMutableCopy(); this.resultFunction = null; return this; } @Override - public EndStep result(Function resultFunction, ItemStack exemplaryResult) { - this.resultFunction = (inv) -> ItemStackUtil.toNative(resultFunction.apply(InventoryUtil.toSponge(inv))); - this.result = exemplaryResult.copy(); + public EndStep result(Function resultFunction, ItemStackLike exemplaryResult) { + this.resultFunction = (inv) -> ItemStackUtil.fromLikeToNative(resultFunction.apply(InventoryUtil.toSponge(inv))); + this.result = exemplaryResult.asMutableCopy(); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/crafting/shapeless/SpongeShapelessCraftingRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/crafting/shapeless/SpongeShapelessCraftingRecipeBuilder.java index cbdab7a7e60..f048d2256e0 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/crafting/shapeless/SpongeShapelessCraftingRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/crafting/shapeless/SpongeShapelessCraftingRecipeBuilder.java @@ -37,7 +37,7 @@ import org.spongepowered.api.datapack.DataPack; import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.ItemType; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.crafting.RecipeInput; import org.spongepowered.api.item.recipe.crafting.ShapelessCraftingRecipe; @@ -90,35 +90,27 @@ public ResultStep addIngredients(org.spongepowered.api.item.recipe.crafting.Ingr } @Override - public ResultStep remainingItems(Function> remainingItemsFunction) { + public ResultStep remainingItems(Function> remainingItemsFunction) { this.remainingItemsFunction = grid -> { final NonNullList mcList = NonNullList.create(); - remainingItemsFunction.apply(InventoryUtil.toSponge(grid)).forEach(stack -> mcList.add(ItemStackUtil.toNative(stack))); + remainingItemsFunction.apply(InventoryUtil.toSponge(grid)).forEach(stack -> mcList.add(ItemStackUtil.fromLikeToNative(stack))); return mcList; }; return this; } @Override - public EndStep result(final ItemStackSnapshot result) { + public EndStep result(ItemStackLike result) { Objects.requireNonNull(result, "result"); - this.result = result.createStack(); + this.result = result.asMutable(); this.resultFunction = null; return this; } @Override - public EndStep result(org.spongepowered.api.item.inventory.ItemStack result) { - Objects.requireNonNull(result, "result"); - this.result = result; - this.resultFunction = null; - return this; - } - - @Override - public EndStep result(Function resultFunction, org.spongepowered.api.item.inventory.ItemStack exemplaryResult) { - this.resultFunction = (input) -> ItemStackUtil.toNative(resultFunction.apply(InventoryUtil.toSponge(input))); - this.result = exemplaryResult.copy(); + public EndStep result(Function resultFunction, ItemStackLike exemplaryResult) { + this.resultFunction = (input) -> ItemStackUtil.fromLikeToNative(resultFunction.apply(InventoryUtil.toSponge(input))); + this.result = exemplaryResult.asMutableCopy(); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/ingredient/IngredientUtil.java b/src/main/java/org/spongepowered/common/item/recipe/ingredient/IngredientUtil.java index 6dfd4c78f46..23c02c5921f 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/ingredient/IngredientUtil.java +++ b/src/main/java/org/spongepowered/common/item/recipe/ingredient/IngredientUtil.java @@ -34,6 +34,7 @@ import org.spongepowered.api.ResourceKey; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.common.item.util.ItemStackUtil; import java.util.Arrays; @@ -70,7 +71,7 @@ public static org.spongepowered.api.item.recipe.crafting.Ingredient of(ItemStack return IngredientUtil.fromNative(ingredient); } - public static org.spongepowered.api.item.recipe.crafting.Ingredient of(ResourceKey key, Predicate predicate, ItemStack... stacks) { + public static org.spongepowered.api.item.recipe.crafting.Ingredient of(ResourceKey key, Predicate predicate, ItemStack... stacks) { final SpongeIngredient ingredient = SpongeIngredient.spongeFromPredicate(key, predicate, IngredientUtil.toNativeStacks(stacks)); return IngredientUtil.fromNative(ingredient); } diff --git a/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredient.java b/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredient.java index 8f3cbb0ef54..887b9e888ff 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredient.java +++ b/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredient.java @@ -33,6 +33,7 @@ import net.minecraft.world.item.crafting.Ingredient; import org.apache.commons.lang3.NotImplementedException; import org.spongepowered.api.ResourceKey; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.item.util.ItemStackUtil; @@ -154,7 +155,7 @@ public static SpongeIngredient spongeFromStacks(net.minecraft.world.item.ItemSta private final static Map> cachedPredicates = new HashMap<>(); - public static SpongeIngredient spongeFromPredicate(ResourceKey key, Predicate predicate, + public static SpongeIngredient spongeFromPredicate(ResourceKey key, Predicate predicate, net.minecraft.world.item.ItemStack... exemplaryIngredients) { final Predicate mcPredicate = stack -> predicate.test(ItemStackUtil.fromNative(stack)); final Predicate registeredPredicate = SpongeIngredient.cachedPredicates.get(key.toString()); diff --git a/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredientBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredientBuilder.java index fcc77af7a9f..f6f37dcee60 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredientBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/ingredient/SpongeIngredientBuilder.java @@ -27,7 +27,7 @@ import org.spongepowered.api.ResourceKey; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.crafting.Ingredient; import java.util.Arrays; @@ -39,7 +39,7 @@ public class SpongeIngredientBuilder implements Ingredient.Builder { private ItemType[] types; private ResourceKey itemTag; private ItemStack[] stacks; - private Predicate predicate; + private Predicate predicate; private ResourceKey key; @Override @@ -75,25 +75,18 @@ public Ingredient.Builder with(ResourceKey itemTag) { } @Override - public Ingredient.Builder with(ItemStack... types) { + public Ingredient.Builder with(ItemStackLike... types) { this.reset(); - this.stacks = types; + this.stacks = Arrays.stream(types).map(ItemStackLike::asMutable).toArray(ItemStack[]::new); return this; } @Override - public Ingredient.Builder with(ItemStackSnapshot... types) { + public Ingredient.Builder with(ResourceKey resourceKey, Predicate predicate, ItemStackLike... exemplaryTypes) { this.reset(); - this.stacks = Arrays.stream(types).map(ItemStackSnapshot::createStack).toArray(ItemStack[]::new); - return this; - } - - @Override - public Ingredient.Builder with(ResourceKey key, Predicate predicate, ItemStack... exemplaryTypes) { - this.reset(); - this.stacks = exemplaryTypes; + this.stacks = Arrays.stream(exemplaryTypes).map(ItemStackLike::asMutable).toArray(ItemStack[]::new); this.predicate = predicate; - this.key = key; + this.key = resourceKey; return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/smithing/SpongeSmithingRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/smithing/SpongeSmithingRecipeBuilder.java index 05c9ee108f6..d7eeb1bd5e7 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/smithing/SpongeSmithingRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/smithing/SpongeSmithingRecipeBuilder.java @@ -35,7 +35,7 @@ import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.crafting.RecipeInput; import org.spongepowered.api.item.recipe.smithing.SmithingRecipe; @@ -98,27 +98,20 @@ public ResultStep addition(org.spongepowered.api.item.recipe.crafting.Ingredient } @Override - public EndStep result(ItemStackSnapshot result) { - this.result = result.createStack(); - this.resultFunction = null; - return this; - } - - @Override - public EndStep result(final ItemStack result) { + public EndStep result(final ItemStackLike result) { Objects.requireNonNull(result, "result"); - this.result = result; + this.result = result.asMutable(); this.resultFunction = null; return this; } @Override - public EndStep result(Function resultFunction, ItemStack exemplaryResult) { + public EndStep result(Function resultFunction, ItemStackLike exemplaryResult) { Objects.requireNonNull(exemplaryResult, "exemplaryResult"); Preconditions.checkState(!exemplaryResult.isEmpty(), "exemplaryResult must not be empty"); - this.result = exemplaryResult; - this.resultFunction = (inv) -> ItemStackUtil.toNative(resultFunction.apply(InventoryUtil.toSponge(inv))); + this.result = exemplaryResult.asMutable(); + this.resultFunction = (inv) -> ItemStackUtil.fromLikeToNative(resultFunction.apply(InventoryUtil.toSponge(inv))); return this; } diff --git a/src/main/java/org/spongepowered/common/item/recipe/stonecutting/SpongeStoneCutterRecipeBuilder.java b/src/main/java/org/spongepowered/common/item/recipe/stonecutting/SpongeStoneCutterRecipeBuilder.java index 86b7be9c191..0c00ca927f2 100644 --- a/src/main/java/org/spongepowered/common/item/recipe/stonecutting/SpongeStoneCutterRecipeBuilder.java +++ b/src/main/java/org/spongepowered/common/item/recipe/stonecutting/SpongeStoneCutterRecipeBuilder.java @@ -35,7 +35,7 @@ import org.spongepowered.api.datapack.DataPacks; import org.spongepowered.api.item.ItemType; import org.spongepowered.api.item.inventory.ItemStack; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.RecipeRegistration; import org.spongepowered.api.item.recipe.crafting.RecipeInput; import org.spongepowered.api.item.recipe.single.StoneCutterRecipe; @@ -72,27 +72,20 @@ public ResultStep ingredient(org.spongepowered.api.item.recipe.crafting.Ingredie } @Override - public EndStep result(ItemStackSnapshot result) { - this.result = result.createStack(); - this.resultFunction = null; - return this; - } - - @Override - public EndStep result(final ItemStack result) { + public EndStep result(final ItemStackLike result) { Objects.requireNonNull(result, "result"); - this.result = result; + this.result = result.asMutable(); this.resultFunction = null; return this; } @Override - public EndStep result(Function resultFunction, ItemStack exemplaryResult) { + public EndStep result(Function resultFunction, ItemStackLike exemplaryResult) { Objects.requireNonNull(exemplaryResult, "exemplaryResult"); Preconditions.checkState(!exemplaryResult.isEmpty(), "exemplaryResult must not be empty"); - this.result = exemplaryResult; - this.resultFunction = (inv) -> ItemStackUtil.toNative(resultFunction.apply(InventoryUtil.toSponge(inv))); + this.result = exemplaryResult.asMutable(); + this.resultFunction = (inv) -> ItemStackUtil.fromLikeToNative(resultFunction.apply(InventoryUtil.toSponge(inv))); return this; } diff --git a/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java b/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java index 01003c458a5..b9b30d606d2 100644 --- a/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java +++ b/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java @@ -26,6 +26,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.inventory.ItemStackSnapshot; import java.util.Arrays; @@ -142,11 +143,11 @@ public static ItemStackSnapshot snapshotOf(net.minecraft.world.item.ItemStack it if (itemStack == null) { return ItemStackSnapshot.empty(); } - return itemStack.isEmpty() ? ItemStackSnapshot.empty() : ItemStackUtil.fromNative(itemStack).createSnapshot(); + return itemStack.isEmpty() ? ItemStackSnapshot.empty() : ItemStackUtil.fromNative(itemStack).asImmutable(); } - public static ItemStackSnapshot snapshotOf(@Nullable ItemStack itemStack) { - return itemStack == null ? ItemStackSnapshot.empty() : itemStack.isEmpty() ? ItemStackSnapshot.empty() : itemStack.createSnapshot(); + public static ItemStackSnapshot snapshotOf(@Nullable ItemStackLike itemStack) { + return itemStack == null ? ItemStackSnapshot.empty() : itemStack.isEmpty() ? ItemStackSnapshot.empty() : itemStack.asImmutable(); } public static List snapshotOf(final List items) { @@ -155,11 +156,15 @@ public static List snapshotOf(final List, Object> generateDefaultsForNamed(P || type == ParticleTypes.FALLING_DUST || type == ParticleTypes.DUST_PILLAR) { options.put(ParticleOptions.BLOCK_STATE.get(), BlockTypes.AIR.get().defaultState()); } else if (type == ParticleTypes.ITEM) { - options.put(ParticleOptions.ITEM_STACK_SNAPSHOT.get(), ItemStack.of(ItemTypes.STONE).createSnapshot()); + options.put(ParticleOptions.ITEM_STACK_SNAPSHOT.get(), ItemStack.of(ItemTypes.STONE).asImmutable()); } else if (type == ParticleTypes.DUST) { options.put(ParticleOptions.COLOR.get(), Color.RED); options.put(ParticleOptions.SCALE.get(), 1.0d); diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/ItemStackMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/ItemStackMixin_API.java index 4f57f1d9060..cca0e04b102 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/ItemStackMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/ItemStackMixin_API.java @@ -97,10 +97,6 @@ public abstract class ItemStackMixin_API implements SerializableDataHolder.Mutab this.shadow$setCount(quantity); } - public int itemStack$maxStackQuantity() { - return this.shadow$getMaxStackSize(); - } - @Override public boolean validateRawData(final DataView container) { Objects.requireNonNull(container); @@ -122,6 +118,18 @@ public void setRawData(final DataView container) throws InvalidDataException { } } + public ItemStack itemStack$asMutable() { + return (ItemStack) this; + } + + public ItemStack itemStack$asMutableCopy() { + return this.itemStack$copy(); + } + + public ItemStackSnapshot itemStack$asImmutable() { + return new SpongeItemStackSnapshot((ItemStack) this); + } + @Override public SerializableDataHolder.Mutable copy() { return this.itemStack$copy(); @@ -168,10 +176,6 @@ public DataContainer toContainer() { return SpongeItemStack.getDataContainer((net.minecraft.world.item.ItemStack) (Object) this); } - public ItemStackSnapshot itemStack$createSnapshot() { - return new SpongeItemStackSnapshot((ItemStack) this); - } - public boolean itemStack$equalTo(final ItemStack that) { return net.minecraft.world.item.ItemStack.matches( (net.minecraft.world.item.ItemStack) (Object) this, diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/AbstractCookingRecipeMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/AbstractCookingRecipeMixin_API.java index 609b3a7dba5..9075a7f4354 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/AbstractCookingRecipeMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/AbstractCookingRecipeMixin_API.java @@ -26,7 +26,7 @@ import net.minecraft.world.item.crafting.AbstractCookingRecipe; import net.minecraft.world.item.crafting.Ingredient; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.cooking.CookingRecipe; import org.spongepowered.api.item.recipe.cooking.CookingResult; import org.spongepowered.api.util.Ticks; @@ -54,12 +54,12 @@ public org.spongepowered.api.item.recipe.crafting.Ingredient ingredient() { } @Override - public boolean isValid(final ItemStackSnapshot ingredient) { - return this.ingredient.test(ItemStackUtil.fromSnapshotToNative(ingredient)); + public boolean isValid(final ItemStackLike ingredient) { + return this.ingredient.test(ItemStackUtil.fromLikeToNative(ingredient)); } @Override - public Optional result(final ItemStackSnapshot ingredient) { + public Optional result(final ItemStackLike ingredient) { if (this.isValid(ingredient)) { return Optional.of(new CookingResult(this.exemplaryResult(), this.shadow$getExperience())); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/RecipeManagerMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/RecipeManagerMixin_API.java index efa6d8b2734..302ab6b23e0 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/RecipeManagerMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/crafting/RecipeManagerMixin_API.java @@ -32,7 +32,7 @@ import net.minecraft.world.item.crafting.SingleRecipeInput; import net.minecraft.world.level.Level; import org.spongepowered.api.ResourceKey; -import org.spongepowered.api.item.inventory.ItemStackSnapshot; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.recipe.Recipe; import org.spongepowered.api.item.recipe.RecipeManager; import org.spongepowered.api.item.recipe.RecipeType; @@ -79,11 +79,11 @@ public > Collection allOfType(final RecipeType type) { } @Override - public > Collection findByResult(final RecipeType type, final ItemStackSnapshot result) { + public > Collection findByResult(final RecipeType type, final ItemStackLike result) { Objects.requireNonNull(type); Objects.requireNonNull(result); return this.allOfType(type).stream() - .filter(r -> r.exemplaryResult().equals(result)) + .filter(r -> r.exemplaryResult().equals(result.asImmutable())) .collect(Collectors.toList()); } @@ -110,11 +110,11 @@ public Optional findCookingRecipe(final RecipeType type, final ItemStackSnapshot ingredient) { + public Optional findCookingRecipe(final RecipeType type, final ItemStackLike ingredient) { Objects.requireNonNull(type); Objects.requireNonNull(ingredient); - final SingleRecipeInput input = new SingleRecipeInput(ItemStackUtil.fromSnapshotToNative(ingredient)); + final SingleRecipeInput input = new SingleRecipeInput(ItemStackUtil.fromLikeToNative(ingredient)); return this.shadow$getRecipeFor((net.minecraft.world.item.crafting.RecipeType) type, input, null); } } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/enchantment/EnchantmentMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/enchantment/EnchantmentMixin_API.java index d8757a27774..3b20df6735d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/enchantment/EnchantmentMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/enchantment/EnchantmentMixin_API.java @@ -28,7 +28,7 @@ import net.minecraft.core.Holder; import net.minecraft.world.item.enchantment.Enchantment; import org.spongepowered.api.item.enchantment.EnchantmentType; -import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -74,13 +74,13 @@ public int maximumEnchantabilityForLevel(final int level) { } @Override - public boolean canBeAppliedByTable(final ItemStack stack) { + public boolean canBeAppliedByTable(final ItemStackLike stack) { return this.canBeAppliedToStack(stack); } @Override - public boolean canBeAppliedToStack(final ItemStack stack) { - return PlatformHooks.INSTANCE.getItemHooks().canEnchantmentBeAppliedToItem((Enchantment) (Object) this, ItemStackUtil.toNative(stack)); + public boolean canBeAppliedToStack(final ItemStackLike stack) { + return PlatformHooks.INSTANCE.getItemHooks().canEnchantmentBeAppliedToItem((Enchantment) (Object) this, ItemStackUtil.fromLikeToNative(stack)); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/trading/MerchantOfferMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/trading/MerchantOfferMixin_API.java index b3b25f14fb4..894ff40cded 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/trading/MerchantOfferMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/trading/MerchantOfferMixin_API.java @@ -55,7 +55,7 @@ public abstract class MerchantOfferMixin_API implements TradeOffer { @Override public ItemStackSnapshot firstBuyingItem() { - return ((ItemStack) (Object) this.shadow$getCostA()).createSnapshot(); + return ((ItemStack) (Object) this.shadow$getCostA()).asImmutable(); } @Override @@ -68,12 +68,12 @@ public Optional secondBuyingItem() { if (this.shadow$getCostB() == null) { return Optional.empty(); } - return Optional.of(((ItemStack) (Object) this.shadow$getCostB()).createSnapshot()); + return Optional.of(((ItemStack) (Object) this.shadow$getCostB()).asImmutable()); } @Override public ItemStackSnapshot sellingItem() { - return ((ItemStack) (Object) this.shadow$getResult()).createSnapshot(); + return ((ItemStack) (Object) this.shadow$getResult()).asImmutable(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/JukeboxBlockEntityMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/JukeboxBlockEntityMixin_API.java index 8c298d407be..885e62a88de 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/JukeboxBlockEntityMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/level/block/entity/JukeboxBlockEntityMixin_API.java @@ -31,7 +31,7 @@ import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.api.block.entity.Jukebox; import org.spongepowered.api.data.value.Value; -import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.common.item.util.ItemStackUtil; @@ -74,8 +74,8 @@ public void eject() { } @Override - public void insert(final ItemStack record) { - final net.minecraft.world.item.ItemStack itemStack = ItemStackUtil.toNative(record); + public void insert(final ItemStackLike record) { + final net.minecraft.world.item.ItemStack itemStack = ItemStackUtil.fromLikeToNative(record); final BlockState block = this.level.getBlockState(this.shadow$getBlockPos()); if (block.getBlock() == Blocks.JUKEBOX) { this.shadow$setTheItem(itemStack); diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/item/EmptyMapItemMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/item/EmptyMapItemMixin.java index 6bb0aeb5a62..9dd8afdc082 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/item/EmptyMapItemMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/item/EmptyMapItemMixin.java @@ -78,7 +78,7 @@ public abstract class EmptyMapItemMixin { frame.addContext(EventContextKeys.PLAYER, player); final HandType handType = (HandType) (Object) usedHand; frame.addContext(EventContextKeys.USED_HAND, handType); - frame.addContext(EventContextKeys.USED_ITEM, player.itemInHand(handType).createSnapshot()); + frame.addContext(EventContextKeys.USED_ITEM, player.itemInHand(handType).asImmutable()); final Set> mapValues = Sets.newHashSet( Value.immutableOf(Keys.MAP_LOCATION, Vector2i.from((int)playerIn.getX(), (int)playerIn.getZ())), diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/projectile/FishingHookMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/projectile/FishingHookMixin.java index 323795d0834..470c0bd30fb 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/projectile/FishingHookMixin.java +++ b/src/mixins/java/org/spongepowered/common/mixin/core/world/entity/projectile/FishingHookMixin.java @@ -144,7 +144,7 @@ public int retrieve(final ItemStack stack) { if (!transaction.isValid()) { continue; } - final ItemStack itemstack = (ItemStack) (Object) transaction.finalReplacement().createStack(); + final ItemStack itemstack = (ItemStack) (Object) transaction.finalReplacement().asMutable(); // Sponge end final ItemEntity entityitem = new ItemEntity(this.shadow$level(), this.shadow$getX(), this.shadow$getY(), this.shadow$getZ(), itemstack); diff --git a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/TraitMixin_ArmorEquipable_Inventory_API.java b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/TraitMixin_ArmorEquipable_Inventory_API.java index 4ab4b5a313d..66569883a51 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/TraitMixin_ArmorEquipable_Inventory_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/TraitMixin_ArmorEquipable_Inventory_API.java @@ -33,6 +33,7 @@ import org.spongepowered.api.data.type.HandType; import org.spongepowered.api.item.inventory.ArmorEquipable; import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.inventory.equipment.EquipmentType; import org.spongepowered.api.item.inventory.equipment.EquipmentTypes; import org.spongepowered.asm.mixin.Mixin; @@ -61,7 +62,7 @@ public boolean canEquip(final EquipmentType type) { } @Override - public boolean canEquip(final EquipmentType type, @Nullable final ItemStack equipment) { + public boolean canEquip(final EquipmentType type, @Nullable final ItemStackLike equipment) { return true; } @@ -74,11 +75,11 @@ public Optional equipped(final EquipmentType type) { } @Override - public boolean equip(final EquipmentType type, @Nullable final ItemStack equipment) { + public boolean equip(final EquipmentType type, @Nullable final ItemStackLike equipment) { final InventoryAdapter inv = ((InventoryBridge) this).bridge$getAdapter(); final EquipmentInventoryLens lens = this.impl$equipmentInventory(inv); final Fabric fabric = inv.inventoryAdapter$getFabric(); - return lens.getSlotLens(type).setStack(fabric, ItemStackUtil.toNative(equipment)); + return lens.getSlotLens(type).setStack(fabric, ItemStackUtil.fromLikeToNative(equipment)); } @Override @@ -89,9 +90,9 @@ public ItemStack itemInHand(HandType handType) { } @Override - public void setItemInHand(HandType handType, @Nullable ItemStack itemInHand) { + public void setItemInHand(HandType handType, @Nullable ItemStackLike itemInHand) { Objects.requireNonNull(handType); - ((LivingEntity) (Object)this).setItemInHand((InteractionHand) (Object) handType, ItemStackUtil.toNative(itemInHand).copy()); + ((LivingEntity) (Object)this).setItemInHand((InteractionHand) (Object) handType, ItemStackUtil.fromLikeToNative(itemInHand).copy()); } @Override @@ -100,7 +101,7 @@ public ItemStack head() { } @Override - public void setHead(ItemStack head) { + public void setHead(ItemStackLike head) { this.equip(EquipmentTypes.HEAD, head); } @@ -110,7 +111,7 @@ public ItemStack chest() { } @Override - public void setChest(ItemStack chest) { + public void setChest(ItemStackLike chest) { this.equip(EquipmentTypes.CHEST, chest); } @@ -120,7 +121,7 @@ public ItemStack legs() { } @Override - public void setLegs(ItemStack legs) { + public void setLegs(ItemStackLike legs) { this.equip(EquipmentTypes.LEGS, legs); } @@ -130,7 +131,7 @@ public ItemStack feet() { } @Override - public void setFeet(ItemStack feet) { + public void setFeet(ItemStackLike feet) { this.equip(EquipmentTypes.FEET, feet); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/inventory/container/ContainerMixin_Inventory_API.java b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/inventory/container/ContainerMixin_Inventory_API.java index b553b02a922..993ad3a9af0 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/inventory/container/ContainerMixin_Inventory_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/inventory/container/ContainerMixin_Inventory_API.java @@ -33,6 +33,7 @@ import org.spongepowered.api.entity.living.player.server.ServerPlayer; import org.spongepowered.api.item.inventory.ContainerType; import org.spongepowered.api.item.inventory.Inventory; +import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.item.inventory.menu.InventoryMenu; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -88,11 +89,11 @@ public List viewed() { } @Override - public boolean setCursor(org.spongepowered.api.item.inventory.ItemStack item) { + public boolean setCursor(ItemStackLike item) { if (!this.isOpen()) { return false; } - ItemStack nativeStack = ItemStackUtil.toNative(item); + ItemStack nativeStack = ItemStackUtil.fromLikeToNative(item); this.listeners().stream().findFirst() .ifPresent(p -> p.containerMenu.setCarried(nativeStack)); return true; diff --git a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/world/inventory/SlotMixin_Inventory_API.java b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/world/inventory/SlotMixin_Inventory_API.java index 3b5837f2531..16790079ee4 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/inventory/api/world/inventory/SlotMixin_Inventory_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/inventory/api/world/inventory/SlotMixin_Inventory_API.java @@ -27,7 +27,7 @@ import net.minecraft.world.Container; import net.minecraft.world.inventory.Slot; 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.transaction.InventoryTransactionResult; import org.spongepowered.api.item.inventory.transaction.SlotTransaction; @@ -62,9 +62,9 @@ public org.spongepowered.api.item.inventory.Slot viewedSlot() { } @Override - public InventoryTransactionResult set(ItemStack stack) { + public InventoryTransactionResult set(ItemStackLike stack) { final InventoryTransactionResult.Builder result = InventoryTransactionResult.builder().type(InventoryTransactionResult.Type.SUCCESS); - final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.toNative(stack); + final net.minecraft.world.item.ItemStack nativeStack = ItemStackUtil.fromLikeToNative(stack); final net.minecraft.world.item.ItemStack old = this.shadow$getItem(); ItemStackSnapshot oldSnap = ItemStackUtil.snapshotOf(old); diff --git a/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java index 84541eb6c7e..67d263c5a9d 100644 --- a/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java @@ -482,7 +482,7 @@ public void testData(final ServerPlayer player) { this.checkGetData(jungleAxe, Keys.DISPLAY_NAME, Component.translatable("chat.square_brackets").args(Component.empty().append(Component.text("Jungle Axe")).decorate(TextDecoration.ITALIC)) - .color(NamedTextColor.WHITE).hoverEvent(jungleAxe.createSnapshot().asHoverEvent())); + .color(NamedTextColor.WHITE).hoverEvent(jungleAxe.asImmutable().asHoverEvent())); this.checkGetData(shulkerBullet, Keys.DISPLAY_NAME, Component.text("Angry Shulker Bullet") .hoverEvent(HoverEvent.showEntity(ResourceKey.minecraft("shulker_bullet"), shulkerBullet.uniqueId(), Component.text("Angry Shulker Bullet"))) .insertion(shulkerBullet.uniqueId().toString())); @@ -968,14 +968,14 @@ public void testData(final ServerPlayer player) { this.checkGetData(jungleAxe, Keys.ITEM_RARITY, ItemRarities.COMMON.get()); this.checkGetData(playerHeadStack, Keys.ITEM_RARITY, ItemRarities.UNCOMMON.get()); - this.checkOfferData(itemEntity, Keys.ITEM_STACK_SNAPSHOT, jungleAxe.createSnapshot()); + this.checkOfferData(itemEntity, Keys.ITEM_STACK_SNAPSHOT, jungleAxe.asImmutable()); final Entity itemFrame = world.createEntity(EntityTypes.ITEM_FRAME.get(), position); - this.checkOfferData(itemFrame, Keys.ITEM_STACK_SNAPSHOT, stoneStack.createSnapshot()); + this.checkOfferData(itemFrame, Keys.ITEM_STACK_SNAPSHOT, stoneStack.asImmutable()); // TODO JukeBox // TODO Lectern final Entity potionEntity = world.createEntity(EntityTypes.POTION.get(), position); - this.checkOfferData(potionEntity, Keys.ITEM_STACK_SNAPSHOT, splashPotion.createSnapshot()); // TODO unset original value causes logging error + this.checkOfferData(potionEntity, Keys.ITEM_STACK_SNAPSHOT, splashPotion.asImmutable()); // TODO unset original value causes logging error // TODO Keys.KNOCKBACK_STRENGTH diff --git a/testplugins/src/main/java/org/spongepowered/test/entity/DisplayEntityTest.java b/testplugins/src/main/java/org/spongepowered/test/entity/DisplayEntityTest.java index 3d9c74a991a..f0317c60f4f 100644 --- a/testplugins/src/main/java/org/spongepowered/test/entity/DisplayEntityTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/entity/DisplayEntityTest.java @@ -94,7 +94,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { textDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.FIXED.get()); var itemDisplay = spawnEntity(player.world(), EntityTypes.ITEM_DISPLAY, centerPos, forwardDir, col2, 0); - itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.NETHERITE_INGOT).createSnapshot()); + itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.NETHERITE_INGOT).asImmutable()); itemDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.FIXED.get()); textDisplay = spawnEntity(player.world(), EntityTypes.TEXT_DISPLAY, centerPos, forwardDir, col1, 0); @@ -105,7 +105,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { textDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.CENTER.get()); itemDisplay = spawnEntity(player.world(), EntityTypes.ITEM_DISPLAY, centerPos, forwardDir, col2, 1); - itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.DIAMOND).createSnapshot()); + itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.DIAMOND).asImmutable()); itemDisplay.offer(Keys.BLOCK_LIGHT, 15); itemDisplay.offer(Keys.SKY_LIGHT, 15); itemDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.CENTER.get()); @@ -118,7 +118,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { textDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.HORIZONTAL.get()); itemDisplay = spawnEntity(player.world(), EntityTypes.ITEM_DISPLAY, centerPos, forwardDir, col2, 2); - itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.IRON_INGOT).createSnapshot()); + itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.IRON_INGOT).asImmutable()); itemDisplay.offer(Keys.BLOCK_LIGHT, 15); itemDisplay.offer(Keys.SKY_LIGHT, 0); itemDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.HORIZONTAL.get()); @@ -132,7 +132,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { textDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.VERTICAL.get()); itemDisplay = spawnEntity(player.world(), EntityTypes.ITEM_DISPLAY, centerPos, forwardDir, col2, 3); - itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.GOLD_INGOT).createSnapshot()); + itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.GOLD_INGOT).asImmutable()); itemDisplay.offer(Keys.BLOCK_LIGHT, 0); itemDisplay.offer(Keys.SKY_LIGHT, 15); itemDisplay.offer(Keys.BILLBOARD_TYPE, BillboardTypes.VERTICAL.get()); @@ -144,7 +144,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { textDisplay.offer(Keys.DISPLAY_NAME, Component.text("Low\nViewRange")); itemDisplay = spawnEntity(player.world(), EntityTypes.ITEM_DISPLAY, centerPos, forwardDir, col2, 4); - itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.EMERALD).createSnapshot()); + itemDisplay.offer(Keys.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.EMERALD).asImmutable()); itemDisplay.offer(Keys.VIEW_RANGE, 0.02); // 1 is supposed to be view range for fireballs in vanilla, 0.02 seems to be around a block diff --git a/testplugins/src/main/java/org/spongepowered/test/entity/EntityTest.java b/testplugins/src/main/java/org/spongepowered/test/entity/EntityTest.java index 7fb814a7561..e8a0a1c2338 100644 --- a/testplugins/src/main/java/org/spongepowered/test/entity/EntityTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/entity/EntityTest.java @@ -92,7 +92,7 @@ public void onRegisterCommand(final RegisterCommandEvent event) { final var item = Objects.requireNonNull(node.node("item").get(ItemStackSnapshot.class)); - player.setItemInHand(HandTypes.MAIN_HAND, item.createStack()); + player.setItemInHand(HandTypes.MAIN_HAND, item.asMutable()); } catch (ConfigurateException e) { throw new RuntimeException(e); } diff --git a/testplugins/src/main/java/org/spongepowered/test/inventory/InventoryTest.java b/testplugins/src/main/java/org/spongepowered/test/inventory/InventoryTest.java index 813a30d99a4..1af8e34d919 100644 --- a/testplugins/src/main/java/org/spongepowered/test/inventory/InventoryTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/inventory/InventoryTest.java @@ -194,7 +194,7 @@ private void onInteractContainer(final InteractContainerEvent event) { @Listener private void beforePickup(final ChangeInventoryEvent.Pickup.Pre event) { if (event.originalStack().type().isAnyOf(ItemTypes.BEDROCK)) { - final ItemStackSnapshot stack = ItemStack.of(ItemTypes.COBBLESTONE, 64).createSnapshot(); + final ItemStackSnapshot stack = ItemStack.of(ItemTypes.COBBLESTONE, 64).asImmutable(); final ArrayList items = new ArrayList<>(); event.setCustom(items); for (int i = 0; i < 100; i++) { @@ -333,7 +333,7 @@ public boolean handle(final Cause cause, final Container container, final Slot s case 45: case 53: this.last = ViewableInventory.builder().type(ContainerTypes.GENERIC_9X6.get()) - .fillDummy().item(slot.peek().createSnapshot()) + .fillDummy().item(slot.peek().asImmutable()) .completeStructure().plugin(this.plugin).build(); Sponge.server().scheduler().submit(Task.builder().execute(() -> this.menu.setCurrentInventory(this.last)).plugin(this.plugin).build()); break; diff --git a/testplugins/src/main/java/org/spongepowered/test/particle/ParticleTest.java b/testplugins/src/main/java/org/spongepowered/test/particle/ParticleTest.java index 0a101f6c267..e58f70dfdee 100644 --- a/testplugins/src/main/java/org/spongepowered/test/particle/ParticleTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/particle/ParticleTest.java @@ -87,7 +87,7 @@ private void spawnParticles(ServerPlayer serverPlayer, ParticleType type) { .type(type) .option(ParticleOptions.BLOCK_STATE, BlockTypes.DIAMOND_BLOCK.get().defaultState()) .option(ParticleOptions.COLOR, Color.LIME) - .option(ParticleOptions.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.GOLDEN_APPLE.get()).createSnapshot()) + .option(ParticleOptions.ITEM_STACK_SNAPSHOT, ItemStack.of(ItemTypes.GOLDEN_APPLE.get()).asImmutable()) .offset(Vector3d.from(0, 1, 1)) .velocity(Vector3d.RIGHT.mul(0.5)) .quantity(20)