Alyssa

bc_importer

Jan 27th, 2017
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.10 KB | None | 0 0
  1. import mcrcon
  2. import sys
  3. import time
  4.  
  5. if len(sys.argv) < 7:
  6.     print("Usage: python3 import.py <server> <port> <password> <start x> <start y> <start z>")
  7.     sys.exit()
  8. address = sys.argv[1]
  9. port = int(sys.argv[2])
  10. password = sys.argv[3]
  11. current_x = int(sys.argv[4])
  12. current_y = int(sys.argv[5])
  13. current_z = int(sys.argv[6]) + 3
  14. relative_x = 0
  15. relative_y = 0
  16. relative_z = 3
  17. y_offset = 0
  18. max_y = 3
  19. highest_y = [0]
  20. cur_highest = 0
  21. dir = 5
  22. length = 31
  23. rlength = length - 1
  24. conditional = False
  25.  
  26. rcon = mcrcon.MCRcon()
  27. rcon.connect(address,port)
  28. rcon.login(password)
  29.  
  30. cmds = []
  31.  
  32. with open("cmds.txt") as f:
  33.     cmd_lines = f.readlines()
  34.     cmds = [x.rstrip().replace('"','\\"') for x in cmd_lines]
  35.  
  36. count = 0
  37. comment = False
  38. first_shift = True
  39. mode = "main"
  40.  
  41. def shift():
  42.     global cur_highest
  43.     global highest_y
  44.     global current_x
  45.     global current_y
  46.     global current_z
  47.     global relative_x
  48.     global relative_y
  49.     global relative_z
  50.     global dir
  51.     global max_y
  52.     global y_offset
  53.     global first_shift
  54.     highest_y.append(cur_highest)
  55.     if mode == "op":
  56.         print(str(count))
  57.         setblock("minecraft:repeating_command_block", store_x, store_y, store_z, store_dir, "{auto:1b,Command:\"execute @e[type=armor_stand,tag=cursor] ~ ~ ~ testforblock ~ ~-1 ~ " + store_block + " -1\",TrackOutput:0b}")
  58.         setblock("minecraft:chain_command_block", store_x+1, store_y, store_z, store_dir+8, "{auto:1b,Command:\"fill ~-1 ~ ~-1 ~" + str(rlength-2) + " ~" + str(cur_highest) + " ~-1 redstone_block 0 replace\",TrackOutput:0b}")
  59.         setblock("minecraft:wall_sign", store_x-1, store_y, store_z, 4, '{Text1:"{\\"text\\":\\"@op\\"}",Text2:"{\\"text\\":\\"' + store_name + '\\"}",Text3:"{\\"text\\":\\"\\"}",Text4:"{\\"text\\":\\"\\"}"}')
  60.         f_command = "fill ~" + str(store_x - current_x) + " ~" + str(store_y - current_y) + " ~-1 ~" + str((store_x + rlength) - current_x) + " ~" + str((store_y + cur_highest) - current_y) + " ~-1 quartz_block 0 replace"
  61.         setblock("minecraft:chain_command_block", current_x, current_y, current_z, dir, "{auto:0b,Command:\"" + f_command + "\",TrackOutput:0b}")
  62.     else:
  63.         first_shift = False
  64.     cur_highest = 0
  65.     max_y = 2 + max(highest_y)
  66.     current_z -= 3
  67.     relative_z -= 3
  68.     current_y -= relative_y
  69.     relative_y = 0
  70.     if relative_z < -rlength:
  71.         current_z += (-rlength - relative_z) + rlength
  72.         relative_z = 0
  73.         y_offset += max_y
  74.     current_y += y_offset
  75.     relative_y += y_offset
  76.     current_x -= relative_x
  77.     relative_x = 0
  78.     dir = 5
  79.     return current_x, current_y, current_z
  80.  
  81. def next():
  82.     global current_x
  83.     global current_y
  84.     global current_z
  85.     global relative_x
  86.     global relative_y
  87.     global relative_z
  88.     global dir
  89.     global cur_highest
  90.     if dir == 5:
  91.         current_x += 1
  92.         relative_x += 1
  93.         if relative_x == rlength:
  94.             dir = 1
  95.     elif dir == 4:
  96.         current_x -= 1
  97.         relative_x -= 1
  98.         if relative_x == 0:
  99.             dir = 1
  100.     elif dir == 1:
  101.         current_y += 1
  102.         relative_y += 1
  103.         cur_highest += 1
  104.         if relative_x == 0:
  105.             dir = 5
  106.         elif relative_x == rlength:
  107.             dir = 4
  108.  
  109. def setblock(id, x, y, z, damage, nbt):
  110.     global rcon
  111.     global conditional
  112.     success = False
  113.     if conditional == True:
  114.         damage += 8
  115.         conditional = False
  116.     if id == "minecraft:wall_sign":
  117.         damage = 4
  118.     while success != True:
  119.         try:
  120.             rcon.command("setblock %s %s %s %s %s replace %s" % (str(x),str(y),str(z),str(id),str(damage),str(nbt)))
  121.             success = True
  122.         except:
  123.             print("Crashed... Waiting 10 seconds to retry.")
  124.             time.sleep(10)
  125.             rcon = mcrcon.MCRcon()
  126.             rcon.connect(address,port)
  127.             rcon.login(password)
  128.  
  129. for cmd in cmds:
  130.     count += 1
  131.     if count % 50 == 0:
  132.         print(str(count) + "/" + str(len(cmds)) + " completed.")
  133.     if cmd[0:2] == "/*":
  134.         comment = True
  135.     if comment == False:
  136.         if cmd[0:1] == "@":
  137.             current_x, current_y, current_z = shift()
  138.             if cmd[1:5] == "Main":
  139.                 setblock("minecraft:repeating_command_block",current_x,current_y,current_z, dir, "{auto:1b,Command:\"//@Main Loop\",TrackOutput:0b}")
  140.                 setblock("minecraft:wall_sign", current_x-1,current_y, current_z, 4, '{Text1:"{\\"text\\":\\"@Main\\"}",Text2:"{\\"text\\":\\"\\"}",Text3:"{\\"text\\":\\"\\"}",Text4:"{\\"text\\":\\"\\"}"}')
  141.                 mode = "main"
  142.             elif cmd[1:3] == "op":
  143.                 block = "minecraft:" + cmd.split(" ")[1]
  144.                 store_x = current_x
  145.                 store_y = current_y
  146.                 store_z = current_z
  147.                 store_block = block
  148.                 store_dir = dir
  149.                 store_name = cmd.split(" ")[1]
  150.                 mode = "op"
  151.                 next()
  152.             next()
  153.         else:
  154.             if len(cmd) < 2048:
  155.                 if mode == "op":
  156.                     setblock("minecraft:chain_command_block", current_x, current_y, current_z, dir, "{auto:0b,Command:\"" + cmd + "\",TrackOutput:0b}")
  157.                 elif mode == "main":
  158.                     setblock("minecraft:chain_command_block", current_x, current_y, current_z, dir,     "{auto:1b,Command:\"" + cmd + "\",TrackOutput:0b}")
  159.             else:
  160.                 print("- CMD TOO LONG- [" + str(count) + "]")
  161.                 print(cmd)
  162.                 print("- CMD TOO LONG- [" + str(count) + "]")
  163.                 setblock("minecraft:chain_command_block", current_x, current_y, current_z, dir, "{auto:1b,Command:\"PASTE HERE\",TrackOutput:0b}")
  164.                 setblock("minecraft:glass", current_x, current_y, current_z+1, 0, "")
  165.             next()
  166.         time.sleep(0.01)
  167.     if cmd.find("*/") >= 0:
  168.         comment = False
  169. shift()
Advertisement
Add Comment
Please, Sign In to add comment