Work in progress

This commit is contained in:
Andrew Miner
2026-10-12 09:38:56 -06:00
parent 331b135544
commit a7a9164e1f
5 changed files with 144 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
.DS_Store
+1
View File
@@ -0,0 +1 @@
unused_args = false
+16
View File
@@ -0,0 +1,16 @@
Copyright (c) 2026, Andrew Miner
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+122
View File
@@ -0,0 +1,122 @@
-- Imports -----------------------------------------------------------------------------------------
local core = _G["core"]
local dump2 = _G["dump2"]
local ItemStack = _G["ItemStack"]
local math = _G["math"]
local table = _G["table"]
-- Constants ---------------------------------------------------------------------------------------
local MAIN = "main"
local HOTBAR_SIZE = 9
-- Local Functions ---------------------------------------------------------------------------------
local function consolidate_stacks(stacks)
local result = {}
for stack in stacks do
local remaining = stack.get_count()
local item_def = core.registered_items[stack.get_name()]
if item_def == nil then goto continue end
if item_def.stack_max == nil then goto continue end
for existing in result do
if stack.get_name() == existing.get_name() then
local available = item_def.stack_max - existing.get_count()
if available > 0 then
local allocate = math.min(stack.get_count(), available)
existing.set_count(existing.get_count() + allocate)
remaining = remaining - allocate
if remaining == 0 then break end
end
end
end
::continue::
end
return result
end
local function extract_node_inventory(inventory)
-- TODO: implement this
end
local function extract_player_inventory(player)
local inventory = player:get_inventory()
if inventory == nil then return end
local result = {}
local max_slots = inventory:get_size(MAIN)
for index in HOTBAR_SIZE+1, max_slots do
local stack = inventory:get_stack(MAIN, index)
if stack ~= nil then
table.insert(result, stack)
end
end
end
local function is_inventory_node(item_def)
if item_def.allow_metadata_inventory_move then return true end
if item_def.allow_metadata_inventory_put then return true end
if item_def.allow_metadata_inventory_take then return true end
return false
end
local function sort_node_inventory(inventory)
local stacks = extract_node_inventory(inventory)
-- TODO: implement this
end
local function sort_player_inventory(player)
local stacks = extract_player_inventory(player:get_inventory())
-- TODO: implement this
end
local function watch_node_inventory(node_def)
local old_omi_move = node_def.on_metadata_inventory_move
local old_omi_put = node_def.on_metadata_inventory_put
local old_omi_take = node_def.on_metadata_inventory_take
core.override_item(node_def.name, {
on_metadata_inventory_move = (function(pos, from_list, from_index, to_list, count, player)
old_omi_move(pos, from_list, from_index, to_list, count, player)
sort_node_inventory(core.get_inventory(pos))
end),
on_metadata_inventory_put = (function(pos, listname, index, stack, player)
old_omi_put(pos, listname, index, stack, player)
sort_node_inventory(core.get_inventory(pos))
end),
on_metadata_inventory_take = (function(pos, listname, index, stack, player)
old_omi_take(pos, listname, index, stack, player)
sort_node_inventory(core.get_inventory(pos))
end)
})
end
-- Registrations -----------------------------------------------------------------------------------
core.register_on_joinplayer(function(player, last_login)
sort_player_inventory(player)
end)
core.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
sort_player_inventory(player)
end)
core.register_on_item_eat(function(hp_change, replace_with_item, itemstack, player, pointed_thing)
sort_player_inventory(player)
end)
core.register_on_mods_loaded(function()
for node_def in core.registered_nodes do
if not is_inventory_node(node_def) then goto continue end
watch_node_inventory(node_def)
::continue::
end
end)
+4
View File
@@ -0,0 +1,4 @@
name = tungstonminer_sort
title = Tungston's Inventory Sort
description = Sort the current inventory with Aux1
author = tungstonminer