Skip to content

Commit

Permalink
add helper method for copying inventory contents
Browse files Browse the repository at this point in the history
  • Loading branch information
crxyne committed May 12, 2024
1 parent bc4e63d commit b35d23b
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,16 @@ public static Optional<Inventory> getInventory(@NotNull final Entity entity) {
return Optional.ofNullable(inventoryHolder.getInventory());
}

public static boolean copyInventoryContents(@NotNull final ItemStack from, @NotNull final ItemStack to) {
return getInventory(from).flatMap(fromInventory -> mapInventory(to, toInventory -> {
for (int i = 0; i < toInventory.getSize(); i++) {
final ItemStack clone = fromInventory.getItem(i);
if (clone == null) continue;

toInventory.setItem(i, clone.clone());
}
return true;
})).orElse(false);
}

}

0 comments on commit b35d23b

Please sign in to comment.