Mod cleanup
This commit is contained in:
parent
91cec3f12d
commit
18051c638f
|
@ -1,99 +0,0 @@
|
||||||
-- Combine stacks into a new list
|
|
||||||
local function compress_list(list)
|
|
||||||
local items = {}
|
|
||||||
local new_list = {}
|
|
||||||
for i, stack in pairs(list or {}) do
|
|
||||||
if not stack:is_empty() then
|
|
||||||
if stack:get_stack_max() == 1 then
|
|
||||||
table.insert(new_list, stack)
|
|
||||||
else
|
|
||||||
items[stack:get_name()] = (items[stack:get_name()] or 0)
|
|
||||||
+ stack:get_count()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for name, count in pairs(items) do
|
|
||||||
local max = ItemStack(name):get_stack_max()
|
|
||||||
|
|
||||||
repeat
|
|
||||||
local take = math.min(max, count)
|
|
||||||
local stack = ItemStack(name)
|
|
||||||
stack:set_count(take)
|
|
||||||
table.insert(new_list, stack)
|
|
||||||
count = count - take
|
|
||||||
until count == 0
|
|
||||||
end
|
|
||||||
return new_list
|
|
||||||
end
|
|
||||||
|
|
||||||
local function list_add_list(inv, list_name, list)
|
|
||||||
local leftover_list = {}
|
|
||||||
for i, stack in pairs(list or {}) do
|
|
||||||
local leftover = inv:add_item(list_name, stack)
|
|
||||||
if not leftover:is_empty() then
|
|
||||||
table.insert(leftover_list, leftover)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if #leftover_list > 0 then
|
|
||||||
minetest.log("warning", "[exchange_shop] List " .. list_name
|
|
||||||
.. " is full. Possible item loss!")
|
|
||||||
end
|
|
||||||
return leftover_list
|
|
||||||
end
|
|
||||||
|
|
||||||
function exchange_shop.migrate_shop_node(pos, node)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local owner = meta:get_string("owner")
|
|
||||||
local title = meta:get_string("infotext")
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
local def = minetest.registered_nodes[exchange_shop.shopname]
|
|
||||||
|
|
||||||
-- Create new slots
|
|
||||||
def.on_construct(pos)
|
|
||||||
meta:set_string("owner", owner)
|
|
||||||
meta:set_string("infotext", title)
|
|
||||||
|
|
||||||
list_add_list(inv, "custm", inv:get_list("customers_gave"))
|
|
||||||
inv:set_size("customers_gave", 0)
|
|
||||||
|
|
||||||
local new_owner_gives = compress_list(inv:get_list("owner_gives"))
|
|
||||||
local new_owner_wants = compress_list(inv:get_list("owner_wants"))
|
|
||||||
local dst_gives = "cust_og"
|
|
||||||
local dst_wants = "cust_ow"
|
|
||||||
if #new_owner_gives > 4 or #new_owner_wants > 4 then
|
|
||||||
-- Not enough space (from 6 slots to 4)
|
|
||||||
-- redirect everything to the stock
|
|
||||||
dst_gives = "stock"
|
|
||||||
dst_wants = "custm"
|
|
||||||
end
|
|
||||||
list_add_list(inv, dst_gives, new_owner_gives)
|
|
||||||
list_add_list(inv, dst_wants, new_owner_wants)
|
|
||||||
|
|
||||||
inv:set_size("owner_gives", 0)
|
|
||||||
inv:set_size("owner_takes", 0)
|
|
||||||
|
|
||||||
node.name = exchange_shop.shopname
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
end
|
|
||||||
|
|
||||||
if exchange_shop.migrate.use_lbm then
|
|
||||||
minetest.register_lbm({
|
|
||||||
label = "currency shop to exchange shop migration",
|
|
||||||
name = "exchange_shop:currency_migrate",
|
|
||||||
nodenames = { "currency:shop" },
|
|
||||||
run_at_every_load = false,
|
|
||||||
action = exchange_shop.migrate_shop_node
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Clean up garbage
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
for i, name in pairs({"customer_gives", "customer_gets"}) do
|
|
||||||
if inv:get_size(name) > 0 then
|
|
||||||
local leftover = list_add_list(inv, "main", inv:get_list(name))
|
|
||||||
list_add_list(inv, "craft", leftover)
|
|
||||||
inv:set_size(name, 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
|
@ -1,20 +0,0 @@
|
||||||
|
|
||||||
minetest.override_item("currency:shop", {
|
|
||||||
on_construct = function() end,
|
|
||||||
after_place_node = function(pos, ...)
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
node.name = exchange_shop.shopname
|
|
||||||
minetest.swap_node(pos, node)
|
|
||||||
|
|
||||||
local new_def = minetest.registered_nodes[exchange_shop.shopname]
|
|
||||||
if new_def.on_construct then
|
|
||||||
new_def.on_construct(pos)
|
|
||||||
end
|
|
||||||
new_def.after_place_node(pos, unpack({...}))
|
|
||||||
end,
|
|
||||||
on_rightclick = function(pos, node, ...)
|
|
||||||
exchange_shop.migrate_shop_node(pos, node)
|
|
||||||
local new_def = minetest.registered_nodes[exchange_shop.shopname]
|
|
||||||
new_def.on_rightclick(pos, node, unpack({...}))
|
|
||||||
end
|
|
||||||
})
|
|
34
init.lua
34
init.lua
|
@ -6,44 +6,12 @@ exchange_shop = {}
|
||||||
exchange_shop.storage_size = 5 * 4
|
exchange_shop.storage_size = 5 * 4
|
||||||
exchange_shop.shopname = "exchange_shop:shop"
|
exchange_shop.shopname = "exchange_shop:shop"
|
||||||
|
|
||||||
local modpath = minetest.get_modpath("exchange_shop")
|
|
||||||
local has_currency = minetest.get_modpath("currency")
|
|
||||||
local has_bitchange = minetest.get_modpath("bitchange")
|
|
||||||
|
|
||||||
-- Internationalisaton
|
-- Internationalisaton
|
||||||
exchange_shop.S = minetest.get_translator("exchange_shop")
|
exchange_shop.S = minetest.get_translator("exchange_shop")
|
||||||
exchange_shop.FS = function(...)
|
exchange_shop.FS = function(...)
|
||||||
return minetest.formspec_escape(exchange_shop.S(...))
|
return minetest.formspec_escape(exchange_shop.S(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Currency migrate options
|
local modpath = minetest.get_modpath("exchange_shop")
|
||||||
exchange_shop.migrate = {
|
|
||||||
use_lbm = false,
|
|
||||||
-- ^ Runs once on each unique loaded mapblock
|
|
||||||
on_interact = true
|
|
||||||
-- ^ Converts shop nodes "on the fly"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if has_bitchange then
|
|
||||||
minetest.register_alias("exchange_shop:shop", "bitchange:shop")
|
|
||||||
exchange_shop.shopname = "bitchange:shop"
|
|
||||||
else
|
|
||||||
minetest.register_alias("bitchange:shop", "exchange_shop:shop")
|
|
||||||
dofile(modpath .. "/shop_functions.lua")
|
dofile(modpath .. "/shop_functions.lua")
|
||||||
dofile(modpath .. "/shop.lua")
|
dofile(modpath .. "/shop.lua")
|
||||||
end
|
|
||||||
dofile(modpath .. "/pipes.lua")
|
|
||||||
|
|
||||||
if has_currency then
|
|
||||||
local new_groups = table.copy(minetest.registered_nodes["currency:shop"].groups)
|
|
||||||
new_groups.not_in_creative_inventory = 1
|
|
||||||
minetest.override_item("currency:shop", {
|
|
||||||
groups = new_groups
|
|
||||||
})
|
|
||||||
|
|
||||||
dofile(modpath .. "/currency_migrate.lua")
|
|
||||||
if exchange_shop.migrate.on_interact then
|
|
||||||
dofile(modpath .. "/currency_override.lua")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
38
pipes.lua
38
pipes.lua
|
@ -1,38 +0,0 @@
|
||||||
if minetest.get_modpath("pipeworks") then
|
|
||||||
minetest.override_item(exchange_shop.shopname, {
|
|
||||||
groups = {choppy=2, oddly_breakable_by_hand=2,
|
|
||||||
tubedevice=1, tubedevice_receiver=1},
|
|
||||||
tube = {
|
|
||||||
insert_object = function(pos, node, stack, direction)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:add_item("stock", stack)
|
|
||||||
end,
|
|
||||||
can_insert = function(pos, node, stack, direction)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
return inv:room_for_item("stock", stack)
|
|
||||||
end,
|
|
||||||
input_inventory = "custm",
|
|
||||||
connect_sides = {left=1, right=1, back=1, top=1, bottom=1}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
if minetest.get_modpath("tubelib") then
|
|
||||||
tubelib.register_node(exchange_shop.shopname, {}, {
|
|
||||||
on_pull_item = function(pos, side)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
return tubelib.get_item(meta, "custm")
|
|
||||||
end,
|
|
||||||
on_push_item = function(pos, side, item)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
return tubelib.put_item(meta, "stock", item)
|
|
||||||
end,
|
|
||||||
on_unpull_item = function(pos, side, item)
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
return tubelib.put_item(meta, "stock", item)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
end
|
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 59 KiB |
Loading…
Reference in New Issue