mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-26 09:03:43 +02:00
fixed issue with door opening interval
This commit is contained in:
parent
4eb98b467f
commit
ccbaca6ecb
1 changed files with 12 additions and 12 deletions
|
@ -1071,16 +1071,6 @@ function startDoorInterval(bot) {
|
||||||
let prev_check = Date.now();
|
let prev_check = Date.now();
|
||||||
let stuck_time = 0;
|
let stuck_time = 0;
|
||||||
|
|
||||||
// adjacent positions to check for doors
|
|
||||||
const positions = [
|
|
||||||
bot.entity.position.clone(),
|
|
||||||
bot.entity.position.offset(0, 0, 1),
|
|
||||||
bot.entity.position.offset(0, 0, -1),
|
|
||||||
bot.entity.position.offset(1, 0, 0),
|
|
||||||
bot.entity.position.offset(-1, 0, 0),
|
|
||||||
]
|
|
||||||
let elevated_positions = positions.map(position => position.offset(0, 1, 0));
|
|
||||||
positions.push(...elevated_positions);
|
|
||||||
|
|
||||||
const doorCheckInterval = setInterval(() => {
|
const doorCheckInterval = setInterval(() => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
@ -1092,6 +1082,16 @@ function startDoorInterval(bot) {
|
||||||
|
|
||||||
if (stuck_time > 1200) {
|
if (stuck_time > 1200) {
|
||||||
// shuffle positions so we're not always opening the same door
|
// shuffle positions so we're not always opening the same door
|
||||||
|
const positions = [
|
||||||
|
bot.entity.position.clone(),
|
||||||
|
bot.entity.position.offset(0, 0, 1), // north
|
||||||
|
bot.entity.position.offset(0, 0, -1),
|
||||||
|
bot.entity.position.offset(1, 0, 0),
|
||||||
|
bot.entity.position.offset(-1, 0, 0),
|
||||||
|
]
|
||||||
|
let elevated_positions = positions.map(position => position.offset(0, 1, 0));
|
||||||
|
positions.push(...elevated_positions);
|
||||||
|
|
||||||
let currentIndex = positions.length;
|
let currentIndex = positions.length;
|
||||||
while (currentIndex != 0) {
|
while (currentIndex != 0) {
|
||||||
let randomIndex = Math.floor(Math.random() * currentIndex);
|
let randomIndex = Math.floor(Math.random() * currentIndex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue