2013-08-04 00:15:51 +02:00
|
|
|
--[[
|
2013-12-20 23:07:39 +01:00
|
|
|
Wrench mod
|
|
|
|
|
|
|
|
Adds a wrench that allows the player to pickup nodes that contain an inventory
|
|
|
|
with items or metadata that needs perserving.
|
|
|
|
The wrench has the same tool capability as the normal hand.
|
|
|
|
To pickup a node simply right click on it. If the node contains a formspec,
|
|
|
|
you will need to shift+right click instead.
|
2013-08-04 00:15:51 +02:00
|
|
|
--]]
|
2013-12-20 23:07:39 +01:00
|
|
|
|
2013-12-21 00:48:46 +01:00
|
|
|
local LATEST_SERIALIZATION_VERSION = 1
|
|
|
|
|
2013-12-20 23:07:39 +01:00
|
|
|
wrench = {}
|
|
|
|
|
|
|
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
dofile(modpath.."/support.lua")
|
|
|
|
dofile(modpath.."/technic.lua")
|
|
|
|
|
2014-04-16 19:10:00 +02:00
|
|
|
-- Boilerplate to support localized strings if intllib mod is installed.
|
|
|
|
local S
|
|
|
|
if intllib then
|
|
|
|
S = intllib.Getter()
|
|
|
|
else
|
|
|
|
S = function(s) return s end
|
|
|
|
end
|
|
|
|
|
2013-12-20 23:07:39 +01:00
|
|
|
local function get_meta_type(name, metaname)
|
|
|
|
local def = wrench.registered_nodes[name]
|
|
|
|
if not def or not def.metas or not def.metas[metaname] then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
return def.metas[metaname]
|
2013-08-04 00:15:51 +02:00
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
|
|
|
|
local function get_pickup_name(name)
|
|
|
|
return "wrench:picked_up_"..(name:gsub(":", "_"))
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
|
|
|
|
2013-12-20 23:07:39 +01:00
|
|
|
local function restore(pos, placer, itemstack)
|
|
|
|
local name = itemstack:get_name()
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local data = minetest.deserialize(itemstack:get_metadata())
|
|
|
|
minetest.set_node(pos, {name = data.name})
|
|
|
|
local lists = data.lists
|
|
|
|
for listname, list in pairs(lists) do
|
|
|
|
inv:set_list(listname, list)
|
|
|
|
end
|
|
|
|
for name, value in pairs(data.metas) do
|
|
|
|
local meta_type = get_meta_type(data.name, name)
|
|
|
|
if meta_type == wrench.META_TYPE_INT then
|
|
|
|
meta:set_int(name, value)
|
|
|
|
elseif meta_type == wrench.META_TYPE_FLOAT then
|
|
|
|
meta:set_float(name, value)
|
|
|
|
elseif meta_type == wrench.META_TYPE_STRING then
|
|
|
|
meta:set_string(name, value)
|
|
|
|
end
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
itemstack:take_item()
|
|
|
|
return itemstack
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
|
|
|
|
2013-12-20 23:07:39 +01:00
|
|
|
for name, info in pairs(wrench.registered_nodes) do
|
2013-07-31 17:55:59 +02:00
|
|
|
local olddef = minetest.registered_nodes[name]
|
2013-12-20 23:07:39 +01:00
|
|
|
if olddef then
|
2013-07-31 17:55:59 +02:00
|
|
|
local newdef = {}
|
2013-12-20 23:07:39 +01:00
|
|
|
for key, value in pairs(olddef) do
|
2013-07-31 17:55:59 +02:00
|
|
|
newdef[key] = value
|
|
|
|
end
|
|
|
|
newdef.stack_max = 1
|
2014-04-16 19:10:00 +02:00
|
|
|
newdef.description = S("%s with items"):format(newdef.description)
|
2013-08-02 00:46:20 +02:00
|
|
|
newdef.groups = {}
|
2013-07-31 17:55:59 +02:00
|
|
|
newdef.groups.not_in_creative_inventory = 1
|
|
|
|
newdef.on_construct = nil
|
|
|
|
newdef.on_destruct = nil
|
2013-12-20 23:07:39 +01:00
|
|
|
newdef.after_place_node = restore
|
|
|
|
minetest.register_node(":"..get_pickup_name(name), newdef)
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_tool("wrench:wrench", {
|
2014-04-16 19:10:00 +02:00
|
|
|
description = S("Wrench"),
|
2013-07-31 17:55:59 +02:00
|
|
|
inventory_image = "technic_wrench.png",
|
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 0.9,
|
|
|
|
max_drop_level = 0,
|
|
|
|
groupcaps = {
|
|
|
|
crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
|
|
|
|
snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
|
2013-12-20 23:07:39 +01:00
|
|
|
oddly_breakable_by_hand = {times={[1]=7.00,[2]=4.00,[3]=1.40},
|
|
|
|
uses=0, maxlevel=3}
|
2013-07-31 17:55:59 +02:00
|
|
|
},
|
|
|
|
damage_groups = {fleshy=1},
|
|
|
|
},
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
local pos = pointed_thing.under
|
2013-12-20 23:07:39 +01:00
|
|
|
if not placer or not pos then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
if minetest.is_protected(pos, placer:get_player_name()) then
|
|
|
|
minetest.record_protection_violation(pos, placer:get_player_name())
|
|
|
|
return
|
|
|
|
end
|
2013-07-31 17:55:59 +02:00
|
|
|
local name = minetest.get_node(pos).name
|
2013-12-20 23:07:39 +01:00
|
|
|
local def = wrench.registered_nodes[name]
|
|
|
|
if not def then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local stack = ItemStack(get_pickup_name(name))
|
|
|
|
local player_inv = placer:get_inventory()
|
|
|
|
if not player_inv:room_for_item("main", stack) then
|
|
|
|
return
|
|
|
|
end
|
2013-08-02 00:46:20 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-12-20 23:07:39 +01:00
|
|
|
if def.owned then
|
2013-08-04 00:15:51 +02:00
|
|
|
local owner = meta:get_string("owner")
|
2013-12-20 23:07:39 +01:00
|
|
|
if owner and owner ~= placer:get_player_name() then
|
|
|
|
minetest.log("action", placer:get_player_name()..
|
|
|
|
" tried to pick up a owned node belonging to "..
|
2013-08-04 00:15:51 +02:00
|
|
|
owner.." at "..
|
2013-08-02 00:46:20 +02:00
|
|
|
minetest.pos_to_string(pos))
|
2013-12-20 23:07:39 +01:00
|
|
|
return
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
|
|
|
|
local metadata = {}
|
|
|
|
metadata.name = name
|
2013-12-21 00:48:46 +01:00
|
|
|
metadata.version = LATEST_SERIALIZATION_VERSION
|
|
|
|
|
2013-08-02 00:46:20 +02:00
|
|
|
local inv = meta:get_inventory()
|
2013-12-20 23:07:39 +01:00
|
|
|
local lists = {}
|
|
|
|
for _, listname in pairs(def.lists or {}) do
|
|
|
|
if not inv:is_empty(listname) then
|
|
|
|
empty = false
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
local list = inv:get_list(listname)
|
|
|
|
for i, stack in pairs(list) do
|
|
|
|
list[i] = stack:to_string()
|
2013-08-02 00:46:20 +02:00
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
lists[listname] = list
|
2013-08-02 00:46:20 +02:00
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
metadata.lists = lists
|
2013-08-02 00:46:20 +02:00
|
|
|
|
2013-12-20 23:07:39 +01:00
|
|
|
local metas = {}
|
|
|
|
for name, meta_type in pairs(def.metas or {}) do
|
|
|
|
if meta_type == wrench.META_TYPE_INT then
|
|
|
|
metas[name] = meta:get_int(name)
|
|
|
|
elseif meta_type == wrench.META_TYPE_FLOAT then
|
|
|
|
metas[name] = meta:get_float(name)
|
|
|
|
elseif meta_type == wrench.META_TYPE_STRING then
|
|
|
|
metas[name] = meta:get_string(name)
|
2013-07-31 17:55:59 +02:00
|
|
|
end
|
|
|
|
end
|
2013-12-20 23:07:39 +01:00
|
|
|
metadata.metas = metas
|
|
|
|
|
|
|
|
stack:set_metadata(minetest.serialize(metadata))
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
itemstack:add_wear(65535 / 20)
|
|
|
|
player_inv:add_item("main", stack)
|
2013-07-31 17:55:59 +02:00
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
|
|
|
output = "wrench:wrench",
|
|
|
|
recipe = {
|
split default iron/steel into three metals
Override the default mod's iron/steel substance, replacing it with three
metals: wrought iron (pure iron), carbon steel (iron alloyed with a little
carbon), and cast iron (iron alloyed with lots of carbon). Wrought iron
is easiest to refine, then cast iron, and carbon steel the most difficult,
matching the historical progression. Recipes that used default steel are
changed to use one of the three, the choice of alloy for each application
being both somewhat realistic and also matching up with game progression.
The default:steel{_ingot,block} items are identified specifically with
wrought iron. This makes the default refining recipes work appropriately.
Iron-using recipes defined outside technic are thus necessarily
reinterpreted to use wrought iron, which is mostly appropriate.
Some objects are renamed accordingly.
Rather than use the default steel textures for wrought iron, with technic
providing textures for the other two, technic now provides textures for
all three metals. This avoids problems that would occur with texture
packs that provide default_steel_{ingot,block} textures that are not
intended to support this wrought-iron/carbon-steel/cast-iron distinction.
A texture pack can provide a distinct set of three textures specifically
for the situation where this distinction is required.
Incidentally make grinding and alloy cooking recipes work correctly when
ingredients are specified by alias.
2014-05-16 23:02:49 +02:00
|
|
|
{"technic:carbon_steel_ingot", "", "technic:carbon_steel_ingot"},
|
|
|
|
{"", "technic:carbon_steel_ingot", ""},
|
|
|
|
{"", "technic:carbon_steel_ingot", ""},
|
2013-07-31 17:55:59 +02:00
|
|
|
},
|
2013-08-04 15:16:00 +02:00
|
|
|
})
|