diff --git a/blocks.py b/blocks.py index 5f3980f1..0b2bc885 100644 --- a/blocks.py +++ b/blocks.py @@ -361,9 +361,14 @@ def update_texture(self): setattr(self, k, get_texture_coordinates(*v)) self.texture_data = self.get_texture_data() - def on_neighbor_change(self, world, neighbor_pos, self_pos): + def on_neighbor_change(self, world: custom_types.World, neighbor_pos: iVector, self_pos: iVector): pass + def generic_on_missing_floor_drop(self, world: custom_types.World, neighbor_pos: iVector, self_pos: iVector): + if not world.get_block_below(self_pos): + world.remove_block(None, self_pos) + # todo: actually drop an item + def can_place_on(self, block_id): return False @@ -445,9 +450,10 @@ def get_color(self, temperature, humidity): ret.extend([1] * 60) return ret - def on_neighbor_change(self, world, neighbor_pos, self_pos): + def on_neighbor_change(self, world: custom_types.World, neighbor_pos: iVector, self_pos: iVector): # something has been put on this grass block, which makes it become dirt block - if (self_pos[0], self_pos[1] + 1, self_pos[-1]) in world: + block_above = world.get_block_above(self_pos) + if block_above and not block_above.transparent: world.remove_block(None, self_pos) world.add_block(self_pos, dirt_block) @@ -878,10 +884,7 @@ class TorchBlock(WoodBlock): id = 50 name = "Torch" - def on_neighbor_change(self, world, neighbor_pos, self_pos): - # the block under this torch has been removed, so remove the torch too - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class YFlowersBlock(Block): vertex_mode = G.VERTEX_CROSS @@ -900,9 +903,7 @@ def __init__(self): super(YFlowersBlock, self).__init__() self.texture_data = self.texture_data[0:2 * 4 * 2] - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None,self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class StoneSlabBlock(HardBlock): @@ -1043,9 +1044,9 @@ def __init__(self): super(FarmBlock, self).__init__() self.drop_id = BlockID(DirtBlock.id) - def on_neighbor_change(self, world, neighbor_pos, self_pos): - # replace self with dirt - if (self_pos[0], self_pos[1] + 1, self_pos[-1]) in world: + def on_neighbor_change(self, world: custom_types.World, neighbor_pos: iVector, self_pos: iVector): + block_above = world.get_block_above(self_pos) + if block_above and not block_above.transparent: world.remove_block(None, self_pos) world.add_block(self_pos, dirt_block) @@ -1322,9 +1323,7 @@ def __init__(self): super(RoseBlock, self).__init__() self.texture_data = self.texture_data[0:2 * 4 * 2] - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class ReedBlock(Block): texture_name = "reeds" @@ -1339,9 +1338,7 @@ class ReedBlock(Block): max_stack_size = 16 amount_label_color = 0, 0, 0, 255 - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class CropBlock(Block): top_texture = -1, -1 @@ -1415,9 +1412,7 @@ def update_tile_entity(self, value): if nbt['action'] == 'fertilize': self.entity.fertilize() - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class PotatoBlock(CropBlock): id = 142 @@ -1519,9 +1514,7 @@ def drop_id(self): def drop_id(self, value): self._drop_id = value - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop # More tall grass blocks @@ -1582,9 +1575,7 @@ class DesertGrassBlock(TallGrassBlock): name = "Desert Grass" texture_name = 'wg_red_bush' - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class DeadBushBlock(TallGrassBlock): @@ -1593,9 +1584,7 @@ class DeadBushBlock(TallGrassBlock): name = "Dead bush" texture_name = 'deadbush' - def on_neighbor_change(self, world, neighbor_pos, self_pos): - if (self_pos[0], self_pos[1] - 1, self_pos[-1]) not in world: - world.remove_block(None, self_pos) + on_neighbor_change = Block.generic_on_missing_floor_drop class DiamondBlock(HardBlock):