Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit ee5307d

Browse files
committed
fixed error with negative region offset
1 parent e8d0f33 commit ee5307d

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed

dwarftest_transformer.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,30 @@ def df2mt_pos(self, region_pos, tile_pos):
107107
return mt_pos
108108

109109
def mt2mt_block_pos(self, mt_pos):
110-
mt_block_pos = (
110+
mt_block_pos = [
111111
int(mt_pos[0] / self.MT_BLOCK_NODE_SIZE[0]),
112112
int(mt_pos[1] / self.MT_BLOCK_NODE_SIZE[1]),
113113
int(mt_pos[2] / self.MT_BLOCK_NODE_SIZE[2]),
114-
)
115-
mt_block_node_pos = (
114+
]
115+
116+
mt_block_node_pos = [
116117
int(mt_pos[0] - mt_block_pos[0] * self.MT_BLOCK_NODE_SIZE[0]),
117118
int(mt_pos[1] - mt_block_pos[1] * self.MT_BLOCK_NODE_SIZE[1]),
118119
int(mt_pos[2] - mt_block_pos[2] * self.MT_BLOCK_NODE_SIZE[2]),
119-
)
120+
]
121+
122+
if mt_block_node_pos[0] < 0:
123+
mt_block_node_pos[0] = mt_block_node_pos[0] + self.MT_BLOCK_NODE_SIZE[0]
124+
if mt_block_node_pos[1] < 0:
125+
mt_block_node_pos[1] = mt_block_node_pos[1] + self.MT_BLOCK_NODE_SIZE[1]
126+
if mt_block_node_pos[2] < 0:
127+
mt_block_node_pos[2] = mt_block_node_pos[2] + self.MT_BLOCK_NODE_SIZE[2]
128+
120129
mt_block_node_index = mt_block_node_pos[0] + \
121130
(mt_block_node_pos[1] * self.MT_BLOCK_NODE_SIZE[1]) + \
122131
(mt_block_node_pos[2] * self.MT_BLOCK_NODE_SIZE[0]*self.MT_BLOCK_NODE_SIZE[1])
123132

124-
return mt_block_pos, mt_block_node_pos, mt_block_node_index
133+
return tuple(mt_block_pos), tuple(mt_block_node_pos), mt_block_node_index
125134

126135
# block manipulation
127136

@@ -146,7 +155,8 @@ def set_mt_node(self, mt_pos, val):
146155

147156
# detect out of range
148157
if mt_block_node_index >= self.mt_blocks[mt_block_pos].size or mt_block_node_index < 0:
149-
raise Exception('Node index {} is out of range!'.format(mt_block_node_index))
158+
raise Exception('Node index {} is out of range! [mt_pos={}, mt_block_pos={}, mt_block_node_pos={}]'.format(
159+
mt_block_node_index, mt_pos, mt_block_pos, mt_block_node_pos))
150160

151161
# set node value
152162
self.mt_blocks[mt_block_pos][mt_block_node_index] = val

main.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from dfhack_rpc import DFHackRPC
1616

1717

18-
def main(): # TODO: map is flopped on X axis!!!
18+
def main(): # TODO: map is flipped on X axis!!!
1919
parser = argparse.ArgumentParser(
2020
description='Dwarftest'
2121
)
@@ -39,6 +39,10 @@ def main(): # TODO: map is flopped on X axis!!!
3939
'--skip_block_build',
4040
action='store_true',
4141
)
42+
parser.add_argument(
43+
'--additional_tile_z_offset',
44+
type=int, default=37
45+
)
4246
parser.add_argument(
4347
'--path',
4448
default='./build',
@@ -127,15 +131,17 @@ def main(): # TODO: map is flopped on X axis!!!
127131

128132
# Init Minetest world and block transformer
129133

130-
print('Init of Minetest world and block transformer..')
134+
print('Init of Minetest world and Dwarftest transformer..')
135+
136+
df_region_offset = (world_map.center_x, world_map.center_y, world_map.center_z + args.additional_tile_z_offset)
137+
print('df_region_offset = {}'.format(df_region_offset))
138+
139+
complex_block_scale = {'tile_x': 2, 'tile_y': 2, 'tile_z_floor': 1, 'tile_z_wall': 2}
140+
print('complex_block_scale = {}'.format(complex_block_scale))
131141

132142
path_world = os.path.join(path_worlds, world_name)
133143
mw = MinetestWorld(path_world, allow_overwrite=True)
134-
dt = DwarftestTransformer(
135-
mw,
136-
df_region_offset=(world_map.center_x, world_map.center_y, world_map.center_z),
137-
complex_block_scale={'tile_x': 2, 'tile_y': 2, 'tile_z_floor': 1, 'tile_z_wall': 2}
138-
)
144+
dt = DwarftestTransformer(mw, df_region_offset=df_region_offset, complex_block_scale=complex_block_scale)
139145

140146
print('-------------------------------------------')
141147

@@ -214,7 +220,7 @@ def main(): # TODO: map is flopped on X axis!!!
214220

215221
dt.dump_mt_blocks()
216222

217-
print('-------------------------------------------')
223+
print('-------------------------------------------')
218224

219225
# save world + close connection
220226

minetest_world.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,30 +97,50 @@ def close_sql_connections(self):
9797
# Init world files
9898

9999
def init_auth_txt(self):
100-
with open(os.path.join(self.path, 'auth.txt'), 'w') as f:
100+
path = os.path.join(self.path, 'auth.txt')
101+
if os.path.exists(path):
102+
return
103+
104+
with open(path, 'w') as f:
101105
f.write(
102106
'singleplayer::server, shout, fly, password, bring, kick, teleport, ban, noclip, debug, '
103107
'privs, fast, basic_privs, zoom, give, protection_bypass, rollback, settime, interact\n'
104108
)
105109

106110
def init_env_meta_txt(self):
107-
with open(os.path.join(self.path, 'env_meta.txt'), 'w') as f:
111+
path = os.path.join(self.path, 'env_meta.txt')
112+
if os.path.exists(path):
113+
return
114+
115+
with open(path, 'w') as f:
108116
f.write(
109117
'game_time = 12000\n'
110118
'time_of_day = 12000\n'
111119
'EnvArgsEnd\n'
112120
)
113121

114122
def init_ipban_txt(self):
115-
with open(os.path.join(self.path, 'ipban.txt'), 'w') as f:
123+
path = os.path.join(self.path, 'ipban.txt')
124+
if os.path.exists(path):
125+
return
126+
127+
with open(path, 'w') as f:
116128
f.write('\n')
117129

118130
def init_map_meta_txt(self):
119-
with open(os.path.join(self.path, 'map_meta.txt'), 'w') as f:
131+
path = os.path.join(self.path, 'map_meta.txt')
132+
if os.path.exists(path):
133+
return
134+
135+
with open(path, 'w') as f:
120136
f.write('[end_of_params]\n')
121137

122138
def init_world_mt(self):
123-
with open(os.path.join(self.path, 'world.mt'), 'w') as f:
139+
path = os.path.join(self.path, 'world.mt')
140+
if os.path.exists(path):
141+
return
142+
143+
with open(path, 'w') as f:
124144
f.write(
125145
'gameid = {}\n'
126146
'creative_mode = true\n'
@@ -195,7 +215,6 @@ def build_map_block(self, nodes):
195215

196216
# zlib-compressed node data
197217

198-
199218
num_name_id_mappings = {}
200219
for n in nodes:
201220
if n['content_id'] not in num_name_id_mappings:

0 commit comments

Comments
 (0)