-
Notifications
You must be signed in to change notification settings - Fork 0
/
GDMCSubmission.py
1574 lines (1423 loc) · 81.2 KB
/
GDMCSubmission.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
# Although there are three options that can be changed in the MCEdit GUI, I strongly recommend keeping them at their default values
import random
from numpy import zeros
import itertools
from pymclevel import alphaMaterials, TAG_Int, TAG_String, TAG_List, TAG_Compound, TileEntity
from pymclevel.level import extractHeights
from pymclevel import level, MCSchematic, BoundingBox, TileEntity
from mcInterface import MCLevelAdapter
import numpy as np
import math
from PIL import Image
from pymclevel.box import Vector
from datetime import datetime
am = alphaMaterials
# Naturally occuring materials
blocks = [
am.Grass,
am.Dirt,
am.Stone,
am.Bedrock,
am.Sand,
am.Gravel,
am.GoldOre,
am.IronOre,
am.CoalOre,
am.LapisLazuliOre,
am.DiamondOre,
am.RedstoneOre,
am.RedstoneOreGlowing,
am.Netherrack,
am.SoulSand,
am.Clay,
am.Glowstone,
am.Water,
am.WaterActive,
am.HardenedClay,
am[159, 0], # The different colored Terracotta blocks
am[159, 1],
am[159, 4],
am[159, 8],
am[159, 12],
am[159, 14],
am[12, 1] # Red sand
]
blocktypes = [b.ID for b in blocks]
def naturalBlockmask():
blockmask = zeros((256,), dtype='bool')
blockmask[blocktypes] = True
return blockmask
# Naturally occuring materials without water
blocksWithoutWater = [
am.Grass,
am.Dirt,
am.Stone,
am.Bedrock,
am.Sand,
am.Gravel,
am.GoldOre,
am.IronOre,
am.CoalOre,
am.LapisLazuliOre,
am.DiamondOre,
am.RedstoneOre,
am.RedstoneOreGlowing,
am.Netherrack,
am.SoulSand,
am.Clay,
am.Glowstone,
am.StainedClay,
am.HardenedClay,
am[159, 0], # The different colored Terracotta blocks
am[159, 1],
am[159, 4],
am[159, 8],
am[159, 12],
am[159, 14],
am[12, 1] # Red sand
]
blocktypesWithoutWater = [b.ID for b in blocksWithoutWater]
def naturalBlockmaskWithoutWater():
blockmask = zeros((256,), dtype='bool')
blockmask[blocktypesWithoutWater] = True
return blockmask
syllables = [
"ba",
"be",
"bi",
"bo",
"bu",
"ca",
"ce",
"ci",
"co",
"cu",
"da",
"de",
"di",
"do",
"du",
"du",
"fe",
"fi",
"fo",
"ba",
"be",
"bi",
"bo",
"bu",
"ca",
"ce",
"ci",
"co",
"cu",
"da",
"de",
"di",
"do",
"du",
"fa",
"fe",
"fi",
"fo",
"fu",
"ga",
"ge",
"gi",
"go",
"gu",
"ha",
"he",
"hi",
"ho",
"hu",
"ja",
"je",
"ji",
"jo",
"ju",
"ka",
"ke",
"ki",
"ko",
"ku",
"la",
"le",
"li",
"lo",
"lu",
"ma",
"me",
"mi",
"mo",
"mu",
"na",
"ne",
"ni",
"no",
"nu",
"pa",
"pe",
"pi",
"po",
"pu",
"qa",
"qe",
"qi",
"qo",
"qu",
"ra",
"re",
"ri",
"ro",
"ru",
"sa",
"se",
"si",
"so",
"su",
"ta",
"te",
"ti",
"to",
"tu",
"va",
"ve",
"vi",
"vo",
"vu",
"wa",
"we",
"wi",
"wo",
"wu",
"xa",
"xe",
"xi",
"xo",
"xu",
"ya",
"ye",
"yi",
"yo",
"yu",
"za",
"ze",
"zi",
"zo",
"zu"
]
def getName():
output = ""
for i in xrange(3):
output += syllables[random.randint(0, len(syllables)-1)]
return output.capitalize()
def crestPatternGenerator(name):
seed = 0
for i in xrange(len(name)):
seed += math.pow(ord(name[i]), i+1)
random.seed(seed)
pattern = []
for i in xrange(3):
pattern.append([])
for j in xrange(2):
pattern[i].append(random.randint(0, 15))
random.seed(datetime.now())
return pattern
class Person:
def __init__(self, family, generation, firstName, parent1=None, parent2=None, lastName=None):
self.family = family
self.generation = generation
self.spouse = None
self.children = []
self.parent1 = parent1
self.parent2 = parent2
self.firstName = firstName
if lastName:
self.lastName = lastName
else:
self.lastName = parent1.lastName
def __str__(self):
output = ""
output += self.firstName + " " + self.lastName
return output
def getParents(self):
output = "Parent 1: "
output += "Unknown" if (self.parent1 == None) else str(self.parent1)
output += ", Parent 2: "
output += "Unknown" if (self.parent2 == None) else str(self.parent2)
return output
def marry(self, otherPerson):
# Both people become eachothers spouses
self.spouse = otherPerson
otherPerson.spouse = self
# The person who gets asked takes the last name of the person who asks
otherPerson.lastName = self.lastName
# The person who got asked gets removed from their old familt and added to the family of the person who asked them
otherPerson.family.members[otherPerson.generation].remove(otherPerson)
otherPerson.family = self.family
self.family.members[otherPerson.generation].append(otherPerson)
class Family:
def __init__(self, generations, manualGenerations=False):
self.lastName = getName()
self.members = []
if not manualGenerations:
for i in xrange(generations):
self.members.append([])
for j in xrange(int(math.pow(2, i))):
parent = self.members[i-1][random.randint(0, len(self.members[i-1])-1)] if i > 0 else None
self.members[i].append(Person(self, i, getName(), parent1=parent, parent2=None, lastName=self.lastName))
else:
self.members.append([])
self.members[0].append(Person(self, 0, getName(), None, None, lastName=self.lastName))
self.members[0].append(Person(self, 0, getName(), None, None, lastName=self.lastName))
def getCurrentGeneration(self):
output = " --- The " + str(self.lastName) + " Family --- \n"
for j in xrange(len(self.members[len(self.members)-1])):
output += str(self.members[len(self.members)-1][j]) + ", " + self.members[len(self.members)-1][j].getParents() + ", Spouse: " + str(self.members[len(self.members)-1][j].spouse) + "\n"
return output
def getCurrentGenerationCount(self):
return len(self.members[len(self.members)-1])
def __str__(self):
output = " --- The " + str(self.lastName) + " Family --- \n"
for i in xrange(len(self.members)):
output += " - Generation " + str(i) + " - \n"
for j in xrange(len(self.members[i])):
output += str(self.members[i][j]) + ", " + self.members[i][j].getParents() + ", Spouse: " + str(self.members[i][j].spouse) + "\n"
return output
class Settlement:
def __init__(self, families, generations):
# Create the number of families specified
self.families = []
for i in xrange(families):
self.families.append(Family(generations, True))
# Simulate the number of generations specified
for g in xrange(generations):
# Get the size of the family that is the biggest at the current generation
biggestFamilySize = 0
for i in xrange(len(self.families)):
biggestFamilySize = max(biggestFamilySize, len(self.families[i].members[g]))
# For the ith person in each family
for i in xrange(biggestFamilySize):
# For family j
for j in xrange(len(self.families)):
# Until they get rejected 10 times
rejectCount = 10
while len(self.families[j].members[g]) > i and self.families[j].members[g][i].spouse == None and rejectCount > 0:
# Pick a random family (and keep picking until you pick one that still has people in it)
spouseFamilyIndex = random.randint(0, len(self.families)-1)
while len(self.families[spouseFamilyIndex].members[g]) < 1:
spouseFamilyIndex = random.randint(0, len(self.families)-1)
# If that family has more than one member
if len(self.families[spouseFamilyIndex].members[g]) > 1:
# Pick a random member of that family
spouseIndex = random.randint(0, len(self.families[spouseFamilyIndex].members[g])-1)
# If their family isn't yours and they are single
if spouseFamilyIndex != j and self.families[spouseFamilyIndex].members[g][spouseIndex].spouse == None:
# Get married to that person
self.families[j].members[g][i].marry(self.families[spouseFamilyIndex].members[g][spouseIndex])
else:
# Otherwise, get rejected
rejectCount -= 1
# If the family that you picked only has one person
elif len(self.families[spouseFamilyIndex].members[g]) == 1:
# If the family isn't yours
if spouseFamilyIndex != j and self.families[spouseFamilyIndex].members[g][0].spouse == None:
# Marry that person
self.families[j].members[g][i].marry(self.families[spouseFamilyIndex].members[g][0])
else:
# Otherwise, get rejected
rejectCount -= 1
# For every family, make a space for the new generation
for i in xrange(len(self.families)):
self.families[i].members.append([])
# For every member of the current generation
for j in xrange(len(self.families[i].members[g])):
# If you currently have a spouse and no children
if self.families[i].members[g][j].spouse != None and len(self.families[i].members[g][j].children) == 0:
# Have between 1 and 3 children
for k in xrange(random.randint(1,3)):
child = Person(self.families[i], len(self.families[i].members)-1, getName(), self.families[i].members[g][j], self.families[i].members[g][j].spouse)
self.families[i].members[len(self.families[i].members)-1].append(child)
# And make sure that it is registered as a child for both parents
self.families[i].members[g][j].children.append(child)
self.families[i].members[g][j].spouse.children.append(child)
def getCurrentGeneration(self):
output = ""
currentGenCount = 0
for i in xrange(len(self.families)):
output += "\n"
output += self.families[i].getCurrentGeneration()
currentGenCount += self.families[i].getCurrentGenerationCount()
output += "Total Population: " + str(currentGenCount)
return output
def __str__(self):
output = ""
for i in xrange(len(self.families)):
output += "\n"
output += str(self.families[i])
return output
# A bunch of constants in arrays used to convert minecrafts different ways of representing direction into a usable standard
doorOffsetX = [1, 0, -1, 0]
doorOffsetZ = [0, -1, 0, 1]
doorOrientation = [3, 0, 1, 2]
turnCountToBannerRotation = [5, 2, 4, 3]
upsideDownStairDirection = [6, 4, 7, 5]
trapdoorLadderDirections = [[5, 6], [2, 5], [4, 7], [3, 4]]
ladderDirections = [[2, 2], [3, 3], [4, 4], [5, 5], [2, 3], [3, 2], [4, 5], [5, 4]]
# A collection of all of the offsets for the streetlights from a given path coordinate
streetLightOffsets = [[[[2,-2],[-2,2]], [[0,-2],[0,2]], [[-2,-2],[2,2]]], [[[-2,0],[2,0]], [[0,0],[0,0]], [[-2,0],[2,0]]], [[[-2,-2],[2,2]], [[0,-2],[0,2]], [[2,-2],[-2,2]]]]
# The possible actions that the AStar pathfinding can take
actions = [[1, 1], [-1, -1], [1, -1], [-1, 1], [0, 1], [0, -1], [1, 0], [-1, 0]]
# AStar node class
class Node:
def __init__(self, x, z, parent, action, g, h):
self.x = x
self.z = z
self.action = action
self.parent = parent
self.g = g
self.h = h
# A 2D vector class mostly used in the Poisson Disc Distribution algorithm
class Vec2:
def __init__(self, x, y, isFromUniqueStructure=False):
self.isFromUniqueStructure = isFromUniqueStructure
self.x = x
self.y = y
def multiply(self, m):
self.x = self.x * m
self.y = self.y * m
def add(self, a):
self.x = self.x + a.x
self.y = self.y + a.y
# The inputs that can be entered in the MCEdit GUI and their defaults
inputs = (
("Cristopher Yates", "label"),
("Poisson Distribution", "label"),
("Radius: ", 28),
("Families: ", 48),
("Generations: ", 3),
)
chunks = None
boundingBox = None
chunks = []
def perform(level, box, options):
print("X: " + str(box.maxx - box.minx) + ", Z: " + str(box.maxz - box.minz))
# If the selected area is too big
tooBig = False
center = None
initialBox = None
offsetsForPathToSettlement = Vec2(0, 0)
if (box.maxx - box.minx) > 256 or (box.maxz - box.minz) > 256:
print("Too big!")
tooBig = True
# Pick a location to build the settlement
halfXSize = (box.maxx - box.minx)/2
halfZSize = (box.maxz - box.minz)/2
print("Half X: " + str(halfXSize) + ", Half Z: " + str(halfZSize))
center = [halfXSize + box.minx, halfZSize + box.minz]
settlementPlacementOffset = Vec2(box.minx, box.maxz-256)
if ((box.maxx - box.minx) > 512):
offsetsForPathToSettlement.x = random.randint(0, (box.maxx - box.minx)/2 - 245)
settlementPlacementOffset.x += offsetsForPathToSettlement.x
if ((box.maxz - box.minz) > 512):
offsetsForPathToSettlement.y = random.randint(0, (box.maxz - box.minz)/2 - 256)
settlementPlacementOffset.y -= offsetsForPathToSettlement.y
# Place the settlement at the chosen location
initialBox = box
box = BoundingBox((settlementPlacementOffset.x, box.miny, settlementPlacementOffset.y), (256, box.maxy, 256))
# Generate the families for the settlement
settlement = Settlement(options["Families: "], options["Generations: "])
print("Calculating HeightMap...")
horizontalHeightmapParts = []
horizontalHeightmapPartsWithoutWater = []
# All of the code between these two "lines" is adapted slightly / comes from the built in MCEdit filter: topsoil.py
##############################################################################
#compute a truth table that we can index to find out whether a block
# is naturally occuring and should be considered in a heightmap
blockmask = naturalBlockmask()
blockmaskWithoutWater = naturalBlockmaskWithoutWater()
currentX = None
#iterate through the slices of each chunk in the selection box
for chunk, slices, point in level.getChunkSlices(box):
# slicing the block array is straightforward. blocks will contain only
# the area of interest in this chunk.
blocks = chunk.Blocks[slices]
# use indexing to look up whether or not each block in blocks is
# naturally-occuring. these blocks will "count" for column height.
maskedBlocks = blockmask[blocks]
maskedBlocksWithoutWater = blockmaskWithoutWater[blocks]
##############################################################################
heightmap = extractHeights(maskedBlocks)
heightmapWithoutWater = extractHeights(maskedBlocksWithoutWater)
if currentX != chunk.chunkPosition[0]:
currentX = chunk.chunkPosition[0]
horizontalHeightmapParts.append(heightmap)
horizontalHeightmapPartsWithoutWater.append(heightmapWithoutWater)
else:
horizontalHeightmapParts[len(horizontalHeightmapParts)-1] = np.hstack((horizontalHeightmapParts[len(horizontalHeightmapParts)-1], heightmap))
horizontalHeightmapPartsWithoutWater[len(horizontalHeightmapPartsWithoutWater)-1] = np.hstack((horizontalHeightmapPartsWithoutWater[len(horizontalHeightmapPartsWithoutWater)-1], heightmapWithoutWater))
completeHeightmap = horizontalHeightmapParts[0]
completeHeightmapWithoutWater = horizontalHeightmapPartsWithoutWater[0]
for i in range(1, len(horizontalHeightmapParts)):
completeHeightmap = np.vstack((completeHeightmap, horizontalHeightmapParts[i]))
completeHeightmapWithoutWater = np.vstack((completeHeightmapWithoutWater, horizontalHeightmapPartsWithoutWater[i]))
print("Finished Calculating HeightMap!")
# Get the direction that all of the flags will be facing
flagDir = random.randint(0,3)
# Initialize the pathfinding grid and the list of door/entrance positions
pathfindingGrid = np.zeros([abs(box.maxx - box.minx), abs(box.maxz - box.minz)])
doorPositions = []
print("Calculating Distribution")
width = box.maxx - box.minx
height = box.maxz - box.minz
r = options["Radius: "]
k = 30
grid = []
w = r / math.sqrt(2)
active = []
# Set Up Grid
cols = math.floor(width / w)
rows = math.floor(height / w)
for i in range(int(cols * rows)):
grid.append(None)
# Placing Unique Structures
# Nether Temple
gridPos = [15, 15]
placeNetherTemple(level, box, 0, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, gridPos, doorPositions)
for i in xrange(int((gridPos[0] + 11)/w)+1):
for j in xrange(int((gridPos[1] + 15)/w)+1):
grid[int(i + j * cols)] = Vec2(int((gridPos[0] - 11)) + (w*i), int((gridPos[1] - 15)) + (w * j), True)
print(str(grid[int(i + j * cols)].x) + ", " + str(grid[int(i + j * cols)].y))
# Cemetary
cemetaryBox = BoundingBox((box.minx + 4, box.miny + 3, box.maxz - 80), (76, box.maxy-3, 76))
cemetaryHeight = generateCemetary(level, cemetaryBox, settlement, completeHeightmap, completeHeightmapWithoutWater, [4, box.maxz - 80 - box.minz])
for i in xrange(int((80)/w)+1):
for j in xrange(int((80)/w)+1):
grid[int((i) + (cols - 1 - j) * cols)] = Vec2(int(w/3) + (w*i), box.maxz - box.minz - (int(w/3) + (w * j)), True)
doorPositions.append([80, box.maxz - box.minz - 40])
# Cemetary Gate
placeCemetaryGateSchematic(level, Vector(box.minx + 77, cemetaryHeight+4, box.maxz - 42))
# Farm Building
gridPos = [240, 240]
placeFarmBuilding(level, box, 2, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, gridPos, doorPositions)
# Set first Point
x = ((width) / 2.0)
y = ((height) / 2.0)
i = math.floor(x / w)
j = math.floor(y / w)
firstPos = Vec2(x, y)
firstPosIndex = int(i + j * cols)
grid[firstPosIndex] = firstPos
active.append(firstPos)
# Populate the rest of the Points
while len(active) > 0:
randIndex = random.randint(0, len(active)-1)
pos = active[randIndex]
found = False
# K times
for n in range(k):
# Get a new point between r and 2r from the currently selected active point
a = random.uniform(0, 2 * math.pi)
sample = Vec2(math.cos(a), math.sin(a))
m = random.uniform(r, 2 * r)
sample.multiply(m)
sample.add(pos)
# Get its appropriate grid coordinates
col = math.floor((sample.x) / w)
row = math.floor((sample.y) / w)
# If it's not off the out of bounds and there's no point in that grid spot already
if col < cols - 1 and col > -1 + 1 and row < rows - 1 and row > -1 + 1 and not grid[int(col + row * cols)]:
ok = True
# In a 3x3 area centered on the point
for i in range(-1, 2):
for j in range(-1, 2):
# If there's a point in one of those grid positions and it's too close to the point we are trying to place
if (col+i) + (row+j) * cols > -1 and (col+i) + (row+j) * cols < len(grid):
neighbor = grid[int((col+i) + (row+j) * cols)]
if neighbor:
diffX = sample.x - neighbor.x
diffY = sample.y - neighbor.y
d = (diffX * diffX) + (diffY * diffY)
if d < (r * r):
# The point will not be placed on the grid
ok = False
# Otherwise place the point on the grid
if ok:
found = True
grid[int(col + row * cols)] = sample
active.append(sample)
break
# After K point placing attempts, pop the currently selected active point from the active list
if not found:
active.pop(randIndex)
# Initialize the index of the person that we are giving a house at 0
personCounter = 0
# Initialize the list of people who are in the current generation as empty
alivePeople = []
# Add all of the people from the current generation to the alive people list
for i in xrange(len(settlement.families)):
for j in range(len(settlement.families[i].members[len(settlement.families[i].members)-1])):
alivePeople.append(settlement.families[i].members[len(settlement.families[i].members)-1][j])
# Randomimze the order of the list
random.shuffle(alivePeople)
for i in xrange(len(grid)):
# If the current house position is the one at the middle of the settlment, place the "lore shrine" there instead of a house
if i == firstPosIndex:
dest = [int(math.floor(box.minx + grid[i].x)), int(math.floor(box.minz + grid[i].y))]
placeLoreShrine(level, box, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, grid[i], dest)
# Otherwise, if the position on the grid is not from a unique structure place a house there
elif grid[i] and not grid[i].isFromUniqueStructure:
person = alivePeople[personCounter]
turnCount = random.randint(0, 3)
dest = [int(math.floor(box.minx + grid[i].x))+1, int(math.floor(box.minz + grid[i].y))+1]
# Pick a random house and place it in the spot specified, and have it be inhabited by the next person in the alivePeople list
houseIndex = random.randint(0,3)
housePlacingFunctions[houseIndex](level, box, turnCount, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, grid[i], dest, doorPositions, flagDir, person)
personCounter += 1
# Store some images of the heightmap and the pathfinding grid for no discernible reason
im = Image.fromarray(np.array(completeHeightmap))
im.convert('RGB').save("heightmap.jpeg")
im = Image.fromarray(np.array(pathfindingGrid))
im.convert('RGB').save("pathfinding.jpeg")
# Paths
# Initialize a 2D array to keep track of where to place path blocks
pathBlocks = np.zeros([abs(box.maxx - box.minx), abs(box.maxz - box.minz)])
# Keep track of the door position that is furthest to the north-east
northEastPos = [0, 256]
# For each door/entrance position in the list
for i in xrange(len(doorPositions)):
# Check if the position is the furthest to the north-east
if (doorPositions[i][0] + (256-doorPositions[i][1])) > (northEastPos[0] + (256-northEastPos[1])):
# If so store the postion
northEastPos = doorPositions[i]
# Get the height at that position
startY = completeHeightmap[doorPositions[i][0], doorPositions[i][1]]
dists = []
# For each door/entrance position in the list that comes after position i
for j in xrange(i, len(doorPositions)):
if i != j:
# Get the height at that position
goalY = completeHeightmap[doorPositions[j][0], doorPositions[j][1]]
# Make a list with the differences in position for the 3 dimensions
deltas = [doorPositions[i][0] - doorPositions[j][0], startY - goalY, doorPositions[i][1] - doorPositions[j][1]]
# Get the squared distance from the first position to the second and append it to the list of distances
distSquared = (deltas[0] * deltas[0]) + (deltas[1] * deltas[1]) + (deltas[2] * deltas[2])
dists.append(distSquared)
print("The distance from house " + str(i) + " to house " + str(j) + " is " + str(distSquared))
# Disregard the rest of this if there were no distances added to the list
if len(dists) == 0:
continue
# Get the index in the doorPositions list of the closest other door/entrance position
minIndex = dists.index(min(dists)) + i + 1
print("Connecting house " + str(i) + " with house " + str(minIndex))
print("Positions: (" + str(doorPositions[i][0]) + ", " + str(doorPositions[i][1]) + ") and (" + str(doorPositions[minIndex][0]) + ", " + str(doorPositions[minIndex][1]) + ")")
# Find the path from position "i" to position "minIndex"
path = aStar(level, box, [int(doorPositions[i][0]), int(doorPositions[i][1])], [int(doorPositions[minIndex][0]), int(doorPositions[minIndex][1])], pathfindingGrid, completeHeightmap)
# For every block in the path
for k in xrange(len(path)):
# Add that block to the array of path blocks
pathBlocks[path[k][0], path[k][1]] = 1
# If it's not at the beginning, or the end, every eighth block
if k != 0 and k + 1 != len(path) and k % 8 == 0:
# Place street lights on either side of the path
xDiff = path[k+1][0] - path[k][0]
zDiff = path[k+1][1] - path[k][1]
pos = streetLightOffsets[xDiff+1][zDiff+1][0]
if pos[0] == 0 and pos[1] == 0:
break
height = completeHeightmap[pos[0] + path[k][0], pos[1] + path[k][1]]
dest = Vector(pos[0] + box.minx + path[k][0], height-1, pos[1] + box.minz + path[k][1])
# Only if they wouldn't intersect with a building
if pathfindingGrid[pos[0] + path[k][0], pos[1] + path[k][1]] != 255:
placeStreetLightSchematic(level, dest)
pathfindingGrid[pos[0], pos[1]] = 255
pos = streetLightOffsets[xDiff+1][zDiff+1][1]
height = completeHeightmap[pos[0] + path[k][0], pos[1] + path[k][1]]
dest = Vector(pos[0] + box.minx + path[k][0], height-1, pos[1] + box.minz + path[k][1])
# Only if they wouldn't intersect with a building: the sequel
if pathfindingGrid[pos[0] + path[k][0], pos[1] + path[k][1]] != 255:
placeStreetLightSchematic(level, dest)
pathfindingGrid[pos[0], pos[1]] = 255
for i in xrange(abs(box.maxx - box.minx)):
for j in xrange(abs(box.maxz - box.minz)):
if pathBlocks[i, j] == 1:
# Get the block below the one that is being replaced
blockBelowReplaced = level.blockAt(box.minx + i, completeHeightmap[i][j]-2, box.minz + j)
# Set the block that the this segment of the path will be made of to Stone Bricks if it's over water, and Path block otherwise
pathBlock = 98 if (blockBelowReplaced == 8 or blockBelowReplaced == 9) else 208
level.setBlockAt(box.minx + i, completeHeightmap[i][j]-1, box.minz + j, pathBlock)
level.setBlockDataAt(box.minx + i, completeHeightmap[i][j]-1, box.minz + j, 0)
# Do the same for a 3x3 area centered on that block
for k in xrange(8):
blockBelowReplaced = level.blockAt(box.minx + i + actions[k][0], completeHeightmap[i + actions[k][0]][j + actions[k][1]]-2, box.minz + j + actions[k][1])
pathBlock = 98 if (blockBelowReplaced == 8 or blockBelowReplaced == 9) else 208
level.setBlockAt(box.minx + i + actions[k][0], completeHeightmap[i + actions[k][0]][j + actions[k][1]]-1, box.minz + j + actions[k][1], pathBlock)
level.setBlockDataAt(box.minx + i + actions[k][0], completeHeightmap[i + actions[k][0]][j + actions[k][1]]-1, box.minz + j + actions[k][1], 0)
print("Blocks Placed!")
print(str(personCounter) + " Houses in total")
# Place the path from the center of the map to the settlement if need be
if tooBig and ((initialBox.maxx - initialBox.minx)-offsetsForPathToSettlement.x > 512 or (initialBox.maxz - initialBox.minz)-offsetsForPathToSettlement.y > 512):
# Create a bounding box with the same dimensions and position as the initial box
anotherBox = initialBox
print("Min Point: X: " + str(anotherBox.minx) + ", Z: " + str(anotherBox.minz))
print("Size: X: " + str(anotherBox.maxx - anotherBox.minx) + ", Z: " + str(anotherBox.maxz - anotherBox.minz))
# Reset some stuff used earlier
currentX = None
horizontalHeightmapParts = []
# The following section is derived from the built in MCEdit filter: topsoil.py
##############################################################################
#iterate through the slices of each chunk in the selection box
for chunk, slices, point in level.getChunkSlices(anotherBox):
# slicing the block array is straightforward. blocks will contain only
# the area of interest in this chunk.
blocks = chunk.Blocks[slices]
# use indexing to look up whether or not each block in blocks is
# naturally-occuring. these blocks will "count" for column height.
maskedBlocks = blockmask[blocks]
##############################################################################
# Construct the heightmap from slices of chunks
heightmap = extractHeights(maskedBlocks)
if currentX != chunk.chunkPosition[0]:
currentX = chunk.chunkPosition[0]
horizontalHeightmapParts.append(heightmap)
else:
horizontalHeightmapParts[len(horizontalHeightmapParts)-1] = np.hstack((horizontalHeightmapParts[len(horizontalHeightmapParts)-1], heightmap))
completeHeightmap = horizontalHeightmapParts[0]
for i in range(1, len(horizontalHeightmapParts)):
completeHeightmap = np.vstack((completeHeightmap, horizontalHeightmapParts[i]))
print("Finished Calculating HeightMap!")
# Find the path from the center of the initial selection to the north-east point of the settlement
pathfindingGrid = np.zeros([abs(anotherBox.maxx - anotherBox.minx), abs(anotherBox.maxz - anotherBox.minz)])
newStart = [(anotherBox.maxx - anotherBox.minx)/2, (anotherBox.maxz - anotherBox.minz)/2]
newGoal = [256 + offsetsForPathToSettlement.x, anotherBox.maxz - anotherBox.minz - 256 - offsetsForPathToSettlement.y]
path = aStar(level, anotherBox, newStart, newGoal, pathfindingGrid, completeHeightmap)
# For every block in the path (except the last few) place blocks on the ground in a 3x3 centered around it
for i in xrange(1, len(path)-5):
for x in xrange(-1, 2):
for y in xrange(-1, 2):
blockBelowReplaced = level.blockAt(anotherBox.minx + path[i][0] + x, completeHeightmap[path[i][0] + x, path[i][1] + y]-2, anotherBox.minz + path[i][1] + y)
pathBlock = 98 if (blockBelowReplaced == 8 or blockBelowReplaced == 9) else 208
level.setBlockAt(anotherBox.minx + path[i][0] + x, completeHeightmap[path[i][0] + x, path[i][1] + y]-1, anotherBox.minz + path[i][1] + y, pathBlock)
level.setBlockDataAt(anotherBox.minx + path[i][0] + x, completeHeightmap[path[i][0] + x, path[i][1] + y]-1, anotherBox.minz + path[i][1] + y, 0)
# The AStar pathfinding algorithm
def aStar(level, box, start, goal, pathfindingGrid, completeHeightmap):
# Functions to estimate the cost using a heuristic, and determine if an action is legal
def estimateCost(x, z, goal):
return (abs(x-goal[0]) + abs(z-goal[1])) * 100
def isLegalAction(x, z, action, pathfindingGrid):
if not (x + action[0] < 0 or x + action[0] >= len(pathfindingGrid) or z + action[1] < 0 or z + action[1] >= len(pathfindingGrid[0]) or pathfindingGrid[x, z] == 255):
return True
# Initialize a bunch of stuff
inProgress = True
path = []
openList = [Node(start[0], start[1], None, None, 0, 0)]
openListGArray = [[0 for i in xrange(len(pathfindingGrid[0]))] for j in xrange(len(pathfindingGrid))]
closed = [[False for i in xrange(len(pathfindingGrid[0]))] for j in xrange(len(pathfindingGrid))]
while inProgress:
print("Open: " + str(len(openList)))
# If the openlist is empty, stop trying to find a path
if len(openList) == 0:
inProgress = False
return path
# Find and pop th enode with the lowest F value
minF = openList[0].g + openList[0].h
minFIndex = 0
for i in xrange(1, len(openList)):
if openList[i].g + openList[i].h < minF:
minF = openList[i].g + openList[i].h
minFIndex = i
# Using H as a tiebreaker if needed
elif openList[i].g + openList[i].h == minF and openList[minFIndex].h > openList[i].h:
minFIndex = i
node = openList.pop(minFIndex)
# Add that node to the closed list
closed[node.x][node.z] = True
# If the popped node is the goal node, stop the search and return the path
if goal[0] == node.x and goal[1] == node.z:
inProgress = False
while node.parent != None:
path.append([node.x, node.z])
node = node.parent
return path
# For all eight surrounding nodes on the grid
for i in xrange(8):
a = actions[i]
# If the action to get to it is legal
if not isLegalAction(node.x, node.z, a, pathfindingGrid):
continue
# And the node isn't in the closed list already
s = [node.x + a[0], node.z + a[1]]
if closed[s[0]][s[1]]:
continue
# And it's G value is grater than any G values already stored for that position in the "openListGArray"
newG = node.g + 100 + (40 * (a[0] and a[1]))
if openListGArray[s[0]][s[1]] and openListGArray[s[0]][s[1]] < newG:
continue
# Append the node to the open list
openListGArray[s[0]][s[1]] = newG
heuristic = estimateCost(s[0], s[1], goal)
openList.append(Node(s[0], s[1], node, a, newG, heuristic))
def placeHouse1(level, box, turnCount, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, gridPos, dest, doorPositions, flagDir, resident):
print("Turn Count: " + str(turnCount))
footprint = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]])
footprint = np.rot90(footprint, k=turnCount*3, axes=(0, 1))
# Place some barriers on the pathfinding grid
if turnCount % 2 == 0:
xRange = [-9, 10]
zRange = [-7, 8]
else:
xRange = [-7, 8]
zRange = [-9, 10]
highestPointUnderStructure = 0
for x in xrange(xRange[0], xRange[1]):
for y in xrange(zRange[0], zRange[1]):
if footprint[x + abs(xRange[0]), y + abs(zRange[0])] == 1:
pathfindingGrid[int(gridPos.x) + x, int(gridPos.y) + y] = 255
highestPointUnderStructure = max(highestPointUnderStructure, completeHeightmap[int(gridPos.x) + x, int(gridPos.y) + y])
# Place the actual house
placeHouse1Schematic(level, Vector(dest[0], highestPointUnderStructure, dest[1]), turnCount)
# Append a point from the entrance of the house to the list of "doorPositions"
doorPos = [int(gridPos.x + (doorOffsetX[turnCount] * 10)), int(gridPos.y + (doorOffsetZ[turnCount] * 10))]
doorPositions.append(doorPos)
otherOffset = [doorPos[0] + box.minx - (doorOffsetX[turnCount]*3), doorPos[1] + box.minz - (doorOffsetZ[turnCount]*3)]
# Pillar to connect to the ground
pillarToGround(level, box, completeHeightmapWithoutWater, highestPointUnderStructure, 6, 3, gridPos, [0, 0], footprint, [xRange[0], zRange[0]], True)
# Ladder to the ground
ladderHeight = highestPointUnderStructure - 1
while (ladderHeight >= completeHeightmap[doorPos[0], doorPos[1]]):
level.setBlockAt(doorPos[0] + box.minx, ladderHeight, doorPos[1] + box.minz, 65)
level.setBlockDataAt(doorPos[0] + box.minx, ladderHeight, doorPos[1] + box.minz, trapdoorLadderDirections[turnCount][0])
if (level.blockAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount]) == 0):
level.setBlockAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount], 96)
level.setBlockDataAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount], trapdoorLadderDirections[turnCount][1])
ladderHeight = ladderHeight - 1
# Randomize the color of the beds and the carpets next to them
prevTurn = (turnCount - 1) % 4
bedColor = random.randint(0, 15)
bedHeight = highestPointUnderStructure+6
bedPos = [dest[0]-1 + (doorOffsetX[turnCount] * 4), dest[1]-1 + (doorOffsetZ[turnCount] * 4)]
placeBed(level, bedPos[0] + (doorOffsetX[prevTurn] * 3), bedHeight, bedPos[1] + (doorOffsetZ[prevTurn] * 3), bedColor, prevTurn)
placeBed(level, bedPos[0] + (doorOffsetX[prevTurn] * 3) + (doorOffsetX[turnCount]), bedHeight, bedPos[1] + (doorOffsetZ[prevTurn] * 3) + (doorOffsetZ[turnCount]), bedColor, prevTurn)
level.setBlockDataAt(bedPos[0] + (doorOffsetX[prevTurn] * 3) - (doorOffsetX[turnCount]), bedHeight, bedPos[1] + (doorOffsetZ[prevTurn] * 3) - (doorOffsetZ[turnCount]), bedColor)
level.setBlockDataAt(bedPos[0] + (doorOffsetX[prevTurn] * 4) - (doorOffsetX[turnCount]), bedHeight, bedPos[1] + (doorOffsetZ[prevTurn] * 4) - (doorOffsetZ[turnCount]), bedColor)
# Place the banner over the fireplace
pattern = crestPatternGenerator(resident.lastName)
banner(level, dest[0]-1 - (doorOffsetX[turnCount]*(4)), highestPointUnderStructure+6, dest[1]-1 - (doorOffsetZ[turnCount]*(4)), pattern, turnCountToBannerRotation[turnCount])
# Place the flag on top of the building
nextTurn = (turnCount + 1) % 4
flag(level, dest[0]-1 + (doorOffsetX[turnCount]*(9)) + (doorOffsetX[nextTurn]*(2)), highestPointUnderStructure+12, dest[1]-1 + (doorOffsetZ[turnCount]*(9)) + (doorOffsetZ[nextTurn]*(2)), flagDir, pattern)
# Randomize the flowers in the flower beds
for j in xrange(3):
flowerIndex = random.randint(0, 10)
level.setBlockAt(otherOffset[0] + (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+1, otherOffset[1] + (doorOffsetX[turnCount]*(3+j)), 38)
level.setBlockDataAt(otherOffset[0] + (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+1, otherOffset[1] + (doorOffsetX[turnCount]*(3+j)), flowerIndex)
flowerIndex = random.randint(0, 10)
level.setBlockAt(otherOffset[0] - (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+1, otherOffset[1] - (doorOffsetX[turnCount]*(3+j)), 38)
level.setBlockDataAt(otherOffset[0] - (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+1, otherOffset[1] - (doorOffsetX[turnCount]*(3+j)), flowerIndex)
flowerIndex = random.randint(0, 10)
level.setBlockAt(otherOffset[0] + (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+7, otherOffset[1] + (doorOffsetX[turnCount]*(3+j)), 38)
level.setBlockDataAt(otherOffset[0] + (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+7, otherOffset[1] + (doorOffsetX[turnCount]*(3+j)), flowerIndex)
flowerIndex = random.randint(0, 10)
level.setBlockAt(otherOffset[0] - (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+7, otherOffset[1] - (doorOffsetX[turnCount]*(3+j)), 38)
level.setBlockDataAt(otherOffset[0] - (doorOffsetZ[turnCount]*(3+j)), highestPointUnderStructure+7, otherOffset[1] - (doorOffsetX[turnCount]*(3+j)), flowerIndex)
def placeHouse2(level, box, turnCount, completeHeightmap, completeHeightmapWithoutWater, pathfindingGrid, gridPos, dest, doorPositions, flagDir, resident):
print("Turn Count: " + str(turnCount))
footprint = np.array([[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, 0, 0, 0, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0]])
footprint = np.rot90(footprint, k=turnCount*3, axes=(0, 1))
# Place some barriers on the pathfinding grid
highestPointUnderStructure = 0
for x in xrange(-8, 9):
for y in xrange(-8, 9):
if footprint[x + 8, y + 8] == 1:
pathfindingGrid[int(gridPos.x) + x, int(gridPos.y) + y] = 255
highestPointUnderStructure = max(highestPointUnderStructure, completeHeightmap[int(gridPos.x) + x, int(gridPos.y) + y])
# Place the actual house
placeHouse2Schematic(level, Vector(dest[0], highestPointUnderStructure, dest[1]), turnCount)
# Append a point from the entrance of the house to the list of "doorPositions"
doorPos = [int(math.floor(gridPos.x) + (doorOffsetX[turnCount] * 9)), int(math.floor(gridPos.y) + (doorOffsetZ[turnCount] * 9))]
doorPositions.append(doorPos)
# Pillar to connect to the ground
pillarToGround(level, box, completeHeightmapWithoutWater, highestPointUnderStructure, 6, 3, gridPos, [0, 0], footprint, [-8, -8], True)
# Ladder to the ground
ladderHeight = highestPointUnderStructure - 1
while (ladderHeight >= completeHeightmap[doorPos[0], doorPos[1]]):
level.setBlockAt(doorPos[0] + box.minx, ladderHeight, doorPos[1] + box.minz, 65)
level.setBlockDataAt(doorPos[0] + box.minx, ladderHeight, doorPos[1] + box.minz, trapdoorLadderDirections[turnCount][0])
if (level.blockAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount]) == 0):
level.setBlockAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount], 96)
level.setBlockDataAt(doorPos[0] + box.minx - doorOffsetX[turnCount], ladderHeight, doorPos[1] + box.minz - doorOffsetZ[turnCount], trapdoorLadderDirections[turnCount][1])
ladderHeight = ladderHeight - 1
# Place the banners over the fireplace
nextTurn = (turnCount + 1) % 4
pattern = crestPatternGenerator(resident.lastName)
bannerHeight = highestPointUnderStructure+5
bannerPos = [dest[0]-1 + (doorOffsetX[turnCount] * -4), dest[1]-1 + (doorOffsetZ[turnCount] * -4)]
banner(level, bannerPos[0], bannerHeight, bannerPos[1], pattern, turnCountToBannerRotation[turnCount])
banner(level, bannerPos[0] - (doorOffsetX[nextTurn]), bannerHeight, bannerPos[1] - (doorOffsetZ[nextTurn]), pattern, turnCountToBannerRotation[turnCount])
banner(level, bannerPos[0] + (doorOffsetX[nextTurn]), bannerHeight, bannerPos[1] + (doorOffsetZ[nextTurn]), pattern, turnCountToBannerRotation[turnCount])
# Randomize the color of the bed and the carpets surrounding it
bedColor = random.randint(0, 15)
bedPos = [dest[0]-1 + (doorOffsetX[turnCount] * 4), dest[1]-1 + (doorOffsetZ[turnCount] * 4)]
bedHeight = highestPointUnderStructure+5