From 687940e16a7b97e2608822ab6f5dba689a9c177e Mon Sep 17 00:00:00 2001 From: Ben Allison Date: Sat, 20 Apr 2019 17:41:50 -0700 Subject: [PATCH 1/2] Fixed Grass (and thus flowers) being removed if a block is placed next to flowers --- blocks.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blocks.py b/blocks.py index 5f3980f1..16a1a639 100644 --- a/blocks.py +++ b/blocks.py @@ -447,7 +447,8 @@ def get_color(self, temperature, humidity): def on_neighbor_change(self, world, neighbor_pos, self_pos): # 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: + above = (self_pos[0], self_pos[1] + 1, self_pos[2]) + if above in world and not world[above].transparent: world.remove_block(None, self_pos) world.add_block(self_pos, dirt_block) From d1b1a8251abd76005593acb46a128f4e7613d245 Mon Sep 17 00:00:00 2001 From: Ben Allison Date: Sat, 20 Apr 2019 18:22:04 -0700 Subject: [PATCH 2/2] Generalize block on_missing_floor_drop functionality --- blocks.py | 52 ++++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/blocks.py b/blocks.py index 16a1a639..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,10 +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 - above = (self_pos[0], self_pos[1] + 1, self_pos[2]) - if above in world and not world[above].transparent: + 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) @@ -879,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 @@ -901,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): @@ -1044,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) @@ -1323,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" @@ -1340,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 @@ -1416,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 @@ -1520,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 @@ -1583,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): @@ -1594,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):