1717"""
1818
1919import array
20+ from math import floor
2021
2122from spockbot .mcp .bbuff import BoundBuffer
2223
@@ -150,10 +151,13 @@ def unpack_column(self, data):
150151 bbuff , data ['primary_bitmap' ], skylight , data ['continuous' ]
151152 )
152153
153- def get_block (self , x , y , z ):
154- x , rx = divmod (x , 16 )
155- y , ry = divmod (y , 16 )
156- z , rz = divmod (z , 16 )
154+ def get_block (self , pos_or_x , y = None , z = None ):
155+ if None in (y , z ): # pos supplied
156+ pos_or_x , y , z = pos_or_x
157+
158+ x , rx = divmod (floor (pos_or_x ), 16 )
159+ y , ry = divmod (floor (y ), 16 )
160+ z , rz = divmod (floor (z ), 16 )
157161
158162 if (x , z ) not in self .columns or y > 0x0F :
159163 return 0 , 0
@@ -163,10 +167,14 @@ def get_block(self, x, y, z):
163167 data = chunk .block_data .get (rx , ry , rz )
164168 return data >> 4 , data & 0x0F
165169
166- def set_block (self , x , y , z , block_id = None , meta = None , data = None ):
167- x , rx = divmod (x , 16 )
168- y , ry = divmod (y , 16 )
169- z , rz = divmod (z , 16 )
170+ def set_block (self , pos_or_x , y = None , z = None ,
171+ block_id = None , meta = None , data = None ):
172+ if None in (y , z ): # pos supplied
173+ pos_or_x , y , z = pos_or_x
174+
175+ x , rx = divmod (floor (pos_or_x ), 16 )
176+ y , ry = divmod (floor (y ), 16 )
177+ z , rz = divmod (floor (z ), 16 )
170178
171179 if y > 0x0F :
172180 return
@@ -184,10 +192,13 @@ def set_block(self, x, y, z, block_id=None, meta=None, data=None):
184192 data = (block_id << 4 ) | (meta & 0x0F )
185193 chunk .block_data .set (rx , ry , rz , data )
186194
187- def get_light (self , x , y , z ):
188- x , rx = divmod (x , 16 )
189- y , ry = divmod (y , 16 )
190- z , rz = divmod (z , 16 )
195+ def get_light (self , pos_or_x , y = None , z = None ):
196+ if None in (y , z ): # pos supplied
197+ pos_or_x , y , z = pos_or_x
198+
199+ x , rx = divmod (floor (pos_or_x ), 16 )
200+ y , ry = divmod (floor (y ), 16 )
201+ z , rz = divmod (floor (z ), 16 )
191202
192203 if (x , z ) not in self .columns or y > 0x0F :
193204 return 0 , 0
@@ -197,10 +208,14 @@ def get_light(self, x, y, z):
197208 return chunk .light_block .get (rx , ry , rz ), chunk .light_sky .get (rx , ry ,
198209 rz )
199210
200- def set_light (self , x , y , z , light_block = None , light_sky = None ):
201- x , rx = divmod (x , 16 )
202- y , ry = divmod (y , 16 )
203- z , rz = divmod (z , 16 )
211+ def set_light (self , pos_or_x , y = None , z = None ,
212+ light_block = None , light_sky = None ):
213+ if None in (y , z ): # pos supplied
214+ pos_or_x , y , z = pos_or_x
215+
216+ x , rx = divmod (floor (pos_or_x ), 16 )
217+ y , ry = divmod (floor (y ), 16 )
218+ z , rz = divmod (floor (z ), 16 )
204219
205220 if y > 0x0F :
206221 return
@@ -220,17 +235,17 @@ def set_light(self, x, y, z, light_block=None, light_sky=None):
220235 chunk .light_sky .set (rx , ry , rz , light_sky & 0xF )
221236
222237 def get_biome (self , x , z ):
223- x , rx = divmod (x , 16 )
224- z , rz = divmod (z , 16 )
238+ x , rx = divmod (floor ( x ) , 16 )
239+ z , rz = divmod (floor ( z ) , 16 )
225240
226241 if (x , z ) not in self .columns :
227242 return 0
228243
229244 return self .columns [(x , z )].biome .get (rx , rz )
230245
231246 def set_biome (self , x , z , data ):
232- x , rx = divmod (x , 16 )
233- z , rz = divmod (z , 16 )
247+ x , rx = divmod (floor ( x ) , 16 )
248+ z , rz = divmod (floor ( z ) , 16 )
234249
235250 if (x , z ) in self .columns :
236251 column = self .columns [(x , z )]
0 commit comments