Implements netherite salvaging #24
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
package net.knarcraft.blacksmith.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@ -43,6 +42,29 @@ public final class SalvageHelper {
|
||||
trimMaterialToMaterial.put(TrimMaterial.REDSTONE, Material.REDSTONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets salvage for a given netherite item
|
||||
*
|
||||
* @param item <p>The netherite armor/tool to salvage</p>
|
||||
* @return <p></p>
|
||||
*/
|
||||
@Nullable
|
||||
public static List<ItemStack> getNetheriteSalvage(@NotNull ItemStack item) {
|
||||
Material newMaterial = Material.matchMaterial(item.getType().name().replace("NETHERITE", "DIAMOND"));
|
||||
if (newMaterial == null) {
|
||||
return null;
|
||||
}
|
||||
ItemStack clone = item.clone();
|
||||
clone.setType(newMaterial);
|
||||
|
||||
List<ItemStack> salvage = new ArrayList<>();
|
||||
salvage.add(clone);
|
||||
salvage.add(new ItemStack(Material.NETHERITE_INGOT, 1));
|
||||
salvage.add(new ItemStack(Material.NETHERITE_UPGRADE_SMITHING_TEMPLATE, 1));
|
||||
|
||||
return salvage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets salvage for the given armor trim
|
||||
*
|
||||
@ -51,7 +73,7 @@ public final class SalvageHelper {
|
||||
* @return <p>The salvage, or null if salvage could not be calculated</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static List<ItemStack> getTrimSalvage(@NotNull ItemStack item, @NotNull ArmorMeta armorMeta) {
|
||||
public static List<ItemStack> getArmorTrimSalvage(@NotNull ItemStack item, @NotNull ArmorMeta armorMeta) {
|
||||
ArmorTrim armorTrim = armorMeta.getTrim();
|
||||
if (armorTrim == null) {
|
||||
return null;
|
||||
@ -82,22 +104,41 @@ public final class SalvageHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether the given item has a valid crafting recipe
|
||||
* Checks whether the given item can be salvaged, assuming no restrictions apply
|
||||
*
|
||||
* @param item <p>The item to check</p>
|
||||
* @return <p>True if the item has a valid crafting recipe</p>
|
||||
* @param server <p>The server to get recipes from</p>
|
||||
* @param item <p>The item to check</p>
|
||||
* @return <p>True if the item can be salvaged</p>
|
||||
*/
|
||||
public static boolean hasRecipe(@NotNull ItemStack item) {
|
||||
List<Recipe> recipes = Bukkit.getRecipesFor(new ItemStack(item.getType(), item.getAmount()));
|
||||
public static boolean isSalvageable(@NotNull Server server, @NotNull ItemStack item) {
|
||||
List<Recipe> recipes = server.getRecipesFor(new ItemStack(item.getType(), item.getAmount()));
|
||||
for (Recipe recipe : recipes) {
|
||||
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
|
||||
// Only crafting recipes are allowed.
|
||||
if ((recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) &&
|
||||
item.getAmount() >= recipe.getResult().getAmount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of an item that's required to salvage that item
|
||||
*
|
||||
* @param server <p>The server to get recipes from</p>
|
||||
* @param item <p>The item to check</p>
|
||||
* @return <p>The number of items required for salvage, or -1 if the recipe was not found</p>
|
||||
*/
|
||||
public static int getRequiredAmountForSalvage(@NotNull Server server, @NotNull ItemStack item) {
|
||||
for (Recipe recipe : server.getRecipesFor(new ItemStack(item.getType(), item.getAmount()))) {
|
||||
// Only crafting recipes are allowed.
|
||||
if (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe) {
|
||||
return recipe.getResult().getAmount();
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sum of all enchantment levels for the given item
|
||||
*
|
||||
|
Reference in New Issue
Block a user