Skip to content

Commit

Permalink
Merge pull request #876 from QwQ-dev/slimefunitem_optional_methods
Browse files Browse the repository at this point in the history
Add SlimefunItem#getOptionalById(String) and SlimefunItem#getOptionalByItem(ItemStack).
  • Loading branch information
StarWishsama authored May 26, 2024
2 parents 951bb5f + eb5391a commit 9fdaeaf
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,17 @@ public final int hashCode() {
return Slimefun.getRegistry().getSlimefunItemIds().get(id);
}

/**
* Retrieve a {@link Optional} {@link SlimefunItem} by its id.
*
* @param id
* The id of the {@link SlimefunItem}
* @return The {@link Optional} {@link SlimefunItem} associated with that id. Empty if non-existent
*/
public static @Nonnull Optional<SlimefunItem> getOptionalById(@Nonnull String id) {
return Optional.ofNullable(getById(id));
}

/**
* Retrieve a {@link SlimefunItem} from an {@link ItemStack}.
*
Expand All @@ -1258,6 +1269,17 @@ public final int hashCode() {
return null;
}

/**
* Retrieve a {@link Optional} {@link SlimefunItem} from an {@link ItemStack}.
*
* @param item
* The {@link ItemStack} to check
* @return The {@link Optional} {@link SlimefunItem} associated with this {@link ItemStack} if present, otherwise empty
*/
public static @Nonnull Optional<SlimefunItem> getOptionalByItem(@Nullable ItemStack item) {
return Optional.ofNullable(getByItem(item));
}

/**
* Should load the {@link SlimefunBlockData} by default.
* If return false, only the item with {@link BlockTicker} will be loaded with {@link ChunkLoadEvent}.
Expand Down

0 comments on commit 9fdaeaf

Please sign in to comment.