-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm3ecWizard.pyw
1637 lines (1534 loc) · 59.1 KB
/
m3ecWizard.pyw
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
import os, sys, json, tempfile, hashlib, shutil, threading, subprocess, m3ec
from zipfile import ZipFile
from base64 import b64encode, b64decode
try:
from PIL import Image
except ImportError:
print("Installing dependency PIL...")
subprocess.run(["python", "-m", "pip", "install", "--user", "--upgrade", "pillow"])
try:
from PIL import Image
except ImportError:
input("Failed to install dependency. Abort.")
exit(1)
from _m3ec.util import *
try:
import PySimpleGUI as sg
except ImportError:
print("Installing dependency PySimpleGUI...")
subprocess.run(["python", "-m", "pip", "install", "--user", "--upgrade", "PySimpleGUI"])
print("Installing dependency tk...")
subprocess.run(["python", "-m", "pip", "install", "--user", "--upgrade", "tk"])
try:
import PySimpleGUI as sg
except ImportError:
input("Failed to install dependency. Abort.")
exit(1)
sg.theme("BrownBlue")
WIN_WIDTH = 500
EDITOR_BUTTON_SIZE = (18,1)
EDITOR_BUTTON_SIZE_X = 140
EDITOR_BUTTON_SIZE_THIN = (10,1)
EDITOR_BUTTON_SIZE_WIDE = (36,1)
TEMP_DIR = os.path.join(tempfile.gettempdir(), "m3ecWizard.ImageTemp")
M3EC_DATA_ROOT = os.path.join(os.path.dirname(__file__), "data")
WIZARD_DATA_ROOT = os.path.join(M3EC_DATA_ROOT, "wizard")
PLACEHOLDER_IMAGE_FILE = os.path.join(WIZARD_DATA_ROOT, "images", "placeholder.png")
if not os.path.exists(PLACEHOLDER_IMAGE_FILE):
PLACEHOLDER_IMAGE_FILE = None
if sys.platform.startswith("win32"):
ICON_FILE = os.path.join(WIZARD_DATA_ROOT, "images", "m3ec.ico")
else:
ICON_FILE = os.path.join(WIZARD_DATA_ROOT, "images", "m3ec.png")
if not os.path.exists(ICON_FILE):
ICON_FILE = None
SOUND_TYPES = load_resource(WIZARD_DATA_ROOT, "sound_types.json")
MATERIAL_TYPES = load_resource(WIZARD_DATA_ROOT, "material_types.json")
TOOL_TYPES_LIST = ["None", "Axes", "Hoes", "Pickaxes", "Shovels"]
TOOL_LEVELS_LIST = ["Wood", "Stone", "Iron", "Diamond", "Netherite"]
TEXTURE_LAYOUTS_LIST = ["Single", "Ground", "Pillar", "Cross", "3 Axis Pillar"]
DROP_TYPES_LIST = ["Self", "Item", "ItemRange", "Fortunable", "None"]
def ContentSelectWindow(manifest_dict, content_type, skip=0, count=16, vanillabutton=True):
while True:
e = _ContentSelectWindow(manifest_dict, content_type, skip, count, vanillabutton)
if type(e) is str:
if e == "Prev":
if skip > count:
skip -= count
else:
skip = 0
elif e == "Next":
if content_type == "vanilla":
if skip+count < len(manifest_dict["mc.names"]):
skip += count
elif type(content_type) is list:
if skip+count < sum([len(manifest_dict[f"mod.registry.{ct}.names"]) for ct in content_type]):
skip += count
else:
if skip+count < len(manifest_dict[f"mod.registry.{content_type}.names"]):
skip += count
else:
if content_type == "vanilla":
if ":" not in e:
return "minecraft:"+e
else:
if ":" not in e:
return manifest_dict["mod.mcpath"]+":"+e
return e
elif not e or e is None:
return None
def _ContentSelectWindow(manifest_dict, content_type, skip, count, vanillabutton):
# global WIN_WIDTH, EDITOR_BUTTON_SIZE, EDITOR_BUTTON_SIZE_WIDE
contentnames = []
if type(content_type) is not list:
if content_type == "vanilla":
content_types = ["block", "item"]
ctstr = "block/item"
contentnames = sorted([("",item) for item in manifest_dict["mc.names"]])
content_types = [content_type]
else:
ctstr = content_type
manifest_dict[f"mod.registry.{content_type}.names"].sort()
for cid in manifest_dict[f"mod.registry.{content_type}.names"]:
contentnames.append((content_type, cid))
else:
content_types = content_type
ctstr = "/".join(content_types)
for ct in content_types:
manifest_dict[f"mod.registry.{ct}.names"].sort()
for cid in manifest_dict[f"mod.registry.{ct}.names"]:
contentnames.append((ct, cid))
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Input(k="itemname"), sg.Button(f"{ctstr} name", k="submititemname")],
[sg.Button(f"Vanilla {ctstr}s", key="Vanilla", size=EDITOR_BUTTON_SIZE)] if content_type != "vanilla" and vanillabutton else [],
[sg.Button(f"Previous {count} {ctstr}s", key="Prev", size=EDITOR_BUTTON_SIZE)] if skip>0 else [],
([sgScaledImage(os.path.join(manifest_dict["project_path"], manifest_dict["mod.textures"]), d=manifest_dict, k=f"mod.{ct}.{name}.texture"),
sg.Button(name, key=f"select_{name}", size=EDITOR_BUTTON_SIZE_WIDE),
] for ct,name in contentnames[skip:skip+min(len(contentnames)-skip, count)]),
[sg.Button(f"Next {count} {ctstr}s", key="Next", size=EDITOR_BUTTON_SIZE)] if skip+count<len(contentnames) else [],
[sg.Button("Go Back", key="Back", size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window(f"Mod {ctstr} List", layout, icon=ICON_FILE)
while True:
event, values = window.read()
if event in ('Back', sg.WIN_CLOSED):
break
elif event in ('Next', 'Prev'):
window.close()
return event
elif event in ('Vanilla',):
window.close()
return ContentSelectWindow(manifest_dict, "vanilla")
elif event in ('submititemname',):
if len(values['itemname']):
window.close()
return values['itemname']
elif event.startswith("select_"):
window.close()
# print(event)
return event.split("_", maxsplit=1)[1]
window.close()
return False
def SelectSound():
return SelectionList("Select Sound Type", SOUND_TYPES)
def SelectMaterial():
return SelectionList("Select Material Type", MATERIAL_TYPES)
def SelectionList(title, items):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Input(k="custom"), sg.Button("submit custom value", k="Submit")],
[],
]
i = 0
for s in items:
layout[-1].append(sg.Button(s, k=s.replace(" ","_"), size=EDITOR_BUTTON_SIZE))
i = (i + 1) % 8
if not i:
layout.append([])
if not len(layout[-1]):
layout[-1].append(sg.Sizer(WIN_WIDTH, 0))
layout.extend([
[sg.Cancel()],
[sg.Sizer(WIN_WIDTH, 0)],
])
event, values = sg.Window(title, layout, icon=ICON_FILE).read(close=True)
if event in ("Cancel", sg.WIN_CLOSED):
return None
elif event == "Submit":
if len(values["custom"]):
return values["custom"]
else:
return None
else:
return event
def CreateRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Text("Recipe Type")],
[sg.Button("Shaped", k="shaped", size=EDITOR_BUTTON_SIZE),
sg.Button("Shapeless", k="shapeless", size=EDITOR_BUTTON_SIZE),
sg.Button("Smelting", k="smelting", size=EDITOR_BUTTON_SIZE),
sg.Button("Stonecutter", k="stonecutter", size=EDITOR_BUTTON_SIZE),
sg.Button("Smithing", k="smithing", size=EDITOR_BUTTON_SIZE),
],
[sg.Cancel()],
]
event, values = sg.Window("Create New Recipe", layout, icon=ICON_FILE).read(close=True)
if event == "shaped":
recipes = CreateShapedRecipe(mfd)
elif event == "shapeless":
recipes = CreateShapelessRecipe(mfd)
elif event == "smelting":
recipes = CreateSmeltingRecipe(mfd)
elif event == "stonecutter":
recipes = CreateStonecutterRecipe(mfd)
elif event == "smithing":
recipes = CreateSmithingRecipe(mfd)
else:
return None
if recipes is None:
return None
for recipe in recipes:
if type(recipe) is dict:
n = 1
cid = ocid = recipe["result"].split(":")[-1]
while cid in mfd["mod.registry.recipe.names"]:
n += 1
cid = ocid+"_"+str(n)
recipe["contentid"] = cid
fname = os.path.join(mfd["project_path"], "recipes", cid+".m3ec")
n = 1
while os.path.exists(fname):
n += 1
fname = os.path.join(mfd["project_path"], "recipes", cid+"_"+str(n)+".m3ec")
writeDictFile(fname, recipe)
add_content(cid, "recipe", recipe, mfd, fname)
return [recipe for recipe in recipes]
def CreateShapedRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH,0)],
[sg.Text("Ingredients"), sg.Button("Set All",k="itemall")],
[sg.Button("empty", k="item1", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item2", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item3", size=EDITOR_BUTTON_SIZE),
],
[sg.Button("empty", k="item4", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item5", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item6", size=EDITOR_BUTTON_SIZE),
sg.Sizer(EDITOR_BUTTON_SIZE_X, 0),
sg.Button("result", k="itemresult", size=EDITOR_BUTTON_SIZE),
],
[sg.Button("empty", k="item7", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item8", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item9", size=EDITOR_BUTTON_SIZE),
sg.Sizer(EDITOR_BUTTON_SIZE_X, 0),
sg.Text("Count:"),
sg.Input(size=EDITOR_BUTTON_SIZE, k="count"),
],
[sg.Checkbox("Minify", k="minify", size=EDITOR_BUTTON_SIZE, default=True),
sg.Checkbox("Mirror X", k="mirrorx", size=EDITOR_BUTTON_SIZE, default=True),
sg.Checkbox("Mirror Y", k="mirrory", size=EDITOR_BUTTON_SIZE, default=False),
],
[sg.Sizer(0, 20)],
[sg.Ok(size=EDITOR_BUTTON_SIZE), sg.Cancel(size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window("Create Shaped Recipe", layout, icon=ICON_FILE)
recipe = {"@": "recipe", "recipe": "ShapedRecipe", "pattern": [[" "]*3]*3, "items":[], "itemkeys":[], "result": "", "count": "1"}
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
break
elif event == "Ok":
if not len(recipe["pattern"]):
ErrorWindow("Recipe must contain at least one item.")
continue
if not len(recipe["result"]):
ErrorWindow("Result must not be empty.")
continue
if len(values["count"]):
if not values["count"].isalnum() or "." in values["count"] or int(values["count"]) < 1:
ErrorWindow("Count must be an integer greater than or equal to 1.")
continue
recipe["count"] = values["count"]
if checkDictKeyTrue(values, "minify"):
mx = my = 0
ex = max([len(s) for s in recipe["pattern"]])
ey = len(recipe["pattern"])
for row in range(len(recipe["pattern"])):
if not all([c==' ' for c in recipe["pattern"][row]]):
sy = row
break
for row in range(len(recipe["pattern"])):
if all([c==' ' for c in recipe["pattern"][row]]):
ey = row
break
for row in range(len(recipe["pattern"])):
x = len(recipe["pattern"][row].rstrip(" "))
y = 0
for col in range(len(recipe["pattern"][row])-1, -1, -1):
if recipe["pattern"][row][col] != ' ':
if col < ex:
ex = col
for col in range(len(recipe["pattern"][row])):
if recipe["pattern"][row][col] != ' ':
if col > sx:
sx = col
for row in range(sy, ey+1):
recipe["pattern"][row] = recipe["pattern"][row][sx:ex+1]
recipe["pattern"] = recipe["pattern"][sy:ey+1]
else:
for row in range(len(recipe["pattern"])):
recipe["pattern"][row] = '"'+"".join(recipe["pattern"][row])+'"'
yield recipe
if checkDictKeyTrue(values, "mirrorx"):
recipe2 = recipe.copy()
recipe2["pattern"] = [s[::-1] for s in recipe2["pattern"]]
yield recipe2
if checkDictKeyTrue(values, "mirrory"):
recipe3 = recipe.copy()
recipe3["pattern"] = recipe2["pattern"][::-1]
yield recipe3
if checkDictKeyTrue(values, "mirrory"):
recipe2 = recipe.copy()
recipe2["pattern"] = recipe2["pattern"][::-1]
yield recipe2
break
elif event.startswith("item"):
item = ContentSelectWindow(mfd, ["block", "item"])
if event == "itemresult":
recipe["result"] = item
elif event == "itemall":
recipe["pattern"] = [["A"]*3]*3
recipe["items"] = [item]
recipe["itemkeys"] = ["A"]
for n in range(9):
if item is None:
window[f"item{n+1}"].update("empty")
else:
window[f"item{n+1}"].update(item)
else:
num = int(event[4])
row = num // 3
col = num % 3
while len(recipe["pattern"]) <= row:
recipe["pattern"].append([])
while len(recipe["pattern"][row]) <= col:
recipe["pattern"][row].append(" ")
if item in recipe["items"]:
recipe["pattern"][row][col] = recipe["itemkeys"][recipe["items"].index(item)]
else:
c = chr(ord('A') + len(recipe["items"]))
recipe["pattern"][row][col] = c
recipe["itemkeys"].append(c)
recipe["items"].append(item)
if item is None:
window[event].update("empty")
else:
window[event].update(item)
window.close()
def CreateShapelessRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Text("Ingredients"), sg.Button("Set All",k="itemall")],
([sg.Button("empty",k=f"item{n+1}",size=EDITOR_BUTTON_SIZE)] for n in range(9)),
[sg.Text("Result:"), sg.Button("empty",k="itemresult"),
sg.Text("Count:"), sg.Input(k="count", size=EDITOR_BUTTON_SIZE),],
[sg.Sizer(0, 20)],
[sg.Ok(size=EDITOR_BUTTON_SIZE), sg.Cancel(size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window("Create Shapeless Recipe", layout, icon=ICON_FILE)
recipe = {"@": "recipe", "recipe": "ShapelessRecipe", "result": "", "count": "1"}
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
break
elif event == "Ok":
items = []
for n in range(9):
if f"item{n+1}" in recipe.keys():
if len(recipe[f"item{n+1}"]):
items.append(recipe[f"item{n+1}"])
if not len(items):
ErrorWindow("At least one ingredient must not be empty.")
continue
if not len(recipe["result"]):
ErrorWindow("Result must not be empty")
continue
if len(values["count"]):
if not values["count"].isalnum() or "." in values["count"] or int(values["count"]) < 1:
ErrorWindow("Count must be an integer greater than or equal to 1.")
continue
recipe["count"] = values["count"]
recipe["ingredients"] = items
for n in range(9):
if f"item{n+1}" in recipe.keys():
del recipe[f"item{n+1}"]
yield recipe
break
elif event.startswith("item"):
item = ContentSelectWindow(mfd, ["block", "item"])
if event == "itemresult":
recipe["result"] = item
elif event =="itemall":
for n in range(9):
if item is None:
if f"item{n+1}" in recipe.keys():
del recipe[f"item{n+1}"]
window[f"item{n+1}"].update("empty")
else:
recipe[f"item{n+1}"] = item
window[f"item{n+1}"].update(item)
else:
if item is None:
if event in recipe.keys():
del recipe[event]
else:
recipe[event] = item
if item is None:
window[event].update("empty")
else:
window[event].update(item)
window.close()
def CreateSmeltingRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Text("Ingredient", size=EDITOR_BUTTON_SIZE_WIDE), sg.Text("Result", size=EDITOR_BUTTON_SIZE_WIDE)],
[sg.Button("empty", k="item1", size=EDITOR_BUTTON_SIZE),
sg.Sizer(EDITOR_BUTTON_SIZE_X, 0),
sg.Button("empty", k="itemresult", size=EDITOR_BUTTON_SIZE),
sg.Input(k="count",size=EDITOR_BUTTON_SIZE_THIN),
],
[sg.Text("Time (ticks)"), sg.Input(k="time"),
sg.Text("Experience Points"), sg.Input(k="experience"),
],
[sg.Checkbox("Smelting",k="smelting",size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Blasting",k="blasting",size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Smoking",k="smoking",size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Campfire",k="campfire",size=EDITOR_BUTTON_SIZE_THIN),
],
[sg.Sizer(0, 20)],
[sg.Ok(size=EDITOR_BUTTON_SIZE), sg.Cancel(size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window("Create Smelting Recipe", layout, icon=ICON_FILE)
result = ingredient = None
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
break
elif event == "Ok":
if result is None or ingredient is None:
ErrorWindow("Ingredient and result must not be empty.");
continue
if not len(values["count"]):
values["count"] = "1"
if not len(values["experience"]):
values["experience"] = "0"
if values["smelting"]:
yield {"@": "recipe", "recipe": "SmeltingRecipe", "ingredient": ingredient,
"result": result, "count":values["count"], "time":values["time"],
"experience":values["experience"]}
if values["blasting"]:
yield {"@": "recipe", "recipe": "BlastingRecipe", "ingredient": ingredient,
"result": result, "count":values["count"], "time":values["time"]/2,
"experience":values["experience"]}
if values["smoking"]:
yield {"@": "recipe", "recipe": "SmokingRecipe", "ingredient": ingredient,
"result": result, "count":values["count"], "time":values["time"]/2,
"experience":values["experience"]}
if values["campfire"]:
yield {"@": "recipe", "recipe": "CampfireRecipe", "ingredient": ingredient,
"result": result, "count":values["count"], "time":values["time"]*3}
break
elif event.startswith("item"):
item = ContentSelectWindow(mfd, ["block", "item"])
if event == "itemresult":
result = item
elif event == "item1":
ingredient = item
if item is None:
window[event].update("empty")
else:
window[event].update(item)
window.close()
def CreateStonecutterRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Text("Ingredient", size=EDITOR_BUTTON_SIZE_WIDE), sg.Text("Result", size=EDITOR_BUTTON_SIZE_WIDE)],
[sg.Button("empty", k="item1", size=EDITOR_BUTTON_SIZE),
sg.Sizer(EDITOR_BUTTON_SIZE_X, 0),
sg.Button("empty", k="itemresult", size=EDITOR_BUTTON_SIZE),
],
[sg.Sizer(0, 20)],
[sg.Ok(size=EDITOR_BUTTON_SIZE), sg.Cancel(size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window("Create Stonecutter Recipe", layout, icon=ICON_FILE)
recipe = {"@": "recipe", "recipe": "Stonecutting", "ingredient": "", "result": ""}
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
break
elif event == "Ok":
if not len(recipe["ingredient"]) or not len(recipe["result"]):
ErrorWindow("Ingredient(s)/result must not be empty.");
continue
yield recipe
break
elif event.startswith("item"):
item = ContentSelectWindow(mfd, ["block", "item"])
if event == "itemresult":
recipe["result"] = item
elif event == "item1":
recipe["ingredient"] = item
if item is None:
window[event].update("empty")
else:
window[event].update(item)
window.close()
def CreateSmithingRecipe(mfd):
layout = [
[sg.Sizer(WIN_WIDTH, 0)],
[sg.Text("Ingredient 1", size=EDITOR_BUTTON_SIZE), sg.Text("Ingredient 2", size=EDITOR_BUTTON_SIZE_WIDE),
sg.Text("Result", size=EDITOR_BUTTON_SIZE),],
[sg.Button("empty", k="item1", size=EDITOR_BUTTON_SIZE),
sg.Button("empty", k="item2", size=EDITOR_BUTTON_SIZE),
sg.Sizer(EDITOR_BUTTON_SIZE_X, 0),
sg.Button("empty", k="itemresult", size=EDITOR_BUTTON_SIZE),
],
[sg.Sizer(0, 20)],
[sg.Ok(size=EDITOR_BUTTON_SIZE), sg.Cancel(size=EDITOR_BUTTON_SIZE)],
]
window = sg.Window("Create Smithing Recipe", layout, icon=ICON_FILE)
recipe = {"@": "recipe", "recipe": "SmithingRecipe", "ingredient": "", "ingredient2": "", "result": ""}
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
break
elif event == "Ok":
if not len(recipe["ingredient"]) or not len(recipe["ingredient2"]) or not len(recipe["result"]):
ErrorWindow("Ingredient(s)/result must not be empty.");
continue
yield recipe
break
elif event.startswith("item"):
item = ContentSelectWindow(mfd, ["block", "item"])
if event == "itemresult":
recipe["result"] = item
elif event == "item1":
recipe["ingredient"] = item
elif event == "item2":
recipe["ingredient2"] = item
if item is None:
window[event].update("empty")
else:
window[event].update(item)
window.close()
def CreateBlock(mfd, contentid=None):
layout = [
[sg.Text("Block Name"), sg.Input(key="title")],
[sg.Sizer(WIN_WIDTH, 5)],
[
sg.Text("Block Hardness"),
sg.Input(key="hardness"),
sg.Text("Block Resistance"),
sg.Input(key="resistance"),
],
[sg.Text("(Note: you can input existing block names to copy)")],
[
sg.Text("Tool type required to mine"),
sg.Combo(TOOL_TYPES_LIST, TOOL_TYPES_LIST[0], k="tooltype", size=EDITOR_BUTTON_SIZE_THIN),
sg.Text("Tool level"),
sg.Combo(TOOL_LEVELS_LIST, TOOL_LEVELS_LIST[0], k="toollevel", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Text("Block Drop Type"),
sg.Combo(DROP_TYPES_LIST, DROP_TYPES_LIST[0], k="droptype", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Button("Item to Drop", k="selectdropitem", size=EDITOR_BUTTON_SIZE_WIDE),
sg.Text(k="dropitem"),
],
[
sg.Text("Drop Count", k="dropcountlabel"),
sg.Input(k="dropcount", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Text("Drop Count Minimum ", k="dropcountminlabel"),
sg.Input(k="dropcountmin", size=EDITOR_BUTTON_SIZE_THIN),
sg.Text("Maximum", k="dropcountmaxlabel"),
sg.Input(k="dropcountmax", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Text("Block Texture Layout"),
sg.Combo(TEXTURE_LAYOUTS_LIST, TEXTURE_LAYOUTS_LIST[0], enable_events=True, k="texturetype"),
],
[
sg.Text("Main/Top Texture"),
sg.Input(),
sg.FileBrowse(key="imgfilemain", file_types=(("PNG Files", "*.png"), ("All Files", "*.* *")), initial_folder=os.path.join(mfd["project_path"], mfd["mod.textures"]))
],
[
sg.Text("Side Texture"), sg.Input(),
sg.FileBrowse(key="imgfileside", file_types=(("PNG Files", "*.png"), ("All Files", "*.* *")), initial_folder=os.path.join(mfd["project_path"], mfd["mod.textures"]))
],
[
sg.Text("Bottom Texture"), sg.Input(),
sg.FileBrowse(key="imgfilebottom", file_types=(("PNG Files", "*.png"), ("All Files", "*.* *")), initial_folder=os.path.join(mfd["project_path"], mfd["mod.textures"]))
],
[
sg.Text("Front Texture"), sg.Input(),
sg.FileBrowse(key="imgfilefront", file_types=(("PNG Files", "*.png"), ("All Files", "*.* *")), initial_folder=os.path.join(mfd["project_path"], mfd["mod.textures"]))
],
[sg.Text("Sounds"), sg.Button("select", k="selectsounds", size=EDITOR_BUTTON_SIZE_WIDE)],
[sg.Text("Material"), sg.Button("select", k="selectmaterial", size=EDITOR_BUTTON_SIZE_WIDE)],
[
sg.Text("Auto-generate"),
sg.Checkbox("All", k="genall", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Checkbox("Button", k="genbutton", size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Fence", k="genfence", size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Fence Gate", k="genfencegate", size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Pressure Plate", k="genplate", size=EDITOR_BUTTON_SIZE_THIN),
],
[
sg.Checkbox("Slab", k="genslab", size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Stairs", k="genstairs", size=EDITOR_BUTTON_SIZE_THIN),
sg.Checkbox("Wall", k="genwall", size=EDITOR_BUTTON_SIZE_THIN)
],
[sg.Ok(size=EDITOR_BUTTON_SIZE_WIDE, bind_return_key=True), sg.Cancel(size=EDITOR_BUTTON_SIZE_WIDE)],
]
window = sg.Window("Create New Block", layout, icon=ICON_FILE)
dropitem = material = sound = None
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
window.close()
return None
elif event in ('selectdropitem',):
dropitem = ContentSelectWindow(mfd, ["block", "item"])
if dropitem is not None:
window["dropitem"].update(dropitem)
elif event in ('selectsounds',):
sound = SelectSound()
if sound is not None:
window["selectsounds"].update(sound)
elif event in ('selectmaterial',):
material = SelectMaterial()
if material is not None:
window["selectmaterial"].update(material)
elif event in ('Ok',):
cid = values["title"]
if not len(cid):
ErrorWindow("Block name must be defined.", parent=window)
continue
title, name, upper = ParseContentTitle(values["title"])
fname = os.path.join(mfd["project_path"], "blocks", name+".m3ec")
if os.path.exists(fname):
d = readDictFile(fname)
else:
d = {}
d["@"] = "block"
d["block"] = "SimpleBlock"
d["contentid"] = name
d["title"] = title
if name in mfd["mod.registry.block.names"] or name in mfd["mod.registry.item.names"]:
ErrorWindow(f"Block/Item {name} already exists.", parent=window)
continue
if sound is None:
ErrorWindow("Sound Type must be defined")
continue
if material is None:
ErrorWindow("Material Type must be defined")
continue
d["sounds"] = sound.upper().replace(" ","_")
d["material"] = material.upper().replace(" ","_")
if values["texturetype"] == "Single":
imgmain = values["imgfilemain"]
if not len(imgmain):
ErrorWindow("Main texture must be defined.", parent=window)
continue
imgmain = GetImageAsPNG(imgmain, mfd)
if imgmain is None:
continue
d["texture"] = imgmain
elif values["texturetype"] == "Cross":
d["block"] = "CrossBlock"
imgmain = values["imgfilemain"]
if not len(imgmain):
ErrorWindow("Main texture must be defined.", parent=window)
continue
imgmain = GetImageAsPNG(imgmain, mfd)
if imgmain is None:
continue
d["texture"] = imgmain
elif values["texturetype"] == "Pillar":
d["block"] = "PillarBlock"
imgtop = values["imgfilemain"]
if not len(imgtop):
ErrorWindow("Top texture must be defined for pillar blocks.", parent=window)
continue
imgtop = GetImageAsPNG(imgtop, mfd)
if imgtop is None:
continue
imgside = values["imgfileside"]
if not len(imgside):
ErrorWindow("Side texture must be defined for pillar blocks.", parent=window)
continue
imgside = GetImageAsPNG(imgside, mfd)
if imgside is None:
continue
d["texture_top"] = imgmain
d["texture_side"] = imgside
elif values["texturetype"] == "Ground":
imgtop = values["imgfilemain"]
if not len(imgtop):
ErrorWindow("Top texture must be defined for ground-like blocks.", parent=window)
continue
imgtop = GetImageAsPNG(imgtop, mfd)
if imgtop is None:
continue
imgbottom = values["imgfilebottom"]
if not len(imgbottom):
ErrorWindow("Bottom texture must be defined for ground-like blocks.", parent=window)
continue
imgbottom = GetImageAsPNG(imgbottom, mfd)
if imgbottom is None:
continue
imgside = values["imgfileside"]
if not len(imgside):
ErrorWindow("Side texture must be defined for ground-like blocks.", parent=window)
continue
imgside = GetImageAsPNG(imgside, mfd)
if imgside is None:
continue
d["texture_bottom"] = imgbottom
d["texture_side"] = imgside
d["texture_top"] = imgtop
elif values["texturetype"] == "3 Axis Pillar":
d["BlockStateType"] = "3Axis"
imgtop = values["imgfilemain"]
if not len(imgtop):
ErrorWindow("Top texture must be defined for ground-like blocks.", parent=window)
continue
imgtop = GetImageAsPNG(imgtop, mfd)
if imgtop is None:
continue
imgbottom = values["imgfilebottom"]
if not len(imgbottom):
ErrorWindow("Bottom texture must be defined for ground-like blocks.", parent=window)
continue
imgbottom = GetImageAsPNG(imgbottom, mfd)
if imgbottom is None:
continue
imgside = values["imgfileside"]
if not len(imgside):
ErrorWindow("Side texture must be defined for ground-like blocks.", parent=window)
continue
imgside = GetImageAsPNG(imgside, mfd)
if imgside is None:
continue
d["texture_bottom"] = imgbottom
d["texture_side"] = imgside
d["texture_top"] = imgtop
# elif values["rotatable"]:
# imgtop = values["imgfilemain"]
# if not len(imgtop):
# ErrorWindow("Top texture must be defined for ground-like blocks.", parent=window)
# continue
# imgtop = GetImageAsPNG(imgtop, mfd)
# if imgtop is None:
# continue
# imgside = values["imgfileside"]
# if not len(imgside):
# ErrorWindow("Side texture must be defined for rotatable blocks.", parent=window)
# continue
# imgside = GetImageAsPNG(imgside, mfd)
# if imgside is None:
# continue
# imgbottom = values["imgfilebottom"]
# if not len(imgbottom):
# ErrorWindow("Bottom texture must be defined for ground-like blocks.", parent=window)
# continue
# imgbottom = GetImageAsPNG(imgbottom, mfd)
# if imgbottom is None:
# continue
# imgfront = values["imgfilefront"]
# if not len(imgfront):
# ErrorWindow("Front texture must be defined for ground-like blocks.", parent=window)
# continue
# imgfront = GetImageAsPNG(imgfront, mfd)
# if imgfront is None:
# continue
# d["texture_bottom"] = imgbottom
# d["texture_front"] = imgfront
# d["texture_side"] = imgside
# d["texture_top"] = imgtop
else:
continue
hardness = values["hardness"]
resistance = values["resistance"]
if not len(hardness):
hardness = "1.0"
else:
if not hardness.isnumeric():
_, hardness, _ = ParseContentTitle(hardness)
if f"mc.{hardness}.hardness" in mfd.keys():
hardness = str(mfd[f"mc.{hardness}.hardness"])
else:
hardness = "1.0"
if "." not in hardness:
hardness = hardness+".0"
if not len(resistance):
resistance = "1.0"
else:
if not resistance.isnumeric():
_, resistance, _ = ParseContentTitle(resistance)
if f"mc.{resistance}.resistance" in mfd.keys():
resistance = str(mfd[f"mc.{resistance}.resistance"])
else:
resistance = "1.0"
if "." not in resistance:
resistance = resistance+".0"
d["hardness"] = mfd[f"mod.block.{name}.hardness"] = hardness
d["resistance"] = mfd[f"mod.block.{name}.resistance"] = resistance
if values["tooltype"] == "None":
d["requiresTool"] = "no"
d["toolclass"] = "NONE"
else:
d["requiresTool"] = "yes"
d["toolclass"] = values["tooltype"].upper()
d["toollevel"] = values["toollevel"].upper()
mfd["mod.files"][f"block.{name}"] = fname
for tex in ["", "_top", "_side", "_bottom", "_front", "_back"]:
if f"texture{tex}" in d.keys():
# print(f"Original texture{tex} path:", d[f"texture{tex}"])
d[f"texture{tex}"] = os.path.relpath(d[f"texture{tex}"], os.path.join(mfd["project_path"], mfd["mod.textures"]))
# print(f"Relative texture{tex} path:", d[f"texture{tex}"])
if not len(values["dropcount"]):
values["dropcount"] = "1"
if values["droptype"] =="Self":
d["droptype"] = "Self"
elif values["droptype"] == "Item":
if not len(dropitem):
ErrorWindow("Item name must not be blank for Item drop type.")
continue
d["droptype"] = "Item"
d["drops"] = dropitem
d["dropcount"] = values["dropcount"]
elif values["droptype"] == "Fortunable":
if not len(dropitem):
ErrorWindow("Item name must not be blank for Fortunable drop type.")
continue
d["droptype"] = "Fortunable"
d["drops"] = dropitem
d["dropchances"] = values["dropcount"]
elif values["droptype"] == "ItemRange":
if not len(dropitem) or not len(values["dropmin"]) or not len(values["dropmax"]):
ErrorWindow("Item name must not be blank for ItemRange drop type.")
continue
d["droptype"] = "ItemRange"
d["drops"] = dropitem
d["dropmin"] = values["dropmin"]
d["dropmax"] = values["dropmax"]
else:
d["droptype"] = "None"
if values["genbutton"] or values["genall"]:
d["autogenerate.button"] = "yes"
d["autogenerate.button.recipe"] = "yes"
d["autogenerate.button.stonecuttingrecipe"] = "yes"
if values["genfence"] or values["genall"]:
d["autogenerate.fence"] = "yes"
d["autogenerate.fence.recipe"] = "yes"
d["autogenerate.fence.stonecuttingrecipe"] = "yes"
if values["genfencegate"] or values["genall"]:
d["autogenerate.fencegate"] = "yes"
d["autogenerate.fencegate.recipe"] = "yes"
d["autogenerate.fencegate.stonecuttingrecipe"] = "yes"
if values["genplate"] or values["genall"]:
d["autogenerate.pressureplate"] = "yes"
d["autogenerate.pressureplate.recipe"] = "yes"
d["autogenerate.pressureplate.stonecuttingrecipe"] = "yes"
if values["genstairs"] or values["genall"]:
d["autogenerate.stairs"] = "yes"
d["autogenerate.stairs.recipe"] = "yes"
d["autogenerate.stairs.stonecuttingrecipe"] = "yes"
if values["genslab"] or values["genall"]:
d["autogenerate.slab"] = "yes"
d["autogenerate.slab.recipe"] = "yes"
d["autogenerate.slab.stonecuttingrecipe"] = "yes"
if values["genwall"] or values["genall"]:
d["autogenerate.wall"] = "yes"
d["autogenerate.wall.recipe"] = "yes"
d["autogenerate.wall.stonecuttingrecipe"] = "yes"
window.close()
writeDictFile(fname, d)
add_content(name, "block", d, mfd, fname)
return d
def CreateItem(mfd):
windowitems = [
[sg.Text('Item Name'), sg.Input(key="itemname")],
[sg.Text('Texture'), sg.Input(key="imgfile"),
sg.FileBrowse(key="imgfile", file_types=(("PNG Files", "*.png"), ("All Files", "*.* *")), initial_folder=os.path.join(mfd["project_path"], mfd["mod.textures"]))
],
[sg.Ok(size=EDITOR_BUTTON_SIZE_WIDE), sg.Cancel(size=EDITOR_BUTTON_SIZE_WIDE)],
]
window = sg.Window("Create New Item", windowitems, icon=ICON_FILE)
while True:
event, values = window.read()
if event in (sg.WINDOW_CLOSED, 'Cancel'):
window.close()
return None
elif event in ('Ok',):
itemtitle = values["itemname"]
if not len(values["imgfile"]):
ErrorWindow("Image file not specified.", parent=window)
continue
img = GetImageAsPNG(values["imgfile"], mfd)
if img is None:
continue
itemtitle, itemname, itemupper = ParseContentTitle(itemtitle)
if itemname in mfd["mod.registry.block.names"] or itemname in mfd["mod.registry.item.names"]:
ErrorWindow(f"Block/Item {itemname} already exists.", parent=window)
continue
mfd["mod.registry.item.names"].append(itemname)
mfd[f"mod.item.{itemname}.contentid"] = itemname
mfd[f"mod.item.{itemname}.title"] = itemtitle
mfd[f"mod.item.{itemname}.texture"] = texture = os.path.relpath(img, os.path.join(mfd["project_path"], mfd["mod.textures"]))
fname = os.path.join(mfd["project_path"], "items", itemname+".m3ec")
if os.path.exists(fname):
d = readDictFile(fname)
else:
d = {}
d["@"] = "item"
d["item"] = "SimpleItem"
d["contentid"] = itemname
d["title"] = itemtitle
d["texture"] = texture
mfd["mod.files"][f"item.{itemname}"] = fname
writeDictFile(fname, d)
window.close()
return d
def LoadProject(fname):
content_types_list = ["item", "food", "fuel", "block", "ore", "recipe", "armor", "tool", "armormaterial", "toolmaterial", "enchantment", "recipetype"]
if not os.path.exists(fname):
ErrorWindow(f"Manifest file/directory \"{fname}\" not found!")
return None
if os.path.isdir(fname):
project_path = fname
manifest_file = os.path.join(fname, "manifest.m3ec")
if not os.path.exists(manifest_file):
manifest_file = os.path.join(fname, "manifest.txt")
if not os.path.exists(manifest_file):
ErrorWindow(f"Manifest file (manifest.m3ec/manifest.txt) not found in \"{fname}\". Aborting.")
else:
project_path = os.path.dirname(fname)
manifest_file = fname
manifest_dict = readDictFile(manifest_file)
manifest_dict["manifest_file"] = manifest_file
manifest_dict["project_path"] = project_path
source_path = os.path.join(os.path.dirname(__file__), "data")
fname = os.path.join(source_path, "mc", "blocks.json")
if not os.path.exists(fname):
print(f"Warning: data file \"{fname}\" not found!")
else:
with open(fname) as f:
blocks = json.load(f)
manifest_dict["mc.names"] = blocks["names"]
for block in blocks["content"]:
blockid = block["name"]
for key in block.keys():
if key != blockid:
manifest_dict[f"mc.{blockid}.{key}"] = block[key]
if "mod.prefix" not in manifest_dict.keys():
manifest_dict["mod.prefix"] = "com"
if EnsureValueExistsWindow(manifest_dict, "mod.author", "Mod Author") is None:
return None
if EnsureValueExistsWindow(manifest_dict, "mod.title", "Mod Title") is None:
return None