Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
package net.tfminecraft.cooking.sausagemaker;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import net.tfminecraft.cooking.item.FoodItem;
import net.tfminecraft.cooking.util.LegacyModelData;
import net.tfminecraft.tlibs.TLibs;

/**
* Sausage casing is plain vanilla paper. Cooking tools and scooped soup use
* paper as their base item, and those must stay in the player's hand.
* Sausage casing is vanilla paper. {@code v.paper} rejects custom items that
* only use paper as their base, such as the masher and a scooped bowl of soup.
*/
final class CasingPaper {

static final String PATH = "v.paper";

private CasingPaper() {}

static boolean isCasing(ItemStack stack) {
if (stack == null || stack.getType() != Material.PAPER || stack.getAmount() <= 0) {
return false;
}
if (hasCustomIdentity(stack)) {
return false;
}
return FoodItem.fromItem(stack) == null;
}

private static boolean hasCustomIdentity(ItemStack stack) {
if (!stack.hasItemMeta()) {
return false;
}
ItemMeta meta = stack.getItemMeta();
if (meta == null) {
return false;
}
if (meta.hasDisplayName() || meta.hasItemName() || meta.hasItemModel()
|| meta.hasCustomModelDataComponent() || LegacyModelData.has(meta)) {
return true;
}
return !meta.getPersistentDataContainer().isEmpty();
return stack != null
&& stack.getAmount() > 0
&& TLibs.getItemAPI().getChecker().checkItemWithPath(stack, PATH);
}
}