Advertisement
antonsavov

swap_slots

Dec 10th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.35 KB | None | 0 0
  1. -- Use this script to swap the contents (key and element) of two slots in the catalgoue
  2. -- requires 20.000 BLOCKS v2.5 with the new horizontal layout
  3.  
  4. -- HOW TO USE
  5. -- You need two people in the world to be able to do this:
  6. -- 1. go to the catalogue and note down the numbers of the two slots you want to swap
  7. -- 2. go to the computer and open it
  8. -- 3. type "swap_slots <number_of_slot_1> <number_of_slot_2>"
  9. -- 4. press ENTER and wait a bit
  10. -- 5. if all goes well it will output "success""
  11.  
  12. ---DONT CHANGE THE CODE BELOW
  13.  
  14. os.loadAPI('registry')
  15.  
  16.  
  17. --a multi builder which uses the vocab constructor to create sets of vocab
  18. local function initCatalogueElements(countX, countZ, sizeX, sizeZ)
  19.     local x,y,z = registry.FIRST_ELEMENT.x, registry.FIRST_ELEMENT.y, registry.FIRST_ELEMENT.z
  20.     local result = {}
  21.     local id = 1
  22.     for i=0,countZ-1 do
  23.         for k=0,countX-1 do
  24.  
  25.             local xpos = x - k * ( registry.GRIDCELL_SIZE * ( 2*registry.CATALOGUE_SLOTSIZE.x + 2 + registry.CATALOGUE_SLOT_OFFSET))
  26.             local ypos = y
  27.             local zpos = z + i*( registry.GRIDCELL_SIZE * ( registry.CATALOGUE_SLOTSIZE.z + 1 + registry.CATALOGUE_SLOT_OFFSET))
  28.             --print("adding an element",i,k)
  29.             local nextElement = newCatalogueElement(
  30.                 id,
  31.                 xpos,ypos,zpos,
  32.                 sizeX, sizeZ
  33.             )
  34.             table.insert(result,nextElement)
  35.             id = id +1
  36.         end
  37.     end
  38.     return result
  39. end
  40.  
  41. --a catalogue slot constructor. Enforces some data structure
  42. function newCatalogueElement(id, x,y,z,sizeX, sizeZ)
  43.     local nvz = {}
  44.     nvz.id = id
  45.     nvz.keyX ,nvz.keyY ,nvz.keyZ = x,y,z
  46.     nvz.sizeX, nvz.sizeZ = sizeX, sizeZ
  47.     nvz.elementX = nvz.keyX - nvz.sizeX - registry.GRIDCELL_SIZE --
  48.     nvz.elementY = nvz.keyY
  49.     nvz.elementZ = nvz.keyZ
  50.     nvz.elementCenterX = nvz.elementX + math.floor ( nvz.sizeX/2 )
  51.     nvz.elementCenterY = nvz.elementY
  52.     nvz.elementCenterZ = nvz.elementZ + math.floor ( nvz.sizeZ/2 )
  53.     nvz.keyCenterX = nvz.keyX + math.floor ( nvz.sizeX/2 )
  54.     nvz.keyCenterY = nvz.keyY
  55.     nvz.keyCenterZ = nvz.keyZ + math.floor ( nvz.sizeZ/2 )
  56.     return nvz 
  57. end
  58.  
  59. --vocabzone creation
  60. --vocabSet = makeVocabZones(NUMBER_OF_VOCAB,VOCAB_WIDTH)
  61. elementSet = initCatalogueElements(
  62.     registry.CATALOGUE_SLOTCOUNT.x,
  63.     registry.CATALOGUE_SLOTCOUNT.z,
  64.     registry.ELEMENT.sizeX,
  65.     registry.ELEMENT.sizeZ
  66. )
  67.  
  68. --- this function does the swapping
  69. -- slot_id1 and slot_id2 are the ids as displayed in the minecraft world  in the catalogue matrix
  70. function swapSlots(slot_id1, slot_id2)
  71.     print("swapping...")
  72.     local element_1 = elementSet[slot_id1]
  73.     local element_2 = elementSet[slot_id2]
  74.     local height_offset = 10
  75.     if element_1 and element_2 then
  76.         --
  77.         --clone element 1 above itself using the VOCAB HEIGHT
  78.         --clone the key
  79.         commands.clone( element_1.keyX, element_1.keyY, element_1.keyZ, element_1.keyX+element_1.sizeX, element_1.keyY+registry.VOCAB_HEIGHT, element_1.keyZ+element_1.sizeZ,
  80.             element_1.keyX, element_1.keyY+registry.VOCAB_HEIGHT+height_offset, element_1.keyZ)
  81.         --clone the element                
  82.         commands.clone( element_1.elementX, element_1.elementY, element_1.elementZ, element_1.elementX+element_1.sizeX, element_1.elementY+registry.VOCAB_HEIGHT, element_1.elementZ+element_1.sizeZ,
  83.             element_1.elementX, element_1.elementY+registry.VOCAB_HEIGHT+height_offset, element_1.elementZ)
  84.         --
  85.         --
  86.         --clone element 2 to element 1
  87.         --clone the key
  88.         commands.clone( element_2.keyX, element_2.keyY, element_2.keyZ, element_2.keyX+element_2.sizeX, element_2.keyY+registry.VOCAB_HEIGHT, element_2.keyZ+element_2.sizeZ,
  89.             element_1.keyX, element_1.keyY, element_1.keyZ)
  90.         --clone the element                
  91.         commands.clone( element_2.elementX, element_2.elementY, element_2.elementZ, element_2.elementX+element_2.sizeX, element_2.elementY+registry.VOCAB_HEIGHT, element_2.elementZ+element_2.sizeZ,
  92.             element_1.elementX, element_1.elementY, element_1.elementZ)
  93.         --
  94.         --
  95.         --clone the copy of element 1 to element 2
  96.         --clone the key
  97.         commands.clone( element_1.keyX, element_1.keyY+registry.VOCAB_HEIGHT+height_offset, element_1.keyZ, element_1.keyX+element_1.sizeX, element_1.keyY+2*registry.VOCAB_HEIGHT+height_offset, element_1.keyZ+element_1.sizeZ,
  98.             element_2.keyX, element_2.keyY, element_2.keyZ)
  99.         --clone the element                
  100.         commands.clone( element_1.elementX, element_1.elementY+registry.VOCAB_HEIGHT+height_offset, element_1.elementZ, element_1.elementX+element_1.sizeX, element_1.elementY+2*registry.VOCAB_HEIGHT+height_offset, element_1.elementZ+element_1.sizeZ,
  101.             element_2.elementX, element_2.elementY, element_2.elementZ)
  102.    
  103.         --delete the copy of element 1
  104.         --delete the key
  105.         fillSmart(registry.BLOCKS.AIR.block, element_1.keyX, element_1.keyY+registry.VOCAB_HEIGHT+height_offset, element_1.keyZ, element_1.sizeX, registry.VOCAB_HEIGHT, element_1.sizeZ)
  106.         --delete the element                   
  107.         fillSmart(registry.BLOCKS.AIR.block, element_1.elementX, element_1.elementY+registry.VOCAB_HEIGHT+height_offset, element_1.elementZ, element_1.sizeX, registry.VOCAB_HEIGHT, element_1.sizeZ)
  108.        
  109.     else
  110.         print("something wrong with element",slot_id1,element_1)
  111.         print("and element",slot_id2,element_2)            
  112.         return
  113.     end
  114.     print("success!")
  115. end
  116.  
  117. -- process command line parameters
  118. local tArgs = { ... } -- get the command line arguments
  119. local id1, id2
  120. if #tArgs == 2 then
  121.     id1 = tonumber(tArgs[1])
  122.     id2 = tonumber(tArgs[2])   
  123.     swapSlots(id1, id2)
  124. elseif #tArgs > 2 then
  125.     print("Usage: swap_slots <number_of_slot_1> <number_of_slot_2>")
  126.     return
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement