Skip to content

Fixed Grass (and thus flowers) being removed on block update #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down