Last active
October 31, 2020 03:12
-
-
Save gitcrtn/455628117d4c221194664fa37d9424a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from mceditlib.findadapter import findAdapter | |
level_dat = sys.argv[1] | |
adapter = findAdapter(level_dat, readonly=False, resume=None) | |
adapter.metadata.allowCommands = 1 | |
adapter.syncToDisk() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Toggle cheat mode | |
Usage: | |
python2 toggle_mc_cheat.py <map name> | |
Notes: | |
Replace SAVE_DIR with your saves directory path. | |
""" | |
import sys | |
import os | |
import traceback | |
from mceditlib.findadapter import findAdapter | |
SAVE_DIR = 'C:/minecraft/sample/saves' | |
LEVEL_DAT_TEMPLATE = '{savedir}/{game}/level.dat' | |
UNDO_DIR_TEMPLATE = '{savedir}/##{game}.UNDO##' | |
def get_filepath(): | |
game = sys.argv[1] | |
print('map: %s' % game) | |
return LEVEL_DAT_TEMPLATE.format(savedir=SAVE_DIR, game=game) | |
def clean_undo_dir(): | |
if len(sys.argv) != 2: | |
return | |
game = sys.argv[1] | |
undo_dir = UNDO_DIR_TEMPLATE.format(savedir=SAVE_DIR, game=game) | |
if os.path.isdir(undo_dir): | |
os.removedirs(undo_dir) | |
def error(msg): | |
print('Error: %s' % msg) | |
sys.exit(1) | |
def bool_to_str(val): | |
return 'ON' if val else 'OFF' | |
def show_transition(current_mode, new_mode): | |
print('%s -> %s' % (bool_to_str(current_mode), bool_to_str(new_mode))) | |
def main(): | |
level_dat = get_filepath() | |
if not os.path.isfile(level_dat): | |
clean_undo_dir() | |
error('level.dat not found.') | |
return | |
adapter = findAdapter(level_dat, readonly=False, resume=None) | |
current_mode = adapter.metadata.allowCommands | |
new_mode = abs(current_mode - 1) | |
show_transition(current_mode, new_mode) | |
adapter.metadata.allowCommands = new_mode | |
adapter.syncToDisk() | |
clean_undo_dir() | |
if __name__ == '__main__': | |
try: | |
if len(sys.argv) != 2: | |
raise RuntimeError('Set map name as argument') | |
main() | |
except Exception: | |
clean_undo_dir() | |
traceback.print_exc() | |
# EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment