Advertisement
antonsavov

test stuff

Nov 15th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.89 KB | None | 0 0
  1. os.loadAPI('utils')
  2. os.loadAPI('registry')
  3. --[[
  4. utils.do_chunk_loaders(
  5.     registry.computer,
  6.     registry.CATALOG_AREA.x ,
  7.     registry.CATALOG_AREA.y + 10,
  8.     registry.CATALOG_AREA.z,
  9.     registry.CATALOG_AREA.dx,
  10.     registry.CATALOG_AREA.dz
  11. )
  12. --]]
  13.  
  14. ll_DEFAULT_ELEMENTS_SETTINGS = {
  15.     {element_id=1, element_name="element",reward_emeralds=0,reward_blocks={{block = "minecraft:wool", data = 0, count=1},{block = "minecraft:wool", data = 10, count=10}}, metric_1=0, metric_2=0, metric_3=0, metric_4=0},
  16.     {element_id=2, element_name="element",reward_emeralds=1,reward_blocks={}, metric_1=0, metric_2=0, metric_3=0, metric_4=0},
  17.     {element_id=3, element_name="element",reward_emeralds=0,reward_blocks={{block = "minecraft:wool", data = 0, count=1}}, metric_1=0, metric_2=0, metric_3=0, metric_4=0}
  18. }
  19.  
  20. DEFAULT_ELEMENTS_SETTINGS = {
  21.     {{______________________________element_start______________________________="______________________________"},{element_id=1}, {element_name="element"}, {{metric_1=0}, {metric_2=0}, {metric_3=0}, {metric_4=0}}, {reward_emeralds=0},{reward_blocks={{block = "minecraft:wool", data = 0, count=1},{block = "minecraft:wool", data = 10, count=10}}},{______________________________element_end______________________________="____________________________________________________________"}},
  22.     {{______________________________element_start______________________________="______________________________"},{element_id=2}, {element_name="element"}, {{metric_1=0}, {metric_2=0}, {metric_3=0}, {metric_4=0}}, {reward_emeralds=1},{reward_blocks={}},{______________________________element_end______________________________="____________________________________________________________"}},
  23.     {{______________________________element_start______________________________="______________________________"},{element_id=3}, {element_name="element"}, {{metric_1=0}, {metric_2=0}, {metric_3=0}, {metric_4=0}}, {reward_emeralds=0},{reward_blocks={{block = "minecraft:wool", data = 0, count=1}}},{______________________________element_end______________________________="____________________________________________________________"}}
  24. }
  25.  
  26. -- function to check if settings file exist and if not create it using the default settings in registry
  27. --if settings file exists then read it and change the variables to reflect the settings there
  28. function loadCustomElementSettings()
  29.     -- does json file exist?
  30.     --local result = nil
  31.     --fs.makeDir("/records")
  32.     local filename = "element_settings"
  33.     local settings = {}
  34.     if utils.file_exists(filename) then
  35.         ---read from file and change the settings
  36.         settings = json.decodeFromFile(filename)
  37.         --set the settings to the ones found in the file
  38.     else
  39.         --create the file with default settings
  40.         local file = fs.open(filename,"w")
  41.         settings = DEFAULT_ELEMENTS_SETTINGS
  42.         file.write(json.encodePretty(settings))
  43.         file.close()
  44.     end
  45.    
  46.     return settings
  47. end
  48.  
  49. --loadCustomElementSettings()
  50.  
  51. --- Clones an area even if it is bigger than the minecraft limit
  52. -- @param maskMode from registry.CLONE_MASK_MODE
  53. -- @param cloneMode from registry.CLONE_MODE
  54. -- @param filteredMaterial table with .block and .variant
  55. function cloneSmart(from_x,from_y,from_z,sizeX,sizeY,sizeZ, to_x, to_y, to_z, maskMode, cloneMode, filteredMaterial)
  56.     -- clone command works as this: https://www.digminecraft.com/game_commands/clone_command.php
  57.     -- /clone <x1> <y1> <z1>  <x2> <y2> <z2>  <x> <y> <z> [maskMode] [cloneMode] [tileName] [tileData]
  58.     --check if volume is bigger than maximum blocks 32768
  59.     local limit = registry.FILL_LIMIT
  60.     local w,h,l = sizeX, sizeY, sizeZ
  61.     --print("which is nil?", w,h,l)
  62.     if math.abs(w*l*h) <= limit then
  63.         --if not then do simple fill
  64.         --print("filling in one go:",x,y,z,x+w-(w/math.abs(w)),y+h-(h/math.abs(h)),z+l-(l/math.abs(l)),material)
  65.         --if replace and replace_material then
  66.         --commands.async.fill(x,y,z,x+w-(w/math.abs(w)),y+h-(h/math.abs(h)),z+l-(l/math.abs(l)),fill_material.block, fill_material.variant, "replace", replace_material.block, replace_material.variant)
  67.         if filteredMaterial then
  68.             commands.clone(
  69.                 from_x, from_y, from_z,
  70.                 from_x+w-(w/math.abs(w)), from_y+h-(h/math.abs(h)), from_z+l-(l/math.abs(l)),
  71.                 to_x, to_y, to_z,
  72.                 maskMode or registry.CLONE_MASK_MODE.REPLACE, cloneMode or registry.CLONE_MODE.NORMAL, filteredMaterial.block, filteredMaterial.variant)   
  73.         else
  74.             commands.clone(
  75.                 from_x, from_y, from_z,
  76.                 from_x+w-(w/math.abs(w)), from_y+h-(h/math.abs(h)), from_z+l-(l/math.abs(l)),
  77.                 to_x, to_y, to_z,
  78.                 maskMode or registry.CLONE_MASK_MODE.REPLACE, cloneMode or registry.CLONE_MODE.NORMAL)
  79.         end
  80.            
  81.         --end
  82.         --else
  83.         --commands.async.fill(x,y,z,x+w-(w/math.abs(w)),y+h-(h/math.abs(h)),z+l-(l/math.abs(l)),fill_material.block, fill_material.variant )
  84.         --end
  85.         return true
  86.     else
  87.         --divide in 8 sub-boxes and run again
  88.        
  89.         local halfW = math.floor(w/2)
  90.         local restW = w-halfW
  91.         local halfH = math.floor(h/2)
  92.         local restH = h-halfH
  93.         local halfL = math.floor(l/2)
  94.         local restL = l-halfL
  95.         --always run
  96.         cloneSmart(from_x+halfW, from_y+halfH, from_z+halfL, restW, restH, restL, to_x+halfW, to_y+halfH, to_z+halfL, maskMode, cloneMode, filteredMaterial)
  97.         --
  98.         --check if one of the halves is zero
  99.         if math.abs(halfW) > 0 then
  100.             --run if halfW is not zero
  101.             cloneSmart(from_x, from_y+halfH, from_z+halfL, halfW, restH, restL, to_x, to_y+halfH, to_z+halfL, maskMode, cloneMode, filteredMaterial)
  102.         end
  103.         if math.abs(halfH) > 0 then
  104.              --run if halfH is not zero
  105.             cloneSmart(from_x+halfW, from_y, from_z+halfL, restW, halfH, restL, to_x+halfW, to_y, to_z+halfL, maskMode, cloneMode, filteredMaterial)
  106.         end
  107.         if math.abs(halfL) > 0 then
  108.              --run if halfL is not zero
  109.             cloneSmart( from_x+halfW, from_y+halfH, from_z, restW, restH, halfL, to_x+halfW, to_y+halfH, to_z, maskMode, cloneMode, filteredMaterial)
  110.         end
  111.         ---
  112.         if math.abs(halfW) > 0 and math.abs(halfH) > 0 then    
  113.              --run if halfs W and H are not zero
  114.             cloneSmart( from_x, from_y, from_z+halfL, halfW, halfH, restL, to_x, to_y, to_z+halfL, maskMode, cloneMode, filteredMaterial)
  115.         end
  116.         if math.abs(halfL) > 0 and math.abs(halfH) > 0 then    
  117.             --run if halfH and halfL are not zero
  118.             cloneSmart( from_x+halfW, from_y, from_z, restW, halfH, halfL, to_x+halfW, to_y, to_z, maskMode, cloneMode, filteredMaterial)
  119.         end
  120.         if math.abs(halfW) > 0 and math.abs(halfL) > 0 then    
  121.              -- run if half W and L are not zero
  122.             cloneSmart( from_x, from_y+halfH, from_z, halfW, restH, halfL, to_x, to_y+halfH, to_z, maskMode, cloneMode, filteredMaterial)
  123.         end
  124.         ---
  125.         if math.abs(halfW) > 0 and math.abs(halfH) > 0 and math.abs(halfL) > 0 then
  126.              --run if neither half is zero     
  127.             cloneSmart( from_x, from_y, from_z, halfW, halfH, halfL, to_x, to_y, to_z, maskMode, cloneMode, filteredMaterial)
  128.         end
  129.         return true
  130.     end
  131.     return false
  132. end
  133.  
  134. cloneSmart(
  135.     -556, 56, -319,
  136.     27, 29, 27,
  137.     -535-27+21, 56, -330-27+21,
  138.     registry.CLONE_MASK_MODE.REPLACE, registry.CLONE_MODE.MOVE
  139. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement