Advertisement
aodminecraft

Arc OS - Worldedit - programs/WE_Core

Aug 1st, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.59 KB | None | 0 0
  1. --Documentation:
  2. --This program is a framework which has a bunch of useful functions that other commands need, like selection.
  3.  
  4. --For the WorldEdit equivalent of each function, the link is right before the function itself.
  5.  
  6. --Common variable name syntax:
  7. --Num[Command]=Number argument for [Command]. Ex: NumLoadClipboard is which clipboard to load.
  8. --Giving certain commands a boolean argument will specify if they should output. (set(true) will output nothing!)
  9. --x1, y1, z1, and x2, y2, and z2 are the coordinates of cuboid selections.
  10. --px, py, and pz are the player's coordinates.
  11. --Blocks and Meta contain the block IDs to be replaced, and Blocks2 and Meta2 are what they are changed to. (So, Blocks2 and Meta2 would be used in set)
  12. --heightmap() returns a heightmap of the selection, used for commands like overlay or naturalize.
  13.  
  14. --message is in lowercase, OriginalMessage is completely unchanged.
  15.  
  16. --The global names for interfacing with the adventure map interface are consistent with Immibis's documentation.
  17.  
  18. --Default program paths (can be changed):
  19. APIPath="programs/GeneralAPI"
  20. CuboidPath="programs/WE_Cuboid"
  21. SelPath="programs/WE_Sel"
  22. ClipboardPath="programs/WE_Clipboard"
  23. debugPath="programs/debug"
  24.  
  25.  
  26. hasChatBox=false
  27. local function getChat()
  28.   local username,message
  29.   while true do
  30.     local args={os.pullEvent()} --Get chat messages
  31.     if args[1]:sub(1,4)=="chat" then
  32.       username=#args~=3 and args[3] or args[2]
  33.       message=#args~=3 and args[4] or args[3]
  34.       break
  35.     end
  36.   end
  37.   return username,message
  38. end
  39.  
  40. p=peripheral.find("adventure map interface")
  41. if not p then
  42.   print("Connect an adventure map interface or a chat box and say something to continue.")
  43.   username,message=getChat()
  44. end
  45.  
  46. hasChatBox=type(commands)=="table" and p==nil
  47. print("Just say your desired command or help for a list of commands.")
  48.  
  49. blockBlacklist={473}
  50. Selection={}
  51. Direction=""
  52. shell.run(APIPath)
  53. shell.run(CuboidPath)
  54. shell.run(SelPath)
  55. if fs.exists(ClipboardPath) then
  56.   hasNBT=true
  57.   shell.run(ClipboardPath)
  58. end
  59. local args={...}
  60. for i=1,#args do
  61.   if args[i]=="-d" or args[i]=="-debug" and fs.exists(debugPath) then
  62.     debug=dofile(debugPath)
  63.     break
  64.   end
  65. end
  66.  
  67. w=p and p.getWorld(p.getPeripheralWorldID())
  68. local BlockNames={{"stone","rock"},{"grass"},{"dirt"},{"cobblestone","cobble"},{"wood","woodplank","plank","woodplanks","planks"},{"sapling","seedling"},{"adminium","bedrock"},{"water_(stationary)","water","waterstationary","stationarywater","stillwater"},{"watermoving","movingwater","flowingwater","waterflowing"},{"lavamoving","movinglava","flowinglava","lavaflowing"},{"lava_(stationary)","lava","lavastationary","stationarylava","stilllava"},{"sand"},{"gravel"},{"gold_ore","goldore"},{"iron_ore","ironore"},{"coal_ore","coalore"},{"log","tree","pine","oak","birch","jungle"},{"leaves","leaf"},{"sponge"},{"glass"},{"lapis_lazuli_ore","lapislazuliore","blueore","lapisore"},{"lapis_lazuli","lapislazuli","lapislazuliblock","bluerock","lapisblock"},{"dispenser"},{"sandstone"},{"note_block","musicblock","noteblock","note","music","instrument"},{"bed"},{"poweredrail","boosterrail","poweredtrack","boostertrack","booster"},{"detector_rail","detectorrail","detector"},{"sticky_piston","stickypiston"},{"web","spiderweb"},{"long_grass","longgrass","tallgrass"},{"deadbush","shrub","deadshrub","tumbleweed"},{"piston"},{"piston_extension","pistonextendsion","pistonhead"},{"cloth","wool"},{"piston_moving_piece","movingpiston"},{"yellow_flower","yellowflower","flower"},{"red_rose","redflower","redrose","rose"},{"brown_mushroom","brownmushroom","mushroom"},{"red_mushroom","redmushroom"},{"gold_block","gold","goldblock"},{"iron_block","iron","ironblock"},{"double_step","doubleslab","doublestoneslab","doublestep"},{"slab","stoneslab","step","halfstep"},{"brick","brickblock"},{"tnt","c4","explosive"},{"bookshelf","bookshelves","bookcase","bookcases"},{"cobblestone_(mossy)","mossycobblestone","mossstone"},{"obsidian"},{"torch","light","candle"},{"fire","flame","flames"},{"mob_spawner","mobspawner","spawner"},{"wooden_stairs","woodstair","woodstairs","woodenstair","woodenstairs"},{"chest","storage","storagechest"},{"redstone_wire","redstone","redstoneblock"},{"diamond_ore","diamondore"},{"diamond_block","diamond","diamondblock"},{"workbench","table","craftingtable","crafting"},{"crops","crop","plant","plants"},{"soil","farmland"},{"furnace"},{"furnace_(burning)","burningfurnace","litfurnace"},{"sign_post","sign","signpost"},{"wooden_door","wooddoor","woodendoor","door"},{"ladder"},{"minecart_tracks","track","tracks","minecrattrack","minecarttracks","rails","rail"},{"cobblestone_stairs","cobblestonestair","cobblestonestairs","cobblestair","cobblestairs"},{"wall_sign","wallsign"},{"lever","switch","stonelever","stoneswitch"},{"stone_pressure_plate","stonepressureplate","stoneplate"},{"iron_door","irondoor"},{"wooden_pressure_plate","woodpressureplate","woodplate","woodenpressureplate","woodenplate","plate","pressureplate"},{"redstone_ore","redstoneore"},{"glowing_redstone_ore","glowingredstoneore"},{"redstone_torch_(off)","redstonetorchoff","rstorchoff"},{"redstone_torch_(on)","redstonetorch","redstonetorchon","rstorchon","redtorch"},{"stone_button","stonebutton","button"},{"snow","snow_layer"},{"ice"},{"snow_block","snowblock"},{"cactus","cacti"},{"clay"},{"reed","cane","sugarcane","sugarcanes"},{"jukebox","stereo","recordplayer"},{"fence","fence"},{"pumpkin"},{"redmossycobblestone","redcobblestone","redmosstone","redcobble","netherstone","netherrack","nether","hellstone"},{"soul_sand","slowmud","mud","soulsand","hellmud"},{"brittlegold","glowstone","lightstone","brimstone","australium"},{"portal","portal"},{"pumpkin_(on)","pumpkinlighted","pumpkinon","litpumpkin","jackolantern"},{"cake","cakeblock"},{"redstone_repeater_(off)","diodeoff","redstonerepeater","repeateroff","delayeroff"},{"redstone_repeater_(on)","diodeon","redstonerepeateron","repeateron","delayeron"},{"stained_glass","stainedglass"},{"trap_door","trapdoor","hatch","floordoor"},{"silverfish_block","silverfish","silver"},{"stone_brick","stonebrick","sbrick","smoothstonebrick"},{"red_mushroom_cap","giantmushroomred","redgiantmushroom","redmushroomcap"},{"brown_mushroom_cap","giantmushroombrown","browngiantmushoom","brownmushroomcap"},{"iron_bars","ironbars","ironfence"},{"glass_pane","window","glasspane","glasswindow"},{"melon_(block)","melonblock"},{"pumpkin_stem","pumpkinstem"},{"melon_stem","melonstem"},{"vine","vines","creepers"},{"fence_gate","fencegate","gate"},{"brick_stairs","brickstairs","bricksteps"},{"stone_brick_stairs","stonebrickstairs","smoothstonebrickstairs"},{"mycelium","fungus","mycel"},{"lily_pad","lilypad","waterlily"},{"nether_brick","netherbrick"},{"nether_brick_fence","netherbrickfence","netherfence"},{"nether_brick_stairs","netherbrickstairs","netherbricksteps","netherstairs","nethersteps"},{"nether_wart","netherwart","netherstalk"},{"enchantment_table","enchantmenttable","enchanttable"},{"brewing_stand","brewingstand"},{"cauldron"},{"end_portal","endportal","blackstuff","airportal","weirdblackstuff"},{"end_portal_frame","endportalframe","airportalframe","crystalblock"},{"end_stone","endstone","enderstone","endersand"},{"dragon_egg","dragonegg","dragons"},{"redstone_lamp_(off)","redstonelamp","redstonelampoff","rslamp","rslampoff","rsglow","rsglowoff"},{"redstone_lamp_(on)","redstonelampon","rslampon","rsglowon"},{"double_wood_step","doublewoodslab","doublewoodstep"},{"wood_step","woodenslab","woodslab","woodstep","woodhalfstep"},{"cocoa_plant","cocoplant","cocoaplant"},{"sandstone_stairs","sandstairs","sandstonestairs"},{"emerald_ore","emeraldore"},{"ender_chest","enderchest"},{"tripwire_hook","tripwirehook"},{"tripwire","string"},{"emerald_block","emeraldblock","emerald"},{"spruce_wood_stairs","sprucestairs","sprucewoodstairs"},{"birch_wood_stairs","birchstairs","birchwoodstairs"},{"jungle_wood_stairs","junglestairs","junglewoodstairs"},{"command_block","commandblock","cmdblock","command","cmd"},{"beacon","beaconblock"},{"cobblestone_wall","cobblestonewall","cobblewall"},{"flower_pot","flowerpot","plantpot","pot"},{"carrots","carrotsplant","carrotsblock"},{"potatoes","potatoesblock"},{"wooden_button","woodbutton","woodenbutton"},{"head","skull"},{"anvil","blacksmith"},{"trapped_chest","trappedchest","redstonechest"},{"weighted_pressure_plate_(light)","lightpressureplate"},{"weighted_pressure_plate_(heavy)","heavypressureplate"},{"redstone_comparator_(inactive)","redstonecomparator","comparator"},{"redstone_comparator_(active)","redstonecomparatoron","comparatoron"},{"daylight_sensor","daylightsensor","lightsensor","daylightdetector"},{"block_of_redstone","redstoneblock","blockofredstone"},{"nether_quartz_ore","quartzore","netherquartzore"},{"hopper"},{"block_of_quartz","quartzblock","quartz"},{"quartz_stairs","quartzstairs"},{"activator_rail","activatorrail","tntrail","activatortrack"},{"dropper"},{"stained_clay","stainedclay","stainedhardenedclay"},{"stained_glass_pane","stainedglasspane"},{"leaves2","acacialeaves","darkoakleaves"},{"log2","acacia","darkoak"},{"acacia_wood_stairs","acaciawoodstairs","acaciastairs"},{"dark_oak_wood_stairs","darkoakwoodstairs","darkoakstairs"},[170]={"hay_block","hayblock","haybale","wheatbale"},[171]={"carpet","carpet"},[172]={"hardened_clay","hardenedclay","hardclay"},[173]={"block_of_coal","coalblock","blockofcoal"},[174]={"packed_ice","packedice","hardice"},[175]={"large_flowers","largeflowers","doubleflowers"},[176]={"large_flowers","largeflowers","doubleflowers"},[0]={"air"}}
  69. local MCNames={[0]="minecraft:air","minecraft:stone","minecraft:grass","minecraft:dirt","minecraft:cobblestone","minecraft:planks","minecraft:sapling","minecraft:bedrock","minecraft:flowing_water","minecraft:water","minecraft:flowing_lava","minecraft:lava","minecraft:sand","minecraft:gravel","minecraft:gold_ore","minecraft:iron_ore","minecraft:coal_ore","minecraft:log","minecraft:leaves","minecraft:sponge","minecraft:glass","minecraft:lapis_ore","minecraft:lapis_block","minecraft:dispenser","minecraft:sandstone","minecraft:noteblock","minecraft:bed","minecraft:golden_rail","minecraft:detector_rail","minecraft:sticky_piston","minecraft:web","minecraft:tallgrass","minecraft:deadbush","minecraft:piston","minecraft:piston_head","minecraft:wool",[37]="minecraft:yellow_flower",[38]="minecraft:red_flower",[39]="minecraft:brown_mushroom",[40]="minecraft:red_mushroom",[41]="minecraft:gold_block",[42]="minecraft:iron_block",[43]="minecraft:double_stone_slab",[44]="minecraft:stone_slab",[45]="minecraft:brick_block",[46]="minecraft:tnt",[47]="minecraft:bookshelf",[48]="minecraft:mossy_cobblestone",[49]="minecraft:obsidian",[50]="minecraft:torch",[51]="minecraft:fire",[52]="minecraft:mob_spawner",[53]="minecraft:oak_stairs",[54]="minecraft:chest",[55]="minecraft:redstone_wire",[56]="minecraft:diamond_ore",[57]="minecraft:diamond_block",[58]="minecraft:crafting_table",[59]="minecraft:wheat",[60]="minecraft:farmland",[61]="minecraft:furnace",[62]="minecraft:lit_furnace",[63]="minecraft:standing_sign",[64]="minecraft:wooden_door",[65]="minecraft:ladder",[66]="minecraft:rail",[67]="minecraft:stone_stairs",[68]="minecraft:wall_sign",[69]="minecraft:lever",[70]="minecraft:stone_pressure_plate",[71]="minecraft:iron_door",[72]="minecraft:wooden_pressure_plate",[73]="minecraft:redstone_ore",[74]="minecraft:lit_redstone_ore",[75]="minecraft:unlit_redstone_torch",[76]="minecraft:redstone_torch",[77]="minecraft:stone_button",[78]="minecraft:snow_layer",[79]="minecraft:ice",[80]="minecraft:snow",[81]="minecraft:cactus",[82]="minecraft:clay",[83]="minecraft:reeds",[84]="minecraft:jukebox",[85]="minecraft:fence",[86]="minecraft:pumpkin",[87]="minecraft:netherrack",[88]="minecraft:soul_sand",[89]="minecraft:glowstone",[90]="minecraft:portal",[91]="minecraft:lit_pumpkin",[92]="minecraft:cake",[93]="minecraft:unpowered_repeater",[94]="minecraft:powered_repeater",[95]="minecraft:stained_glass",[96]="minecraft:trapdoor",[97]="minecraft:monster_egg",[98]="minecraft:stonebrick",[99]="minecraft:stonebrick",[100]="minecraft:stonebrick",[101]="minecraft:iron_bars",[102]="minecraft:glass_pane",[103]="minecraft:melon_block",[104]="minecraft:pumpkin_stem",[105]="minecraft:melon_stem",[106]="minecraft:vine",[107]="minecraft:fence_gate",[108]="minecraft:brick_stairs",[109]="minecraft:stone_brick_stairs",[110]="minecraft:mycelium",[111]="minecraft:waterlily",[112]="minecraft:nether_brick",[113]="minecraft:nether_brick_fence",[114]="minecraft:nether_brick_stairs",[115]="minecraft:nether_wart",[116]="minecraft:enchanting_table",[117]="minecraft:brewing_stand",[118]="minecraft:cauldron",[119]="minecraft:end_portal",[120]="minecraft:end_portal_frame",[121]="minecraft:end_stone",[122]="minecraft:dragon_egg",[123]="minecraft:redstone_lamp",[124]="minecraft:lit_redstone_lamp",[125]="minecraft:double_wooden_slab",[126]="minecraft:wooden_slab",[127]="minecraft:cocoa",[128]="minecraft:sandstone_stairs",[129]="minecraft:emerald_ore",[130]="minecraft:ender_chest",[131]="minecraft:tripwire_hook",[132]="minecraft:tripwire_hook",[133]="minecraft:emerald_block",[134]="minecraft:spruce_stairs",[135]="minecraft:birch_stairs",[136]="minecraft:jungle_stairs",[137]="minecraft:command_block",[138]="minecraft:beacon",[139]="minecraft:cobblestone_wall",[140]="minecraft:flower_pot",[141]="minecraft:carrots",[142]="minecraft:potatoes",[143]="minecraft:wooden_button",[144]="minecraft:skull",[145]="minecraft:anvil",[146]="minecraft:trapped_chest",[147]="minecraft:light_weighted_pressure_plate",[148]="minecraft:heavy_weighted_pressure_plate",[149]="minecraft:unpowered_comparator",[150]="minecraft:powered_comparator",[151]="minecraft:daylight_detector",[152]="minecraft:redstone_block",[153]="minecraft:quartz_ore",[154]="minecraft:hopper",[155]="minecraft:quartz_block",[156]="minecraft:quartz_stairs",[157]="minecraft:activator_rail",[158]="minecraft:dropper",[159]="minecraft:stained_hardened_clay",[160]="minecraft:stained_glass_pane",[161]="minecraft:leaves2",[162]="minecraft:logs2",[163]="minecraft:acacia_stairs",[164]="minecraft:dark_oak_stairs",[170]="minecraft:hay_block",[171]="minecraft:carpet",[172]="minecraft:hardened_clay",[173]="minecraft:coal_block",[174]="minecraft:packed_ice",[175]="minecraft:double_plant"}
  70. local IDs={["minecraft:bed"]=26,["minecraft:unlit_redstone_torch"]=75,["minecraft:mob_spawner"]=52,["minecraft:stone_brick_stairs"]=109,["minecraft:end_portal"]=119,["minecraft:web"]=30,["minecraft:oak_stairs"]=53,["minecraft:nether_brick"]=112,["minecraft:noteblock"]=25,["minecraft:dropper"]=158,["minecraft:ladder"]=65,["minecraft:detector_rail"]=28,["minecraft:lapis_block"]=22,["minecraft:emerald_ore"]=129,["minecraft:water"]=9,["minecraft:stained_hardened_clay"]=159,["minecraft:beacon"]=138,["minecraft:soul_sand"]=88,["minecraft:wooden_door"]=64,["minecraft:pumpkin"]=86,["minecraft:wheat"]=59,["minecraft:iron_bars"]=101,["minecraft:redstone_ore"]=73,["minecraft:jukebox"]=84,["minecraft:dragon_egg"]=122,["minecraft:spruce_stairs"]=134,["minecraft:hopper"]=154,["minecraft:stone_slab"]=44,["minecraft:skull"]=144,["minecraft:carpet"]=171,["minecraft:mycelium"]=110,["minecraft:sand"]=12,["minecraft:coal_ore"]=16,["minecraft:stained_glass"]=95,["minecraft:snow"]=80,["minecraft:fire"]=51,["minecraft:enchanting_table"]=116,["minecraft:lava"]=11,["minecraft:potatoes"]=142,["minecraft:unpowered_repeater"]=93,["minecraft:stone_stairs"]=67,["minecraft:cauldron"]=118,["minecraft:stone_pressure_plate"]=70,["minecraft:deadbush"]=32,["minecraft:torch"]=50,["minecraft:hay_block"]=170,["minecraft:sandstone_stairs"]=128,["minecraft:netherrack"]=87,["minecraft:sandstone"]=24,["minecraft:gold_ore"]=14,["minecraft:bookshelf"]=47,["minecraft:cake"]=92,["minecraft:logs2"]=162,["minecraft:melon_stem"]=105,["minecraft:piston_head"]=34,["minecraft:brick_block"]=45,["minecraft:acacia_stairs"]=163,["minecraft:brown_mushroom"]=39,["minecraft:lit_furnace"]=62,["minecraft:glass"]=20,["minecraft:stone_button"]=77,["minecraft:air"]=0,["minecraft:packed_ice"]=174,["minecraft:sapling"]=6,["minecraft:pumpkin_stem"]=104,["minecraft:leaves"]=18,["minecraft:fence"]=85,["minecraft:obsidian"]=49,["minecraft:snow_layer"]=78,["minecraft:wool"]=35,["minecraft:powered_comparator"]=150,["minecraft:jungle_stairs"]=136,["minecraft:iron_block"]=42,["minecraft:chest"]=54,["minecraft:diamond_ore"]=56,["minecraft:glowstone"]=89,["minecraft:dispenser"]=23,["minecraft:nether_brick_fence"]=113,["minecraft:sticky_piston"]=29,["minecraft:end_portal_frame"]=120,["minecraft:nether_brick_stairs"]=114,["minecraft:tnt"]=46,["minecraft:redstone_wire"]=55,["minecraft:command_block"]=137,["minecraft:golden_rail"]=27,["minecraft:flowing_water"]=8,["minecraft:coal_block"]=173,["minecraft:double_wooden_slab"]=125,["minecraft:dark_oak_stairs"]=164,["minecraft:double_plant"]=175,["minecraft:mossy_cobblestone"]=48,["minecraft:gravel"]=13,["minecraft:reeds"]=83,["minecraft:trapdoor"]=96,["minecraft:planks"]=5,["minecraft:stained_glass_pane"]=160,["minecraft:activator_rail"]=157,["minecraft:quartz_stairs"]=156,["minecraft:nether_wart"]=115,["minecraft:flowing_lava"]=10,["minecraft:waterlily"]=111,["minecraft:quartz_block"]=155,["minecraft:light_weighted_pressure_plate"]=147,["minecraft:brick_stairs"]=108,["minecraft:wooden_button"]=143,["minecraft:quartz_ore"]=153,["minecraft:standing_sign"]=63,["minecraft:unpowered_comparator"]=149,["minecraft:daylight_detector"]=151,["minecraft:redstone_block"]=152,["minecraft:heavy_weighted_pressure_plate"]=148,["minecraft:vine"]=106,["minecraft:lit_redstone_lamp"]=124,["minecraft:anvil"]=145,["minecraft:carrots"]=141,["minecraft:flower_pot"]=140,["minecraft:cobblestone_wall"]=139,["minecraft:birch_stairs"]=135,["minecraft:emerald_block"]=133,["minecraft:tripwire_hook"]=132,["minecraft:farmland"]=60,["minecraft:furnace"]=61,["minecraft:cocoa"]=127,["minecraft:stone"]=1,["minecraft:wooden_slab"]=126,["minecraft:trapped_chest"]=146,["minecraft:redstone_lamp"]=123,["minecraft:double_stone_slab"]=43,["minecraft:tallgrass"]=31,["minecraft:monster_egg"]=97,["minecraft:sponge"]=19,["minecraft:end_stone"]=121,["minecraft:iron_ore"]=15,["minecraft:gold_block"]=41,["minecraft:red_flower"]=38,["minecraft:piston"]=33,["minecraft:powered_repeater"]=94,["minecraft:brewing_stand"]=117,["minecraft:wall_sign"]=68,["minecraft:clay"]=82,["minecraft:wooden_pressure_plate"]=72,["minecraft:lapis_ore"]=21,["minecraft:ender_chest"]=130,["minecraft:crafting_table"]=58,["minecraft:lever"]=69,["minecraft:grass"]=2,["minecraft:cactus"]=81,["minecraft:dirt"]=3,["minecraft:ice"]=79,["minecraft:bedrock"]=7,["minecraft:hardened_clay"]=172,["minecraft:stonebrick"]=100,["minecraft:yellow_flower"]=37,["minecraft:fence_gate"]=107,["minecraft:melon_block"]=103,["minecraft:red_mushroom"]=40,["minecraft:lit_redstone_ore"]=74,["minecraft:redstone_torch"]=76,["minecraft:iron_door"]=71,["minecraft:leaves2"]=161,["minecraft:diamond_block"]=57,["minecraft:lit_pumpkin"]=91,["minecraft:cobblestone"]=4,["minecraft:portal"]=90,["minecraft:rail"]=66,["minecraft:glass_pane"]=102,["minecraft:log"]=17}
  71.  
  72. --Converts a block ID to minecraft's unlocalized name. removeMinecraft will remove the "minecraft:" at the beginning.
  73. function idToMCName(id,removeMinecraft)
  74.   if tonumber(id) and tonumber(id)<=175 then
  75.     return (removeMinecraft and MCNames[id]:sub(11)) or MCNames[id]
  76.   end
  77. end
  78.  
  79. function MCNameToID(name,addMinecraft)
  80.   if type(name)=="string" then
  81.     return IDs[((addMinecraft and "minecraft:"..name) or name)]
  82.   end
  83. end
  84.  
  85. function sendChat(msg)
  86.   msg=tostring(msg) or type(msg)
  87.   if msg=="" then
  88.     return false
  89.   end
  90.   if hasChatBox then
  91.     local splitMsg=msg:find("\n") and stringx.split(msg,"\n") or {msg}
  92.     for k,v in pairs(splitMsg) do
  93.       commands.execAsync("say "..v)
  94.     end
  95.   else
  96.     pl.sendChat(msg)
  97.   end
  98. end
  99.  
  100. function getBlockID(x,y,z)
  101.   if not tonumber(x) or not tonumber(y) or not tonumber(z) then
  102.     print(debug.traceback())
  103.   end
  104.   return (not hasChatBox and w.getBlockID(x,y,z)) or MCNameToID(commands.getBlockInfo(x,y,z).name) or commands.getBlockInfo(x,y,z).name
  105. end
  106.  
  107. function getMetadata(x,y,z)
  108.   if not tonumber(x) or not tonumber(y) or not tonumber(z) then
  109.     sendChat(debug.traceback())
  110.   end
  111.   return ((not hasChatBox and w.getMetadata(x,y,z)) or commands.getBlockInfo(x,y,z).metadata)
  112. end
  113.  
  114. function setBlock(x,y,z,ID,Meta)
  115.   if not hasChatBox then
  116.     return w.setBlockWithoutNotify(x,y,z,tonumber(ID) or MCNameToID(ID),tonumber(Meta)) --Set the block to the appropriate block type.
  117.   else
  118.     return commands.execAsync("setblock "..x.." "..y.." "..z.." "..((tonumber(ID) and (idToMCName(tonumber(ID),false))) or ID).." "..Meta.." replace")
  119.   end
  120. end
  121.  
  122. function debugPrintBlock(x,y,z) --Prints the block at the given coords in a human-readable format to make sure getBlockID and getMetadata work.
  123.   sendChat("Block @ ("..x..", "..y..", "..z.."): "..(idToMCName(getBlockID(x,y,z),true) or getBlockID(x,y,z))..":"..getMetadata(x,y,z))
  124. end
  125.  
  126. function makeCuboidSelection()
  127.   Selection={}
  128.   for x=math.min(x1,x2),math.max(x1,x2) do
  129.     for y=math.min(y1,y2),math.max(y1,y2) do
  130.       for z=math.min(z1,z2),math.max(z1,z2) do
  131.         table.insert(Selection,{["x"]=x,["y"]=y,["z"]=z})
  132.       end
  133.     end
  134.   end
  135.   Selection.type="cuboid"
  136. end
  137.  
  138. function getFlatSelection(selection)
  139.   local sel={}
  140.   sel[1]=selection[1]
  141.   for i=1,#selection do
  142.     for j=1,#sel do
  143.       if selection[i].x==sel[j].x and selection[i].z==sel[j].z then
  144.         break
  145.       elseif j==#sel then
  146.         sel[#sel+1]={x=selection[i].x,z=selection[i].z}
  147.       end
  148.     end
  149.   end
  150.   return sel
  151. end
  152.  
  153. --Seperates command into usable data for set and replace--
  154. local function SeparateString()
  155.   local function splitTbls(text,needsPercent)
  156.     local BlocksTbl={}
  157.     local MetaTbl={}
  158.     local PercentagesTbl={}
  159.     tmpBlocks=stringx.split(text,",")
  160.     for i=1,#tmpBlocks do
  161.       findColon=tmpBlocks[i]:find(":")
  162.       if findColon then
  163.         table.insert(BlocksTbl,tonumber(tmpBlocks[i]:sub(1,findColon-1)) or tmpBlocks[i]:sub(1,findColon-1))
  164.         table.insert(MetaTbl,tmpBlocks[i]:sub(findColon+1))
  165.       else
  166.         table.insert(BlocksTbl,tonumber(tmpBlocks[i]) or tmpBlocks[i])
  167.         table.insert(MetaTbl,0)
  168.       end
  169.     end
  170.     if needsPercent then
  171.       for i=1,#BlocksTbl do
  172.         local tmpBlocks2=stringx.split(tostring(BlocksTbl[i]),"%")
  173.         if #tmpBlocks2==2 then
  174.           BlocksTbl[i]=tonumber(tmpBlocks2[2]) or tmpBlocks2[2]
  175.           PercentagesTbl[i]=tmpBlocks2[1]
  176.         else
  177.           BlocksTbl[i]=tonumber(tmpBlocks2[1]) or tmpBlocks2[1]
  178.           PercentagesTbl[i]=PercentagesTbl[i] or false --This could be any non-number.
  179.         end
  180.       end
  181.       for i=1,#MetaTbl do
  182.         local tmpMeta2=stringx.split(tostring(MetaTbl[i]),"%")
  183.         if #tmpMeta2==2 then
  184.           MetaTbl[i]=tmpMeta2[2]
  185.           PercentagesTbl[i]=tmpMeta2[1]
  186.         else
  187.           MetaTbl[i]=tmpMeta2[1]
  188.           PercentagesTbl[i]=PercentagesTbl[i] or false --This could be any non-number.
  189.         end
  190.       end
  191.     end
  192.     if needsPercent then
  193.       return BlocksTbl,MetaTbl,PercentagesTbl
  194.     else
  195.       return BlocksTbl,MetaTbl
  196.     end
  197.   end
  198.   local tmp=stringx.split(message:sub(message:find(" ")+1)," ")
  199.   if message:sub(1,message:find(" ")-1)=="replace" then
  200.     Blocks,Meta=splitTbls(tmp[1],false)
  201.     Blocks2,Meta2,Percentages=splitTbls(tmp[2],true)
  202.   else
  203.     Blocks2,Meta2,Percentages=splitTbls(tmp[1],true)
  204.   end
  205.   TotalPercent=0 --Convert ones without percentages to ones WITH percentages!
  206.   Spaces=0
  207.   for i=1,#Percentages do
  208.     if not tonumber(Percentages[i]) then
  209.       Spaces=Spaces+1
  210.     end
  211.   end
  212.   if Spaces==#Percentages then
  213.     for i=1,#Percentages do
  214.       Percentages[i]=100
  215.     end
  216.   end
  217.   for i=1,#Percentages do
  218.     if tonumber(Percentages[i]) then
  219.       TotalPercent=TotalPercent+Percentages[i]
  220.     end
  221.   end
  222.   for i=1,#Percentages do
  223.     if not tonumber(Percentages[i]) then
  224.       Percentages[i]=TotalPercent/(#Percentages-Spaces)
  225.     end
  226.   end
  227. end
  228.  
  229. --change block names into block IDs--
  230. function ConvertName(tbl,tbl2)
  231.   if tbl and tbl2 then
  232.     for i=1,#tbl do
  233.       if tonumber(tbl[i])==nil then
  234.         for k,v in pairs(BlockNames) do
  235.           if table.indexOf(v,tostring(tbl[i])) then
  236.             if k==17 then
  237.               if tbl[i]=="pine" then
  238.                 tbl2[i]=1
  239.               elseif tbl[i]=="birch" then
  240.                 tbl2[i]=2
  241.               elseif tbl[i]=="jungle" then
  242.                 tbl2[i]=3
  243.               end
  244.               break
  245.             elseif k==162 then
  246.               if tbl[i]=="darkoak" then
  247.                 tbl2[i]=1
  248.               end
  249.               break
  250.             elseif next(BlockNames,k)==nil then
  251.               sendChat('Invalid Block: "'..tbl[i]..'"')
  252.               return false            
  253.             else
  254.               tbl[i]=tonumber(k)
  255.               break
  256.             end
  257.           end
  258.         end
  259.       end
  260.     end
  261.   end
  262.   if not tbl and not tbl2 and Blocks2 and Meta2 then --Yay, Laziness
  263.     if Blocks and Meta and #Blocks>0 and #Meta>0 then
  264.       ConvertName(Blocks,Meta)
  265.     end
  266.     ConvertName(Blocks2,Meta2)
  267.   end
  268. end
  269.  
  270. --Returns a heightmap for the selected area.
  271. function heightmap()
  272.   local map={}
  273.   local i=0
  274.   local cnt=1
  275.   local BlocksChecked=0
  276.   local timeDelay=2.5
  277.   local x,z
  278.   local Selection=getFlatSelection(Selection)
  279.   if #Selection>0 then
  280.     for i=1,#Selection do
  281.       if not map[cnt] then
  282.         map[cnt]={} --Make sure there is a subtable in there
  283.       end
  284.       map[cnt].x=Selection[i].x --Store X coordinate
  285.       map[cnt].z=Selection[i].z --Store Z coordinate
  286.       x,z=Selection[i].x,Selection[i].z
  287.       for yVal=math.max(y1,y2),math.min(y1,y2),-1 do
  288.         if getBlockID(x,yVal,z)~=0 then
  289.           map[cnt].y=yVal --Store Y coordinate
  290.           y=yVal
  291.           break
  292.         end
  293.         BlocksChecked=BlocksChecked+1
  294.         if BlocksChecked%(timeDelay*20)==1 then
  295.           sendChat(math.round(i/#Selection*100).."% Complete.")
  296.         end
  297.       end --Note, it WILL return nil if there isn't a highest block.
  298.       cnt=cnt+1
  299.     end
  300.   else
  301.     sendChat("Make a selection first!")
  302.     return false
  303.   end
  304.   return map
  305. end
  306.  
  307. --finds direction for commands with directions--
  308. function getDirection(shouldReturn)
  309.   if not ent then
  310.     sendChat("Cannot get the direction the player is looking in. Try specifying the direction in the command.")
  311.     return false
  312.   end
  313.   local xDir,yDir,zDir=ent.getLooking()
  314.   local function between(num,limit1,limit2)
  315.     return num>math.min(limit1,limit2) and num<math.max(limit1,limit2)
  316.   end
  317.   if between(xDir,.5,1) then
  318.     Direction="East"
  319.   elseif between(xDir,-.5,-1) then
  320.     Direction="West"
  321.   elseif between(xDir,-.5,.5) and between(zDir,.5,1) then
  322.     Direction="South"
  323.   elseif between(xDir,-.5,.5) and between(zDir,-1,-.5) then
  324.     Direction="North"
  325.   elseif yDir > 0.85 then
  326.     Direction="Up"
  327.   elseif yDir < -0.15 then
  328.     Direction="Down"
  329.   else
  330.     sendChat("I believe you are looking inside out.")
  331.     return false
  332.   end
  333.   Direction=Direction:lower()
  334. --If shouldReturn is false, it's just modifying the Direction in the global table.
  335.   if shouldReturn then
  336.     return Direction
  337.   end
  338. end
  339.  
  340. function getPlayerPos(name)
  341.   if not w then
  342.     local state,result=commands.exec("/tp "..name.." ~ ~ ~")
  343.     if state then
  344.       local coords=result[1]:sub(16+#name)
  345.       local returnVal=stringx.split(coords,",")
  346.       for i=1,#returnVal do
  347.         returnVal[i]=math.floor(tonumber(returnVal[i]))
  348.       end
  349.       return unpack(returnVal)
  350.     end
  351.   else
  352.     return ent.getPosition()
  353.   end
  354. end
  355.  
  356. local function pos1()
  357.   x1,y1,z1=unpack((ent and {ent.getPosition()}) or {getPlayerPos(username)})
  358.   y1=y1-1 --Select the block UNDERNEATH them, not the block they're in.
  359.   x1,y1,z1=math.floor(x1,y1,z1)
  360.   if x1 and x2 and y1 and y2 and z1 and z2 then
  361.     makeCuboidSelection()
  362.   end
  363.   sendChat("First position set to ("..x1..", "..y1..", "..z1..")"..((#Selection>0 and (" ("..#Selection..")")) or ""))
  364. end
  365.  
  366. local function pos2()
  367.   x2,y2,z2=unpack((ent and {ent.getPosition()}) or {getPlayerPos(username)})
  368.   y2=y2-1 --Select the block UNDERNEATH them, not the block they're in!
  369.   x2,y2,z2=math.floor(x2,y2,z2)
  370.   if x1 and x2 and y1 and y2 and z1 and z2 then
  371.     makeCuboidSelection()
  372.   end
  373.   sendChat("Second position set to ("..x2..", "..y2..", "..z2..")"..((#Selection>0 and (" ("..#Selection..")")) or ""))
  374. end
  375.  
  376. local function hpos1()
  377.   if hasChatBox then
  378.     sendChat("Command computers cannot see where a player is looking!")
  379.     return
  380.   end
  381.   local x,y,z=ent.getLooking()
  382.   local mult=0
  383.   while mult<1000 do
  384.     x1=math.floor(x*mult+px) --Extend the line from ent.getLooking() out linearly
  385.     y1=math.floor(y*mult+py+1.62) --The player's eyes are 1.62 blocks from the ground
  386.     z1=math.floor(z*mult+pz)
  387.     if getBlockID(x1,y1,z1)~=0 and not table.indexOf(blockBlacklist,getBlockID(x1,y1,z1)) then --Check if it hit a block
  388.       break
  389.     else
  390.       mult=mult+0.05 --Otherwise check another point along the line.
  391.     end
  392.   end
  393.   if x1 and x2 and y1 and y2 and z1 and z2 then
  394.     makeCuboidSelection()
  395.   end
  396.   sendChat("First position set to ("..x1..", "..y1..", "..z1..")"..((#Selection>0 and (" ("..#Selection..")")) or ""))
  397. end
  398.  
  399. local function hpos2()
  400.   if hasChatBox then
  401.     sendChat("Command computers cannot see where a player is looking!")
  402.     return
  403.   end
  404.   local x,y,z=ent.getLooking()
  405.   local mult=0
  406.   while mult<1000 do
  407.     x2=math.floor(x*mult+px)
  408.     y2=math.floor(y*mult+py+1.62)
  409.     z2=math.floor(z*mult+pz)
  410.     if getBlockID(x2,y2,z2)~=0 and not table.indexOf(blockBlacklist,getBlockID(x2,y2,z2)) then
  411.       break
  412.     else
  413.       mult=mult+0.05
  414.     end
  415.   end
  416.   if x1 and x2 and y1 and y2 and z1 and z2 then
  417.     makeCuboidSelection()
  418.   end
  419.   sendChat("Second position set to ("..x2..", "..y2..", "..z2..")"..((#Selection>0 and (" ("..#Selection..")")) or ""))
  420. end
  421.  
  422. local function sel2()
  423.   local findSpace=message:find(" ")
  424.   Selection={}
  425.   if not findSpace then
  426.     x1=nil
  427.     y1=nil
  428.     z1=nil
  429.     x2=nil
  430.     y2=nil
  431.     z2=nil
  432.   else
  433.     if message:sub(findSpace+1)=="1" then
  434.       x1=nil
  435.       y1=nil
  436.       z1=nil
  437.     elseif message:sub(findSpace+1)=="2" then
  438.       x2=nil
  439.       y2=nil
  440.       z2=nil
  441.     end
  442.   end
  443.   sendChat("Selection cleared.")
  444. end
  445.  
  446. local helpText={
  447.   pos1="Selects the first position using the block the player is standing on.",
  448.   pos2="Selects the second position using the block the player is standing on.",
  449.   hpos1="Selects the first position using the block the player is looking at.",
  450.   hpos2="Selects the second position using the block the player is looking at.",
  451.   sel="Clears the selection, with an argument specifying which position to clear, or \"vert\", to expand the selection to Y 0-256.",
  452.   set="Sets all blocks in the selection to the given block(s) with the given proportion(s).",
  453.   replace="Replaces all block(s) in the first argument with the block(s) in the second with their given proportion(s).",
  454.   expand="Expands the selection in the given direction, or in the direction the player is looking if not specified.",
  455.   contract="Contracts the selection in the given direction, or in the direction the player is looking if not specified.",
  456.   inset="Shrinks the selection by one block in all directions.",
  457.   outset="Expands the selection by one block in all directions.",
  458.   shift="Moves the selection by one block in all directions.",
  459.   chunk="Changes the selection to the chunk the player is in.",
  460.   naturalize="Makes the terrain look more natural.",
  461.   copy="Copies the blocks in the selection into the clipboard.",
  462.   paste="Puts the current clipboard in the world. -a does not paste air blocks, -ao pastes it at the origin of the clipboard.",
  463.   load="Loads a saved clipboard.",
  464.   move="Moves the blocks in the selection in the given direction, or in the direction the player is looking if not specified.",
  465.   cut="Copies all blocks in the selection into the clipboard, then sets them to air.",
  466.   stack="Repeats the blocks in the selection.",
  467.   terminate="Ends the program.",
  468.   refresh="Re-runs all the files other than WE_Core, allowing all changes to take effect.",
  469.   save="Saves a clipboard to a file.",
  470.   reboot="Reboots the computer.",
  471.   blockpatterns='A number of commands that take a "block" parameter really take a pattern. Rather than set one single block, a pattern allows you to set more complex patterns. For example, you can set a pattern where each block has a 10% chance of being brick and a 90% chance of being smooth stone.\nBlock probability pattern is specified with a list of block types (and support block:meta) with their respective probability.\nExample: Setting all blocks to a random pattern using a list with percentages (Which do not need to add to 100):\r"set 5%planks:3,95%dirt"\nFor a truly random pattern, no probability percentage is needed.\nExample: Setting all blocks to a random pattern using a list without percentages\n"set obsidian,stone"',
  472. }
  473.  
  474. local commandSyntax={
  475.   pos1="pos1 (Takes no arguments)",
  476.   pos2="pos2 (Takes no arguments)",
  477.   hpos1="hpos1 (Takes no arguments)",
  478.   hpos2="hpos2 (Takes no arguments)",
  479.   sel="sel [1/2/vert]",
  480.   set="set block[:meta][,...] (See \"help BlockPatterns\" for more information)",
  481.   replace="replace block1[:meta1][,...] block2[:meta2][,...] (See \"help BlockPatterns\" for more information)",
  482.   expand="expand (amount) [direction] (Direction defaults to \"self\")",
  483.   contract="contract (amount) [direction] (Direction defaults to \"self\")",
  484.   inset="inset (amount)",
  485.   outset="outset (amount)",
  486.   shift="shift (amount) [direction] (Direction defaults to \"self\")",
  487.   chunk="chunk (Takes no arguments)",
  488.   naturalize="naturalize (Takes no arguments)",
  489.   copy="copy (Takes no arguments)",
  490.   paste="paste [-a] [-ao]",
  491.   load="load (name)",
  492.   move="move (amount) [direction] (Direction defaults to \"self\")",
  493.   cut="cut (Takes no arguments)",
  494.   stack="stack (amount) [direction] (Direction defaults to \"self\")",
  495.   terminate="terminate (Takes no arguments)",
  496.   refresh="refresh (Takes no arguments)",
  497.   save="save (name)",
  498.   reboot="reboot (Takes no arguments)",
  499. }
  500.  
  501. local iteratableHelpText={} --These are used to traverse the table in order. It contains the keys alphabetically.
  502. for k in pairs(helpText) do table.insert(iteratableHelpText,k) end
  503. table.sort(iteratableHelpText)
  504.  
  505. local function help(command)
  506.   command=(command~=nil and command~="") and command or 1
  507.   local commandsPerPage=8
  508.   local numPages=math.ceil(#iteratableHelpText/commandsPerPage)
  509.   if tonumber(command) then
  510.     local pageNum=math.min(tonumber(command),numPages)
  511.     sendChat("Run \"help (commandname)\" for a description of the command and its syntax.")
  512.     for i=1,commandsPerPage do
  513.       local index=i+(pageNum-1)*commandsPerPage
  514.       if index>#iteratableHelpText then
  515.         break
  516.       end
  517.       sendChat(iteratableHelpText[index]..((iteratableHelpText[index]~="blockpatterns" and (" - "..helpText[iteratableHelpText[index]])) or ""))
  518.     end
  519.     sendChat("Page "..command.."/"..numPages)
  520.   elseif helpText[command] then
  521.     sendChat(command.." - "..helpText[command])
  522.     if commandSyntax[command] then
  523.       sendChat("Syntax: "..commandSyntax[command])
  524.     end
  525.   else
  526.     sendChat("Command \""..command.."\" not found.")
  527.   end
  528. end
  529.  
  530. --Main program loop
  531. local firstRun=hasChatBox
  532. while true do
  533.   if not firstRun then
  534.     username,message=getChat()
  535.   else
  536.     firstRun=false
  537.   end
  538.   pl=p and p.getPlayerByName(username) --Short circuit if p is nil.
  539.   ent=pl and pl.asEntity()
  540.   if ent then
  541.     px,py,pz=ent.getPosition()
  542.   end
  543.   OriginalMessage=message
  544.   message=message:lower() --Make it case-insensitive, but keep the original just in case it's needed.
  545.   if message==nil then
  546.   elseif message=="pos1" then
  547.     pos1()
  548.   elseif message=="pos2" then
  549.     pos2()
  550.   elseif message=="hpos1" then
  551.     hpos1()
  552.   elseif message=="hpos2" then --See hpos1!
  553.     hpos2()
  554.   elseif message:sub(1,3)=="sel" then --Clear the selection
  555.     sel2()
  556.   elseif message:sub(1,3)=="set" then
  557.     if #Selection>0 then
  558.       SeparateString()
  559.       ConvertName()
  560.       sel.set()
  561.     else
  562.       sendChat("Set a position first with pos1 and pos2!")
  563.     end
  564.   elseif message:sub(1,7)=="replace" then
  565.     if #Selection>0 then
  566.       SeparateString()
  567.       ConvertName()
  568.       sel.replace()
  569.     else
  570.       sendChat("Set a position first with pos1 and pos2!")
  571.     end
  572.   elseif message:sub(1,6)=="expand" then
  573.     if #Selection>0 then
  574.       cuboid.expand()
  575.     else
  576.       sendChat("Set a position first with pos1 and pos2!")
  577.     end
  578.   elseif message:sub(1,8)=="contract" then
  579.     if #Selection>0 then
  580.       cuboid.contract()
  581.     else
  582.       sendChat("Set a position first with pos1 and pos2!")
  583.     end
  584.   elseif message:sub(1,5)=="inset" then
  585.     if #Selection>0 then
  586.       cuboid.inset()
  587.     else
  588.       sendChat("Set a position first with pos1 and pos2!")
  589.     end
  590.   elseif message:sub(1,6)=="outset" then
  591.     if #Selection>0 then
  592.       cuboid.outset()
  593.     else
  594.       sendChat("Set a position first with pos1 and pos2!")
  595.     end
  596.   elseif message:sub(1,5)=="shift" then
  597.     if #Selection>0 then
  598.       cuboid.shift()
  599.     else
  600.       sendChat("Set a position first with pos1 and pos2!")
  601.     end
  602.   elseif message:sub(1,5)=="chunk" then
  603.     if #Selection>0 then
  604.       cuboid.chunk()
  605.     else
  606.       sendChat("Set a position first with pos1 and pos2!")
  607.     end
  608.   elseif message:sub(1,10)=="naturalize" then
  609.     if #Selection>0 then
  610.       sel.naturalize()
  611.     else
  612.       sendChat("Set a position first with pos1 and pos2!")
  613.     end
  614.   elseif message:sub(1,7)=="overlay" then
  615.     if #Selection>0 then
  616.       SeparateString()
  617.       ConvertName()
  618.       sel.overlay()
  619.     else
  620.       sendChat("Set a position first with pos1 and pos2!")
  621.     end
  622.   elseif message:sub(1,4)=="copy" and hasNBT then
  623.     if #Selection>0 then
  624.       clipboard.copy()
  625.     else
  626.       sendChat("Set a position first with pos1 and pos2!")
  627.     end
  628.   elseif message:sub(1,5)=="paste" and hasNBT then
  629.     clipboard.paste()
  630.   elseif message:sub(1,4)=="move" and hasNBT then
  631.     clipboard.move()
  632.   elseif message:sub(1,3)=="cut" and hasNBT then
  633.     clipboard.cut()
  634.   elseif message:sub(1,5)=="stack" and hasNBT then
  635.     clipboard.stack()
  636.   elseif message:sub(1,9)=="terminate" then
  637.     break
  638.   elseif message:sub(1,7)=="refresh" then
  639.     shell.run(APIPath)
  640.     shell.run(CuboidPath)
  641.     shell.run(SelPath)
  642.     if fs.exists(ClipboardPath) then
  643.       hasNBT=true
  644.       shell.run(ClipboardPath)
  645.     else
  646.       hasNBT=false
  647.     end
  648.   elseif message:sub(1,4)=="save" and hasNBT then
  649.     clipboard.save()
  650.   elseif message:sub(1,6)=="reboot" then
  651.     os.reboot()
  652.   elseif message:sub(1,4)=="load" and hasNBT then
  653.     clipboard.load()
  654.   elseif message:sub(1,4)=="help" then
  655.     help(message:sub(6))
  656.   elseif message=="endchatspam" then
  657.     sendChat("Spam ended.")
  658.     commands.exec("gamerule commandBlockOutput false")
  659.   end
  660. end
  661. --Program(s) made by moomoomoo309 and exlted--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement