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