Align bed placement along supported lanes
This commit is contained in:
1 parent
243e34e26f
commit
1b4f32060d
5 files changed
+208
-75
No files matched your search
+45
-35
@@ -1,5 +1,6 @@
|
||||
import collections
|
||||
import json
|
||||
from collections import namedtuple
|
||||
import re
|
||||
import time
|
||||
import random
|
||||
@@ -15,6 +16,7 @@ from mosfet.info import mobs
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
CHEST_OPENING_RADIUS = 3
|
||||
BedArea = namedtuple('BedArea', 'foot head opening facing')
|
||||
|
||||
|
||||
class World:
|
||||
@@ -479,51 +481,59 @@ class World:
|
||||
|
||||
return navpath
|
||||
|
||||
def find_bed_areas(self, center, distance):
|
||||
"""Yield nearby two-block bed footprints on solid, safe ground."""
|
||||
# Only search loaded-neighborhood distance. The old 3-D flood fill
|
||||
# explored millions of air blocks and used overly broad 5x5 clearance.
|
||||
def find_bed_areas(self, center, distance, include_layout=False):
|
||||
"""Find bed lanes with a stand tile and two supported bed tiles.
|
||||
|
||||
The three-block lane is ordered from the standing tile toward the bed
|
||||
head. Default callers receive the standing tile; placement callers can
|
||||
request the full layout to retain its intended facing.
|
||||
"""
|
||||
center = tuple(center)
|
||||
distance = min(distance, 32)
|
||||
headroom = path.BLOCK_ABOVE
|
||||
support = path.BLOCK_BELOW
|
||||
seen = set()
|
||||
for offset in utils.search_2d(distance):
|
||||
if utils.hypot(offset[0], offset[2]) > distance:
|
||||
continue
|
||||
for dy in (0, 1, -1, 2, -2):
|
||||
area = (center[0] + offset[0], center[1] + dy,
|
||||
center[2] + offset[2])
|
||||
if area == center:
|
||||
opening = (center[0] + offset[0], center[1] + dy,
|
||||
center[2] + offset[2])
|
||||
if opening == center:
|
||||
continue
|
||||
if self.block_at(*area) != blocks.AIR:
|
||||
continue
|
||||
if self.block_at(*utils.padd(area, headroom)) != blocks.AIR:
|
||||
continue
|
||||
support_block = self.block_at(*utils.padd(area, support))
|
||||
if (support_block is None or
|
||||
support_block in blocks.NON_SOLID_IDS or
|
||||
support_block in blocks.AVOID_IDS):
|
||||
continue
|
||||
|
||||
footprint_found = False
|
||||
for direction in path.CHECK_DIRECTIONS:
|
||||
head = utils.padd(area, direction)
|
||||
if (self.block_at(*head) != blocks.AIR or
|
||||
self.block_at(*utils.padd(head, headroom)) != blocks.AIR):
|
||||
for facing in path.CHECK_DIRECTIONS:
|
||||
foot = utils.padd(opening, facing)
|
||||
head = utils.padd(foot, facing)
|
||||
lane = (opening, foot, head)
|
||||
if lane in seen:
|
||||
continue
|
||||
head_support = self.block_at(*utils.padd(head, support))
|
||||
if (head_support is None or
|
||||
head_support in blocks.NON_SOLID_IDS or
|
||||
head_support in blocks.AVOID_IDS):
|
||||
continue
|
||||
footprint_found = True
|
||||
break
|
||||
if not footprint_found:
|
||||
continue
|
||||
seen.add(lane)
|
||||
|
||||
# Avoid placing a bed within range of nearby monsters.
|
||||
if self.find_monsters(area, 20):
|
||||
continue
|
||||
yield area
|
||||
valid = True
|
||||
for index, position in enumerate(lane):
|
||||
if self.block_at(*position) != blocks.AIR:
|
||||
valid = False
|
||||
break
|
||||
if self.block_at(*utils.padd(position, headroom)) != blocks.AIR:
|
||||
valid = False
|
||||
break
|
||||
support_block = self.block_at(*utils.padd(position, support))
|
||||
if (support_block is None or
|
||||
support_block in blocks.NON_SOLID_IDS or
|
||||
support_block in blocks.AVOID_IDS):
|
||||
valid = False
|
||||
break
|
||||
if (index == 0 and self.block_at(*utils.padd(
|
||||
position, path.BLOCK_ABOVE2)) != blocks.AIR):
|
||||
valid = False
|
||||
break
|
||||
if not valid or self.find_monsters(foot, 20):
|
||||
continue
|
||||
|
||||
if include_layout:
|
||||
yield BedArea(foot, head, opening, facing)
|
||||
else:
|
||||
yield opening
|
||||
|
||||
def find_cache_areas(self, center, distance):
|
||||
"""Yield nearby, supported air blocks suitable for placing a chest."""
|
||||
|
||||
Reference in new issue
Block a user