fixed filtering
still has inventory fragmentaition issue
This commit is contained in:
parent
7d2d85169f
commit
48fc623785
2 changed files with 11 additions and 7 deletions
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
use rstar::{self, AABB};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use crate::{blocks::{Position, Vec3, Block, Direction}, turtle::{TurtleTask, Iota, self, Turtle, TurtleCommand, TurtleCommander, TurtleCommandResponse, InventorySlot}};
|
||||
use crate::{blocks::{Position, Vec3, Block, Direction}, turtle::{TurtleTask, Iota, self, Turtle, TurtleCommand, TurtleCommander, TurtleCommandResponse, InventorySlot}, paths::TRANSPARENT};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct TurtleMineJobParams {
|
||||
|
@ -154,8 +154,11 @@ pub async fn mine(turtle: TurtleCommander, pos: Vec3, fuel: Position, storage: P
|
|||
valuables.append(&mut near_valuables(&turtle, pos, chunk).await);
|
||||
|
||||
while let Some(block) = valuables.pop() {
|
||||
if turtle.world().get(block).await.is_none() {
|
||||
continue;
|
||||
}
|
||||
let near = turtle.goto_adjacent(block).await?;
|
||||
turtle.execute(dbg!(near.dig(block))?).await;
|
||||
turtle.execute(near.dig(block)?).await;
|
||||
observe(turtle.clone(), block).await;
|
||||
valuables.append(&mut near_valuables(&turtle, near.pos, Vec3::new(2,2,2)).await);
|
||||
}
|
||||
|
@ -166,7 +169,7 @@ pub async fn mine(turtle: TurtleCommander, pos: Vec3, fuel: Position, storage: P
|
|||
refuel(turtle.clone()).await;
|
||||
}
|
||||
|
||||
if dump_filter(turtle.clone(), |i| USELESS.iter().any(|u| **u == i.name)).await > 13 {
|
||||
if dump_filter(turtle.clone(), |i| USELESS.iter().any(|u| **u == i.name)).await > 12 {
|
||||
println!("storage rtb");
|
||||
turtle.goto(storage).await?;
|
||||
dump(turtle.clone()).await;
|
||||
|
@ -189,13 +192,13 @@ pub async fn mine_chunk(turtle: TurtleCommander, pos: Vec3, chunk: Vec3) -> Opti
|
|||
let volume = chunk.x * chunk.y * chunk.z;
|
||||
|
||||
for n in (0..volume).map(|n| fill(chunk, n) + pos) {
|
||||
if turtle.world().get(n).await.is_some_and(|b| b.name == "minecraft:air") {
|
||||
if turtle.world().get(n).await.is_some_and(|b| TRANSPARENT.contains(&b.name.as_str())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let near = turtle.goto_adjacent(n).await?;
|
||||
|
||||
turtle.execute(dbg!(near.dig(n))?).await;
|
||||
turtle.execute(near.dig(n)?).await;
|
||||
|
||||
}
|
||||
Some(())
|
||||
|
@ -234,8 +237,9 @@ async fn dump_filter<F>(turtle: TurtleCommander, mut filter: F) -> u32
|
|||
where F: FnMut(InventorySlot) -> bool {
|
||||
let mut counter = 0;
|
||||
for i in 1..=16 {
|
||||
if let TurtleCommandResponse::Item(item) = turtle.execute(Select(i)).await.ret {
|
||||
if let TurtleCommandResponse::Item(item) = turtle.execute(ItemInfo(i)).await.ret {
|
||||
if filter(item) {
|
||||
turtle.execute(Select(i)).await;
|
||||
turtle.execute(DropFront(64)).await;
|
||||
} else {
|
||||
counter += 1;
|
||||
|
|
|
@ -259,7 +259,7 @@ impl TurtleCommander {
|
|||
'route: for (next_position, command) in route.into_iter().skip(1).zip(steps) {
|
||||
if world.occupied(next_position.pos).await {
|
||||
if world.garbage(next_position.pos).await {
|
||||
let command = dbg!(recent.dig(next_position.pos));
|
||||
let command = recent.dig(next_position.pos);
|
||||
match command {
|
||||
Some(command) => self.execute(command).await,
|
||||
None => break 'route,
|
||||
|
|
Loading…
Reference in a new issue