Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
-- 植物魔法活石活木 local args = {...}; if args[1] == nil or args[1] == 0 or args[2] == nil or args[2] == 0 then print("invalid arg expect program range range"); return; end local mData = { wood = { solt = 4, layer = 2, productSolt = 2, radio = 0.3 }, stone = { solt = 5, layer = 3, productSolt = 3, radio = 0.7 }, currLayer = 1; } local range = {x = tonumber(args[1]), z = tonumber(args[2])}; -- 传输活石或活木到箱子中 function reap(solt) print("current solt = ", solt); local itemData = turtle.getItemDetail(solt); print("item name = ", itemData.name); for i = 1, 16, 1 do print("try get itemData now"); local currItemData = turtle.getItemDetail(i); -- 如果物品存在并且与指定位置的物品相同 if (currItemData ~= nil) then print("cant get itemData at ", i, "solt"); print("this item name = ", currItemData.name); if (itemData.name == currItemData.name) then local itemCount = turtle.getItemCount(i); print("this item count = ", itemCount); turtle.select(i); if i == solt then turtle.drop(itemCount - 1); end if i ~= solt then turtle.drop(itemCount); end end end if currItemData == nil then print("cant get itemData at ", i, "solt"); end end end function fetch(solt, need, layer) turtle.select(solt); local itemCount = turtle.getItemCount(); if itemCount == nil then return 0; end if itemCount + 1 >= need then return itemCount + 1; else goLayer(layer); turtle.suck(need - itemCount + 1); print("layer suck item count = ", need - itemCount + 1, " then itemCount = ", turtle.getItemCount()); return turtle.getItemCount(); end end function goLayer(layer) print("go layer = ", layer, "currLayer = ", mData.currLayer); local step = layer - mData.currLayer; while (mData.currLayer < 10) and (mData.currLayer > 0) do if layer == mData.currLayer then return true; end if step < 0 then turtle.down(); mData.currLayer = mData.currLayer - 1; end if step > 0 then turtle.up(); mData.currLayer = mData.currLayer + 1; end end return false; end function tryStart(totalStep) local totalCount = totalStep - (totalStep / 9); -- 32 local woodNeed = math.floor(totalCount * mData.wood.radio); -- 9 local stoneNeed = totalCount - woodNeed; -- 23 local fetchCount = fetch(mData.wood.solt, woodNeed, mData.wood.layer) + fetch(mData.stone.solt, stoneNeed, mData.stone.layer); goLayer(1); return fetchCount >= totalCount; end function patrolling(range) local totalStep = range.x * range.z; -- 18 local postion = {x = 1, z = 1}; local totalCount = totalStep - (totalStep / 9); local woodStep = {math.floor(totalCount * mData.wood.radio)}; turtle.turnRight(); turtle.turnRight(); for i = 1, totalStep, 1 do action(woodStep, i); -- print("i=", i, ",postion.z=", postion.z, ",postion.x=", postion.x); if math.fmod(i, range.x) == 0 then -- 如果达到x坐标的变界 print("reach x border, postion.z=", postion.z, ",range.z=", range.z); if postion.z == range.z then -- 如果当前z坐标等于范围z坐标,说明已经走到最大的范围 print("start back currx=", postion.x, " currz=", postion.z); if math.fmod(postion.z, 2) == 1 then back(range.x, range.z); end if math.fmod(postion.z, 2) == 0 then back(1, range.z); end break; end if math.fmod(postion.z, 2) == 1 then -- 如果是奇数列 turtle.turnRight(); turtle.forward(); turtle.turnRight(); end if math.fmod(postion.z, 2) == 0 then -- 如果是偶数列 turtle.turnLeft(); turtle.forward(); turtle.turnLeft(); end postion.z = postion.z + 1; else -- 如果没有达到x坐标的边界 turtle.forward(); end end end function back(x, z) -- x == 6 z == 6 local home = {x = 1, z = 1}; if x > home.x then turtle.turnLeft(); turtle.turnLeft(); end while true do if x == home.x then break; else turtle.forward(); end x = x - 1; end if z > home.z then turtle.turnRight(); while true do if z == home.z then turtle.turnLeft(); break; else turtle.forward(); end z = z - 1; end end reap(mData.wood.productSolt); reap(mData.stone.productSolt); end function compareAndDig(woodStep, step) turtle.select(mData.wood.productSolt); if turtle.compareDown() then turtle.digDown(); placeBlock(woodStep, step); return true; end turtle.select(mData.stone.productSolt); if turtle.compareDown() then turtle.digDown(); placeBlock(woodStep, step); return true; end return false; end function action(woodStep, step) -- 如果检测到下方有方块,则挖掘并放置 if turtle.detectDown() and not compareAndDig(woodStep, step) then woodStep[1] = woodStep[1] + 1; -- 如果没有检测到方块则直接放置 else placeBlock(woodStep, step); end end function placeBlock(woodStep, step) if step <= woodStep[1] then turtle.select(mData.wood.solt); else turtle.select(mData.stone.solt); end if turtle.getItemCount() > 1 then turtle.placeDown(); end end while true do if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then turtle.select(1); turtle.refuel(1); end if turtle.getFuelLevel() < 1 then print("need fuel!!"); break; end if redstone.getInput("right") then break end if tryStart(range.x * range.z) then if turtle.detectDown() then turtle.select(mData.wood.productSolt); if turtle.compareDown() then patrolling(range); end turtle.select(mData.stone.productSolt); if turtle.compareDown() then patrolling(range); end else patrolling(range); end end os.sleep(2); end
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
C | 4 min ago
crappy program in...
C | 15 min ago
Timesmasher
C# | 60 min ago
bfs clasa
C++ | 1 hour ago
ввод, сортировка и...
C++ | 1 hour ago
Untitled
Java | 1 hour ago
17-06-2020.c
C | 2 hours ago
31-08-2020.c
C | 2 hours ago
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!