Don't pick up bed items near other bots
This commit is contained in:
1 parent
032b4cfd33
commit
185cefced9
4 files changed
+142
-1
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import importlib
|
||||
import collections
|
||||
import re
|
||||
from math import floor, ceil, sqrt
|
||||
|
||||
from mosfet.info import blocks
|
||||
@@ -23,6 +24,44 @@ def pmul(p, s):
|
||||
def phyp(p1, p2):
|
||||
return hypot(p1[0] - p2[0], p1[1] - p2[1], p1[2] - p2[2])
|
||||
|
||||
|
||||
def bot_name_family(name):
|
||||
"""Return a bot username with all digits removed, case-insensitively."""
|
||||
return re.sub(r'\d', '', str(name)).casefold()
|
||||
|
||||
|
||||
def find_nearby_bots(global_state, position, distance):
|
||||
"""Find nearby online bots sharing this bot's digits-stripped name."""
|
||||
own_name = str(global_state.get('name', '') or '')
|
||||
family = bot_name_family(own_name)
|
||||
if not family:
|
||||
return []
|
||||
|
||||
names = global_state.get('player_names') or {}
|
||||
players = global_state.get('players') or {}
|
||||
result = []
|
||||
for entity_id, player in players.items():
|
||||
player_uuid = str(player.get('player_uuid', '') or '')
|
||||
name = (player.get('name') or names.get(player_uuid) or
|
||||
names.get(player_uuid.casefold()))
|
||||
if not name:
|
||||
continue
|
||||
name = str(name)
|
||||
if (name.casefold() == own_name.casefold() or
|
||||
bot_name_family(name) != family):
|
||||
continue
|
||||
player_position = (player.x, player.y, player.z)
|
||||
player_distance = phyp(position, player_position)
|
||||
if player_distance <= distance:
|
||||
result.append({
|
||||
'entity_id': entity_id,
|
||||
'name': name,
|
||||
'position': player_position,
|
||||
'distance': player_distance,
|
||||
})
|
||||
result.sort(key=lambda bot: (bot['distance'], bot['name']))
|
||||
return result
|
||||
|
||||
def phyp_bias(p1, p2, origin):
|
||||
origin_distance = phyp(origin, p2)
|
||||
height_diff = p2[1] - p1[1]
|
||||
|
||||
Reference in new issue
Block a user