forked from orphu/mcdungeon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeatures.py
2735 lines (2435 loc) · 102 KB
/
features.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
import sys
import inspect
import materials
import loottable
import items
import shop
from utils import *
import perlin
from pymclevel import nbt
class Blank(object):
_name = 'blank'
_is_stairwell = False
_is_secret = False
def __init__(self, parent):
self.parent = parent
def placed(self):
pass
def render(self):
pass
class Entrance(Blank):
_name = 'entrance'
def placed(self):
# Default height of the doors into the entrance.
self.height = self.parent.parent.room_height
self.high_height = self.parent.parent.room_height
self.low_height = self.parent.parent.room_height
# Height of the tower above entry.
self.u = self.parent.parent.room_height * 2
self.inwater = False
def render(self):
start = self.parent.loc.trans(6, self.parent.parent.room_height - 3, 6)
wstart = start.trans(-1, 0, -1)
# Clear air space
for p in iterate_cube(wstart,
wstart.trans(5, -self.height, 5)):
self.parent.parent.setblock(p, materials.Air)
# Walls
for p in iterate_four_walls(wstart,
wstart.trans(5, 0, 5),
self.height):
self.parent.parent.setblock(p, materials._wall)
# Lower level openings
# W side
for p in iterate_cube(wstart.trans(1, 0, 0), wstart.trans(4, -3, 0)):
self.parent.parent.setblock(p, materials.Air)
# E side
for p in iterate_cube(wstart.trans(1, 0, 5), wstart.trans(4, -3, 5)):
self.parent.parent.setblock(p, materials.Air)
# N side
for p in iterate_cube(wstart.trans(0, 0, 1), wstart.trans(0, -3, 4)):
self.parent.parent.setblock(p, materials.Air)
# S side
for p in iterate_cube(wstart.trans(5, 0, 1), wstart.trans(5, -3, 4)):
self.parent.parent.setblock(p, materials.Air)
# Draw the staircase
mat = materials.StoneSlab
for p in iterate_spiral(Vec(0, 0, 0),
Vec(4, 0, 4),
self.height * 2 + 2):
self.parent.parent.setblock(start.trans(p.x,
floor(float(p.y) / 2.0),
p.z),
mat, mat.data + (p.y % 2) * 8)
class Stairwell(Blank):
_name = 'stairwell'
_is_stairwell = True
def render(self):
if (sum_points_inside_flat_poly(*self.parent.canvas) > 0):
start = self.parent.loc.trans(
5,
self.parent.parent.room_height -
3,
5)
# Clear a stairwell
for x in iterate_cube(start.trans(0, 0, 1), start.trans(5, -5, 4)):
self.parent.parent.setblock(x, materials.Air)
mat = random.choice([
(materials.StoneStairs, materials.meta_mossycobble),
(materials.OakWoodStairs, materials.Wood),
(materials.StoneBrickStairs, materials.meta_stonedungeon)
])
# Draw the steps
for x in xrange(6):
for p in iterate_cube(start.trans(x, -x, 1),
start.trans(x, -x, 4)):
self.parent.parent.setblock(p,
mat[0])
self.parent.parent.setblock(p.trans(0, 1, 0),
mat[1])
class TripleStairs(Blank):
_name = 'triplestairs'
_is_stairwell = True
def render(self):
# create a shortcut to the set block fN
sb = self.parent.parent.setblock
center = self.parent.canvasCenter()
start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5)
start = start.trans(0, -6, 0)
# handrail
for x in iterate_four_walls(start.trans(-1, -1, -1), start.trans(6, -1, 6), 0):
sb(x, materials.IronBars, 0)
sb(start.trans(2, -1, -1), materials.Air, 0)
sb(start.trans(3, -1, -1), materials.Air, 0)
# add a random deco object at the top
decos = ((materials.Cauldron, 2),
(materials.Torch, 0),
(materials.FlowerPot, 10),
(materials.StoneDoubleSlab, 0),
(materials.Air, 0))
deco = random.choice(decos)
sb(start.trans(1, -1, 1), deco[0], deco[1])
sb(start.trans(4, -1, 1), deco[0], deco[1])
# using the following materials...
mats = [
(materials.Air, 0), # 0
(materials.StoneBrick, 0), # 1
(materials.StoneBrickStairs, 6), # 2 upside down ascending south
(materials.StoneBrickStairs, 0), # 3 ascending east
(materials.StoneBrickStairs, 1), # 4 ascending west
(materials.StoneBrickStairs, 3), # 5 ascending north
(materials.StoneBrickStairs, 7), # 6 upside down ascending north
(materials.Torch, 3) # 7
]
#...create the stairs
template = [
[[0, 3, 1, 1, 4, 0],
[0, 1, 5, 5, 1, 0],
[0, 7, 0, 0, 7, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[2, 2, 2, 2, 2, 2]],
[[1, 1, 1, 1, 1, 1],
[5, 6, 1, 1, 6, 5],
[0, 0, 5, 5, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 0, 1],
[5, 0, 1, 1, 0, 5],
[0, 0, 5, 5, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 0, 1],
[5, 0, 1, 1, 0, 5],
[0, 0, 5, 5, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[1, 1, 1, 1, 1, 1],
[1, 5, 1, 1, 5, 1],
[1, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 0, 1],
[5, 0, 1, 1, 0, 5],
[0, 0, 5, 5, 0, 0],
[0, 0, 0, 0, 0, 0]],
[[1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1],
[1, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 0, 1],
[1, 0, 1, 1, 0, 1],
[5, 0, 1, 1, 0, 5],
[0, 0, 5, 5, 0, 0]]
]
# place the stuff
for y in xrange(6):
for x in xrange(6):
for z in xrange(7):
sb(start.trans(x, y, z),
mats[template[y][z][x]][0],
mats[template[y][z][x]][1])
class TowerWithLadder(Blank):
_name = 'towerwithladder'
_is_stairwell = True
def render(self):
# create a shortcut to the set block fN
sb = self.parent.parent.setblock
center = self.parent.canvasCenter()
start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5)
start = start.trans(0, -6, 0)
mats = [
(materials.Air, 0), # 0
(materials.StoneBrick, 0), # 1
(materials.Ladder, 3), # 2 facing south
(materials.Ladder, 2), # 3 facing north
(materials.StoneBrickStairs, 6), # 4 upside down ascending south
(materials.StoneBrickStairs, 7), # 5 upside down ascending north
(materials.IronBars, 0) # 6
]
template = [
[0, 1, 1, 1, 1, 0],
[1, 0, 2, 2, 0, 1],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 1],
[0, 1, 6, 6, 1, 0]]
top = [
[0, 1, 1, 1, 1, 0],
[1, 0, 2, 2, 0, 1],
[5, 0, 0, 0, 0, 5],
[4, 0, 0, 0, 0, 4],
[1, 0, 0, 0, 0, 1],
[0, 1, 1, 1, 1, 0]]
# place the stuff
for y in xrange(2):
for x in xrange(6):
for z in xrange(6):
sb(start.trans(x, y * 6 - 1, z),
mats[template[z][x]][0],
mats[template[z][x]][1])
sb(start.trans(x, y * 6 - 2, z),
mats[template[z][x]][0],
mats[template[z][x]][1])
sb(start.trans(x, y * 6 - 3, z),
mats[top[z][x]][0],
mats[top[z][x]][1])
# finish ladder
for x in iterate_cube(start.trans(2, 0, 1), start.trans(3, 2, 1)):
sb(x, materials.Ladder, 3)
class Scaffolding(Blank):
_name = 'scaffolding'
_is_stairwell = True
def render(self):
# create a shortcut to the set block fN
sb = self.parent.parent.setblock
start = self.parent.loc.trans(5, self.parent.parent.room_height - 2, 5)
start = start.trans(0, -7, 0)
mats = [
(materials.Air, 0), # 0
(materials.Fence, 0), # 1
(materials.OakWoodSlab, 0), # 2
(materials.OakWoodStairs, 0), # 3 Acending East
(materials.OakWoodStairs, 3) # 4 Ascending North
]
template = [
[[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1]],
[[0, 0, 0, 0, 2, 2],
[0, 0, 0, 0, 2, 2],
[0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1]],
[[0, 0, 0, 3, 1, 1],
[0, 0, 0, 3, 1, 1],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1]],
[[2, 2, 3, 1, 1, 1],
[2, 2, 3, 1, 1, 1],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1]],
[[1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 0, 0],
[4, 4, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1]],
[[1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 0, 0, 0, 0],
[4, 4, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1]],
[[1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 0, 0],
[1, 1, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0],
[4, 4, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1]],
]
# place the stuff
for y in xrange(7):
for x in xrange(6):
for z in xrange(6):
sb(start.trans(x, y, z),
mats[template[y][z][x]][0],
mats[template[y][z][x]][1])
class Chasm(Blank):
_name = 'chasm'
material = materials.Air
depth = 2
def render(self):
if (self.parent.canvasWidth() < 4 or
self.parent.canvasLength() < 4):
return
# We'll render across the whole block, since that will look cool
y = self.parent.canvasHeight()
flip = random.randint(0, 1)
for x in xrange(2, self.parent.parent.room_size * self.parent.size.x - 2):
if (flip == 1):
for p in iterate_cube(self.parent.loc +
Vec(self.parent.parent.room_size * self.parent.size.x - x - 1,
y,
x + random.randint(-1, 0)),
self.parent.loc +
Vec(self.parent.parent.room_size * self.parent.size.x - x - 1,
y + self.depth,
x + random.randint(1, 2))
):
self.parent.parent.setblock(p, self.material)
else:
for p in iterate_cube(self.parent.loc +
Vec(x,
y,
x + random.randint(-1, 0)),
self.parent.loc +
Vec(x,
y + self.depth,
x + random.randint(1, 2))
):
self.parent.parent.setblock(p, self.material)
class LavaChasm(Chasm):
_name = 'lavachasm'
material = materials.Lava
depth = 0
class River(Chasm):
_name = 'river'
material = materials.Water
depth = 0
class Columns(Blank):
_name = 'columns'
mats = (
materials.Stone,
materials.Wood,
materials.Spruce,
materials.Jungle,
materials.Acacia,
materials.DarkOak,
materials.ChiseledSandstone,
materials.SmoothSandstone,
materials.ChiseledRedSandstone,
materials.SmoothRedSandstone,
materials.StoneDoubleSlab,
materials.Obsidian,
materials.StoneBrick,
materials.meta_mossycobblewall,
materials.meta_mossystonebrick,
materials.meta_stonedungeon,
materials.IronBars,
materials.Fence,
materials.NetherBrick,
materials.NetherBrickFence,
materials.Glowstone,
materials.Prismarine,
materials.PrismarineBricks,
materials.DarkPrismarine
)
def render(self):
limit = int(min(self.parent.canvasWidth(), self.parent.canvasLength()))
if (limit < 6):
return
c = self.parent.canvasCenter()
height = self.parent.canvasHeight() - 1
start = random.randint(0, limit / 2 - 1)
stop = limit / 2
step = random.randint(2, 3)
mat = random.choice(self.mats)
for x in xrange(start, stop, step):
for p in iterate_cube(Vec(c.x - x, 1, c.z - x),
Vec(c.x - x, height, c.z - x)):
self.parent.parent.setblock(self.parent.loc + p, mat)
for p in iterate_cube(Vec(c.x + x + 1, 1, c.z - x),
Vec(c.x + x + 1, height, c.z - x)):
self.parent.parent.setblock(self.parent.loc + p, mat)
for p in iterate_cube(Vec(c.x - x, 1, c.z + x + 1),
Vec(c.x - x, height, c.z + x + 1)):
self.parent.parent.setblock(self.parent.loc + p, mat)
for p in iterate_cube(Vec(c.x + x + 1, 1, c.z + x + 1),
Vec(c.x + x + 1, height, c.z + x + 1)):
self.parent.parent.setblock(self.parent.loc + p, mat)
class Arcane(Blank):
_name = 'arcane'
def render(self):
if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8):
return
# Custom block placer. Don't place stuff where things already exist,
# also check for things we aren't alowed to place stuff on.
dun = self.parent.parent
def sb(p, mat):
if (p in dun.blocks and
dun.blocks[p].material == materials.Air and
dun.blocks[p.down(1)].material != materials.Farmland and
dun.blocks[p.down(1)].material != materials.SoulSand and
dun.blocks[p.down(1)].material != materials.Water and
dun.blocks[p.down(1)].material != materials.Lava and
dun.blocks[p.down(1)].material != materials.CobblestoneSlab and
dun.blocks[p.down(1)].material != materials.StillWater):
dun.setblock(p, mat)
mode = random.choice(['one', 'boxes', 'conc'])
if mode == 'boxes':
center = self.parent.canvasCenter()
o = self.parent.loc + Vec(center.x,
self.parent.canvasHeight() - 1,
center.z)
o = o + Vec(-self.parent.canvasWidth() / 2,
0,
-self.parent.canvasLength() / 2)
for x in xrange(self.parent.canvasWidth() / 3 + 1):
for z in xrange(self.parent.canvasLength() / 3 + 1):
if random.random() < 0.5:
q = Vec(o.x + x * 3, o.y, o.z + z * 3)
sb(q, materials.RedstoneWire)
sb(q.trans(1, 0, 0), materials.RedstoneWire)
sb(q.trans(0, 0, 1), materials.RedstoneWire)
sb(q.trans(1, 0, 1), materials.RedstoneWire)
return
if mode == 'conc':
center = self.parent.canvasCenter()
c = self.parent.loc + Vec(center.x,
self.parent.canvasHeight() - 1,
center.z)
sb(c, materials.RedstoneWire)
for p in iterate_ellipse(c.trans(-2, 0, -2), c.trans(2, 0, 2)):
sb(p, materials.RedstoneWire)
for p in iterate_ellipse(c.trans(-4, 0, -4), c.trans(4, 0, 4)):
sb(p, materials.RedstoneWire)
return
center = self.parent.canvasCenter()
c = self.parent.loc + Vec(center.x,
self.parent.canvasHeight() - 1,
center.z)
for p in iterate_cube(c.n(4), c.s(4)):
sb(p, materials.RedstoneWire)
for p in iterate_cube(c.e(4), c.w(4)):
sb(p, materials.RedstoneWire)
for p in iterate_four_walls(c.trans(-2, 0, -2), c.trans(2, 0, 2), 0):
sb(p, materials.RedstoneWire)
class Mushrooms(Blank):
_name = 'mushrooms'
def render(self):
if (self.parent.canvasWidth() < 2 or self.parent.canvasLength() < 2):
return
# Custom block placer. Don't place stuff where things already exist,
# also check for things we aren't alowed to place stuff on.
# Picks red or brown mushrooms randomly if no material is supplied.
dun = self.parent.parent
def sb(p, mat=''):
if (p in dun.blocks and
dun.blocks[p].material == materials.Air and
dun.blocks[p.down(1)].material != materials.Farmland and
dun.blocks[p.down(1)].material != materials.SoulSand and
dun.blocks[p.down(1)].material != materials.Water and
dun.blocks[p.down(1)].material != materials.StillWater):
if mat == '':
mat = random.choice([materials.RedMushroom,
materials.BrownMushroom,
materials.Air])
dun.setblock(p, mat)
mode = random.choice(['perlin', 'fairyring'])
if mode == 'perlin':
pn = perlin.SimplexNoise(256)
r = random.randint(1, 1000)
for p in iterate_points_inside_flat_poly(*self.parent.canvas):
if (pn.noise3(p.x / 4.0, r / 4.0, p.z / 4.0) > .8):
q = p + self.parent.loc
sb(q.trans(1, -1, 0))
sb(q.trans(-1, -1, 0))
sb(q.trans(0, -1, -1))
sb(q.trans(0, -1, 1))
return
if mode == 'fairyring':
center = self.parent.canvasCenter()
c = self.parent.loc + Vec(center.x,
self.parent.canvasHeight() - 1,
center.z)
radius = random.randint(2, 5)
for p in iterate_ellipse(c.trans(-radius, 0, -radius),
c.trans(radius, 0, radius)):
sb(p)
return
class MessHall(Blank):
_name = 'messhall'
def render(self):
if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8):
return
sb = self.parent.parent.setblock
# Draw tables. cram several in the room if it is large enough.
for x in xrange(self.parent.size.x):
for z in xrange(self.parent.size.z):
rp = self.parent.pos + Vec(x, 0, z)
if (self.parent.parent.rooms[rp].features[0]._is_stairwell is False and
self.parent.parent.rooms[rp].features[0]._name is not 'blank'):
p = self.parent.loc + Vec(
x * self.parent.parent.room_size,
self.parent.canvasHeight() - 1,
z * self.parent.parent.room_size)
for q in iterate_cube(p + Vec(5, 0, 7), p + Vec(10, 0, 8)):
sb(q, materials.Fence)
sb(q.up(1), materials.WoodenPressurePlate)
# Seating
q = p + Vec(5, 0, 6)
o = random.randint(0, 1)
while o <= 5:
sb(q.e(o), materials.OakWoodStairs, 3)
o += random.randint(2, 3)
q = p + Vec(5, 0, 9)
o = random.randint(0, 1)
while o <= 5:
sb(q.e(o), materials.OakWoodStairs, 2)
o += random.randint(2, 3)
# If the room is 1x1, stop here.
if (self.parent.size.x < 2 and self.parent.size.z < 2):
return
# Draw a fire pit in the middle
center = self.parent.canvasCenter()
size = 2
p0 = Vec(center.x - size / 2 + 1,
self.parent.canvasHeight(),
center.z - size / 2 + 1) + self.parent.loc
p1 = p0.trans(size - 1, 0, size - 1)
for p in iterate_disc(p0 + Vec(-2, 0, -2), p1 + Vec(2, 0, 2)):
sb(p, materials._floor)
sb(p.up(1), materials.IronBars)
for p in iterate_disc(p0, p1):
sb(p, materials.Netherrack)
sb(p.up(1), materials.Fire)
class Dais(Blank):
_name = 'dais'
def render(self):
if (self.parent.canvasWidth() < 8 or self.parent.canvasLength() < 8):
return
center = self.parent.canvasCenter()
size = random.randint(4,
min(self.parent.canvasWidth(),
self.parent.canvasLength()) - 4)
torches = (random.random() < .5)
platform = random.choice([materials.meta_mossycobble,
materials.meta_mossystonebrick,
materials.meta_stonedungeon,
materials.Stone,
materials.StoneBrick])
steps = random.choice([materials.CobblestoneSlab,
materials.StoneSlab,
materials.StoneBrickSlab])
pfunc = iterate_cube
sfunc = iterate_four_walls
if (random.random() < .5):
pfunc = iterate_disc
sfunc = iterate_tube
p0 = Vec(center.x - size / 2 + 1,
self.parent.canvasHeight(),
center.z - size / 2 + 1) + self.parent.loc
p1 = p0.trans(size - 1, 0, size - 1)
if torches:
for p in (Vec(p0.x + 1, p0.y - 1, p0.z + 1), Vec(p1.x - 1, p0.y - 1, p1.z - 1),
Vec(p0.x + 1, p0.y - 1, p1.z - 1), Vec(p1.x - 1, p0.y - 1, p0.z + 1)):
self.parent.parent.setblock(p, materials.Fence)
self.parent.parent.setblock(p.up(1), materials.Fence)
self.parent.parent.setblock(p.up(2), materials.Torch)
for p in pfunc(p0, p1):
self.parent.parent.setblock(p.up(1), platform)
for p in sfunc(p0, p1, 0):
if self.parent.parent.blocks[p.up(2)].material != materials.Fence:
self.parent.parent.setblock(p.up(1), steps)
class SecretRoom(Blank):
_name = 'secretroom'
_is_secret = True
def placed(self):
self.parent._pistontrap = False
def renderSecretPost(self):
pass
def render(self):
sb = self.parent.parent.setblock
# Reform the basic room shape.
for p in iterate_cube(self.parent.loc,
self.parent.loc + Vec(self.parent.parent.room_size - 1,
self.parent.parent.room_height - 2,
self.parent.parent.room_size - 1)):
# Remove all blocks.
sb(p, None)
# Clear out any doors or extra torches.
if p in self.parent.parent.doors:
del(self.parent.parent.doors[p])
if p in self.parent.parent.torches:
del(self.parent.parent.torches[p])
self.c1 = self.parent.loc + Vec(3,
self.parent.parent.room_height - 2,
3)
self.c3 = self.parent.loc + Vec(self.parent.parent.room_size - 4,
self.parent.parent.room_height - 2,
self.parent.parent.room_size - 4)
for q in iterate_cube(self.c1.up(1), self.c3.up(3)):
sb(q, materials.Air)
for q in iterate_cube(self.c1.up(4), self.c3.up(4)):
sb(q, materials._ceiling)
for q in iterate_cube(self.c1, self.c3):
sb(q, materials._floor)
for q in iterate_four_walls(self.c1, self.c3, self.parent.parent.room_height - 2):
sb(q, materials._wall)
# Fix the hallway and create the secret door mechansm.
# Find the direction, room, and connecting room.
# room = this room
# d = direction out of this room
# offset = offset of the hallways
# oroom = connecting room
# od = direction out of the connecting room
# length = legth of the opposite hall
o = self.parent.loc.trans(2, 0, 2)
# hall positions to grid direction
dirs = {3: Vec(-1, 0, 0),
1: Vec(1, 0, 0),
2: Vec(0, 0, 1),
0: Vec(0, 0, -1)}
room = self.parent
d = 0
for x in xrange(4):
if room.halls[x]._name != 'blank':
d = x
offset = room.halls[d].offset
oroom = self.parent.parent.rooms[room.pos + dirs[d]]
od = (d + 2) % 4
length = oroom.hallLength[od] - 2
# Save d for any inherited secret rooms.
self.direction = d
# Figure our our deltas. There are 8 possibilities based on direction
# and offset. Offset will basically mirror across width.
# dw = delta width
# dl = delta length
# spos = start pos for the mechanism
# d = 0 (West)
if d == 0:
dw = Vec(1, 0, 0)
dl = Vec(0, 0, -1)
spos = o.trans(offset, 0, 0)
# d = 1 (South)
elif d == 1:
dw = Vec(0, 0, 1)
dl = Vec(1, 0, 0)
spos = o.trans(11, 0, offset)
# d = 2 (East)
elif d == 2:
dw = Vec(1, 0, 0)
dl = Vec(0, 0, 1)
spos = o.trans(offset, 0, 11)
# d = 3 (North)
else:
dw = Vec(0, 0, 1)
dl = Vec(-1, 0, 0)
spos = o.trans(0, 0, offset)
if offset >= 7:
dw = dw * -1
if (d == 0 or d == 2):
spos = spos.trans(-2, 0, 0)
elif (d == 1 or d == 3):
spos = spos.trans(0, 0, -2)
# Position the start block for the mechanism
spos = spos + dl * length - dw * 2
if self.parent.parent.args.debug:
print
print 'room:', room.pos
print 'dir:', d
print 'offset:', offset
print 'dl:', dl
print 'dw:', dw
print
mats = [
[materials.Air, 0], # 0 (ignore these)
[materials.Air, 0], # 1
[materials._wall, 0], # 2
[materials.Stone, 0], # 3
[materials._wall, 0], # 4
[materials.RedstoneWire, 0], # 5
[materials.StickyPiston, 3], # 6 - toggle piston
[materials.RedstoneTorchOn, 2], # 7
[materials._ceiling, 0], # 8
[materials.StickyPiston, 4], # 9 - pusher piston
[materials.RedstoneRepeaterOff, 3], # 10 - piston repeater
[materials.RedstoneRepeaterOff, 7], # 11 - toggle repeater
[materials.Torch, 0], # 12
[materials._secret_door, 0], # 13
[materials._floor, 0], # 14
[materials._subfloor, 0] # 15
]
template = [
[[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8]],
[[2, 4, 4, 4, 4],
[1, 1, 1, 12, 4],
[2, 4, 4, 4, 4],
[2, 1, 1, 1, 4],
[2, 1, 1, 1, 4],
[2, 1, 1, 1, 4]],
[[2, 4, 4, 4, 4],
[1, 7, 1, 1, 13],
[2, 4, 6, 1, 4],
[2, 11, 9, 9, 4],
[2, 5, 10, 10, 4],
[2, 5, 5, 5, 4]],
[[2, 4, 4, 4, 4],
[1, 1, 1, 1, 13],
[2, 4, 6, 1, 4],
[2, 3, 9, 9, 4],
[2, 3, 3, 3, 4],
[2, 3, 3, 3, 4]],
[[14, 14, 14, 14, 14],
[14, 14, 14, 14, 14],
[14, 14, 14, 14, 14],
[14, 14, 14, 14, 14],
[14, 14, 14, 14, 14],
[14, 14, 14, 14, 14]],
[[15, 15, 15, 15, 15],
[15, 15, 15, 15, 15],
[15, 15, 15, 15, 15],
[15, 15, 15, 15, 15],
[15, 15, 15, 15, 15],
[15, 15, 15, 15, 15]],
]
bdata = 3
# Data adjustments for directions. There are 8, but the defaults are
# for East, low offset.
# West
if d == 0:
bdata = 4
if offset >= 7:
mats[6][1] = 2
mats[7][1] = 1
mats[9][1] = 5
mats[10][1] = 1
mats[11][1] = 5
else:
mats[6][1] = 2
# South
if d == 1:
bdata = 1
if offset >= 7:
mats[6][1] = 5
mats[7][1] = 3
mats[9][1] = 3
mats[10][1] = 2
mats[11][1] = 6
else:
mats[6][1] = 5
mats[7][1] = 4
mats[9][1] = 2
mats[10][1] = 0
mats[11][1] = 4
# East, flipped
if (d == 2 and offset >= 7):
# flip the pusher piston
mats[7][1] = 1
mats[9][1] = 5
mats[10][1] = 1
mats[11][1] = 5
# North
if d == 3:
bdata = 2
if offset >= 7:
mats[6][1] = 4
mats[7][1] = 3
mats[9][1] = 3
mats[10][1] = 2
mats[11][1] = 6
else:
mats[6][1] = 4
mats[7][1] = 4
mats[9][1] = 2
mats[10][1] = 0
mats[11][1] = 4
# Draw the mechanism
for y in xrange(6):
for w in xrange(6):
for l in xrange(5):
p = spos + dl * l + dw * w + Vec(0, 1, 0) * y
sb(p, mats[template[y][w][l]][0],
mats[template[y][w][l]][1])
# The button.
p = spos + dl * 3 + dw * 5 + Vec(0, 1, 0) * 2
blocks = self.parent.parent.blocks
while blocks[p + dl].material != materials.Air:
sb(p.up(1), materials.Air)
sb(p, materials.RedstoneWire)
sb(p.down(1), materials.Stone)
p = p + dl
sb(p + dl, materials.StoneButton, bdata)
# Extend the hallway into the room.
o = spos + dw
p = o - dl * (length + 1) + Vec(0, 4, 0)
for q in iterate_cube(o, p):
sb(q - dw, materials._wall, lock=True)
if q.y == o.y:
sb(q, materials._ceiling)
elif q.y == p.y:
sb(q, materials._floor)
else:
sb(q, materials.Air, lock=True)
sb(q - dl, materials.Air, lock=True)
sb(q + dw, materials._wall, lock=True)
# Clear out any additional doors or extra torches in the hall.
for q in iterate_cube(o + dw * 2 + dl * 5, p - dw - dl):
if q in self.parent.parent.doors:
del(self.parent.parent.doors[q])
if q in self.parent.parent.torches:
del(self.parent.parent.torches[q])
# Kill the canvas to prevent spawners and chests from appearing
self.parent.canvas = (
Vec(0, 0, 0),
Vec(0, 0, 0),
Vec(0, 0, 0))
# Call the room post-renderer.
self.renderSecretPost()
class SecretStudy(SecretRoom):
_name = 'secretstudy'
def renderSecretPost(self):
sb = self.parent.parent.setblock
blocks = self.parent.parent.blocks
# Bookshelves
for p in iterate_four_walls(Vec(1, -1, 1), Vec(8, -1, 8), 2):
if (p.x not in (3, 6) and
p.z not in (3, 6)):
sb(self.c1 + p, materials.Bookshelf)
else:
sb(self.c1 + p, materials.Air)
# Framed study stuff
loot = weighted_choice((("clock", 4),
("written book", 1),
("custom painting", 1)))
sb(self.c1 + Vec(2, -3, 1), materials._wall)
self.parent.parent.addentity(
get_entity_other_tags("ItemFrame",
Pos=self.c1 + Vec(2, -3, 1),
Direction="S",
ItemTags=self.parent.parent.inventory.buildFrameItemTag(loot)
)
)
# Lighting
for p in (Vec(2, -1, 2), Vec(2, -1, 7),
Vec(7, -1, 2), Vec(7, -1, 7)):
sb(self.c1 + p, materials.Fence)
sb(self.c1 + p.up(1), materials.Torch, 5)
# Desk
mats = [
(materials.Air, 0), # 0
(materials.OakWoodStairs, 7), # 1
(materials.Chest, 0), # 2
(materials.CraftingTable, 0), # 3
(materials.WallSign, 0), # 4
(materials.OakWoodStairs, 0), # 5
(materials.OakWoodStairs, 6), # 6
]
template = [
[3, 1, 6, 2],
[0, 4, 5, 4]
]
oo = self.c1.trans(4, -1, 3)
for x in xrange(2):
for z in xrange(4):
p = oo.trans(x, 0, z)
sb(p,
mats[template[x][z]][0],
mats[template[x][z]][1])
self.parent.parent.blocks[self.c1 + Vec(5, -1, 4)].data = 2
self.parent.parent.blocks[self.c1 + Vec(5, -1, 5)].data = 0
self.parent.parent.blocks[self.c1 + Vec(5, -1, 6)].data = 3
if (random.random() < 0.1):
sb(self.c1.trans(4, -2, 4), materials.Cake, random.randrange(0, 6))
elif (random.random() < 0.4):
sb(self.c1.trans(4, -2, 4),
materials.FlowerPot, random.randrange(1, 12))
else:
sb(self.c1.trans(4, -2, 4), materials.Torch)