diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/PlayerInventoryStorage.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/PlayerInventoryStorage.java index ef2d7a77c..87da3927f 100644 --- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/PlayerInventoryStorage.java +++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/api/transfer/v1/item/PlayerInventoryStorage.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.ApiStatus; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; +import net.minecraft.item.ItemStack; import net.minecraft.screen.ScreenHandler; import net.minecraft.util.Hand; @@ -110,15 +111,47 @@ public interface PlayerInventoryStorage extends InventoryStorage { long offer(ItemVariant variant, long maxAmount, TransactionContext transaction); /** - * Drop items in the world at the player's location. + * Throw items in the world from the player's location. + * + *
Note: This function has full transaction support, and will not actually drop the items until the outermost transaction is committed. + * + * @param variant The variant to drop. + * @param amount How many of the variant to drop. + * @param throwRandomly If true, the variant will be thrown in a random direction from the entity regardless of which direction the entity is facing. + * @param retainOwnership If true, set the {@code Thrower} NBT data to the player's UUID. + * @param transaction The transaction this operation is part of. + * @see PlayerEntity#dropItem(ItemStack, boolean, boolean) + */ + void drop(ItemVariant variant, long amount, boolean throwRandomly, boolean retainOwnership, TransactionContext transaction); + + /** + * Throw items in the world from the player's location. + * + *
Note: This function has full transaction support, and will not actually drop the items until the outermost transaction is committed. + * + * @param variant The variant to drop. + * @param amount How many of the variant to drop. + * @param retainOwnership If true, set the {@code Thrower} NBT data to the player's UUID. + * @param transaction The transaction this operation is part of. + * @see PlayerEntity#dropItem(ItemStack, boolean, boolean) + */ + default void drop(ItemVariant variant, long amount, boolean retainOwnership, TransactionContext transaction) { + drop(variant, amount, false, retainOwnership, transaction); + } + + /** + * Throw items in the world from the player's location. * *
Note: This function has full transaction support, and will not actually drop the items until the outermost transaction is committed.
*
* @param variant The variant to drop.
* @param amount How many of the variant to drop.
* @param transaction The transaction this operation is part of.
+ * @see PlayerEntity#dropItem(ItemStack, boolean, boolean)
*/
- void drop(ItemVariant variant, long amount, TransactionContext transaction);
+ default void drop(ItemVariant variant, long amount, TransactionContext transaction) {
+ drop(variant, amount, false, transaction);
+ }
/**
* Return a wrapper around the current slot of the passed hand.
diff --git a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/PlayerInventoryStorageImpl.java b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/PlayerInventoryStorageImpl.java
index be700e453..79d305318 100644
--- a/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/PlayerInventoryStorageImpl.java
+++ b/fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer/item/PlayerInventoryStorageImpl.java
@@ -71,13 +71,13 @@ class PlayerInventoryStorageImpl extends InventoryStorageImpl implements PlayerI
}
@Override
- public void drop(ItemVariant resource, long amount, TransactionContext tx) {
- StoragePreconditions.notBlankNotNegative(resource, amount);
+ public void drop(ItemVariant variant, long amount, boolean throwRandomly, boolean retainOwnership, TransactionContext transaction) {
+ StoragePreconditions.notBlankNotNegative(variant, amount);
// Drop in the world on the server side (will be synced by the game with the client).
// Dropping items is server-side only because it involves randomness.
if (amount > 0 && !playerInventory.player.world.isClient()) {
- droppedStacks.addDrop(resource, amount, tx);
+ droppedStacks.addDrop(variant, amount, throwRandomly, retainOwnership, transaction);
}
}
@@ -97,18 +97,16 @@ class PlayerInventoryStorageImpl extends InventoryStorageImpl implements PlayerI
}
private class DroppedStacks extends SnapshotParticipant