ComputerCraft Archive

mobfarm

turtle utility OcWebb github

Description

A collection of scripts used to automate tasks in Minecraft using the Computercraft mod and the Lua language

Installation

Copy one of these commands into your ComputerCraft terminal:

wget:wget https://raw.githubusercontent.com/OcWebb/computercraft-scripts/main/mobfarm.lua mobfarm
Archive:wget https://cc.shobie.xyz/cc/get/gh-OcWebb-computercraft-scripts-mobfarm mobfarm
Quick Install: wget https://cc.shobie.xyz/cc/get/gh-OcWebb-computercraft-scripts-mobfarm mobfarm

Usage

Run: mobfarm

Tags

turtle

Source

View Original Source

Code Preview

function inventory_full()
    for i = 1, 16 do
        if turtle.getItemCount(i) == 0 then
            return false
        end
    end
    return true
end
 
function empty_inventory()
    for i = 1, 16 do
        turtle.select(i)
        turtle.drop()
    end
end
 
local i = 0
while true do
    turtle.attack()
    if i > 10 and inventory_full() then
        turtle.turnRight()
        turtle.turnRight()
        empty_inventory()
        turtle.turnRight()
        turtle.turnRight()
        i = 0
    end
    i = i + 1
end