mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-05 06:53:52 +01:00
Merge pull request #78 from metalstache/master
Add node metadata storage and Technic machine support
This commit is contained in:
commit
f68d305252
136
wrench/init.lua
136
wrench/init.lua
@ -1,29 +1,44 @@
|
|||||||
|
--[""] = {name="", lists={}, metas={}},
|
||||||
local supported_nodes = {
|
local supported_nodes = {
|
||||||
["default:chest"] = {name="wrench:default_chest", lists={"main"}},
|
["default:chest"] = {name="wrench:default_chest", lists={"main"}, metas={}},
|
||||||
["default:furnace"] = {name="wrench:default_furnace", lists={"fuel", "src", "dst"}},
|
["default:chest_locked"] = {name="wrench:default_chest_locked", lists={"main"}, metas={{string="owner"},{string="infotext"}}},
|
||||||
["default:furnace_active"] = {name="wrench:default_furnace", lists={"fuel", "src", "dst"}},
|
["default:furnace"] = {name="wrench:default_furnace", lists={"fuel", "src", "dst"}, metas={{string="infotext"},{float="fuel_totaltime"},{float="fuel_time"},{float="src_totaltime"},{float="src_time"}}},
|
||||||
["technic:iron_chest"] = {name="wrench:technic_iron_chest", lists={"main"}},
|
["default:furnace_active"] = {name="wrench:default_furnace", lists={"fuel", "src", "dst"}, metas={{string="infotext"},{float="fuel_totaltime"},{float="fuel_time"},{float="src_totaltime"},{float="src_time"}}},
|
||||||
["technic:iron_locked_chest"] = {name="wrench:technic_iron_locked_chest", lists={"main"}},
|
["default:sign_wall"] = {name="wrench:default_sing_wall", lists={}, metas={{string="infotext"},{string="text"}}},
|
||||||
["technic:copper_chest"] = {name="wrench:technic_copper_chest", lists={"main"}},
|
["technic:iron_chest"] = {name="wrench:technic_iron_chest", lists={"main"}, metas={}},
|
||||||
["technic:copper_locked_chest"] = {name="wrench:technic_copper_locked_chest", lists={"main"}},
|
["technic:iron_locked_chest"] = {name="wrench:technic_iron_locked_chest", lists={"main"}, metas={{string="infotext"},{string="owner"}}},
|
||||||
["technic:silver_chest"] = {name="wrench:technic_silver_chest", lists={"main"}},
|
["technic:copper_chest"] = {name="wrench:technic_copper_chest", lists={"main"}, metas={}},
|
||||||
["technic:silver_locked_chest"] = {name="wrench:technic_silver_locked_chest", lists={"main"}},
|
["technic:copper_locked_chest"] = {name="wrench:technic_copper_locked_chest", lists={"main"}, metas={{string="infotext"},{string="owner"}}},
|
||||||
["technic:gold_chest"] = {name="wrench:technic_gold_chest", lists={"main"}},
|
["technic:silver_chest"] = {name="wrench:technic_silver_chest", lists={"main"}, metas={{string="infotext"},{string="formspec"}}},
|
||||||
["technic:gold_locked_chest"] = {name="wrench:technic_gold_locked_chest", lists={"main"}},
|
["technic:silver_locked_chest"] = {name="wrench:technic_silver_locked_chest", lists={"main"}, metas={{string="infotext"},{string="owner"},{string="formspec"}}},
|
||||||
["technic:mithril_chest"] = {name="wrench:technic_mithril_chest", lists={"main"}},
|
["technic:gold_chest"] = {name="wrench:technic_gold_chest", lists={"main"}, metas={{string="infotext"},{string="formspec"}}},
|
||||||
["technic:mithril_locked_chest"] = {name="wrench:technic_mithril_locked_chest", lists={"main"}},
|
["technic:gold_locked_chest"] = {name="wrench:technic_gold_locked_chest", lists={"main"}, metas={{string="infotext"},{string="owner"},{string="formspec"}}},
|
||||||
["technic:electric_furnace"] = {name="wrench:technic_electric_furnace", lists={"src", "dst"}},
|
["technic:mithril_chest"] = {name="wrench:technic_mithril_chest", lists={"main"}, metas={{string="infotext"},{string="formspec"}}},
|
||||||
["technic:electric_furnace_active"] = {name="wrench:technic_electric_furnace_active", lists={"src", "dst"}},
|
["technic:mithril_locked_chest"] = {name="wrench:technic_mithril_locked_chest", lists={"main"}, metas={{string="infotext"},{string="owner"},{string="formspec"}}},
|
||||||
["technic:mv_electric_furnace"] = {name="wrench:technic_mv_electric_furnace", lists={"src", "dst", "upgrade1", "upgrade2"}},
|
["technic:battery_box"] = {name="wrench:technic_battery_box", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="LV_EU_demand"},{int="LV_EU_supply"},{int="LV_EU_input"},{int="internal_EU_charge"},{float="last_side_shown"}}},
|
||||||
["technic:mv_electric_furnace_active"] = {name="wrench:technic_mv_electric_furnace_active", lists={"src", "dst", "upgrade1", "upgrade2"}},
|
["technic:mv_battery_box"] = {name="wrench:technic_mv_battery_box", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="MV_EU_demand"},{int="MV_EU_supply"},{int="MV_EU_input"},{int="internal_EU_charge"},{float="last_side_shown"}}},
|
||||||
["technic:coal_alloy_furnace"] = {name="wrench:technic_coal_alloy_furnace", lists={"fuel", "src", "src2", "dst"}},
|
["technic:hv_battery_box"] = {name="wrench:technic_hv_battery_box", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="HV_EU_demand"},{int="HV_EU_supply"},{int="HV_EU_input"},{int="internal_EU_charge"},{float="last_side_shown"}}},
|
||||||
["technic:coal_alloy_furnace_active"] = {name="wrench:technic_coal_alloy_furnace_active", lists={"fuel", "src", "src2", "dst"}},
|
["technic:electric_furnace"] = {name="wrench:technic_electric_furnace", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
["technic:alloy_furnace"] = {name="wrench:technic_alloy_furnace", lists={"src", "src2", "dst"}},
|
["technic:electric_furnace_active"] = {name="wrench:technic_electric_furnace_active", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
["technic:alloy_furnace_active"] = {name="wrench:technic_alloy_furnace_active", lists={"src", "src2", "dst"}},
|
["technic:mv_electric_furnace"] = {name="wrench:technic_mv_electric_furnace", lists={"src", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
["technic:mv_alloy_furnace"] = {name="wrench:technic_mv_alloy_furnace", lists={"src", "src2", "dst", "upgrade1", "upgrade2"}},
|
["technic:mv_electric_furnace_active"] = {name="wrench:technic_mv_electric_furnace_active", lists={"src", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
["technic:mv_alloy_furnace_active"] = {name="wrench:technic_mv_alloy_furnace_active", lists={"src", "src2", "dst", "upgrade1", "upgrade2"}},
|
["technic:coal_alloy_furnace"] = {name="wrench:technic_coal_alloy_furnace", lists={"fuel", "src", "src2", "dst"}, metas={{string="infotext"},{float="fuel_totaltime"},{float="fuel_time"},{float="src_totaltime"},{float="src_time"}}},
|
||||||
["technic:grinder"] = {name="wrench:technic_grinder", lists={"src", "dst"}},
|
["technic:coal_alloy_furnace_active"] = {name="wrench:technic_coal_alloy_furnace_active", lists={"fuel", "src", "src2", "dst"}, metas={{string="infotext"},{float="fuel_totaltime"},{float="fuel_time"},{float="src_totaltime"},{float="src_time"}}},
|
||||||
["technic:grinder_active"] = {name="wrench:technic_grinder_active", lists={"src", "dst"}},
|
["technic:alloy_furnace"] = {name="wrench:technic_alloy_furnace", lists={"src", "src2", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:alloy_furnace_active"] = {name="wrench:technic_alloy_furnace_active", lists={"src", "src2", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:mv_alloy_furnace"] = {name="wrench:technic_mv_alloy_furnace", lists={"src", "src2", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:mv_alloy_furnace_active"] = {name="wrench:technic_mv_alloy_furnace_active", lists={"src", "src2", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:tool_workshop"] = {name="wrench:technic_tool_workshop", lists={"src"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"}}},
|
||||||
|
["technic:grinder"] = {name="wrench:technic_grinder", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:grinder_active"] = {name="wrench:technic_grinder_active", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:mv_grinder"] = {name="wrench:technic_mv_grinder", lists={"src", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:mv_grinder_active"] = {name="wrench:technic_mv_grinder_active", lists={"src", "dst", "upgrade1", "upgrade2"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="MV_EU_demand"},{int="MV_EU_input"},{int="tube_time"},{int="src_time"}}},
|
||||||
|
["technic:extractor"] = {name="wrench:technic_extractor", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:extractor_active"] = {name="wrench:technic_extractor_active", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:compressor"] = {name="wrench:technic_compressor", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:compressor_active"] = {name="wrench:technic_compressor_active", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"}}},
|
||||||
|
["technic:cnc"] = {name="wrench:technic_cnc", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"},{string="cnc_product"}}},
|
||||||
|
["technic:cnc_active"] = {name="wrench:technic_cnc_active", lists={"src", "dst"}, metas={{string="infotext"},{string="formspec"},{int="state"},{int="LV_EU_demand"},{int="LV_EU_input"},{int="src_time"},{string="cnc_product"}}},
|
||||||
}
|
}
|
||||||
local chest_mark_colors = {
|
local chest_mark_colors = {
|
||||||
{'_black','Black'},
|
{'_black','Black'},
|
||||||
@ -44,8 +59,8 @@ local chest_mark_colors = {
|
|||||||
{'','None'}
|
{'','None'}
|
||||||
}
|
}
|
||||||
for i=1,15,1 do
|
for i=1,15,1 do
|
||||||
supported_nodes["technic:gold_chest"..chest_mark_colors[i][1]] = {name="wrench:technic_gold_chest"..chest_mark_colors[i][1], lists={"main"}}
|
supported_nodes["technic:gold_chest"..chest_mark_colors[i][1]] = {name="wrench:technic_gold_chest"..chest_mark_colors[i][1], lists={"main"}, metas={{string="infotext"},{string="formspec"}}}
|
||||||
supported_nodes["technic:gold_locked_chest"..chest_mark_colors[i][1]] = {name="wrench:technic_gold_locked_chest"..chest_mark_colors[i][1], lists={"main"}}
|
supported_nodes["technic:gold_locked_chest"..chest_mark_colors[i][1]] = {name="wrench:technic_gold_locked_chest"..chest_mark_colors[i][1], lists={"main"}, metas={{string="infotext"},{string="owner"},{string="formspec"}}}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function convert_to_original_name(name)
|
local function convert_to_original_name(name)
|
||||||
@ -54,35 +69,49 @@ local function convert_to_original_name(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for name,_ in pairs(supported_nodes) do
|
for name,info in pairs(supported_nodes) do
|
||||||
local olddef = minetest.registered_nodes[name]
|
local olddef = minetest.registered_nodes[name]
|
||||||
if olddef ~= nil then
|
if olddef ~= nil then
|
||||||
local newdef = {}
|
local newdef = {}
|
||||||
for key,value in pairs(olddef) do
|
for key,value in pairs(olddef) do
|
||||||
newdef[key] = value
|
newdef[key] = value
|
||||||
end
|
end
|
||||||
name = supported_nodes[name].name
|
|
||||||
newdef.stack_max = 1
|
newdef.stack_max = 1
|
||||||
newdef.description = newdef.description.." with items"
|
newdef.description = newdef.description.." with items"
|
||||||
|
newdef.groups = {}
|
||||||
newdef.groups.not_in_creative_inventory = 1
|
newdef.groups.not_in_creative_inventory = 1
|
||||||
newdef.on_construct = nil
|
newdef.on_construct = nil
|
||||||
newdef.on_destruct = nil
|
newdef.on_destruct = nil
|
||||||
newdef.after_place_node = function(pos, placer, itemstack)
|
newdef.after_place_node = function(pos, placer, itemstack)
|
||||||
if olddef.after_place_node ~= nil then olddef.after_place_node(pos, placer, itemstack) end
|
|
||||||
if not placer:is_player() then return end
|
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
local item = convert_to_original_name(itemstack:get_name())
|
local item = convert_to_original_name(itemstack:get_name())
|
||||||
minetest.set_node(pos, {name = item, param2 = node.param2})
|
minetest.set_node(pos, {name = item, param2 = node.param2})
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
minetest.after(0.5, function(pos, placer, itemstack)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
local data = minetest.deserialize(itemstack:get_metadata())
|
local data = minetest.deserialize(itemstack:get_metadata())
|
||||||
for listname,list in pairs(data) do
|
local lists = data.lists
|
||||||
|
for listname,list in pairs(lists) do
|
||||||
inv:set_list(listname, list)
|
inv:set_list(listname, list)
|
||||||
end
|
end
|
||||||
|
local metas = data.metas
|
||||||
|
for i=1,#metas,1 do
|
||||||
|
local temp = metas[i]
|
||||||
|
if temp.string ~= nil then
|
||||||
|
meta:set_string(temp.string, temp.value)
|
||||||
end
|
end
|
||||||
minetest.register_node(name, newdef)
|
if temp.int ~= nil then
|
||||||
|
meta:set_int(temp.int, temp.value)
|
||||||
|
end
|
||||||
|
if temp.float ~= nil then
|
||||||
|
meta:set_float(temp.float, temp.value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, pos, placer, itemstack)
|
||||||
|
end
|
||||||
|
minetest.register_node(info.name, newdef)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
minetest.register_tool("wrench:wrench", {
|
minetest.register_tool("wrench:wrench", {
|
||||||
description = "Wrench",
|
description = "Wrench",
|
||||||
@ -104,19 +133,23 @@ minetest.register_tool("wrench:wrench", {
|
|||||||
local name = minetest.get_node(pos).name
|
local name = minetest.get_node(pos).name
|
||||||
local support = supported_nodes[name]
|
local support = supported_nodes[name]
|
||||||
if support == nil then return end
|
if support == nil then return end
|
||||||
if name:find("_locked_chest") ~= nil then
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if not has_locked_chest_privilege(meta, placer) then
|
if name:find("_locked") ~= nil then
|
||||||
minetest.log("action", player:get_player_name()..
|
if meta:get_string("owner") ~= nil then
|
||||||
|
if meta:get_string("owner") ~= placer:get_player_name() then
|
||||||
|
minetest.log("action", placer:get_player_name()..
|
||||||
" tried to destroy a locked chest belonging to "..
|
" tried to destroy a locked chest belonging to "..
|
||||||
meta:get_string("owner").." at "..
|
meta:get_string("owner").." at "..
|
||||||
minetest.pos_to_string(pos))
|
minetest.pos_to_string(pos))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local lists = support.lists
|
local lists = support.lists
|
||||||
local inv = minetest.get_meta(pos):get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local empty = true
|
local empty = true
|
||||||
|
local metadata_str = {}
|
||||||
local list_str = {}
|
local list_str = {}
|
||||||
for i=1,#lists,1 do
|
for i=1,#lists,1 do
|
||||||
if not inv:is_empty(lists[i]) then empty = false end
|
if not inv:is_empty(lists[i]) then empty = false end
|
||||||
@ -126,17 +159,34 @@ minetest.register_tool("wrench:wrench", {
|
|||||||
end
|
end
|
||||||
list_str[lists[i]] = list
|
list_str[lists[i]] = list
|
||||||
end
|
end
|
||||||
|
metadata_str.lists = list_str
|
||||||
|
|
||||||
|
local metas = support.metas
|
||||||
|
local meta_str = {}
|
||||||
|
for i=1,#metas,1 do
|
||||||
|
local temp = metas[i]
|
||||||
|
if temp.string ~= nil then
|
||||||
|
meta_str[i] = {string = temp.string, value = meta:get_string(temp.string)}
|
||||||
|
end
|
||||||
|
if temp.int ~= nil then
|
||||||
|
meta_str[i] = {int = temp.int, value = meta:get_int(temp.int)}
|
||||||
|
end
|
||||||
|
if temp.float ~= nil then
|
||||||
|
meta_str[i] = {float = temp.float, value = meta:get_float(temp.float)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
metadata_str.metas = meta_str
|
||||||
|
|
||||||
inv = placer:get_inventory()
|
inv = placer:get_inventory()
|
||||||
local stack = {}
|
local stack = {name = name}
|
||||||
stack.name = name
|
|
||||||
if inv:room_for_item("main", stack) then
|
if inv:room_for_item("main", stack) then
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
itemstack:add_wear(65535/20)
|
itemstack:add_wear(65535/20)
|
||||||
if empty then
|
if empty and #lists > 0 then
|
||||||
inv:add_item("main", stack)
|
inv:add_item("main", stack)
|
||||||
else
|
else
|
||||||
stack.name = supported_nodes[name].name
|
stack.name = supported_nodes[name].name
|
||||||
stack.metadata = minetest.serialize(list_str)
|
stack.metadata = minetest.serialize(metadata_str)
|
||||||
inv:add_item("main", stack)
|
inv:add_item("main", stack)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user