-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
77 lines (59 loc) · 2.36 KB
/
main.py
File metadata and controls
77 lines (59 loc) · 2.36 KB
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
import sys
import numpy as np
from gdpc import __url__, Editor, Block
from gdpc.exceptions import InterfaceConnectionError, BuildAreaNotSetError
from gdpc.vector_tools import addY
from settler import map_water, find_settlement_location, find_building_locations, place_outlines
from foundationPlacement import createFoundations
from schematics import build_structure
from roads import buildRoads
from remove_trees import remove
# Create an editor object.
# The Editor class provides a high-level interface to interact with the Minecraft world.
editor = Editor()
editor.buffering = True
editor.caching = True
# Check if the editor can connect to the GDMC HTTP interface.
try:
editor.checkConnection()
except InterfaceConnectionError:
print(
f"Error: Could not connect to the GDMC HTTP interface at {editor.host}!\n"
"To use GDPC, you need to use a \"backend\" that provides the GDMC HTTP interface.\n"
"For example, by running Minecraft with the GDMC HTTP mod installed.\n"
f"See {__url__}/README.md for more information."
)
sys.exit(1)
# Get the build area.
try:
buildArea = editor.getBuildArea()
except BuildAreaNotSetError:
print(
"Error: failed to get the build area!\n"
"Make sure to set the build area with the /setbuildarea command in-game.\n"
"For example: /setbuildarea ~0 0 ~0 ~64 200 ~64"
)
sys.exit(1)
print("Loading world slice...")
buildRect = buildArea.toRect()
worldSlice = editor.loadWorldSlice(buildRect)
print("World slice loaded!")
vec = addY(buildRect.center, 30)
heightmap = worldSlice.heightmaps["MOTION_BLOCKING_NO_LEAVES"]
print(f"Heightmap shape: {heightmap.shape}")
print(f"Average height: {int(np.mean(heightmap))}")
begin = buildArea.begin
end = buildArea.end
# remove(editor, buildArea)
water_array = map_water(editor, begin, end, heightmap)
settlement_plot, settlement_water, negative, positive = find_settlement_location(begin, water_array, heightmap)
building_plots = find_building_locations(editor, settlement_plot, settlement_water, negative)
num_buildings = 12
createFoundations(editor, building_plots, num_buildings)
structures = []
for plot in building_plots[:num_buildings]:
structure = build_structure(editor, plot)
#TODO set custom door location for houses
structure.set_door((-1, -1, -6))
structures.append(structure)
buildRoads(heightmap, begin, structures)