Skip to content

Commit

Permalink
Use the new Result#item methods & remove CustomItem usages
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyScript committed Nov 14, 2023
1 parent 6f07c40 commit 5d99bba
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ButtonSlotResult extends ItemInputButton<CCCache> {
Conditions.Data.of(player).setBlock(block).setInventoryView(player.getOpenInventory()).setEliteCraftingTableSettings(cacheEliteCraftingTable.getSettings()),
RecipeType.Container.ELITE_CRAFTING,
cacheEliteCraftingTable.isAdvancedCraftingRecipes() ? RecipeType.Container.CRAFTING : null
).map(data -> data.getResult().getItem(data, player, block)).orElse(null));
).map(data -> data.getResult().item(data, player, block)).orElse(null));
}, (hashMap, cache, guiHandler, player, inventory, itemStack, slot, help) -> {
CacheEliteCraftingTable cacheEliteCraftingTable = cache.getEliteWorkbench();
return cacheEliteCraftingTable.getResult() != null ? cacheEliteCraftingTable.getResult() : new ItemStack(Material.AIR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void onInit() {
RecipeType.Container.ELITE_CRAFTING,
cacheEliteCraftingTable.isAdvancedCraftingRecipes() ? RecipeType.Container.CRAFTING : null
)
.map(data -> data.getResult().getItem(data, player, targetBlock))
.map(data -> data.getResult().item(data, player, targetBlock))
.ifPresent(cacheEliteCraftingTable::setResult);
} else {
cacheEliteCraftingTable.setResult(new ItemStack(Material.AIR));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void onPreCraft(PrepareItemCraftEvent e) {
ItemStack[] matrix = e.getInventory().getMatrix();
Block block = e.getInventory().getLocation() == null ? player.getLocation().getBlock() : e.getInventory().getLocation().getBlock();
craftManager.checkCraftingMatrix(matrix, Conditions.Data.of(player).setInventoryView(e.getView()).setBlock(block), RecipeType.Container.CRAFTING)
.map(craftingData -> craftingData.getResult().getItem(craftingData, player, block))
.map(craftingData -> craftingData.getResult().item(craftingData, player, block))
.ifPresentOrElse(result -> {
e.getInventory().setResult(result);
Bukkit.getScheduler().runTask(customCrafting, player::updateInventory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Stream;

import com.wolfyscript.utilities.bukkit.world.items.reference.StackReference;
import me.wolfyscript.customcrafting.CustomCrafting;
import me.wolfyscript.customcrafting.recipes.CustomRecipeSmithing;
import me.wolfyscript.customcrafting.recipes.ICustomVanillaRecipe;
Expand All @@ -36,7 +38,6 @@
import me.wolfyscript.customcrafting.recipes.items.Result;
import me.wolfyscript.customcrafting.recipes.items.target.MergeAdapter;
import me.wolfyscript.customcrafting.recipes.items.target.MergeOption;
import me.wolfyscript.customcrafting.utils.NamespacedKeyUtils;
import me.wolfyscript.utilities.api.inventory.custom_items.CustomItem;
import me.wolfyscript.utilities.util.NamespacedKey;
import me.wolfyscript.utilities.util.inventory.InventoryUtils;
Expand Down Expand Up @@ -114,8 +115,8 @@ public void onPrepare(PrepareSmithingEvent event) {
private static void applyResult(PrepareSmithingEvent event, SmithingInventory inv, Player player, ItemStack base, Result result, boolean onlyChangeMaterial, List<MergeAdapter> adapters, RecipeData<?> data) {
//Process result
Block block = inv.getLocation() != null ? inv.getLocation().getBlock() : null;
CustomItem chosenResult = result.getItem(player, block).orElse(new CustomItem(Material.AIR));
ItemStack endResult = result.getItem(data, chosenResult, player, block);
StackReference chosenResult = result.item(player, block).orElse(StackReference.of(new ItemStack(Material.AIR)));
ItemStack endResult = result.item(data, chosenResult, player, block);
if (onlyChangeMaterial) {
//Take the base item and just change the material.
var baseCopy = base.clone();
Expand Down Expand Up @@ -178,7 +179,7 @@ public void onCollectResult(InventoryClickEvent event) {
}
preCraftedRecipes.remove(player.getUniqueId());

inventory.setItem(CustomRecipeSmithing.RESULT_SLOT, smithingData.getResult().getItem(smithingData, player, inventory.getLocation() != null ? inventory.getLocation().getBlock() : player.getLocation().getBlock()));
inventory.setItem(CustomRecipeSmithing.RESULT_SLOT, smithingData.getResult().item(smithingData, player, inventory.getLocation() != null ? inventory.getLocation().getBlock() : player.getLocation().getBlock()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void setPlayerCraftTime(Player player, CraftingRecipe<?, ?> recipe) {
}

private int calculateClick(Player player, InventoryClickEvent event, CraftingData craftingData, CraftingRecipe<?, ?> recipe, Result recipeResult) {
var result = recipeResult.getItem(craftingData, player, null);
var result = recipeResult.item(craftingData, player, null);
var inventory = event.getClickedInventory();
int possible = event.isShiftClick() ? Math.min(InventoryUtils.getInventorySpace(player.getInventory(), result) / result.getAmount(), recipe.getAmountCraftable(craftingData)) : 1;
recipeResult.executeExtensions(inventory.getLocation() == null ? event.getWhoClicked().getLocation() : inventory.getLocation(), inventory.getLocation() != null, (Player) event.getWhoClicked(), possible);
Expand Down

0 comments on commit 5d99bba

Please sign in to comment.