def forceload_add(from_pos, to=None): if len(Pos(from_pos)) != 2: raise ValueError( 'Error: %s is invalid for this argument. You must use 2D (X,Z) coordinate' % from_pos) if to is None: if len(Pos(to)) != 2: raise ValueError( 'Error: %s is invalid for this argument. You must use 2D (X,Z) coordinate' % to) return mcfunctions.write_output('forceload add %s' % Pos(from_pos)) else: return mcfunctions.write_output('forceload add %s %s' % (Pos(from_pos), Pos(to)))
def give(target, item, data=None, count=None): istr = item if data is not None: if type(data) == str: if data.strip()[0] != '{': istr += '{%s}' % data.strip() else: istr += data.strip() else: istr += json.dumps(data) if count is not None: return mcfunctions.write_output('give %s %s %s' % (target, istr, count)) else: return mcfunctions.write_output('give %s %s' % (target, istr))
def forceload_remove(from_pos, to=None): if len(Pos(from_pos)) != 2: raise ValueError( 'Error: %s is invalid for this argument. You must use 2D (X,Z) coordinate' % from_pos) if str(from_pos).lower() == 'all': return forceload_remove_all() if to is None: if len(Pos(to)) != 2: raise ValueError( 'Error: %s is invalid for this argument. You must use 2D (X,Z) coordinate' % to) return mcfunctions.write_output('forceload remove %s' % Pos(from_pos)) else: return mcfunctions.write_output('forceload remove %s %s' % (Pos(from_pos), Pos(to)))
def clear(target, item=None, maxCount=None): command = 'clear %s' % target if item is not None: command += ' %s' % item if maxCount is not None: command += ' %s' % maxCount return mcfunctions.write_output(command)
def weather(w, seconds=None): if re.match('clear|rain|thunder', w) == None: raise ValueError( 'invalid weather option: %s is not one of [clear|rain|thunder]' % w) command = 'weather %s' % w if seconds is not None: command += ' %s' % int(seconds) return mcfunctions.write_output(command)
def spawnpoint(target, pos, angle=None): command = 'spawnpoint %s %s' % (target, Pos(pos)) if angle is not None: a = float(angle) while a < -180: a += 360 while a > 180: a -= 360 command += ' %.3f' % a return mcfunctions.write_output(command)
def spreadplayers(center, spreadDistance, maxRange, respectTeams=True, target='@a'): if len(Pos(center)) != 2: raise ValueError( 'Error: %s is invalid for this argument. You must use 2D (X,Z) coordinate' % center) return mcfunctions.write_output('spreadplayers %s %s %s %s %s' % (Pos(center), spreadDistance, maxRange, str(bool(respectTeams)).lower(), target))
def clone(startPos, endPos, destPos, copyAirBlocks=True, mode='force'): if copyAirBlocks: mask = 'replace' else: mask = 'masked' if re.match('force|move|normal', mode) == None: raise ValueError( 'invalid clone mode option: %s is not one of [force|move|normal]' % mode) return mcfunctions.write_output( 'clone %s %s %s %s %s' % (Pos(startPos), Pos(endPos), Pos(destPos), mask, mode))
def gamerule(rule, setting): if type(setting) == str: setting = bool(setting) if type(setting) == int: setting = setting != 0 if type(setting) != bool: raise ValueError('invalid boolean: %s should be either True or False' % setting) if setting == True: sstr = 'true' else: sstr = 'false' return mcfunctions.write_output('gamerule %s %s' % (rule, sstr))
def effect_give(target, effect, seconds=None, amplifier=None, showParticles=True): hideParticles = not showParticles #effect give <targets> <effect> [<seconds>] [<amplifier>] [<hideParticles>] command = 'effect give %s %s' % (target, effect) if seconds is not None or amplifier is not None or hideParticles: if seconds == None: seconds = 30 if amplifier is None: amplifier = 1 command += ' %s %s %s' % (seconds, amplifier, str(hideParticles).lower()) return mcfunctions.write_output(command)
def setblock(pos, block, blockstate=None, data=None, dest=''): if len(str(dest)) > 0 and re.match('destroy|keep|replace', dest) == None: raise ValueError( 'invalid fill option: %s is not one of [destroy|keep|replace]' % dest) blockstr = block if blockstate is not None: blockstr += '[' for key in blockstate: value = blockstate[key] blockstr += '%s=%s' % (key, value) blockstr += ']' if data is not None: if type(data) == str: if data.strip()[0] != '{': blockstr += '{%s}' % data.strip() else: blockstr += data.strip() else: blockstr += json.dumps(data) command = 'setblock %s %s %s' % (Pos(pos), blockstr, dest) command = command.strip() return mcfunctions.write_output(command)
def scoreboard_setdisplay(scoreboard, display='sidebar'): # setting a display a second time removes it command = 'scoreboard objectives setdisplay %s %s' % (display, scoreboard) return mcfunctions.write_output(command)
def scoreboard_remove(scoreboard): command = 'scoreboard objectives remove %s' % scoreboard return mcfunctions.write_output(command)
def scoreboard_new(scoreboard, criteria='dummy', displayname=None): # example: /scoreboard objectives add highscore minecraft.custom:minecraft.time_since_death "High Score" command = 'scoreboard objectives add %s %s' % (scoreboard, criteria) if displayname is not None: command += ' "%s"' % displayname return mcfunctions.write_output(command)
def say(msg): command = 'say %s' % msg return mcfunctions.write_output(command)
def gamemode(mode, target): if re.match('adventure|creative|spectator|survival', mode) == None: raise ValueError( 'invalid gamemode option: %s is not one of [adventure|creative|spectator|survival]' % mode) return mcfunctions.write_output('gamemode %s %s' % (mode, target))
def forceload_remove_all(): return mcfunctions.write_output('forceload remove all') # TODO: minecraft commands
def teleport(target, pos): command = 'tp %s %s' % (target, Pos(pos)) return mcfunctions.write_output(command)
def enchant(target, enchantment, level=None): command = 'enchant %s %s' % (target, enchantment) if level is not None: command += ' %s' % str(int(level)) return mcfunctions.write_output(command)
def tell(target, message): return mcfunctions.write_output('tell %s %s' % (target, message))
def scoreboard_add_score(target, scoreboard, amount): command = 'scoreboard players add %s %s %s' % (target, scoreboard, amount) return mcfunctions.write_output(command)
def kill(target): return mcfunctions.write_output('kill %s' % target)
def scoreboard_subtract_score(target, scoreboard, amount): command = 'scoreboard players remove %s %s %s' % (target, scoreboard, amount) return mcfunctions.write_output(command)
def effect_clear(target, effect=None): if effect is None: return mcfunctions.write_output('effect clear %s' % target) else: return mcfunctions.write_output('effect clear %s %s' % (target, effect))