ComputerCraft Archive

PotionBottler

computer mod-integration Caitlin-Sykes github

Description

The following repository is a collection of small scripts that do various things. There are ReadMe's within each folder that describes what the scripts do.

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/Caitlin-Sykes/ComputerCraft-Scripts/main/Misc%20Scripts/PotionBottler.lua potionbottler
Archive:wget https://cc.shobie.xyz/cc/get/gh-Caitlin-Sykes-ComputerCraft-Scripts-misc-scripts-potionbottler potionbottler
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-Caitlin-Sykes-ComputerCraft-Scripts-misc-scripts-potionbottler PotionBottler

Usage

Run: PotionBottler

Tags

none

Source

View Original Source

Code Preview

local ME = peripheral.wrap("meBridge_1")
local tunnel = peripheral.wrap("create:brass_tunnel_0")
local cableColor = 0x1
local bundledDir = "bottom"
local cur_output = redstone.getBundledOutput(bundledDir)

function CheckForPotionRecipe()
    while true do
        local craftableItems = ME.listCraftableItems()

        -- Looks for crafting job, if ME has one going, export bottles
        for _, item in pairs(craftableItems) do
            if item.tags then
                for _, tag in pairs(item.tags) do
                    if tag == "minecraft:item/utilitix:potions" or tag == "Potion" then
                        if ME.isItemCrafting(item) then
                            -- Turn on Power
                            cur_output = colours.combine(cur_output, cableColor)
                            redstone.setBundledOutput(bundledDir, cur_output)

                            -- Export bottles
                            print("Exporting bottles to tunnel")
                            ME.exportItemToPeripheral({
                                name = "minecraft:glass_bottle"
                            }, "create:brass_tunnel_0")
                        else
                            print("Turning off the power...")
                            -- Turn off the power
                            cur_output = colours.subtract(cur_output, cableColor)
                            redstone.setBundledOutput(bundledDir, cur_output)
                        end
                    end
                end
            end
        end
        sleep(10)
    end
end

parallel.waitForAll(CheckForPotionRecipe)