-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasy_map_updater.py
1370 lines (1133 loc) · 51 KB
/
easy_map_updater.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Easy Map Updater
# Copyright (C) 2024 Jesse Spicer, and StickyPiston Hosting
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Modifications and additions to world saves made by this program are
# not covered by this license and instead fall under the MIT license.
# Check that correct Python version is running
import sys
if not (
(sys.version_info[0] == 3 and sys.version_info[1] >= 12)
or
(sys.version_info[0] > 3)
):
print("\nERROR: Easy Map Updater requires Python 3.12 or newer!")
input()
exit()
# Import things
import shutil
import json
import traceback
from typing import cast, TypedDict, Callable, Any
from enum import Enum
from pathlib import Path
from lib.log import log, get_log_path
from lib import defaults
from lib import utils
from lib import finalize
from lib import data_pack
from lib import resource_pack
from lib import option_manager
from lib import json_manager
from lib.data_pack_files import command
from lib.data_pack_files import json_text_component
from lib.data_pack_files import breakpoints
from lib.data_pack_files import mcfunction
from lib.data_pack_files import advancement
from lib.data_pack_files import item_modifier
from lib.data_pack_files import loot_table
from lib.data_pack_files import predicate
from lib.data_pack_files import recipe
from lib.data_pack_files.restore_behavior import tag_replacements
from lib.data_pack_files.restore_behavior import spawner_bossbar
from lib.data_pack_files.restore_behavior import ore_fixer
from lib.data_pack_files.restore_behavior import area_effect_cloud_killer
from lib.data_pack_files.restore_behavior import firework_damage_canceler
from lib.data_pack_files.restore_behavior import unwaterloggable_leaves
from lib.data_pack_files.restore_behavior import old_adventure_mode
from lib.data_pack_files.restore_behavior import effect_overflow
from lib.data_pack_files.restore_behavior import attribute_reset
from lib.data_pack_files.restore_behavior import lock_fixer
from lib.data_pack_files.admin_controls import admin_kickback
from lib.region_files import command_blocks
from lib.region_files import entity_extractor
from lib.region_files import fix_world
from lib.region_files import stats_scanner
from lib.region_files import illegal_chunk
from lib.region_files import structure
# Initialize variables
PROGRAM_PATH = Path(__file__).parent
MINECRAFT_PATH = PROGRAM_PATH.parent
class Action(Enum):
RESET = "reset"
ALL = "all"
UPDATE = "update"
SCAN = "scan"
RP_IMPORT = "rp.import"
RP_ORIGINAL = "rp.original"
RP_RELOAD = "rp.reload"
RP_PURGE = "rp.purge"
RP_UPDATE = "rp.update"
RP_FIX = "rp.fix"
RP_EXPORT = "rp.export"
RP_EXPORT_ORIGINAL = "rp.export_original"
DP_UNZIP = "dp.unzip"
DP_ZIP = "dp.zip"
DP_LOG = "dp.log"
DP_DIRECTORY = "dp.directory"
DP_VANILLA = "dp.vanilla"
DP_MERGE = "dp.merge"
DP_STORED_FUNCTION = "dp.stored_function"
DP_STORED_ADVANCEMENT = "dp.stored_advancement"
DP_ADVANCEMENT = "dp.advancement"
DP_RECIPE = "dp.recipe"
DP_UPDATE = "dp.update"
DP_TAG = "dp.tag"
DP_BOSSBAR = "dp.bossbar"
DP_AEC_KILL = "dp.aec_kill"
DP_FIREWORK = "dp.firework"
DP_ORE_FIXER = "dp.ore"
DP_WATER_LEAVES = "dp.water_leaves"
DP_ADVENTURE = "dp.adventure"
DP_EFFECT = "dp.effect"
DP_ATTRIBUTE = "dp.attribute"
DP_LOCK_FIXER = "dp.lock_fixer"
DP_BREAK = "dp.break"
WORLD_ORIGINAL = "world.original"
WORLD_ORIGINAL_PLAY = "world.original.play"
WORLD_RELOAD = "world.reload"
WORLD_SOURCE = "world.source"
WORLD_PLAY = "world.play"
WORLD_FIX = "world.fix"
OPTIMIZE = "optimize"
ENTITY_EXTRACT = "entity.extract"
STATS_SCAN = "stats.scan"
ILLEGAL_CHUNK = "illegal.chunk"
CMD_READ = "cmd.read"
CMD_UPDATE = "cmd.update"
CMD_WRITE = "cmd.write"
CMD_CLEAR = "cmd.clear"
CMD_EXTRACT = "cmd.extract"
FINAL_SCORE = "final.score"
FINAL = "final"
ADMIN_KICKBACK = "admin.kickback"
CLEAN = "clean"
VERSION = "version"
LICENSE = "license"
EXIT = "exit"
DEBUG = "debug"
DEBUG_CMD = "debug.cmd"
DEBUG_JSON = "debug.json"
DEBUG_FUNCTION = "debug.function"
DEBUG_ADVANCEMENT = "debug.advancement"
DEBUG_LOOT_TABLE = "debug.loot_table"
DEBUG_ITEM_MODIFIER = "debug.item_modifier"
DEBUG_PREDICATE = "debug.predicate"
DEBUG_RECIPE = "debug.recipe"
DEBUG_STRUCTURE = "debug.structure"
class ActionDefinition(TypedDict):
show: bool
function: Callable
name: str
actions: dict[str, ActionDefinition]
class UpdateProgressDefinition(TypedDict):
stage: int
world_scan: finalize.WorldScan
fix_world_flags: fix_world.FixWorldFlags
def default_update_progress() -> UpdateProgressDefinition:
return {
"stage": 0,
"world_scan": {
"world": False,
"resource_pack": False,
"disabled_vanilla": False,
"zipped_data_packs": False,
"stored_functions": False,
"stored_advancements": False,
"advancements": False,
"recipes": False,
},
"fix_world_flags": {
"spawner_bossbar": False,
"locked_containers": False,
},
}
update_progress: UpdateProgressDefinition = default_update_progress()
# Define functions
def program():
# Show title
print("")
log("Easy Map Updater")
log("- By Dominexis, and StickyPiston Hosting")
# Initialize variables
option_manager.get_options()
action_reset()
load_session()
save_session()
print("")
print_version()
print("")
list_actions()
# Program loop
while True:
# Get action
action = input("\nAction: ")
if action not in actions:
log("ERROR: Must be a valid action!")
continue
print("")
# Run action
actions[action]["show"] = True
try:
actions[action]["function"]()
except Exception:
save_session()
utils.log_error()
print("")
save_session()
list_actions()
class SessionDefinition(TypedDict):
actions: dict[str, bool]
update_progress: UpdateProgressDefinition
def load_session():
session_path = PROGRAM_PATH / "session.json"
if not session_path.exists():
return
with session_path.open("r", encoding="utf-8") as file:
session = cast(SessionDefinition, json.load(file))
if "debug.cmd" in session:
session = cast(SessionDefinition, {"actions": session})
if "actions" not in session:
session["actions"] = cast(dict[str, bool], {})
for action in session["actions"]:
if action in actions:
actions[action]["show"] = session["actions"][action]
if "update_progress" in session:
session_update_progress = session["update_progress"]
for key in ["stage", "world_scan", "fix_world_flags"]:
if key in session_update_progress:
update_progress[key] = session_update_progress[key]
def save_session():
session: SessionDefinition = {
"actions": {},
"update_progress": update_progress
}
for action in actions:
session["actions"][action] = actions[action]["show"]
session_path = PROGRAM_PATH / "session.json"
with session_path.open("w", encoding="utf-8", newline="\n") as file:
json.dump(session, file, indent=4)
def list_options():
log("Options:")
options = option_manager.get_options()
for key in options:
log(f"{key}: {options[key]}")
def list_actions():
print("Actions:")
for action in actions:
if action == Action.VERSION.value:
print("")
if actions[action]["show"]:
print(f" {action}) {' '*max(21-len(action), 0)}{actions[action]['name']}")
# Define actions
def action_reset():
global actions
actions = {
Action.RESET.value: { "show": True, "function": action_reset, "name": "Reset actions" },
Action.ALL.value: { "show": True, "function": action_show_all_actions, "name": "Show all actions" },
Action.UPDATE.value: { "show": True, "function": action_update, "name": "Update map" },
Action.SCAN.value: { "show": True, "function": action_scan_world, "name": "Scans your world to gather relevant information" },
Action.WORLD_ORIGINAL.value: { "show": False, "function": action_prepare_original_copy_world, "name": "Prepare original copy of world (do this before updating)" },
Action.WORLD_ORIGINAL_PLAY.value: { "show": False, "function": action_prepare_original_play_copy, "name": "Prepare play version of original copy of world" },
Action.WORLD_RELOAD.value: { "show": False, "function": action_reload_from_original_world, "name": "Reload world from original copy" },
Action.RP_IMPORT.value: { "show": False, "function": action_import_resource_pack, "name": "Import resource pack from world" },
Action.RP_ORIGINAL.value: { "show": False, "function": action_prepare_original_copy_resource_pack, "name": "Prepare original copy of resource pack" },
Action.RP_RELOAD.value: { "show": False, "function": action_reload_from_original_resource_pack, "name": "Reload resource pack from original copy" },
Action.RP_PURGE.value: { "show": False, "function": action_purge_vanilla_assets, "name": "Purge vanilla assets from resource pack" },
Action.RP_UPDATE.value: { "show": False, "function": action_update_resource_pack, "name": "Update resource pack" },
Action.RP_FIX.value: { "show": False, "function": action_fix_resource_pack, "name": "Fix resource pack" },
Action.DP_UNZIP.value: { "show": False, "function": action_unzip_data_packs, "name": "Unzip data packs" },
Action.DP_LOG.value: { "show": False, "function": action_log_data_packs, "name": "Log data packs" },
Action.DP_DIRECTORY.value: { "show": False, "function": action_rename_data_pack_directories, "name": "Rename data pack directories" },
Action.DP_VANILLA.value: { "show": False, "function": action_fix_disabled_vanilla, "name": "Fix disabled vanilla data pack (must be done before merging)" },
Action.DP_MERGE.value: { "show": False, "function": action_merge_data_packs, "name": "Merge data packs" },
Action.DP_STORED_FUNCTION.value: { "show": False, "function": action_stored_functions, "name": "Extract stored functions" },
Action.DP_STORED_ADVANCEMENT.value: { "show": False, "function": action_stored_advancements, "name": "Extract stored advancements" },
Action.DP_ADVANCEMENT.value: { "show": False, "function": action_disable_advancements, "name": "Disable advancements (if one of the data packs makes them all impossible)" },
Action.DP_RECIPE.value: { "show": False, "function": action_disable_recipes, "name": "Disable recipes (if one of the data packs makes them all impossible)" },
Action.WORLD_SOURCE.value: { "show": False, "function": action_prepare_source_copy, "name": "Prepare source copy of world (do this before opening world)" },
Action.DP_UPDATE.value: { "show": False, "function": action_update_data_packs, "name": "Update data packs" },
Action.OPTIMIZE.value: { "show": False, "function": action_optimize_world, "name": "Mark world as optimized" },
Action.ENTITY_EXTRACT.value: { "show": False, "function": action_entity_extract, "name": "Extract entities from regions" },
Action.STATS_SCAN.value: { "show": False, "function": action_stats_scan, "name": "Scan world for stats usage" },
Action.WORLD_FIX.value: { "show": False, "function": action_fix_world, "name": "Fix broken data in world" },
Action.DP_BOSSBAR.value: { "show": False, "function": action_spawner_bossbar, "name": "Create spawner bossbar data pack" },
Action.DP_AEC_KILL.value: { "show": False, "function": action_area_effect_cloud_killer, "name": "Create area effect cloud killer data pack" },
Action.DP_ORE_FIXER.value: { "show": False, "function": action_ore_fixer, "name": "Create ore fixer data pack" },
Action.DP_WATER_LEAVES.value: { "show": False, "function": action_unwaterloggable_leaves, "name": "Create unwaterloggable leaves data pack" },
Action.DP_ADVENTURE.value: { "show": False, "function": action_old_adventure_mode, "name": "Create old adventure mode data pack" },
Action.DP_EFFECT.value: { "show": False, "function": action_effect_overflow, "name": "Create effect overflow data pack" },
Action.DP_ATTRIBUTE.value: { "show": False, "function": action_attribute_reset, "name": "Create attribute reset data pack" },
Action.DP_LOCK_FIXER.value: { "show": False, "function": action_lock_fixer, "name": "Create lock fixer data pack" },
Action.CMD_READ.value: { "show": False, "function": action_read_commands, "name": "Read command block data" },
Action.CMD_UPDATE.value: { "show": False, "function": action_update_commands, "name": "Update command block data" },
Action.CMD_WRITE.value: { "show": False, "function": action_write_commands, "name": "Write command block data" },
Action.CMD_CLEAR.value: { "show": False, "function": action_clear_command_helper, "name": "Clear command helper" },
Action.CMD_EXTRACT.value: { "show": False, "function": action_extract_commands, "name": "Extract commands from a command block chain" },
Action.DP_TAG.value: { "show": False, "function": action_tag_replacements, "name": "Create tag replacements data pack" },
Action.DP_FIREWORK.value: { "show": False, "function": action_firework_damage_canceler, "name": "Create firework damage canceler data pack" },
Action.ILLEGAL_CHUNK.value: { "show": False, "function": action_illegal_chunk, "name": "Insert illegal block state chunk into world" },
Action.DP_BREAK.value: { "show": False, "function": action_breakpoint, "name": "Apply breakpoints to data pack" },
Action.FINAL_SCORE.value: { "show": False, "function": action_get_player_names, "name": "Get player names from scoreboard" },
Action.FINAL.value: { "show": False, "function": action_finalize_map, "name": "Finalize map" },
Action.WORLD_PLAY.value: { "show": False, "function": action_prepare_play_copy, "name": "Prepare play version of world (use for testing map)" },
Action.ADMIN_KICKBACK.value: { "show": False, "function": action_admin_kickback, "name": "Create admin control (kickback) data pack" },
Action.DP_ZIP.value: { "show": False, "function": action_zip_data_packs, "name": "Zip data packs" },
Action.RP_EXPORT.value: { "show": False, "function": action_export_resource_pack, "name": "Export resource pack to world" },
Action.RP_EXPORT_ORIGINAL.value: { "show": False, "function": action_export_original_resource_pack, "name": "Export original resource pack to source world" },
Action.CLEAN.value: { "show": False, "function": action_clean_up, "name": "Clean up files (remove worlds and resource pack)" },
Action.VERSION.value: { "show": True, "function": action_set_version, "name": "Edit source version" },
Action.LICENSE.value: { "show": True, "function": action_license, "name": "Show software license" },
Action.EXIT.value: { "show": True, "function": action_exit, "name": "Exit program" },
Action.DEBUG.value: { "show": False, "function": action_toggle_debug_mode, "name": "Toggle debug mode" },
Action.DEBUG_CMD.value: { "show": False, "function": action_update_single_command, "name": "Update single command (for testing)" },
Action.DEBUG_JSON.value: { "show": False, "function": action_update_json_text_component, "name": "Update JSON text component (for testing)" },
Action.DEBUG_FUNCTION.value: { "show": False, "function": action_update_function, "name": "Update function (for testing)" },
Action.DEBUG_ADVANCEMENT.value: { "show": False, "function": action_update_advancement, "name": "Update advancement from file (for testing)" },
Action.DEBUG_LOOT_TABLE.value: { "show": False, "function": action_update_loot_table, "name": "Update loot table from file (for testing)" },
Action.DEBUG_ITEM_MODIFIER.value: { "show": False, "function": action_update_item_modifier, "name": "Update item modifier from file (for testing)" },
Action.DEBUG_PREDICATE.value: { "show": False, "function": action_update_predicate, "name": "Update predicate from file (for testing)" },
Action.DEBUG_RECIPE.value: { "show": False, "function": action_update_recipe, "name": "Update recipe from file (for testing)" },
Action.DEBUG_STRUCTURE.value: { "show": False, "function": action_update_structure, "name": "Update structure from file (for testing)" },
}
def action_show_all_actions():
global actions
for action in actions:
actions[action]["show"] = True
def action_update(): # Needs confirmation
log("Updating map")
# Make sure that world exists
world: Path = MINECRAFT_PATH / "saves" / option_manager.get_map_name()
og_world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_original'
source_world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_source'
resource_pack: Path = MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack()
if not world.exists():
log("ERROR: World does not exist!")
return
# Get confirmation
log(f'This action will update: {world.as_posix()}')
confirm = input("Is this okay? (Y/N): ")
if confirm not in ["y", "Y"]:
log("Action canceled")
return
# Reset flags
json_text_component.translation_keys_retrieved = False
# Get confirmation for starting in the middle
if update_progress["stage"] > 0:
confirm = input("The map was partially updated. Do you wish to resume where it last stopped? (Y/N): ")
if confirm not in ["y" ,"Y"]:
log("Starting update from beginning")
reset_update_progress()
else:
log("Resuming update")
# Reload world if original world exists
if update_progress["stage"] == 0:
if og_world.exists():
print("")
confirm = input("Original copy of world found, do you wish to update from the original? (Y/N): ")
if confirm in ["y", "Y"]:
action_reload_from_original_world(False)
else:
action_prepare_original_copy_world(False)
next_update_progress_section()
# Scan world
progress_scan = update_progress["world_scan"]
progress_flags = update_progress["fix_world_flags"]
if update_progress["stage"] == 100:
world_scan = finalize.scan_world(
world,
resource_pack
)
scan_again = False
for key in world_scan:
progress_scan[key] = world_scan[key]
if world_scan["resource_pack"]:
action_import_resource_pack(False)
scan_again = True
if world_scan["zipped_data_packs"]:
action_unzip_data_packs(False)
scan_again = True
if world_scan["stored_functions"]:
action_stored_functions(False)
scan_again = True
if world_scan["stored_advancements"]:
action_stored_advancements(False)
scan_again = True
if scan_again:
world_scan = finalize.scan_world(
world,
resource_pack
)
for key in world_scan:
progress_scan[key] = world_scan[key]
next_update_progress_section()
version: int = option_manager.get_version()
# Update resource pack
if update_progress["stage"] == 200:
if resource_pack.exists():
action_prepare_original_copy_resource_pack(False)
action_update_resource_pack()
next_update_progress_section()
# Update data pack
if update_progress["stage"] == 300:
if version <= 2006:
action_rename_data_pack_directories(False)
next_update_progress()
if update_progress["stage"] == 301:
if progress_scan["disabled_vanilla"]:
action_fix_disabled_vanilla()
next_update_progress()
if update_progress["stage"] == 302:
if progress_scan["advancements"]:
print("")
log("Advancements in the 'minecraft' namespace were found, which may be used to disable advancements in older maps")
confirm = input("Do you wish to disable them via pack.mcmeta filters instead? (Y/N): ")
if confirm in ["y", "Y"]:
action_disable_advancements(False)
if progress_scan["recipes"]:
print("")
log("Recipes in the 'minecraft' namespace were found, which may be used to disable recipes in older maps")
confirm = input("Do you wish to disable them via pack.mcmeta filters instead? (Y/N): ")
if confirm in ["y", "Y"]:
action_disable_recipes(False)
next_update_progress()
if update_progress["stage"] == 303:
action_prepare_source_copy(False)
next_update_progress()
if update_progress["stage"] == 304:
action_update_data_packs(False)
next_update_progress_section()
# Optimize world
if update_progress["stage"] == 400:
print("")
log(f'The world must now be optimized, boot up Minecraft {utils.get_version_string(defaults.PACK_VERSION)} and optimize the main copy of your world')
confirm = input("Confirm when it has been optimized, decline to cancel (Y/N): ")
if confirm not in ["y", "Y"]:
log("Updated canceled")
return
next_update_progress_section()
# Fix world
if update_progress["stage"] == 500:
if version <= 1605:
action_entity_extract(False)
next_update_progress()
if update_progress["stage"] == 501:
fix_world_flags = action_fix_world(False)
for key in fix_world_flags:
progress_flags[key] = fix_world_flags[key]
next_update_progress_section()
# Update command blocks
if update_progress["stage"] == 600:
action_read_commands(False)
next_update_progress()
if update_progress["stage"] == 601:
action_update_commands(False)
next_update_progress()
if update_progress["stage"] == 602:
action_write_commands(False)
next_update_progress_section()
# Add various things to the world to restore old behavior
if update_progress["stage"] == 700:
if progress_flags["spawner_bossbar"]:
action_spawner_bossbar()
next_update_progress()
if update_progress["stage"] == 701:
if version <= 710:
action_old_adventure_mode()
next_update_progress()
if update_progress["stage"] == 702:
if version <= 809:
action_area_effect_cloud_killer()
next_update_progress()
if update_progress["stage"] == 703:
if version <= 1100:
action_firework_damage_canceler()
next_update_progress()
if update_progress["stage"] == 704:
if version <= 1202:
action_tag_replacements()
next_update_progress()
if update_progress["stage"] == 705:
if version <= 1502:
action_illegal_chunk()
next_update_progress()
if update_progress["stage"] == 706:
if version <= 1605:
action_ore_fixer()
next_update_progress()
if update_progress["stage"] == 707:
if version <= 1802:
action_unwaterloggable_leaves()
next_update_progress()
if update_progress["stage"] == 708:
if version <= 2006:
action_attribute_reset()
next_update_progress()
if update_progress["stage"] == 709:
if version <= 2101 and progress_flags["locked_containers"]:
action_lock_fixer()
next_update_progress_section()
# Finalize map
if update_progress["stage"] == 800:
print("")
if (world / "data" / "scoreboard.dat").exists():
confirm = input("Do you wish to remove player score data from your map? (Y/N): ")
else:
confirm = "n"
if confirm in ["y", "Y"]:
action_get_player_names(False)
print("")
log("Player names have been logged in player_names.json")
log("Go through the list and remove non-player names from the list (e.g. fakeplayer variable names)")
confirm = input("Confirm when the non-player names have been removed, declined to cancel (Y/N): ")
if confirm not in ["y", "Y"]:
with (PROGRAM_PATH / "player_names.json").open("w", encoding="utf-8", newline="\n") as file:
file.write("{}")
else:
with (PROGRAM_PATH / "player_names.json").open("w", encoding="utf-8", newline="\n") as file:
file.write("{}")
next_update_progress()
if update_progress["stage"] == 801:
action_finalize_map(False)
next_update_progress()
if update_progress["stage"] == 802:
if progress_scan["zipped_data_packs"]:
action_zip_data_packs(False)
next_update_progress()
if update_progress["stage"] == 803:
if resource_pack.exists():
action_export_resource_pack(False)
action_export_original_resource_pack(False)
next_update_progress()
if update_progress["stage"] == 804:
action_prepare_play_copy(False)
next_update_progress_section()
print("")
log("Map updated")
log("Join the play copy of the world and playtest it", True)
global actions
actions[Action.CLEAN.value]["show"] = True
reset_update_progress()
def reset_update_progress():
global update_progress
update_progress = default_update_progress()
save_session()
def next_update_progress():
update_progress["stage"] += 1
save_session()
def next_update_progress_section():
update_progress["stage"] = (update_progress["stage"] + 100)//100*100
save_session()
def action_scan_world():
world_scan = finalize.scan_world(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack()
)
if not world_scan["world"]:
return
global actions
if world_scan["resource_pack"]:
actions[Action.RP_IMPORT.value]["show"] = True
if world_scan["disabled_vanilla"]:
actions[Action.DP_VANILLA.value]["show"] = True
if world_scan["zipped_data_packs"]:
actions[Action.DP_UNZIP.value]["show"] = True
if world_scan["stored_functions"]:
actions[Action.DP_STORED_FUNCTION.value]["show"] = True
if world_scan["stored_advancements"]:
actions[Action.DP_STORED_ADVANCEMENT.value]["show"] = True
if world_scan["advancements"]:
actions[Action.DP_ADVANCEMENT.value]["show"] = True
if world_scan["recipes"]:
actions[Action.DP_RECIPE.value]["show"] = True
actions[Action.WORLD_ORIGINAL.value]["show"] = True
def action_import_resource_pack(manual: bool = True): # Needs confirmation
resource_pack.import_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack(),
manual
)
if manual:
global actions
actions[Action.RP_IMPORT.value]["show"] = True
actions[Action.RP_ORIGINAL.value]["show"] = True
actions[Action.RP_PURGE.value]["show"] = True
def action_export_resource_pack(manual: bool = True): # Needs confirmation
resource_pack.export_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack(),
manual
)
def action_export_original_resource_pack(manual: bool = True): # Needs confirmation
resource_pack.export_pack(
MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_source',
MINECRAFT_PATH / "resourcepacks" / f'{option_manager.get_resource_pack()}_original',
manual
)
def action_update_resource_pack():
resource_pack.update(
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack(),
option_manager.get_version()
)
def action_fix_resource_pack():
resource_pack.fix(
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack()
)
def action_purge_vanilla_assets(): # Needs confirmation
resource_pack.purge_vanilla_assets(
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack()
)
def action_unzip_data_packs(manual: bool = True): # Needs confirmation
data_pack.unzip_packs(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_zip_data_packs(manual: bool = True): # Needs confirmation
data_pack.zip_packs(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_merge_data_packs(manual: bool = True): # Needs confirmation
data_pack.merge_packs(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
option_manager.get_fancy_name()
)
if manual:
global actions
actions[Action.DP_MERGE.value]["show"] = True
def action_rename_data_pack_directories(manual: bool = True):
data_pack.rename_directories(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_update_data_packs(manual: bool = True):
data_pack.update(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
option_manager.get_version()
)
if manual:
global actions
if option_manager.get_version() <= 1202:
actions[Action.DP_TAG.value]["show"] = True
def action_tag_replacements():
tag_replacements.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_spawner_bossbar():
spawner_bossbar.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_area_effect_cloud_killer():
area_effect_cloud_killer.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_ore_fixer():
ore_fixer.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_unwaterloggable_leaves():
unwaterloggable_leaves.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_old_adventure_mode():
old_adventure_mode.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_firework_damage_canceler():
firework_damage_canceler.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_effect_overflow():
effect_overflow.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_attribute_reset():
attribute_reset.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_lock_fixer():
lock_fixer.create_pack(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_stored_functions(manual: bool = True): # Needs confirmation
data_pack.extract_stored_functions(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_stored_advancements(manual: bool = True): # Needs confirmation
data_pack.extract_stored_advancements(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_disable_advancements(manual: bool = True): # Needs confirmation
data_pack.disable_advancements(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_disable_recipes(manual: bool = True): # Needs confirmation
data_pack.disable_recipes(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_fix_disabled_vanilla():
data_pack.fix_disabled_vanilla(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_breakpoint(): # Needs confirmation
breakpoints.apply_breakpoints(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_read_commands(manual: bool = True):
command_blocks.read_commands(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
if manual:
global actions
actions[Action.CMD_READ.value]["show"] = True
actions[Action.CMD_WRITE.value]["show"] = True
actions[Action.CMD_UPDATE.value]["show"] = True
actions[Action.CMD_CLEAR.value]["show"] = True
actions[Action.CMD_EXTRACT.value]["show"] = True
def action_write_commands(manual: bool = True): # Needs confirmation
command_blocks.write_commands(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
manual
)
def action_update_commands(manual: bool = True):
command_blocks.update_commands(
option_manager.get_version()
)
if manual:
global actions
if option_manager.get_version() <= 1100:
actions[Action.DP_FIREWORK.value]["show"] = True
if option_manager.get_version() <= 1202:
actions[Action.DP_TAG.value]["show"] = True
def action_clear_command_helper(): # Needs confirmation
data_pack_path: Path = MINECRAFT_PATH / "saves" / option_manager.get_map_name() / "datapacks" / "command_helper"
log(f'This action will delete: {data_pack_path.as_posix()}')
confirm = input("Is this okay? (Y/N): ")
if confirm not in ["Y", "y"]:
log("Action canceled")
return
log("Clearing command helper")
if not data_pack_path.exists():
log("ERROR: Command helper does not exist!")
return
shutil.rmtree(data_pack_path)
log("Command helper cleared")
def action_extract_commands():
command_blocks.extract_commands(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
def action_get_player_names(manual: bool = True):
finalize.get_player_names(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
if manual:
global actions
actions[Action.FINAL.value]["show"] = True
def action_finalize_map(manual: bool = True): # Needs confirmation
finalize.finalize(
MINECRAFT_PATH / "saves" / option_manager.get_map_name(),
MINECRAFT_PATH / "resourcepacks" / option_manager.get_resource_pack(),
manual
)
if manual:
global actions
actions[Action.WORLD_PLAY.value]["show"] = True
if actions[Action.DP_UNZIP.value]["show"]:
actions[Action.DP_ZIP.value]["show"] = True
if actions[Action.RP_IMPORT.value]["show"]:
actions[Action.RP_EXPORT.value]["show"] = True
actions[Action.CLEAN.value]["show"] = True
def action_log_data_packs():
finalize.log_data_packs(
MINECRAFT_PATH / "saves" / option_manager.get_map_name()
)
global actions
actions[Action.DP_LOG.value]["show"] = True
def action_prepare_original_copy_world(manual: bool = True): # Needs confirmation
log("Preparing original world copy")
world: Path = MINECRAFT_PATH / "saves" / option_manager.get_map_name()
og_world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_original'
if og_world.exists() and manual:
log(f'This action will overwrite: {og_world.as_posix()}')
confirm = input("Is this okay? (Y/N): ")
if confirm not in ["Y", "y"]:
log("Action canceled")
return
if not world.exists():
log("ERROR: World does not exist!")
return
if og_world.exists():
shutil.rmtree(og_world)
shutil.copytree(world, og_world)
log("Original world copy prepared")
if manual:
global actions
actions[Action.WORLD_ORIGINAL_PLAY.value]["show"] = True
actions[Action.WORLD_RELOAD.value]["show"] = True
actions[Action.WORLD_SOURCE.value]["show"] = True
def action_prepare_original_play_copy(): # Needs confirmation
log("Preparing original play world copy")
world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_original'
play_world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_original_play'
if play_world.exists():
log(f'This action will overwrite: {play_world.as_posix()}')
confirm = input("Is this okay? (Y/N): ")
if confirm not in ["Y", "y"]:
log("Action canceled")
return
if not world.exists():
log("ERROR: World does not exist!")
return
if play_world.exists():
shutil.rmtree(play_world)
shutil.copytree(world, play_world)
log("Play world copy prepared")
def action_reload_from_original_world(manual: bool = True): # Needs confirmation
log("Reloading world from original")
world: Path = MINECRAFT_PATH / "saves" / option_manager.get_map_name()
og_world: Path = MINECRAFT_PATH / "saves" / f'{option_manager.get_map_name()}_original'
if world.exists() and manual:
log(f'This action will overwrite: {world.as_posix()}')
confirm = input("Is this okay? (Y/N): ")
if confirm not in ["Y", "y"]:
log("Action canceled")
return
if not og_world.exists():
log("ERROR: World does not exist!")
return
if world.exists():
shutil.rmtree(world)
shutil.copytree(og_world, world)
log("World reloaded from original")
if manual:
global actions
actions[Action.WORLD_ORIGINAL_PLAY.value]["show"] = True
actions[Action.WORLD_RELOAD.value]["show"] = True
actions[Action.WORLD_SOURCE.value]["show"] = True