diff --git a/chunk.py b/chunk.py index aa0dcb7..1f07f7f 100644 --- a/chunk.py +++ b/chunk.py @@ -365,7 +365,7 @@ class ChunkRenderer(object): return self._up_left_blocks up_left_blocks = property(_load_up_left_blocks) - def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = ll ): + def generate_pseudo_ancildata(self,x,y,z,blockid, north_position = 0 ): """ Generates a pseudo ancillary data for blocks that depend of what are surrounded and don't have ancillary data @@ -374,12 +374,22 @@ class ChunkRenderer(object): Bit: 1 2 3 4 Side: x y -x -y - Values: bit = 0 -> The corresponding side block is not blockid - bit = 1 -> The corresponding side block is not blockid + Values: bit = 0 -> The corresponding side block has different blockid + bit = 1 -> The corresponding side block has same blockid Example: if the bit1 is 1 that means that there is a block with blockid in the side of the +x direction. - Once generate the pseudo_ancildata + You can rotate the pseudo data multiplying by 2 and + if it is > 15 subtracting 15 and adding 1. (moving bits + in the left direction is like rotate 90 degree in anticlockwise + direction). In this way can be used for maps with other + north orientation. + + North position can have the values 0, 1, 2, 3, corresponding to + north in bottom-left, bottom-right, top-right and top-left of + the screen. + + The rotation feature is not used anywhere yet. """ blocks = self.blocks @@ -389,50 +399,40 @@ class ChunkRenderer(object): right_blocks = self.right_blocks pseudo_data = 0 + # ll, ul, ur, lr stands for lower-left, upper-left, upper-right + # and lower-right # check if we are in the border of a chunk and the chunk # is in the border of the map - if up_right_blocks[0,0,0] == None and x == 15 or - right_blocks[0,0,0] == None and y == 15 or - left_blocks[0,0,0] == None and x == 0 or - up_left_blocks[0,0,0] == None and y == 0: + if ((up_right_blocks[0,0,0] == None and x == 15) or + (right_blocks[0,0,0] == None and y == 15) or + (left_blocks[0,0,0] == None and x == 0) or + (up_left_blocks[0,0,0] == None and y == 0)): return None if up_right_blocks[0,y,z] == blockid if x == 15 else blocks[x+1,y,z] == blockid: - pseudo_data |= 0b1000 + pseudo_data = pseudo_data | 0b1000 if right_blocks[x,0,z] == blockid if y == 15 else blocks[x,y + 1,z] == blockid: - pseudo_data |= 0b0100 + pseudo_data = pseudo_data | 0b0100 if left_blocks[15,y,z] == blockid if x == 0 else blocks[x - 1,y,z] == blockid: - pseudo_data |= 0b0010 + pseudo_data = pseudo_data | 0b0010 if up_left_blocks[x,15,z] == blockid if y == 0 else blocks[x,y - 1,z] == blockid: - pseudo_data |= 0b0001 - - if north_position == ll: - return pseudo_data + pseudo_data = pseudo_data | 0b0001 + + + while north_position > 0: + pseudo_data *= 2 + if pseudo_data > 15: + pseudo_data -= 16 + pseudo_data +=1 + north_position -= 1 - elif north_position == ul: - pseudo_data *= 2 - if pseudo_data > 15: - pseudo_data -= 15 - pseudo_data +=1 - return pseudo_data - - elif north_position == ul: - pseudo_data *= 2 - if pseudo_data > 15: - pseudo_data -= 15 - pseudo_data +=1 - - elif north_position == ul: - pseudo_data *= 2 - if pseudo_data > 15: - pseudo_data -= 15 - pseudo_data +=1 - + return pseudo_data + def _hash_blockarray(self): """Finds a hash of the block array""" if hasattr(self, "_digest"): diff --git a/textures.py b/textures.py index 5efb889..bc2eb41 100644 --- a/textures.py +++ b/textures.py @@ -761,115 +761,21 @@ def generate_special_texture(blockID, data): # +y axis points bottom right direction # First compose small sticks in the back of the image, # then big stick and thecn small sticks in the front. - if data == 1: - img = fence_big - return (img.convert("RGB"),img.split()[3]) - - elif data == 2: #fence in line with x axis + + if (data & 0b0001) == 1: + composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left + if (data & 0b1000) == 8: composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - elif data == 3: #fence in line with y axis - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 4: #fence corner +x, -y - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 5: #fence corner -x, -y - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 6: #fence corner -x, +y - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) + composite.alpha_over(img,fence_big,(0,0),fence_big) - elif data == 7: #fence corner +x, +y - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 8: #fence dead end +x - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 9: #fence dead end -y - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) - return (img.convert("RGB"),img.split()[3]) - - elif data == 10: #fence dead end -x - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 11: #fence dead end +y - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 12: #fence cross with +y missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - return (img.convert("RGB"),img.split()[3]) - - elif data == 13: #fence cross with +x missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_big,(0,0),fence_big) + if (data & 0b0010) == 2: composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left + if (data & 0b0100) == 4: composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == 14: #fence cross with -y missing - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == 15: #fence cross with -x missing - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - - elif data == 16: #fence cross - composite.alpha_over(img,fence_small_side, pos_top_left,fence_small_side) # top left - composite.alpha_over(img,fence_small_other_side, pos_top_right,fence_small_other_side) # top right - composite.alpha_over(img,fence_big,(0,0),fence_big) - composite.alpha_over(img,fence_small_other_side, pos_bottom_left,fence_small_other_side) # bottom left - composite.alpha_over(img,fence_small_side, pos_bottom_right,fence_small_side) # bottom right - return (img.convert("RGB"),img.split()[3]) - - elif data == None: # This can happend if a fence is in the border - # of a chunk and the chunk is in the border of the map. - composite.alpha_over(img,fence_big,(0,0),) - return (img.convert("RGB"), img.split()[3]) - - else: # just in case - composite.alpha_over(img,fence_big,(0,0),) - return (img.convert("RGB"), img.split()[3]) + return (img.convert("RGB"),img.split()[3]) + return None