summaryrefslogtreecommitdiff
path: root/src/main/java/net/uomc/mineshaft/crafting/CraftingRecipe.java
blob: cb4892ea4e0e5f47ecc216d0ad8741eb9b89ba2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package net.uomc.mineshaft.crafting;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.uomc.mineshaft.MineshaftItem;

public class CraftingRecipe {
    MineshaftItem item;
    long quantity;
    Map<MineshaftItem, Long> ingredients;

    String buyMessage;

    private CraftingRecipe(MineshaftItem item, long quantity, Map<MineshaftItem, Long> ingredients) {
        this.item = item;
        this.quantity = quantity;
        this.ingredients = ingredients;
    }

    public static CraftingRecipe make(MineshaftItem item) {
        Map<MineshaftItem, Long> ingredients = new HashMap<>();
        return new CraftingRecipe(item, 1, ingredients);
    }

    public CraftingRecipe addIngredient(MineshaftItem item, long amount) {
        ingredients.put(item, amount);
        return this;
    }

    public MineshaftItem getItem() {
        return item;
    }

    public long getQuantity() {
        return quantity;
    }

    public Map<MineshaftItem, Long> getIngredients() {
        return ingredients;
    }

    public String getBuyMessage() {
        return buyMessage;
    }

    public CraftingRecipe setBuyMessage(String message) {
        buyMessage = message;
        return this;
    }
    public Map<MineshaftItem, Long> getMissingIngredients(Map<MineshaftItem, Long> items) {
        return getMissingIngredients(items, 1);
    }

    public Map<MineshaftItem, Long> getMissingIngredients(Map<MineshaftItem, Long> items, long amount) {
        Map<MineshaftItem, Long> lacking = new HashMap<MineshaftItem, Long>();
        getIngredients().forEach((item, q) -> {
            if (items.get(item)  < q* amount) {
                lacking.put(item, (q * amount) - items.get(item));
            }
        });

        return Collections.unmodifiableMap(lacking);
    }

}