Search in sources :

Example 1 with RecipePattern

use of fi.dy.masa.itemscroller.recipes.RecipePattern in project MasaGadget by plusls.

the class RestockUtil method tryCraftingRestocking.

public static void tryCraftingRestocking(PlayerEntity player, Hand hand, ItemStack itemStack) {
    if (player.isCreative()) {
        return;
    }
    updateRecipes();
    // TODO: Lazy update (on itemscoller's RecipeStorage updated or config changed)
    MinecraftClient mc = MinecraftClient.getInstance();
    HandledScreen<? extends ScreenHandler> gui = new InventoryScreen(player);
    gui.init(MinecraftClient.getInstance(), 0, 0);
    for (RecipePattern recipe : RestockUtil.recipes) {
        if (ItemStack.canCombine(recipe.getResult(), itemStack)) {
            InventoryUtils.tryMoveItemsToFirstCraftingGrid(recipe, gui, false);
            mc.interactionManager.clickSlot(player.playerScreenHandler.syncId, 0, 0, SlotActionType.PICKUP, player);
            if (player.playerScreenHandler.getCursorStack().isItemEqual(itemStack)) {
                mc.interactionManager.clickSlot(player.playerScreenHandler.syncId, hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot + 36 : 45, 0, SlotActionType.PICKUP, player);
                return;
            } else {
                Slot slot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui);
                CraftingHandler.SlotRange range = CraftingHandler.getCraftingGridSlots(gui, slot);
                for (int s = range.getFirst(); s <= range.getLast(); s++) {
                    mc.interactionManager.clickSlot(gui.getScreenHandler().syncId, s, 0, SlotActionType.QUICK_MOVE, mc.player);
                }
            }
        }
    }
}
Also used : RecipePattern(fi.dy.masa.itemscroller.recipes.RecipePattern) MinecraftClient(net.minecraft.client.MinecraftClient) Slot(net.minecraft.screen.slot.Slot) CraftingHandler(fi.dy.masa.itemscroller.recipes.CraftingHandler) InventoryScreen(net.minecraft.client.gui.screen.ingame.InventoryScreen)

Aggregations

CraftingHandler (fi.dy.masa.itemscroller.recipes.CraftingHandler)1 RecipePattern (fi.dy.masa.itemscroller.recipes.RecipePattern)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 InventoryScreen (net.minecraft.client.gui.screen.ingame.InventoryScreen)1 Slot (net.minecraft.screen.slot.Slot)1