Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "1.2.2"
- local function validateItem(itemName)
- if itemName == 'minecraft:wheat_seeds' or itemName == 'minecraft:carrot' or itemName == 'minecraft:potato' then
- return true
- end
- end
- local function validateBlock(blockName)
- if blockName == 'minecraft:wheat' or blockName == 'minecraft:carrots' or blockName == 'minecraft:potatoes' then
- return true
- end
- end
- local function replaceCrop()
- local success, blockBelow = turtle.inspectDown()
- if success and validateBlock(blockBelow.name) and blockBelow.metadata == 7 then
- turtle.digDown()
- turtle.placeDown()
- end
- end
- local move = {
- forward = function()
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- end,
- up = function()
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- end
- end,
- down = function()
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- end
- end
- }
- local function checkSeeds()
- seedCount = 0
- for i = 1, 16 do
- item = turtle.getItemDetail(i)
- if item and validateItem(item.name) then
- seedCount = seedCount + item.count
- end
- end
- if seedCount >= 16 then
- return true
- end
- end
- local function getSeeds()
- firstSeed = nil
- gotSeed = false
- for i = 1, 16 do
- item = turtle.getItemDetail(i)
- if item and validateItem(item.name) then
- if firstSeed then
- if turtle.getItemCount(firstSeed) >= 16 then
- turtle.select(firstSeed)
- break
- else
- turtle.select(i)
- turtle.transferTo(firstSeed)
- end
- else
- firstSeed = i
- end
- end
- end
- if turtle.getItemCount(firstSeed) >= 16 then
- turtle.select(firstSeed)
- end
- end
- local function checkLog(dir)
- local success, blockData = turtle['inspect' .. (dir and dir or '')]()
- if success and blockData.name:find('minecraft:log') then
- return true
- end
- end
- local function chopTree()
- if checkLog('Down') then
- turtle.digDown()
- local height = 0
- while checkLog('Up') do
- height = height + 1
- move.up()
- end
- for i=1, height do
- move.down()
- end
- end
- end
- local function line(numBlocks, update)
- for x = 1, tonumber(numBlocks) - 1 do
- move.forward()
- update()
- end
- end
- local function grid(dim, update)
- update()
- for y = 1, tonumber(dim[2]) - 1 do
- line(dim[1], update)
- if y % 2 == 0 then
- turtle.turnLeft()
- move.forward()
- update()
- turtle.turnLeft()
- else
- turtle.turnRight()
- move.forward()
- update()
- turtle.turnRight()
- end
- end
- line(dim[2], update)
- end
- local function validateNum(num, lower, upper)
- if tonumber(num) then
- local lowerCondition = lower and tonumber(lower) and tonumber(num) >= lower or not lower
- local upperCondition = upper and tonumber(upper) and tonumber(num) <= upper or not upper
- if lowerCondition and upperCondition then
- return true
- end
- end
- end
- status = {harvest = 1, treefarm = 1}
- helpTable = {harvest = 'Harvest a custom size field of crops', treefarm = 'Harvest a grid of trees'}
- functionTable = {
- harvest = function(item, id, prot)
- seeds = checkSeeds()
- if seeds and validateNum(item[1], 1, 40) and validateNum(item[2], 1, 40) then
- rednet.send(id, 'Harvesting a field of crops', prot)
- getSeeds()
- grid(item, replaceCrop)
- elseif not seeds then
- rednet.send(id, 'Error: i need atleast 16 seeds in me to operate', prot)
- else
- rednet.send(id, 'Usage: Harvest [arg1] [arg2] where both arguments must be numbers from 1-40', prot)
- end
- end,
- treefarm = function(item, id, prot)
- if validateNum(item[1], 1, 40) and validateNum(item[2], 1, 40) then
- rednet.send(id, 'Chopping down a grid of trees', prot)
- move.forward()
- grid(item, chopTree)
- else
- rednet.send(id, 'Usage: treefarm [arg1] [arg2] where both arguments must be numbers from 1-40', prot)
- end
- end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement