-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathSkyblockerJEIPlugin.java
88 lines (79 loc) · 4.61 KB
/
SkyblockerJEIPlugin.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package de.hysky.skyblocker.compatibility.jei;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.Location;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.datafixer.ItemStackComponentizationFixer;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.registration.IRecipeCategoryRegistration;
import mezz.jei.api.registration.IRecipeRegistration;
import mezz.jei.api.registration.ISubtypeRegistration;
import mezz.jei.library.ingredients.subtypes.SubtypeInterpreters;
import mezz.jei.library.load.registration.SubtypeRegistration;
import mezz.jei.library.plugins.vanilla.crafting.CraftingCategoryExtension;
import net.minecraft.client.gui.screen.ingame.InventoryScreen;
import net.minecraft.client.util.math.Rect2i;
import net.minecraft.item.ItemStack;
import net.minecraft.recipe.*;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
@JeiPlugin
public class SkyblockerJEIPlugin implements IModPlugin {
private SkyblockCraftingRecipeCategory skyblockCraftingRecipeCategory;
@Override
@NotNull
public Identifier getPluginUid() {
return Identifier.of(SkyblockerMod.NAMESPACE, "skyblock");
}
@Override
public void registerItemSubtypes(@NotNull ISubtypeRegistration registration) {
SubtypeInterpreters interpreters = ((SubtypeRegistration) registration).getInterpreters();
ItemRepository.getItemsStream().filter(stack -> !interpreters.contains(VanillaTypes.ITEM_STACK, stack)).map(ItemStack::getItem).distinct().forEach(item ->
registration.registerSubtypeInterpreter(item, (stack, context) -> ItemStackComponentizationFixer.componentsAsString(stack))
);
}
@Override
public void registerCategories(@NotNull IRecipeCategoryRegistration registration) {
skyblockCraftingRecipeCategory = new SkyblockCraftingRecipeCategory(registration.getJeiHelpers().getGuiHelper());
skyblockCraftingRecipeCategory.addExtension(CraftingRecipe.class, new CraftingCategoryExtension());
registration.addRecipeCategories(skyblockCraftingRecipeCategory);
}
@Override
public void registerGuiHandlers(@NotNull IGuiHandlerRegistration registration) {
registration.addGuiContainerHandler(InventoryScreen.class, new InventoryContainerHandler());
}
@Override
public void registerRecipes(@NotNull IRecipeRegistration registration) {
//FIXME no clue what to replace any of this with, we can't use items as that does not work
/*registration.getIngredientManager().addIngredientsAtRuntime(VanillaTypes.ITEM_STACK, ItemRepository.getItems());
registration.addRecipes(skyblockCraftingRecipeCategory.getRecipeType(), ItemRepository.getRecipesStream().map(recipe ->
new RecipeEntry<CraftingRecipe>(recipe.getId(), new ShapedRecipe("", CraftingRecipeCategory.MISC, RawShapedRecipe.create(Map.of(
'a', Ingredient.ofStacks(recipe.getGrid().get(0)),
'b', Ingredient.ofStacks(recipe.getGrid().get(1)),
'c', Ingredient.ofStacks(recipe.getGrid().get(2)),
'd', Ingredient.ofStacks(recipe.getGrid().get(3)),
'e', Ingredient.ofStacks(recipe.getGrid().get(4)),
'f', Ingredient.ofStacks(recipe.getGrid().get(5)),
'g', Ingredient.ofStacks(recipe.getGrid().get(6)),
'h', Ingredient.ofStacks(recipe.getGrid().get(7)),
'i', Ingredient.ofStacks(recipe.getGrid().get(8))
), "abc", "def", "ghi"), recipe.getResult()))
).toList());*/
}
private static class InventoryContainerHandler implements IGuiContainerHandler<InventoryScreen> {
@Override
public @NotNull List<Rect2i> getGuiExtraAreas(@NotNull InventoryScreen containerScreen) {
if (!SkyblockerConfigManager.get().farming.garden.gardenPlotsWidget || !Utils.getLocation().equals(Location.GARDEN)) return List.of();
HandledScreenAccessor accessor = (HandledScreenAccessor) containerScreen;
return Collections.singletonList(new Rect2i(accessor.getX() + accessor.getBackgroundWidth() + 4, accessor.getY(), 104, 127));
}
}
}