-
Notifications
You must be signed in to change notification settings - Fork 18
/
InspirationsRegistry.java
56 lines (49 loc) · 1.58 KB
/
InspirationsRegistry.java
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
package knightminer.inspirations.library;
import knightminer.inspirations.Inspirations;
import knightminer.inspirations.common.Config;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import slimeknights.mantle.util.RegistryHelper;
import java.util.HashMap;
import java.util.Map;
// This is an API.
public class InspirationsRegistry {
public static final Logger log = LogManager.getLogger(Inspirations.modID + "-" + "api");
/*
* Books
*/
private static final Map<Item,Float> bookCache = new HashMap<>();
/**
* Checks if the given item stack is a book
* @param stack Input stack
* @return True if its a book
*/
public static boolean isBook(ItemStack stack) {
return !stack.isEmpty() && getBookEnchantingPower(stack) >= 0;
}
/**
* Checks if the given item stack is a book
* @param book Input stack
* @return True if its a book
*/
public static float getBookEnchantingPower(ItemStack book) {
if (book.isEmpty()) {
return 0;
}
return bookCache.computeIfAbsent(book.getItem(), InspirationsRegistry::bookPower);
}
/**
* Helper function to check if a stack is a book, used internally by the book map
* @param item The item.
* @return The enchantment power, or -1F.
*/
private static Float bookPower(Item item) {
// TODO: custom enchanting power
if (RegistryHelper.contains(InspirationsTags.Items.BOOKS, item)) {
return Config.defaultEnchantingPower.get().floatValue();
}
return -1f;
}
}