mirror of
https://github.com/theFox6/microexpansion.git
synced 2024-11-25 00:24:02 +01:00
fixed varous item vanishing bugs
This commit is contained in:
parent
4c5b36fc88
commit
482eb7bebd
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
|||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2017 Elijah Duffy
|
Copyright (c) 2019-2020 theFox6
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
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
|
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
|
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
18
README.md
18
README.md
@ -4,12 +4,16 @@ MicroExpansion - ME [microexpansion]
|
|||||||
======================================
|
======================================
|
||||||
|
|
||||||
* **Licence:** Code: MIT (see LICENSE), Media: CC-BY-SA 3.0
|
* **Licence:** Code: MIT (see LICENSE), Media: CC-BY-SA 3.0
|
||||||
* [Github Repository](https://github.com/octacian/microexpansion)
|
|
||||||
* **Downloads:**
|
|
||||||
* [Master (Unstable)](https://github.com/octacian/microexpansion/archive/master.zip)
|
|
||||||
* ...or browse the code on [GitHub](https://github.com/octacian/microexpansion)
|
|
||||||
|
|
||||||
When you really get into a survival world, you typically end up with a lot of items, like a ton of items. Sometimes literally. But with that huge amount of resources, comes something annoying and typically unwanted: chests. Well, of course. You have to have chests to store items, but no biggie, it's just chests. Then your storage room starts to grow, soon you have 25 chests, then 50, then 100. Management gets kinda hard. MicroExpansion, is the solution.
|
When you really get into a survival world, you typically end up with a lot of items, like a ton of items.
|
||||||
|
Sometimes literally.
|
||||||
|
But with that huge amount of resources, comes something annoying and typically unwanted: chests.
|
||||||
|
Well, of course. You have to have chests to store items, but no biggie, it's just chests.
|
||||||
|
Then your storage room starts to grow, soon you have 25 chests, then 50, then 100.
|
||||||
|
When management gets too hard. MicroExpansion, is the solution.
|
||||||
|
|
||||||
Remade by theFox, original mod by octacian.
|
Forked and continued by theFox6 from the original mod by octacian.
|
||||||
Originally inspired by Applied Energistics 2 for Minecraft, MicroExpansion introduces many new nodes and items giving the player simpler and more compact ways to store thousands of items inside of a single ME drive.
|
[Original Repository](https://github.com/octacian/microexpansion)
|
||||||
|
Original license: MIT
|
||||||
|
This mod was inspired by Applied Energistics 2 for Minecraft
|
||||||
|
MicroExpansion introduces many new nodes and items giving the player simpler and more compact ways to store thousands of items inside of a single ME drive.
|
||||||
|
@ -3,11 +3,7 @@ me.networks = {}
|
|||||||
local networks = me.networks
|
local networks = me.networks
|
||||||
local path = microexpansion.get_module_path("network")
|
local path = microexpansion.get_module_path("network")
|
||||||
|
|
||||||
function me.insert_item(stack, inv, listname)
|
local function split_stack_values(stack)
|
||||||
if me.settings.huge_stacks == false then
|
|
||||||
inv:add_item(listname, stack)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local stack_name
|
local stack_name
|
||||||
local stack_count
|
local stack_count
|
||||||
if type(stack) == "string" then
|
if type(stack) == "string" then
|
||||||
@ -22,6 +18,14 @@ function me.insert_item(stack, inv, listname)
|
|||||||
stack_name = stack:get_name()
|
stack_name = stack:get_name()
|
||||||
stack_count = stack:get_count()
|
stack_count = stack:get_count()
|
||||||
end
|
end
|
||||||
|
return stack_name, stack_count
|
||||||
|
end
|
||||||
|
|
||||||
|
function me.insert_item(stack, inv, listname)
|
||||||
|
if me.settings.huge_stacks == false then
|
||||||
|
return inv:add_item(listname, stack)
|
||||||
|
end
|
||||||
|
local stack_name,stack_count = split_stack_values(stack)
|
||||||
local found = false
|
local found = false
|
||||||
for i = 0, inv:get_size(listname) do
|
for i = 0, inv:get_size(listname) do
|
||||||
local inside = inv:get_stack(listname, i)
|
local inside = inv:get_stack(listname, i)
|
||||||
@ -40,7 +44,7 @@ function me.insert_item(stack, inv, listname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not found then
|
if not found then
|
||||||
inv:add_item(listname, stack)
|
return inv:add_item(listname, stack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ local network = {
|
|||||||
power_load = 0,
|
power_load = 0,
|
||||||
power_storage = 0
|
power_storage = 0
|
||||||
}
|
}
|
||||||
microexpansion.network = network
|
local me = microexpansion
|
||||||
|
me.network = network
|
||||||
|
|
||||||
--- construct a new network
|
--- construct a new network
|
||||||
-- @function [parent=#network] new
|
-- @function [parent=#network] new
|
||||||
@ -30,7 +31,7 @@ function network.can_connect(np)
|
|||||||
if np.name then
|
if np.name then
|
||||||
nn = np.name
|
nn = np.name
|
||||||
else
|
else
|
||||||
local node = microexpansion.get_node(np)
|
local node = me.get_node(np)
|
||||||
nn = node.name
|
nn = node.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -55,7 +56,7 @@ function network.adjacent_connected_nodes(pos, include_ctrl)
|
|||||||
local nodes = {}
|
local nodes = {}
|
||||||
|
|
||||||
for _,apos in pairs(adjacent) do
|
for _,apos in pairs(adjacent) do
|
||||||
local napos = microexpansion.get_node(apos)
|
local napos = me.get_node(apos)
|
||||||
local nn = napos.name
|
local nn = napos.name
|
||||||
if network.can_connect(nn) then
|
if network.can_connect(nn) then
|
||||||
if include_ctrl == false then
|
if include_ctrl == false then
|
||||||
@ -123,7 +124,7 @@ local function get_drive_capacity(pos)
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
for i = 1, inv:get_size("main") do
|
for i = 1, inv:get_size("main") do
|
||||||
cap = cap + microexpansion.get_cell_size(inv:get_stack("main", i):get_name())
|
cap = cap + me.get_cell_size(inv:get_stack("main", i):get_name())
|
||||||
end
|
end
|
||||||
return cap
|
return cap
|
||||||
end
|
end
|
||||||
@ -133,8 +134,8 @@ end
|
|||||||
-- @return #number the total number of items that can be stored in the network
|
-- @return #number the total number of items that can be stored in the network
|
||||||
function network:get_item_capacity()
|
function network:get_item_capacity()
|
||||||
local cap = 0
|
local cap = 0
|
||||||
for npos in microexpansion.connected_nodes(self.controller_pos) do
|
for npos in me.connected_nodes(self.controller_pos) do
|
||||||
if microexpansion.get_node(npos).name == "microexpansion:drive" then
|
if me.get_node(npos).name == "microexpansion:drive" then
|
||||||
cap = cap + get_drive_capacity(npos)
|
cap = cap + get_drive_capacity(npos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -142,7 +143,22 @@ function network:get_item_capacity()
|
|||||||
return cap
|
return cap
|
||||||
end
|
end
|
||||||
|
|
||||||
function network:add_storage_slots(count,listname)
|
local function remove_slots(inv,ln,target,csize)
|
||||||
|
for i = target, csize do
|
||||||
|
local s = inv:get_stack(ln,i)
|
||||||
|
if not s:is_empty() then
|
||||||
|
inv:set_stack(ln, i, "")
|
||||||
|
me.insert_item(s, inv, ln)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
--perhaps allow list removal
|
||||||
|
if target < 0 then
|
||||||
|
target = 1
|
||||||
|
end
|
||||||
|
inv:set_size(ln, target)
|
||||||
|
end
|
||||||
|
|
||||||
|
function network:set_storage_space(count,listname)
|
||||||
local c = count or 1
|
local c = count or 1
|
||||||
local ln = listname or "main"
|
local ln = listname or "main"
|
||||||
local inv = self:get_inventory()
|
local inv = self:get_inventory()
|
||||||
@ -167,18 +183,17 @@ function network:add_storage_slots(count,listname)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local needed = c - space
|
local needed = c - space
|
||||||
needed = needed + csize
|
if needed > 0 then
|
||||||
--TODO allow list removal
|
needed = needed + csize
|
||||||
if needed == 0 then
|
inv:set_size(ln, needed)
|
||||||
needed = 1
|
elseif needed < 0 then
|
||||||
|
needed = needed + csize
|
||||||
|
remove_slots(inv,ln,needed,csize)
|
||||||
end
|
end
|
||||||
inv:set_size(ln, needed)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--FIXME: add size removal function because items are removed when size decreases
|
|
||||||
|
|
||||||
function network:update()
|
function network:update()
|
||||||
self:add_storage_slots(true)
|
self:set_storage_space(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function network:get_inventory_name()
|
function network:get_inventory_name()
|
||||||
@ -217,14 +232,14 @@ local function create_inventory(net)
|
|||||||
end,
|
end,
|
||||||
on_put = function(inv, listname, _, stack)
|
on_put = function(inv, listname, _, stack)
|
||||||
inv:remove_item(listname, stack)
|
inv:remove_item(listname, stack)
|
||||||
microexpansion.insert_item(stack, inv, listname)
|
me.insert_item(stack, inv, listname)
|
||||||
net:add_storage_slots(true)
|
net:set_storage_space(true)
|
||||||
end,
|
end,
|
||||||
allow_take = function(_, _, _, stack)
|
allow_take = function(_, _, _, stack)
|
||||||
return math.min(stack:get_count(),stack:get_stack_max())
|
return math.min(stack:get_count(),stack:get_stack_max())
|
||||||
end,
|
end,
|
||||||
on_take = function()
|
on_take = function()
|
||||||
net:add_storage_slots(true)
|
net:set_storage_space(true)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -51,18 +51,36 @@ function microexpansion.int_to_pagenum(int)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- [function] Move items from inv to inv
|
-- [function] Move items from inv to inv
|
||||||
function microexpansion.move_inv(inv1, inv2)
|
function microexpansion.move_inv(inv1, inv2, max)
|
||||||
local finv, tinv = inv1.inv, inv2.inv
|
if max <= 0 then return end
|
||||||
local fname, tname = inv1.name, inv2.name
|
local finv, tinv = inv1.inv, inv2.inv
|
||||||
|
local fname, tname = inv1.name, inv2.name
|
||||||
|
local huge = inv2.huge
|
||||||
|
local inserted = 0
|
||||||
|
|
||||||
--FIXME only as many as allowed in a drive
|
for _,v in ipairs(finv:get_list(fname) or {}) do
|
||||||
for _,v in ipairs(finv:get_list(fname) or {}) do
|
local left = max-inserted
|
||||||
if tinv and tinv:room_for_item(tname, v) then
|
if left <= 0 then
|
||||||
local leftover = tinv:add_item( tname, v )
|
break;
|
||||||
finv:remove_item(fname, v)
|
end
|
||||||
if leftover and not(leftover:is_empty()) then
|
if not v:is_empty() then
|
||||||
finv:add_item(fname, v)
|
if v:get_count() > left then
|
||||||
end
|
v = v:peek_item(left)
|
||||||
|
end
|
||||||
|
if tinv and tinv:room_for_item(tname, v) then
|
||||||
|
if huge then
|
||||||
|
microexpansion.insert_item(v, tinv, tname)
|
||||||
|
finv:remove_item(fname, v)
|
||||||
|
else
|
||||||
|
local leftover = tinv:add_item(tname, v)
|
||||||
|
finv:remove_item(fname, v)
|
||||||
|
if leftover and not(leftover:is_empty()) then
|
||||||
|
minetest.log("warning","leftover items when transfering inventory")
|
||||||
|
finv:add_item(fname, leftover)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
inserted = inserted + v:get_count()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -80,7 +80,7 @@ microexpansion.register_node("drive", {
|
|||||||
me.update_connected_machines(pos)
|
me.update_connected_machines(pos)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
network:add_storage_slots(#items)
|
network:set_storage_space(#items)
|
||||||
for _,s in pairs(items) do
|
for _,s in pairs(items) do
|
||||||
me.insert_item(s, ctrl_inv, "main")
|
me.insert_item(s, ctrl_inv, "main")
|
||||||
end
|
end
|
||||||
@ -114,10 +114,10 @@ microexpansion.register_node("drive", {
|
|||||||
if stack_name ~= "" then
|
if stack_name ~= "" then
|
||||||
local item_count = stack_inside:get_count()
|
local item_count = stack_inside:get_count()
|
||||||
while item_count ~= 0 and cell_idx ~= nil do
|
while item_count ~= 0 and cell_idx ~= nil do
|
||||||
|
--print(("stack to store: %s %i"):format(stack_name,item_count))
|
||||||
if size < items_in_cell_count + item_count then
|
if size < items_in_cell_count + item_count then
|
||||||
local space = size - items_in_cell_count
|
local space = size - items_in_cell_count
|
||||||
item_count = item_count - space
|
table.insert(cell_items,("%s %i"):format(stack_name,space))
|
||||||
table.insert(cell_items,stack_name.." "..space)
|
|
||||||
items_in_cell_count = items_in_cell_count + space
|
items_in_cell_count = items_in_cell_count + space
|
||||||
|
|
||||||
own_inv:set_stack("main", cell_idx, write_to_cell(cells[cell_idx],cell_items,items_in_cell_count))
|
own_inv:set_stack("main", cell_idx, write_to_cell(cells[cell_idx],cell_items,items_in_cell_count))
|
||||||
@ -125,13 +125,14 @@ microexpansion.register_node("drive", {
|
|||||||
size = microexpansion.get_cell_size(cells[cell_idx]:get_name())
|
size = microexpansion.get_cell_size(cells[cell_idx]:get_name())
|
||||||
items_in_cell_count = 0
|
items_in_cell_count = 0
|
||||||
cell_items = {}
|
cell_items = {}
|
||||||
|
item_count = item_count - space
|
||||||
if cell_idx == nil then
|
if cell_idx == nil then
|
||||||
--there may be other drives within the network
|
--there may be other drives within the network
|
||||||
minetest.log("info","too many items to store in drive")
|
minetest.log("info","too many items to store in drive")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
items_in_cell_count = items_in_cell_count + item_count
|
items_in_cell_count = items_in_cell_count + item_count
|
||||||
table.insert(cell_items,stack_inside:to_string())
|
table.insert(cell_items, ("%s %i"):format(stack_name,item_count))
|
||||||
item_count = 0
|
item_count = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -165,7 +166,7 @@ microexpansion.register_node("drive", {
|
|||||||
--this returns 99 (max count) even if it removes more
|
--this returns 99 (max count) even if it removes more
|
||||||
ctrl_inv:remove_item("main", ostack)
|
ctrl_inv:remove_item("main", ostack)
|
||||||
end
|
end
|
||||||
print(stack:to_string())
|
--print(stack:to_string())
|
||||||
|
|
||||||
network:update()
|
network:update()
|
||||||
me.update_connected_machines(pos)
|
me.update_connected_machines(pos)
|
||||||
|
@ -191,9 +191,16 @@ microexpansion.register_node("term", {
|
|||||||
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
|
meta:set_string("formspec", chest_formspec(pos, 1, "main", page_max))
|
||||||
elseif fields.tochest then
|
elseif fields.tochest then
|
||||||
local pinv = minetest.get_inventory({type="player", name=sender:get_player_name()})
|
local pinv = minetest.get_inventory({type="player", name=sender:get_player_name()})
|
||||||
net:add_storage_slots(pinv:get_size("main"))
|
net:set_storage_space(pinv:get_size("main"))
|
||||||
microexpansion.move_inv({ inv=pinv, name="main" }, { inv=ctrl_inv, name="main" })
|
local space = net:get_item_capacity()
|
||||||
net:add_storage_slots(true)
|
local contents = ctrl_inv:get_list("main") or {}
|
||||||
|
for _,s in pairs(contents) do
|
||||||
|
if not s:is_empty() then
|
||||||
|
space = space - s:get_count()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
microexpansion.move_inv({ inv=pinv, name="main" }, { inv=ctrl_inv, name="main",huge=true }, space)
|
||||||
|
net:set_storage_space(true)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user