Mostly works
This commit is contained in:
@@ -400,6 +400,20 @@ class Database {
|
||||
`, [itemName]);
|
||||
}
|
||||
|
||||
// Find chests with available slots, ordered nearest-first from a reference point.
|
||||
// Returns an array of { id, pos_x, pos_y, pos_z, chest_type, empty_slots }.
|
||||
async findNearestChestsWithSpace(neededSlots, refX, refY, refZ) {
|
||||
return await this.db.all(`
|
||||
SELECT c.id, c.pos_x, c.pos_y, c.pos_z, c.chest_type,
|
||||
(CASE WHEN c.chest_type = 'double' THEN 54 ELSE 27 END) - COUNT(s.id) as empty_slots
|
||||
FROM chests c
|
||||
LEFT JOIN shulkers s ON s.chest_id = c.id
|
||||
GROUP BY c.id
|
||||
HAVING empty_slots > 0
|
||||
ORDER BY ((c.pos_x - ?) * (c.pos_x - ?) + (c.pos_y - ?) * (c.pos_y - ?) + (c.pos_z - ?) * (c.pos_z - ?)) ASC
|
||||
`, [refX, refX, refY, refY, refZ, refZ]);
|
||||
}
|
||||
|
||||
// Find a chest slot that doesn't have a shulker (for placing newly crafted ones)
|
||||
async findEmptyChestSlot() {
|
||||
const chests = await this.db.all(`
|
||||
@@ -560,7 +574,7 @@ class Database {
|
||||
// Clear and rebuild from shulker_items
|
||||
await this.db.run('DELETE FROM item_index');
|
||||
await this.db.run(`
|
||||
INSERT INTO item_index (item_id, item_name, total_count, shulker_ids, last_updated)
|
||||
INSERT OR REPLACE INTO item_index (item_id, item_name, total_count, shulker_ids, last_updated)
|
||||
SELECT
|
||||
si.item_id,
|
||||
si.item_name,
|
||||
|
||||
Reference in New Issue
Block a user