2020-05-09 14:56:58 +02:00
|
|
|
package de.ellpeck.prettypipes.compat.jei;
|
|
|
|
|
2022-06-27 14:19:51 +02:00
|
|
|
import de.ellpeck.prettypipes.Registry;
|
|
|
|
import de.ellpeck.prettypipes.packets.PacketGhostSlot;
|
|
|
|
import de.ellpeck.prettypipes.packets.PacketHandler;
|
|
|
|
import de.ellpeck.prettypipes.terminal.containers.CraftingTerminalContainer;
|
|
|
|
import mezz.jei.api.constants.RecipeTypes;
|
|
|
|
import mezz.jei.api.constants.VanillaTypes;
|
|
|
|
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
|
|
|
|
import mezz.jei.api.recipe.RecipeIngredientRole;
|
|
|
|
import mezz.jei.api.recipe.RecipeType;
|
|
|
|
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
|
|
|
import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
|
|
|
import net.minecraft.world.entity.player.Player;
|
|
|
|
import net.minecraft.world.inventory.MenuType;
|
|
|
|
import net.minecraft.world.item.crafting.CraftingRecipe;
|
2024-02-03 22:01:43 +01:00
|
|
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
2022-06-27 14:19:51 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2024-02-03 22:01:43 +01:00
|
|
|
public class CraftingTerminalTransferHandler implements IRecipeTransferHandler<CraftingTerminalContainer, RecipeHolder<CraftingRecipe>> {
|
2021-12-19 17:27:21 +01:00
|
|
|
|
2020-05-09 14:56:58 +02:00
|
|
|
@Override
|
|
|
|
public Class<CraftingTerminalContainer> getContainerClass() {
|
|
|
|
return CraftingTerminalContainer.class;
|
|
|
|
}
|
|
|
|
|
2021-12-19 17:27:21 +01:00
|
|
|
@Override
|
2022-06-27 14:19:51 +02:00
|
|
|
public Optional<MenuType<CraftingTerminalContainer>> getMenuType() {
|
|
|
|
return Optional.of(Registry.craftingTerminalContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-02-03 22:01:43 +01:00
|
|
|
public RecipeType<RecipeHolder<CraftingRecipe>> getRecipeType() {
|
2022-06-27 14:19:51 +02:00
|
|
|
return RecipeTypes.CRAFTING;
|
2021-12-19 17:27:21 +01:00
|
|
|
}
|
|
|
|
|
2020-05-09 14:56:58 +02:00
|
|
|
@Override
|
2024-02-03 22:01:43 +01:00
|
|
|
public @Nullable IRecipeTransferError transferRecipe(CraftingTerminalContainer container, RecipeHolder<CraftingRecipe> recipe, IRecipeSlotsView slots, Player player, boolean maxTransfer, boolean doTransfer) {
|
2020-05-09 14:56:58 +02:00
|
|
|
if (!doTransfer)
|
|
|
|
return null;
|
2022-06-27 14:19:51 +02:00
|
|
|
List<PacketGhostSlot.Entry> stacks = new ArrayList<>();
|
|
|
|
var ingredients = slots.getSlotViews(RecipeIngredientRole.INPUT);
|
|
|
|
for (var entry : ingredients)
|
2023-07-07 19:54:52 +02:00
|
|
|
stacks.add(new PacketGhostSlot.Entry(player.level(), entry.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList())));
|
2021-12-19 17:27:21 +01:00
|
|
|
PacketHandler.sendToServer(new PacketGhostSlot(container.getTile().getBlockPos(), stacks));
|
2020-05-09 14:56:58 +02:00
|
|
|
return null;
|
|
|
|
}
|
2024-02-03 22:01:43 +01:00
|
|
|
|
2020-05-09 14:56:58 +02:00
|
|
|
}
|