Check immediate support under neighboring sand

This commit is contained in:
Tanner committed 2026-11-17 16:26:14 +00:00
1 parent 142381d40f
commit e50b9dc697
2 files changed
+38 -3

No files matched your search

+28 -3
View File
@@ -789,6 +789,18 @@ class World:
return False
return True
def _sand_has_immediate_support(self, position):
support_pos = utils.padd(position, path.BLOCK_BELOW)
support = self.block_at(*support_pos)
if support is None:
return False, 'support under sand at {} is not loaded'.format(
support_pos)
if support in blocks.NON_SOLID_IDS:
name = blocks.BLOCKS.get(support, 'non-solid block')
return False, 'sand at {} is unsupported: {} immediately below at {}'.format(
position, name, support_pos)
return True, None
def sand_safety(self, position):
"""Return whether a sand block is safe to dig and the reason."""
position = tuple(int(value) for value in position)
@@ -819,15 +831,28 @@ class World:
return False, 'block above at {} is {} (needs headroom)'.format(
above_pos, name)
for direction in path.CHECK_DIRECTIONS:
adjacent_pos = utils.padd(position, direction)
adjacent_positions = [
utils.padd(position, direction)
for direction in path.CHECK_DIRECTIONS
]
adjacent_positions.append(utils.padd(position, path.BLOCK_BELOW))
for adjacent_pos in adjacent_positions:
adjacent = self.block_at(*adjacent_pos)
if adjacent is None:
return False, 'adjacent block at {} is not loaded'.format(
adjacent_pos)
if adjacent in blocks.AVOID_IDS:
name = blocks.BLOCKS.get(adjacent, 'hazard block')
return False, 'unsafe adjacent {} at {}'.format(
name, adjacent_pos)
if adjacent == blocks.SAND:
supported, reason = self._sand_has_immediate_support(
adjacent_pos)
if not supported:
return False, reason
return True, 'solid support below, headroom above, no adjacent hazards'
return (True, 'solid support below, headroom above, adjacent sand '
'supported, no hazards')
def find_sand(self, center, distance, player):
sand = []