From 122e022ac89d872b05cb5b320b72411201d7854f Mon Sep 17 00:00:00 2001 From: Indyuce Date: Wed, 25 Aug 2021 20:58:24 +0200 Subject: [PATCH] fixed crafting amount --- .../source/CraftItemExperienceSource.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java b/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java index edbe0363..e3f0322f 100644 --- a/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java +++ b/src/main/java/net/Indyuce/mmocore/experience/source/CraftItemExperienceSource.java @@ -1,16 +1,18 @@ package net.Indyuce.mmocore.experience.source; import io.lumine.mythic.lib.api.MMOLineConfig; +import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.experience.provider.ExperienceDispenser; import net.Indyuce.mmocore.experience.source.type.SpecificExperienceSource; -import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.manager.profession.ExperienceSourceManager; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.InventoryAction; +import org.bukkit.inventory.ItemStack; public class CraftItemExperienceSource extends SpecificExperienceSource { public final Material material; @@ -29,10 +31,11 @@ public class CraftItemExperienceSource extends SpecificExperienceSource + * The idea is to find the item with the lowest count which is basically + * the amount of items that are crafted. Minecraft uses the same calculation + * + * @return Amount of items crafted + */ + private final int getAmountCrafted(CraftItemEvent event) { + ItemStack craftedItem = event.getInventory().getResult(); //Get result of recipe + ClickType clickType = event.getClick(); + + // No shift click + if (!clickType.isShiftClick()) + return craftedItem.getAmount(); + + // Find lowest amount of all ingredients + int lowerAmount = craftedItem.getMaxStackSize() + 1000; //Set lower at recipe result max stack size + 1000 (or just highter max stacksize of reciped item) + for (ItemStack actualItem : event.getInventory().getContents()) //For each item in crafting inventory + if (!actualItem.getType().isAir() && lowerAmount > actualItem.getAmount() && !actualItem.getType().equals(craftedItem.getType())) //if slot is not air && lowerAmount is highter than this slot amount && it's not the recipe amount + lowerAmount = actualItem.getAmount(); //Set new lower amount + + //Calculate the final amount : lowerAmount * craftedItem.getAmount + return lowerAmount * craftedItem.getAmount(); + } }