update to new JEI API
This commit is contained in:
		@@ -104,8 +104,9 @@ processResources {
 | 
			
		||||
dependencies {
 | 
			
		||||
    minecraft 'net.minecraftforge:forge:1.18.2-40.1.48'
 | 
			
		||||
 | 
			
		||||
    compileOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.4.171:api")
 | 
			
		||||
    runtimeOnly fg.deobf("mezz.jei:jei-1.18.2:9.5.4.171")
 | 
			
		||||
    compileOnly fg.deobf("mezz.jei:jei-1.18.2-common-api:10.1.0.208")
 | 
			
		||||
    compileOnly fg.deobf("mezz.jei:jei-1.18.2-forge-api:10.1.0.208")
 | 
			
		||||
    runtimeOnly fg.deobf("mezz.jei:jei-1.18.2-forge:10.1.0.208")
 | 
			
		||||
 | 
			
		||||
    compileOnly fg.deobf('curse.maven:mouse-tweaks-60089:3578801')
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,10 @@ import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
 | 
			
		||||
import com.refinedmods.refinedstorage.item.CoverItem;
 | 
			
		||||
import com.refinedmods.refinedstorage.recipe.CoverRecipe;
 | 
			
		||||
import mezz.jei.api.constants.VanillaTypes;
 | 
			
		||||
import mezz.jei.api.gui.IRecipeLayout;
 | 
			
		||||
import mezz.jei.api.ingredients.IIngredients;
 | 
			
		||||
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICustomCraftingCategoryExtension;
 | 
			
		||||
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.ICraftingGridHelper;
 | 
			
		||||
import mezz.jei.api.recipe.IFocusGroup;
 | 
			
		||||
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICraftingCategoryExtension;
 | 
			
		||||
import net.minecraft.core.NonNullList;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.CreativeModeTab;
 | 
			
		||||
@@ -16,25 +17,24 @@ import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.Items;
 | 
			
		||||
import net.minecraft.world.level.block.Block;
 | 
			
		||||
import net.minecraftforge.common.Tags;
 | 
			
		||||
import net.minecraftforge.common.util.Size2i;
 | 
			
		||||
import net.minecraftforge.registries.ForgeRegistries;
 | 
			
		||||
import net.minecraftforge.registries.tags.ITag;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class CoverCraftingCategoryExtension implements ICustomCraftingCategoryExtension {
 | 
			
		||||
public class CoverCraftingCategoryExtension implements ICraftingCategoryExtension {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setIngredients(IIngredients ingredients) {
 | 
			
		||||
    public void setRecipe(IRecipeLayoutBuilder builder, ICraftingGridHelper craftingGridHelper, IFocusGroup focuses) {
 | 
			
		||||
        List<ItemStack> input = new ArrayList<>();
 | 
			
		||||
        List<ItemStack> output = new ArrayList<>();
 | 
			
		||||
        for (Block block : ForgeRegistries.BLOCKS.getValues()) {
 | 
			
		||||
            Item item = Item.byBlock(block);
 | 
			
		||||
            if (item == Items.AIR) {
 | 
			
		||||
            Item item = Item.BY_BLOCK.get(block);
 | 
			
		||||
            if (item == null || item == Items.AIR) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            NonNullList<ItemStack> subBlocks = NonNullList.create();
 | 
			
		||||
@@ -48,15 +48,26 @@ public class CoverCraftingCategoryExtension implements ICustomCraftingCategoryEx
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        ITag<Item> nuggets = ForgeRegistries.ITEMS.tags().getTag(Tags.Items.NUGGETS_IRON);
 | 
			
		||||
        ingredients.setInputLists(VanillaTypes.ITEM, Arrays.asList(nuggets.stream().map(ItemStack::new).collect(Collectors.toList()), input));
 | 
			
		||||
        ingredients.setOutputs(VanillaTypes.ITEM, output);
 | 
			
		||||
 | 
			
		||||
        ITag<Item> nuggetTag = ForgeRegistries.ITEMS.tags().getTag(Tags.Items.NUGGETS_IRON);
 | 
			
		||||
        List<ItemStack> nuggets = nuggetTag.stream().map(ItemStack::new).toList();
 | 
			
		||||
        List<List<ItemStack>> inputs = new ArrayList<>(Collections.nCopies(9, new ArrayList<>()));
 | 
			
		||||
        inputs.set(4, nuggets);
 | 
			
		||||
        inputs.set(5, input);
 | 
			
		||||
        craftingGridHelper.setInputs(builder, VanillaTypes.ITEM_STACK, inputs, 3, 3);
 | 
			
		||||
        craftingGridHelper.setOutputs(builder, VanillaTypes.ITEM_STACK, output);
 | 
			
		||||
 | 
			
		||||
        //builder.createFocusLink(in, out); //waiting on API update
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public Size2i getSize() {
 | 
			
		||||
        return new Size2i(2, 1);
 | 
			
		||||
    public int getWidth() {
 | 
			
		||||
        return 3;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getHeight() {
 | 
			
		||||
        return 3;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
@@ -64,21 +75,4 @@ public class CoverCraftingCategoryExtension implements ICustomCraftingCategoryEx
 | 
			
		||||
    public ResourceLocation getRegistryName() {
 | 
			
		||||
        return CoverRecipe.SERIALIZER.getRegistryName();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
 | 
			
		||||
        ITag<Item> nuggets = ForgeRegistries.ITEMS.tags().getTag(Tags.Items.NUGGETS_IRON);
 | 
			
		||||
        ItemStack stack = recipeLayout.getFocus(VanillaTypes.ITEM).getValue();
 | 
			
		||||
        if (stack.getItem() instanceof CoverItem) {
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(4, nuggets.stream().map(ItemStack::new).collect(Collectors.toList()));
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, CoverItem.getItem(stack));
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, stack);
 | 
			
		||||
        } else {
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(4, nuggets.stream().map(ItemStack::new).collect(Collectors.toList()));
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, stack);
 | 
			
		||||
            ItemStack output = new ItemStack(RSItems.COVER.get());
 | 
			
		||||
            CoverItem.setItem(output, stack);
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, output);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -9,8 +9,11 @@ import com.refinedmods.refinedstorage.network.grid.GridTransferMessage;
 | 
			
		||||
import com.refinedmods.refinedstorage.screen.grid.GridScreen;
 | 
			
		||||
import com.refinedmods.refinedstorage.screen.grid.stack.IGridStack;
 | 
			
		||||
import com.refinedmods.refinedstorage.screen.grid.stack.ItemGridStack;
 | 
			
		||||
import mezz.jei.api.gui.IRecipeLayout;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
 | 
			
		||||
import mezz.jei.api.constants.VanillaTypes;
 | 
			
		||||
import mezz.jei.api.forge.ForgeTypes;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
 | 
			
		||||
import mezz.jei.api.recipe.RecipeIngredientRole;
 | 
			
		||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
 | 
			
		||||
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
 | 
			
		||||
import net.minecraft.client.gui.screens.Screen;
 | 
			
		||||
@@ -19,11 +22,9 @@ import net.minecraft.world.inventory.CraftingContainer;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraft.world.item.crafting.CraftingRecipe;
 | 
			
		||||
import net.minecraftforge.fluids.FluidStack;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nonnull;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.LinkedList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.*;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridContainerMenu, Object> {
 | 
			
		||||
@@ -47,23 +48,22 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public IRecipeTransferError transferRecipe(@Nonnull GridContainerMenu container, Object recipe, @Nonnull IRecipeLayout recipeLayout, @Nonnull Player player, boolean maxTransfer, boolean doTransfer) {
 | 
			
		||||
    public @Nullable IRecipeTransferError transferRecipe(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) {
 | 
			
		||||
        if (!(container.getScreenInfoProvider() instanceof GridScreen)) {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        GridType type = container.getGrid().getGridType();
 | 
			
		||||
 | 
			
		||||
        if (type == GridType.CRAFTING) {
 | 
			
		||||
            return transferRecipeForCraftingGrid(container, recipe, recipeLayout, player, doTransfer);
 | 
			
		||||
            return transferRecipeForCraftingGrid(container, recipe, recipeSlots, player, doTransfer);
 | 
			
		||||
        } else if (type == GridType.PATTERN) {
 | 
			
		||||
            return transferRecipeForPatternGrid(container, recipe, recipeLayout, player, doTransfer);
 | 
			
		||||
            return transferRecipeForPatternGrid(container, recipe, recipeSlots, player, doTransfer);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContainerMenu container, Object recipe, IRecipeLayout recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
    private RecipeTransferCraftingGridError transferRecipeForCraftingGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
        IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer);
 | 
			
		||||
 | 
			
		||||
        if (doTransfer) {
 | 
			
		||||
@@ -88,7 +88,7 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private IRecipeTransferError transferRecipeForPatternGrid(GridContainerMenu container, Object recipe, IRecipeLayout recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
    private IRecipeTransferError transferRecipeForPatternGrid(GridContainerMenu container, Object recipe, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
        IngredientTracker tracker = createTracker(container, recipeLayout, player, doTransfer);
 | 
			
		||||
 | 
			
		||||
        if (doTransfer) {
 | 
			
		||||
@@ -102,7 +102,7 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private IngredientTracker createTracker(GridContainerMenu container, IRecipeLayout recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
    private IngredientTracker createTracker(GridContainerMenu container, IRecipeSlotsView recipeLayout, Player player, boolean doTransfer) {
 | 
			
		||||
        IngredientTracker tracker = new IngredientTracker(recipeLayout, doTransfer);
 | 
			
		||||
 | 
			
		||||
        // Using IGridView#getStacks will return a *filtered* list of items in the view,
 | 
			
		||||
@@ -145,66 +145,74 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
 | 
			
		||||
        return System.currentTimeMillis() - lastTransferTimeMs <= TRANSFER_SCROLLBAR_DELAY_MS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void moveItems(GridContainerMenu gridContainer, Object recipe, IRecipeLayout recipeLayout, IngredientTracker tracker) {
 | 
			
		||||
    private void moveItems(GridContainerMenu gridContainer, Object recipe, IRecipeSlotsView recipeLayout, IngredientTracker tracker) {
 | 
			
		||||
        this.lastTransferTimeMs = System.currentTimeMillis();
 | 
			
		||||
 | 
			
		||||
        if (gridContainer.getGrid().getGridType() == GridType.PATTERN && !(recipe instanceof CraftingRecipe)) {
 | 
			
		||||
            moveForProcessing(recipeLayout, tracker);
 | 
			
		||||
        } else {
 | 
			
		||||
            move(gridContainer, recipeLayout, recipe);
 | 
			
		||||
            move(recipeLayout);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void move(GridContainerMenu gridContainer, IRecipeLayout recipeLayout, Object recipe) {
 | 
			
		||||
        RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
 | 
			
		||||
            recipeLayout.getItemStacks().getGuiIngredients(),
 | 
			
		||||
            gridContainer.slots.stream().filter(s -> s.container instanceof CraftingContainer).collect(Collectors.toList()),
 | 
			
		||||
            recipe instanceof CraftingRecipe
 | 
			
		||||
        ));
 | 
			
		||||
    private void move(IRecipeSlotsView recipeSlotsView) {
 | 
			
		||||
        List<List<ItemStack>> inputs = recipeSlotsView.getSlotViews(RecipeIngredientRole.INPUT).stream().map(view -> {
 | 
			
		||||
 | 
			
		||||
            //Creating a mutable list
 | 
			
		||||
            List<ItemStack> stacks = view.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toCollection(ArrayList::new));
 | 
			
		||||
 | 
			
		||||
            //moving the displayed stack to first
 | 
			
		||||
            Optional<ItemStack> displayStack = view.getDisplayedIngredient(VanillaTypes.ITEM_STACK);
 | 
			
		||||
            displayStack.ifPresent(stack -> {
 | 
			
		||||
                int index = stacks.indexOf(stack);
 | 
			
		||||
                if (index > -1) {
 | 
			
		||||
                    stacks.remove(index);
 | 
			
		||||
                    stacks.add(0, stack);
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            return stacks;
 | 
			
		||||
        }).toList();
 | 
			
		||||
 | 
			
		||||
        RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(inputs));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void moveForProcessing(IRecipeLayout recipeLayout, IngredientTracker tracker) {
 | 
			
		||||
    private void moveForProcessing(IRecipeSlotsView recipeLayout, IngredientTracker tracker) {
 | 
			
		||||
        List<ItemStack> inputs = new LinkedList<>();
 | 
			
		||||
        List<ItemStack> outputs = new LinkedList<>();
 | 
			
		||||
 | 
			
		||||
        List<FluidStack> fluidInputs = new LinkedList<>();
 | 
			
		||||
        List<FluidStack> fluidOutputs = new LinkedList<>();
 | 
			
		||||
 | 
			
		||||
        for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
 | 
			
		||||
            handleItemIngredient(inputs, outputs, guiIngredient, tracker);
 | 
			
		||||
        List<IRecipeSlotView> inputSlots = recipeLayout.getSlotViews(RecipeIngredientRole.INPUT);
 | 
			
		||||
        for (IRecipeSlotView view : inputSlots) {
 | 
			
		||||
            handleItemIngredient(inputs, view, tracker);
 | 
			
		||||
            handleFluidIngredient(fluidInputs, view);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (IGuiIngredient<FluidStack> guiIngredient : recipeLayout.getFluidStacks().getGuiIngredients().values()) {
 | 
			
		||||
            handleFluidIngredient(fluidInputs, fluidOutputs, guiIngredient);
 | 
			
		||||
        List<IRecipeSlotView> outputSlots = recipeLayout.getSlotViews(RecipeIngredientRole.OUTPUT);
 | 
			
		||||
        for (IRecipeSlotView view : outputSlots) {
 | 
			
		||||
            handleItemIngredient(outputs, view, tracker);
 | 
			
		||||
            handleFluidIngredient(fluidOutputs, view);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        RS.NETWORK_HANDLER.sendToServer(new GridProcessingTransferMessage(inputs, outputs, fluidInputs, fluidOutputs));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void handleFluidIngredient(List<FluidStack> fluidInputs, List<FluidStack> fluidOutputs, IGuiIngredient<FluidStack> guiIngredient) {
 | 
			
		||||
        if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
 | 
			
		||||
            FluidStack ingredient = guiIngredient.getDisplayedIngredient().copy();
 | 
			
		||||
 | 
			
		||||
            if (guiIngredient.isInput()) {
 | 
			
		||||
                fluidInputs.add(ingredient);
 | 
			
		||||
            } else {
 | 
			
		||||
                fluidOutputs.add(ingredient);
 | 
			
		||||
            }
 | 
			
		||||
    private void handleFluidIngredient(List<FluidStack> list, IRecipeSlotView slotView) {
 | 
			
		||||
        if (slotView != null) {
 | 
			
		||||
            slotView.getDisplayedIngredient(ForgeTypes.FLUID_STACK).ifPresent(list::add);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void handleItemIngredient(List<ItemStack> inputs, List<ItemStack> outputs, IGuiIngredient<ItemStack> guiIngredient, IngredientTracker tracker) {
 | 
			
		||||
        if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
 | 
			
		||||
            ItemStack ingredient = tracker.findBestMatch(guiIngredient.getAllIngredients()).copy();
 | 
			
		||||
    private void handleItemIngredient(List<ItemStack> list, IRecipeSlotView slotView, IngredientTracker tracker) {
 | 
			
		||||
        if (slotView != null && slotView.getIngredients(VanillaTypes.ITEM_STACK).findAny().isPresent()) {
 | 
			
		||||
            ItemStack stack = tracker.findBestMatch(slotView.getIngredients(VanillaTypes.ITEM_STACK).toList());
 | 
			
		||||
 | 
			
		||||
            if (ingredient == ItemStack.EMPTY) {
 | 
			
		||||
                ingredient = guiIngredient.getDisplayedIngredient().copy();
 | 
			
		||||
            if (stack.isEmpty() && slotView.getDisplayedIngredient(VanillaTypes.ITEM_STACK).isPresent()) {
 | 
			
		||||
                stack = slotView.getDisplayedIngredient(VanillaTypes.ITEM_STACK).get();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (guiIngredient.isInput()) {
 | 
			
		||||
                inputs.add(ingredient);
 | 
			
		||||
            } else {
 | 
			
		||||
                outputs.add(ingredient);
 | 
			
		||||
            if (!stack.isEmpty()) {
 | 
			
		||||
                list.add(stack);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,30 +1,58 @@
 | 
			
		||||
package com.refinedmods.refinedstorage.integration.jei;
 | 
			
		||||
 | 
			
		||||
import com.refinedmods.refinedstorage.RSItems;
 | 
			
		||||
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
 | 
			
		||||
import com.refinedmods.refinedstorage.item.CoverItem;
 | 
			
		||||
import com.refinedmods.refinedstorage.recipe.HollowCoverRecipe;
 | 
			
		||||
import mezz.jei.api.constants.VanillaTypes;
 | 
			
		||||
import mezz.jei.api.gui.IRecipeLayout;
 | 
			
		||||
import mezz.jei.api.ingredients.IIngredients;
 | 
			
		||||
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICustomCraftingCategoryExtension;
 | 
			
		||||
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.ICraftingGridHelper;
 | 
			
		||||
import mezz.jei.api.recipe.IFocusGroup;
 | 
			
		||||
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICraftingCategoryExtension;
 | 
			
		||||
import net.minecraft.core.NonNullList;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.CreativeModeTab;
 | 
			
		||||
import net.minecraft.world.item.Item;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraftforge.common.util.Size2i;
 | 
			
		||||
import net.minecraft.world.item.Items;
 | 
			
		||||
import net.minecraft.world.level.block.Block;
 | 
			
		||||
import net.minecraftforge.registries.ForgeRegistries;
 | 
			
		||||
 | 
			
		||||
import javax.annotation.Nullable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class HollowCoverCraftingCategoryExtension implements ICustomCraftingCategoryExtension {
 | 
			
		||||
public class HollowCoverCraftingCategoryExtension implements ICraftingCategoryExtension {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setIngredients(IIngredients ingredients) {
 | 
			
		||||
        ingredients.setInput(VanillaTypes.ITEM, new ItemStack(RSItems.COVER.get()));
 | 
			
		||||
        ingredients.setOutput(VanillaTypes.ITEM, new ItemStack(RSItems.HOLLOW_COVER.get()));
 | 
			
		||||
    }
 | 
			
		||||
    public void setRecipe(IRecipeLayoutBuilder builder, ICraftingGridHelper craftingGridHelper, IFocusGroup focuses) {
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
    @Override
 | 
			
		||||
    public Size2i getSize() {
 | 
			
		||||
        return new Size2i(2, 1);
 | 
			
		||||
        List<List<ItemStack>> stacks = new ArrayList<>(Collections.nCopies(9, new ArrayList<>()));
 | 
			
		||||
        List<ItemStack> input = new ArrayList<>();
 | 
			
		||||
        List<ItemStack> output = new ArrayList<>();
 | 
			
		||||
        for (Block block : ForgeRegistries.BLOCKS.getValues()) {
 | 
			
		||||
            Item item = Item.BY_BLOCK.get(block);
 | 
			
		||||
            if (item == null || item == Items.AIR) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
            NonNullList<ItemStack> subBlocks = NonNullList.create();
 | 
			
		||||
            block.fillItemCategory(CreativeModeTab.TAB_SEARCH, subBlocks);
 | 
			
		||||
            for (ItemStack subBlock : subBlocks) {
 | 
			
		||||
                if (CoverManager.isValidCover(subBlock)) {
 | 
			
		||||
                    ItemStack fullCover = new ItemStack(RSItems.COVER.get());
 | 
			
		||||
                    CoverItem.setItem(fullCover, subBlock);
 | 
			
		||||
                    input.add(fullCover);
 | 
			
		||||
                    ItemStack hollowCover = new ItemStack(RSItems.HOLLOW_COVER.get());
 | 
			
		||||
                    CoverItem.setItem(hollowCover, subBlock);
 | 
			
		||||
                    output.add(hollowCover);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        stacks.set(4, input);
 | 
			
		||||
        craftingGridHelper.setInputs(builder, VanillaTypes.ITEM_STACK, stacks, 0, 0);
 | 
			
		||||
        craftingGridHelper.setOutputs(builder, VanillaTypes.ITEM_STACK, output);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Nullable
 | 
			
		||||
@@ -34,18 +62,12 @@ public class HollowCoverCraftingCategoryExtension implements ICustomCraftingCate
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
 | 
			
		||||
        ItemStack stack = recipeLayout.getFocus(VanillaTypes.ITEM).getValue();
 | 
			
		||||
        if (stack.getItem() == RSItems.COVER.get()) {
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, stack);
 | 
			
		||||
            ItemStack output = new ItemStack(RSItems.HOLLOW_COVER.get());
 | 
			
		||||
            CoverItem.setItem(output, CoverItem.getItem(stack));
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, output);
 | 
			
		||||
        } else {
 | 
			
		||||
            ItemStack input = new ItemStack(RSItems.COVER.get());
 | 
			
		||||
            CoverItem.setItem(input, CoverItem.getItem(stack));
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, input);
 | 
			
		||||
            recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, stack);
 | 
			
		||||
        }
 | 
			
		||||
    public int getWidth() {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int getHeight() {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,19 +1,18 @@
 | 
			
		||||
package com.refinedmods.refinedstorage.integration.jei;
 | 
			
		||||
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
class Ingredient {
 | 
			
		||||
    private final IGuiIngredient<ItemStack> guiIngredient;
 | 
			
		||||
    private final IRecipeSlotView slotView;
 | 
			
		||||
    private final int required;
 | 
			
		||||
    private UUID craftStackId;
 | 
			
		||||
    private int fulfilled;
 | 
			
		||||
 | 
			
		||||
    public Ingredient(IGuiIngredient<ItemStack> guiIngredient) {
 | 
			
		||||
        this.guiIngredient = guiIngredient;
 | 
			
		||||
        this.required = guiIngredient.getAllIngredients().get(0).getCount();
 | 
			
		||||
    public Ingredient(IRecipeSlotView view, int count) {
 | 
			
		||||
        this.slotView = view;
 | 
			
		||||
        this.required = count;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAvailable() {
 | 
			
		||||
@@ -28,8 +27,8 @@ class Ingredient {
 | 
			
		||||
        return craftStackId != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public IGuiIngredient<ItemStack> getGuiIngredient() {
 | 
			
		||||
        return guiIngredient;
 | 
			
		||||
    public IRecipeSlotView getSlotView() {
 | 
			
		||||
        return slotView;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public UUID getCraftStackId() {
 | 
			
		||||
 
 | 
			
		||||
@@ -6,8 +6,10 @@ import com.refinedmods.refinedstorage.api.util.IComparer;
 | 
			
		||||
import com.refinedmods.refinedstorage.apiimpl.API;
 | 
			
		||||
import com.refinedmods.refinedstorage.item.PatternItem;
 | 
			
		||||
import com.refinedmods.refinedstorage.screen.grid.stack.IGridStack;
 | 
			
		||||
import mezz.jei.api.gui.IRecipeLayout;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
 | 
			
		||||
import mezz.jei.api.constants.VanillaTypes;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
 | 
			
		||||
import mezz.jei.api.recipe.RecipeIngredientRole;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
import net.minecraft.resources.ResourceLocation;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
@@ -20,12 +22,13 @@ public class IngredientTracker {
 | 
			
		||||
    private final Map<ResourceLocation, Integer> storedItems = new HashMap<>();
 | 
			
		||||
    private boolean doTransfer;
 | 
			
		||||
 | 
			
		||||
    public IngredientTracker(IRecipeLayout recipeLayout, boolean doTransfer) {
 | 
			
		||||
        for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
 | 
			
		||||
            if (guiIngredient.isInput() && !guiIngredient.getAllIngredients().isEmpty()) {
 | 
			
		||||
                ingredients.add(new Ingredient(guiIngredient));
 | 
			
		||||
            }
 | 
			
		||||
    public IngredientTracker(IRecipeSlotsView recipeLayout, boolean doTransfer) {
 | 
			
		||||
        for (IRecipeSlotView slotView : recipeLayout.getSlotViews(RecipeIngredientRole.INPUT)) {
 | 
			
		||||
            Optional<ItemStack> optionalItemStack = slotView.getIngredients(VanillaTypes.ITEM_STACK).findAny();
 | 
			
		||||
 | 
			
		||||
            optionalItemStack.ifPresent(stack -> ingredients.add(new Ingredient(slotView, stack.getCount())));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        this.doTransfer = doTransfer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -55,9 +58,8 @@ public class IngredientTracker {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Optional<ItemStack> match = ingredient
 | 
			
		||||
                .getGuiIngredient()
 | 
			
		||||
                .getAllIngredients()
 | 
			
		||||
                .stream()
 | 
			
		||||
                .getSlotView()
 | 
			
		||||
                .getIngredients(VanillaTypes.ITEM_STACK)
 | 
			
		||||
                .filter(s -> API.instance().getComparer().isEqual(stack, s, IComparer.COMPARE_NBT))
 | 
			
		||||
                .findFirst();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
package com.refinedmods.refinedstorage.integration.jei;
 | 
			
		||||
 | 
			
		||||
import com.mojang.blaze3d.vertex.PoseStack;
 | 
			
		||||
import mezz.jei.api.gui.IRecipeLayout;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
 | 
			
		||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
 | 
			
		||||
import net.minecraft.ChatFormatting;
 | 
			
		||||
import net.minecraft.client.Minecraft;
 | 
			
		||||
@@ -29,11 +29,11 @@ public class RecipeTransferCraftingGridError implements IRecipeTransferError {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void showError(PoseStack stack, int mouseX, int mouseY, IRecipeLayout recipeLayout, int recipeX, int recipeY) {
 | 
			
		||||
        List<Component> message = drawIngredientHighlights(stack, recipeX, recipeY);
 | 
			
		||||
    public void showError(PoseStack poseStack, int mouseX, int mouseY, IRecipeSlotsView recipeSlotsView, int recipeX, int recipeY) {
 | 
			
		||||
        List<Component> message = drawIngredientHighlights(poseStack, recipeX, recipeY);
 | 
			
		||||
 | 
			
		||||
        Screen currentScreen = Minecraft.getInstance().screen;
 | 
			
		||||
        currentScreen.renderComponentTooltip(stack, message, mouseX, mouseY);
 | 
			
		||||
        currentScreen.renderComponentTooltip(poseStack, message, mouseX, mouseY);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected List<Component> drawIngredientHighlights(PoseStack stack, int recipeX, int recipeY) {
 | 
			
		||||
@@ -46,10 +46,10 @@ public class RecipeTransferCraftingGridError implements IRecipeTransferError {
 | 
			
		||||
        for (Ingredient ingredient : tracker.getIngredients()) {
 | 
			
		||||
            if (!ingredient.isAvailable()) {
 | 
			
		||||
                if (ingredient.isCraftable()) {
 | 
			
		||||
                    ingredient.getGuiIngredient().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB(), recipeX, recipeY);
 | 
			
		||||
                    ingredient.getSlotView().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB());
 | 
			
		||||
                    craftMessage = true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    ingredient.getGuiIngredient().drawHighlight(stack, MISSING_HIGHLIGHT_COLOR.getRGB(), recipeX, recipeY);
 | 
			
		||||
                    ingredient.getSlotView().drawHighlight(stack, MISSING_HIGHLIGHT_COLOR.getRGB());
 | 
			
		||||
                    missingMessage = true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -22,7 +22,7 @@ public class RecipeTransferPatternGridError extends RecipeTransferCraftingGridEr
 | 
			
		||||
 | 
			
		||||
        for (Ingredient ingredient : tracker.getIngredients()) {
 | 
			
		||||
            if (ingredient.isCraftable()) {
 | 
			
		||||
                ingredient.getGuiIngredient().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB(), recipeX, recipeY);
 | 
			
		||||
                ingredient.getSlotView().drawHighlight(stack, AUTOCRAFTING_HIGHLIGHT_COLOR.getRGB());
 | 
			
		||||
                craftMessage = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,47 +1,36 @@
 | 
			
		||||
package com.refinedmods.refinedstorage.network.grid;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
import com.refinedmods.refinedstorage.api.network.grid.GridType;
 | 
			
		||||
import com.refinedmods.refinedstorage.api.network.grid.IGrid;
 | 
			
		||||
import com.refinedmods.refinedstorage.container.GridContainerMenu;
 | 
			
		||||
import com.refinedmods.refinedstorage.util.StackUtils;
 | 
			
		||||
import mezz.jei.api.gui.ingredient.IGuiIngredient;
 | 
			
		||||
import net.minecraft.network.FriendlyByteBuf;
 | 
			
		||||
import net.minecraft.world.entity.player.Player;
 | 
			
		||||
import net.minecraft.world.inventory.Slot;
 | 
			
		||||
import net.minecraft.world.item.ItemStack;
 | 
			
		||||
import net.minecraftforge.network.NetworkEvent;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
 | 
			
		||||
public class GridTransferMessage {
 | 
			
		||||
    private final ItemStack[][] recipe = new ItemStack[9][];
 | 
			
		||||
    private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs;
 | 
			
		||||
    private List<Slot> slots;
 | 
			
		||||
    boolean isCraftingRecipe;
 | 
			
		||||
    List<List<ItemStack>> inputs;
 | 
			
		||||
 | 
			
		||||
    public GridTransferMessage() {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public GridTransferMessage(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots, boolean isCraftingRecipe) {
 | 
			
		||||
    public GridTransferMessage(List<List<ItemStack>> inputs) {
 | 
			
		||||
        this.inputs = inputs;
 | 
			
		||||
        this.slots = slots;
 | 
			
		||||
        this.isCraftingRecipe = isCraftingRecipe;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static GridTransferMessage decode(FriendlyByteBuf buf) {
 | 
			
		||||
        GridTransferMessage msg = new GridTransferMessage();
 | 
			
		||||
 | 
			
		||||
        int slots = buf.readInt();
 | 
			
		||||
        for (int i = 0; i < slots; i++) {
 | 
			
		||||
            int numberOfIngredients = buf.readInt();
 | 
			
		||||
            msg.recipe[i] = new ItemStack[numberOfIngredients];
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < slots; ++i) {
 | 
			
		||||
            int ingredients = buf.readInt();
 | 
			
		||||
 | 
			
		||||
            msg.recipe[i] = new ItemStack[ingredients];
 | 
			
		||||
 | 
			
		||||
            for (int j = 0; j < ingredients; ++j) {
 | 
			
		||||
            for (int j = 0; j < numberOfIngredients; j++) {
 | 
			
		||||
                msg.recipe[i][j] = StackUtils.readItemStack(buf);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -50,29 +39,18 @@ public class GridTransferMessage {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void encode(GridTransferMessage message, FriendlyByteBuf buf) {
 | 
			
		||||
        buf.writeInt(message.slots.size());
 | 
			
		||||
 | 
			
		||||
        for (Slot slot : message.slots) {
 | 
			
		||||
            IGuiIngredient<ItemStack> ingredient = message.inputs.get(slot.getSlotIndex() + (message.isCraftingRecipe ? 1 : 0));
 | 
			
		||||
        buf.writeInt(message.inputs.size());
 | 
			
		||||
        for (List<ItemStack> stacks : message.inputs) {
 | 
			
		||||
            buf.writeInt(stacks.size());
 | 
			
		||||
 | 
			
		||||
            List<ItemStack> ingredients = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
            if (ingredient != null) {
 | 
			
		||||
                for (ItemStack possibleStack : ingredient.getAllIngredients()) {
 | 
			
		||||
                    if (possibleStack != null) {
 | 
			
		||||
                        ingredients.add(possibleStack);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            buf.writeInt(ingredients.size());
 | 
			
		||||
 | 
			
		||||
            for (ItemStack possibleStack : ingredients) {
 | 
			
		||||
            for (ItemStack possibleStack : stacks) {
 | 
			
		||||
                StackUtils.writeItemStack(buf, possibleStack);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public static void handle(GridTransferMessage message, Supplier<NetworkEvent.Context> ctx) {
 | 
			
		||||
        Player player = ctx.get().getSender();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user