Skip to content

Commit

Permalink
Add convenience functions to reduce the need for using VanillaTypes.I…
Browse files Browse the repository at this point in the history
…TEM_STACK
  • Loading branch information
mezz committed Jul 27, 2022
1 parent 4f0c07e commit 66a18cc
Show file tree
Hide file tree
Showing 34 changed files with 261 additions and 53 deletions.
@@ -1,6 +1,5 @@
package mezz.jei.common.gui;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.handlers.IGhostIngredientHandler;
import mezz.jei.api.gui.handlers.IGlobalGuiHandler;
import mezz.jei.api.gui.handlers.IGuiClickableArea;
Expand Down Expand Up @@ -171,7 +170,7 @@ public static <T> ImmutableRect2i getSlotArea(ITypedIngredient<T> typedIngredien
if (slotUnderMouse == null) {
return null;
}
return typedIngredient.getIngredient(VanillaTypes.ITEM_STACK)
return typedIngredient.getItemStack()
.filter(i -> ItemStack.matches(slotUnderMouse.getItem(), i))
.map(i ->
new ImmutableRect2i(
Expand Down
1 change: 0 additions & 1 deletion Common/src/main/java/mezz/jei/common/input/UserInput.java
Expand Up @@ -7,7 +7,6 @@
import net.minecraft.SharedConstants;
import net.minecraft.client.KeyMapping;

import java.util.Collection;
import java.util.Optional;

public class UserInput {
Expand Down
@@ -1,6 +1,5 @@
package mezz.jei.common.load.registration;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.ingredients.IIngredientTypeWithSubtypes;
import mezz.jei.api.ingredients.subtypes.IIngredientSubtypeInterpreter;
import mezz.jei.api.ingredients.subtypes.UidContext;
Expand All @@ -24,7 +23,7 @@ public class SubtypeRegistration implements ISubtypeRegistration {
@Override
public void useNbtForSubtypes(Item... items) {
for (Item item : items) {
registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, item, AllNbt.INSTANCE);
registerSubtypeInterpreter(item, AllNbt.INSTANCE);
}
}

Expand Down
Expand Up @@ -4,7 +4,6 @@
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.ModIds;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
Expand Down Expand Up @@ -66,7 +65,7 @@ public DebugRecipeCategory(IGuiHelper guiHelper, IPlatformFluidHelper<F> platfor
ResourceLocation backgroundTexture = new ResourceLocation(ModIds.JEI_ID, Constants.TEXTURE_GUI_PATH + "debug.png");
this.tankBackground = guiHelper.createDrawable(backgroundTexture, 220, 196, 18, 60);
this.tankOverlay = guiHelper.createDrawable(backgroundTexture, 238, 196, 18, 60);
this.item = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Items.ACACIA_LEAVES));
this.item = guiHelper.createDrawableItemStack(new ItemStack(Items.ACACIA_LEAVES));
}

@Override
Expand Down
Expand Up @@ -3,7 +3,6 @@
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.constants.ModIds;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.handlers.IGuiContainerHandler;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.helpers.IJeiHelpers;
Expand Down Expand Up @@ -82,15 +81,14 @@ public void registerRecipes(IRecipeRegistration registration) {
JeiDebugPlugin.ingredientManager = registration.getIngredientManager();

if (ClientConfig.getInstance().isDebugModeEnabled()) {
registration.addIngredientInfo(List.of(
registration.addItemStackInfo(List.of(
new ItemStack(Blocks.OAK_DOOR),
new ItemStack(Blocks.SPRUCE_DOOR),
new ItemStack(Blocks.BIRCH_DOOR),
new ItemStack(Blocks.JUNGLE_DOOR),
new ItemStack(Blocks.ACACIA_DOOR),
new ItemStack(Blocks.DARK_OAK_DOOR)
),
VanillaTypes.ITEM_STACK,
Component.translatable("description.jei.wooden.door.1"), // actually 2 lines
Component.translatable("description.jei.wooden.door.2"),
Component.translatable("description.jei.wooden.door.3")
Expand Down Expand Up @@ -199,7 +197,7 @@ private <T> void registerRecipeCatalysts(IRecipeCatalystRegistration registratio

registration.addRecipeCatalyst(DebugIngredient.TYPE, new DebugIngredient(7), DebugRecipeCategory.TYPE);
registration.addRecipeCatalyst(fluidHelper.getFluidIngredientType(), fluidHelper.create(Fluids.WATER, bucketVolume, null), DebugRecipeCategory.TYPE);
registration.addRecipeCatalyst(VanillaTypes.ITEM_STACK, new ItemStack(Items.STICK), DebugRecipeCategory.TYPE);
registration.addRecipeCatalyst(new ItemStack(Items.STICK), DebugRecipeCategory.TYPE);
IPlatformRegistry<Item> registry = Services.PLATFORM.getRegistry(Registry.ITEM_REGISTRY);
registry.getValues()
.limit(30)
Expand Down
Expand Up @@ -135,11 +135,11 @@ public ResourceLocation getPluginUid() {

@Override
public void registerItemSubtypes(ISubtypeRegistration registration) {
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.TIPPED_ARROW, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.SPLASH_POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.LINGERING_POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(VanillaTypes.ITEM_STACK, Items.ENCHANTED_BOOK, (itemStack, context) -> {
registration.registerSubtypeInterpreter(Items.TIPPED_ARROW, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(Items.POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(Items.SPLASH_POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(Items.LINGERING_POTION, PotionSubtypeInterpreter.INSTANCE);
registration.registerSubtypeInterpreter(Items.ENCHANTED_BOOK, (itemStack, context) -> {
List<String> enchantmentNames = new ArrayList<>();
ListTag enchantments = EnchantedBookItem.getEnchantments(itemStack);
for (int i = 0; i < enchantments.size(); ++i) {
Expand Down
Expand Up @@ -2,10 +2,10 @@

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.IRecipeSlotBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
Expand All @@ -20,7 +20,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;

import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand All @@ -36,7 +35,7 @@ public AnvilRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.drawableBuilder(Constants.RECIPE_GUI_VANILLA, 0, 168, 125, 18)
.addPadding(0, 20, 0, 0)
.build();
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.ANVIL));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.ANVIL));
}

@Override
Expand Down Expand Up @@ -90,10 +89,10 @@ public void setRecipe(IRecipeLayoutBuilder builder, IJeiAnvilRecipe recipe, IFoc
@Override
public void draw(IJeiAnvilRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) {
Optional<ItemStack> leftStack = recipeSlotsView.findSlotByName(leftSlotName)
.flatMap(slot1 -> slot1.getDisplayedIngredient(VanillaTypes.ITEM_STACK));
.flatMap(IRecipeSlotView::getDisplayedItemStack);

Optional<ItemStack> rightStack = recipeSlotsView.findSlotByName(rightSlotName)
.flatMap(slot -> slot.getDisplayedIngredient(VanillaTypes.ITEM_STACK));
.flatMap(IRecipeSlotView::getDisplayedItemStack);

if (leftStack.isEmpty() || rightStack.isEmpty()) {
return;
Expand Down
@@ -1,6 +1,5 @@
package mezz.jei.common.plugins.vanilla.anvil;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.recipe.vanilla.IJeiAnvilRecipe;
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
import mezz.jei.api.runtime.IIngredientManager;
Expand Down Expand Up @@ -90,7 +89,7 @@ private static Stream<IJeiAnvilRecipe> getBookEnchantmentRecipes(
.map(EnchantmentData::new)
.toList();

return ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK)
return ingredientManager.getAllItemStacks()
.stream()
.filter(ItemStack::isEnchantable)
.flatMap(ingredient -> getBookEnchantmentRecipes(vanillaRecipeFactory, enchantmentDatas, ingredient));
Expand Down
@@ -1,7 +1,6 @@
package mezz.jei.common.plugins.vanilla.anvil;

import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.IGuiHelper;
Expand All @@ -24,7 +23,7 @@ public class SmithingRecipeCategory implements IRecipeCategory<UpgradeRecipe> {

public SmithingRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createDrawable(Constants.RECIPE_GUI_VANILLA, 0, 168, 125, 18);
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.SMITHING_TABLE));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.SMITHING_TABLE));
}

@Override
Expand Down
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.ITickTimer;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
Expand Down Expand Up @@ -38,7 +37,7 @@ public BrewingRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.drawableBuilder(location, 0, 0, 64, 60)
.addPadding(1, 0, 0, 50)
.build();
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.BREWING_STAND));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.BREWING_STAND));
localizedName = Component.translatable("gui.jei.category.brewing");

arrow = guiHelper.drawableBuilder(location, 64, 0, 9, 28)
Expand Down
Expand Up @@ -2,15 +2,14 @@

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.recipe.vanilla.IJeiCompostingRecipe;
import mezz.jei.common.util.Translator;
import net.minecraft.client.Minecraft;
Expand All @@ -31,7 +30,7 @@ public class CompostableRecipeCategory implements IRecipeCategory<IJeiComposting
public CompostableRecipeCategory(IGuiHelper guiHelper) {
background = guiHelper.createBlankDrawable(width, height);
slot = guiHelper.getSlotDrawable();
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.COMPOSTER));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.COMPOSTER));
localizedName = Component.translatable("gui.jei.category.compostable");
}

Expand Down
@@ -1,7 +1,6 @@
package mezz.jei.common.plugins.vanilla.compostable;

import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.recipe.vanilla.IJeiCompostingRecipe;
import mezz.jei.api.runtime.IIngredientManager;
import net.minecraft.world.item.Item;
Expand All @@ -16,7 +15,7 @@
public class CompostingRecipeMaker {
public static List<IJeiCompostingRecipe> getRecipes(IIngredientManager ingredientManager) {
Object2FloatMap<ItemLike> compostables = ComposterBlock.COMPOSTABLES;
Collection<ItemStack> allIngredients = ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK);
Collection<ItemStack> allIngredients = ingredientManager.getAllItemStacks();

return allIngredients.stream()
.<IJeiCompostingRecipe>mapMulti((itemStack, consumer) -> {
Expand Down
Expand Up @@ -4,7 +4,6 @@
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
Expand Down Expand Up @@ -33,7 +32,7 @@ public AbstractCookingCategory(IGuiHelper guiHelper, Block icon, String translat
super(guiHelper);
this.background = guiHelper.createDrawable(Constants.RECIPE_GUI_VANILLA, 0, 114, 82, 54);
this.regularCookTime = regularCookTime;
this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(icon));
this.icon = guiHelper.createDrawableItemStack(new ItemStack(icon));
this.localizedName = Component.translatable(translationKey);
this.cachedArrows = CacheBuilder.newBuilder()
.maximumSize(25)
Expand Down
@@ -1,6 +1,5 @@
package mezz.jei.common.plugins.vanilla.cooking.fuel;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.recipe.vanilla.IJeiFuelingRecipe;
import mezz.jei.api.runtime.IIngredientManager;
import mezz.jei.common.platform.IPlatformItemStackHelper;
Expand All @@ -16,7 +15,7 @@ private FuelRecipeMaker() {

public static List<IJeiFuelingRecipe> getFuelRecipes(IIngredientManager ingredientManager) {
IPlatformItemStackHelper itemStackHelper = Services.PLATFORM.getItemStackHelper();
return ingredientManager.getAllIngredients(VanillaTypes.ITEM_STACK).stream()
return ingredientManager.getAllItemStacks().stream()
.<IJeiFuelingRecipe>mapMulti((stack, consumer) -> {
int burnTime = itemStackHelper.getBurnTime(stack);
if (burnTime > 0) {
Expand Down
@@ -1,6 +1,5 @@
package mezz.jei.common.plugins.vanilla.crafting;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.ingredient.ICraftingGridHelper;
import mezz.jei.api.recipe.IFocusGroup;
Expand Down Expand Up @@ -30,8 +29,8 @@ public void setRecipe(IRecipeLayoutBuilder builder, ICraftingGridHelper crafting

int width = getWidth();
int height = getHeight();
craftingGridHelper.createAndSetOutputs(builder, VanillaTypes.ITEM_STACK, List.of(resultItem));
craftingGridHelper.createAndSetInputs(builder, VanillaTypes.ITEM_STACK, inputs, width, height);
craftingGridHelper.createAndSetOutputs(builder, List.of(resultItem));
craftingGridHelper.createAndSetInputs(builder, inputs, width, height);
}

@Nullable
Expand Down
Expand Up @@ -3,7 +3,6 @@
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.ICraftingGridHelper;
Expand Down Expand Up @@ -41,7 +40,7 @@ public class CraftingRecipeCategory implements IExtendableRecipeCategory<Craftin
public CraftingRecipeCategory(IGuiHelper guiHelper) {
ResourceLocation location = Constants.RECIPE_GUI_VANILLA;
background = guiHelper.createDrawable(location, 0, 60, width, height);
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.CRAFTING_TABLE));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.CRAFTING_TABLE));
localizedName = Component.translatable("gui.jei.category.craftingTable");
craftingGridHelper = guiHelper.createCraftingGridHelper();
}
Expand Down
@@ -1,7 +1,6 @@
package mezz.jei.common.plugins.vanilla.stonecutting;

import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
Expand All @@ -28,7 +27,7 @@ public class StoneCuttingRecipeCategory implements IRecipeCategory<StonecutterRe
public StoneCuttingRecipeCategory(IGuiHelper guiHelper) {
ResourceLocation location = Constants.RECIPE_GUI_VANILLA;
background = guiHelper.createDrawable(location, 0, 220, width, height);
icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, new ItemStack(Blocks.STONECUTTER));
icon = guiHelper.createDrawableItemStack(new ItemStack(Blocks.STONECUTTER));
localizedName = Component.translatable("gui.jei.category.stoneCutter");
}

Expand Down
@@ -1,6 +1,5 @@
package mezz.jei.common.transfer;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IStackHelper;
Expand Down Expand Up @@ -214,7 +213,7 @@ public static RecipeTransferOperationsResult getRecipeTransferOperations(
@Nullable
public static <T> Map.Entry<T, ItemStack> containsAnyStackIndexed(IStackHelper stackhelper, Map<T, ItemStack> stacks, IRecipeSlotView recipeSlotView) {
MatchingIndexed<T> matchingStacks = new MatchingIndexed<>(stacks);
List<ItemStack> ingredients = recipeSlotView.getIngredients(VanillaTypes.ITEM_STACK).toList();
List<ItemStack> ingredients = recipeSlotView.getItemStacks().toList();
MatchingIterable matchingContains = new MatchingIterable(ingredients);
return containsStackMatchable(stackhelper, matchingStacks, matchingContains);
}
Expand Down
3 changes: 1 addition & 2 deletions Common/src/main/java/mezz/jei/common/util/StackHelper.java
@@ -1,6 +1,5 @@
package mezz.jei.common.util;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.helpers.IStackHelper;
import mezz.jei.api.ingredients.subtypes.ISubtypeManager;
import mezz.jei.api.ingredients.subtypes.UidContext;
Expand Down Expand Up @@ -42,7 +41,7 @@ public boolean isEquivalent(@Nullable ItemStack lhs, @Nullable ItemStack rhs, Ui
@Override
public String getUniqueIdentifierForStack(ItemStack stack, UidContext context) {
String result = getRegistryNameForStack(stack);
String subtypeInfo = subtypeManager.getSubtypeInfo(VanillaTypes.ITEM_STACK, stack, context);
String subtypeInfo = subtypeManager.getSubtypeInfo(stack, context);
if (!subtypeInfo.isEmpty()) {
result = result + ':' + subtypeInfo;
}
Expand Down
Expand Up @@ -2,10 +2,12 @@

import com.mojang.blaze3d.vertex.PoseStack;

import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IRecipeManager;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.world.item.ItemStack;

import java.util.Optional;

Expand Down Expand Up @@ -37,6 +39,16 @@ public interface IRecipeLayoutDrawable {
*/
boolean isMouseOver(double mouseX, double mouseY);

/**
* Returns the ItemStack currently under the mouse, if there is one.
*
* @see #getIngredientUnderMouse(int, int, IIngredientType) to get other types of ingredient.
* @since 11.1.1
*/
default Optional<ItemStack> getItemStackUnderMouse(int mouseX, int mouseY) {
return getIngredientUnderMouse(mouseX, mouseY, VanillaTypes.ITEM_STACK);
}

/**
* Returns the ingredient currently under the mouse, if there is one.
* Can be an ItemStack, FluidStack, or any other ingredient type registered with JEI.
Expand Down

0 comments on commit 66a18cc

Please sign in to comment.