2013-10-30 18:45:32 +01:00
|
|
|
-- Tool workshop
|
2013-07-17 21:34:35 +02:00
|
|
|
-- This machine repairs tools.
|
|
|
|
|
|
|
|
minetest.register_alias("tool_workshop", "technic:tool_workshop")
|
2013-10-30 18:45:32 +01:00
|
|
|
|
|
|
|
local S = technic.getter
|
|
|
|
|
2013-07-17 21:34:35 +02:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'technic:tool_workshop',
|
|
|
|
recipe = {
|
|
|
|
{'group:wood', 'group:wood', 'group:wood'},
|
|
|
|
{'group:wood', 'default:diamond', 'group:wood'},
|
|
|
|
{'default:stone', 'default:copper_ingot', 'default:stone'},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
local workshop_formspec =
|
|
|
|
"invsize[8,9;]"..
|
|
|
|
"list[current_name;src;3,1;1,1;]"..
|
2013-10-30 18:45:32 +01:00
|
|
|
"label[0,0;"..S("Tool Workshop").."]"..
|
2013-07-17 21:34:35 +02:00
|
|
|
"list[current_player;main;0,5;8,4;]"
|
|
|
|
|
|
|
|
minetest.register_node("technic:tool_workshop", {
|
2013-10-30 18:45:32 +01:00
|
|
|
description = S("Tool Workshop"),
|
2013-07-17 21:34:35 +02:00
|
|
|
tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png",
|
|
|
|
"technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"},
|
|
|
|
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
|
|
|
sounds = default.node_sound_wood_defaults(),
|
|
|
|
on_construct = function(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("Tool Workshop"))
|
2013-07-17 21:34:35 +02:00
|
|
|
meta:set_string("formspec", workshop_formspec)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
inv:set_size("src", 1)
|
|
|
|
end,
|
2013-11-27 18:28:56 +01:00
|
|
|
can_dig = technic.machine_can_dig,
|
|
|
|
allow_metadata_inventory_put = technic.machine_inventory_put,
|
|
|
|
allow_metadata_inventory_take = technic.machine_inventory_take,
|
2013-07-17 21:34:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm({
|
|
|
|
nodenames = {"technic:tool_workshop"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local eu_input = meta:get_int("MV_EU_input")
|
2013-10-30 18:45:32 +01:00
|
|
|
local machine_name = S("Tool Workshop")
|
2013-07-17 21:34:35 +02:00
|
|
|
local machine_node = "technic:tool_workshop"
|
|
|
|
local demand = 5000
|
|
|
|
|
|
|
|
-- Setup meta data if it does not exist.
|
|
|
|
if not eu_input then
|
|
|
|
meta:set_int("MV_EU_demand", demand)
|
|
|
|
meta:set_int("MV_EU_input", 0)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Power off automatically if no longer connected to a switching station
|
|
|
|
technic.switching_station_timeout_count(pos, "MV")
|
|
|
|
|
Genericise handling of multiple meanings of wear
The tool workshop is meant to repair mechanical damage to tools, so
is at risk of `repairing' tools that use the wear bar to represent
something other than mechanical wear. It had special-case recognition
of the water and lava cans, which use the wear bar to represent how much
content they're carrying, and wouldn't repair them. But it didn't avoid
`repairing' RE chargeable items, which use the wear bar to represent
how much energy they have stored. It would modify the wear bar without
actually affecting the charge, so the wear bar would jump back to the
correct place when the next charging or discharging event occurred.
To genericise, introduce a new item property, "wear_represents", which
indicates how the wear bar is used for this item. Currently defined
values are "mechanical_wear" (straightforward damage to tools that
start out perfect), "technic_RE_charge" (electrical energy, canonically
represented in the meta rather than the wear bar), and "content_level"
(how full a container is). For backcompat, nil is interpreted as
"mechanical_wear". The tool workshop will only repair "mechanical_wear"
tools. As a bonus, set_RE_wear() will only set the wear bar for
"technic_RE_charge" items: this means developers will notice if they
forget to declare wear_represents, but also means that with no further
changes it's possible to have an RE chargeable item that uses its wear
bar to represent something else.
2014-04-28 11:44:07 +02:00
|
|
|
local repairable = false
|
2013-12-18 01:51:38 +01:00
|
|
|
local srcstack = inv:get_stack("src", 1)
|
2014-05-31 03:00:58 +02:00
|
|
|
if not srcstack:is_empty() then
|
Genericise handling of multiple meanings of wear
The tool workshop is meant to repair mechanical damage to tools, so
is at risk of `repairing' tools that use the wear bar to represent
something other than mechanical wear. It had special-case recognition
of the water and lava cans, which use the wear bar to represent how much
content they're carrying, and wouldn't repair them. But it didn't avoid
`repairing' RE chargeable items, which use the wear bar to represent
how much energy they have stored. It would modify the wear bar without
actually affecting the charge, so the wear bar would jump back to the
correct place when the next charging or discharging event occurred.
To genericise, introduce a new item property, "wear_represents", which
indicates how the wear bar is used for this item. Currently defined
values are "mechanical_wear" (straightforward damage to tools that
start out perfect), "technic_RE_charge" (electrical energy, canonically
represented in the meta rather than the wear bar), and "content_level"
(how full a container is). For backcompat, nil is interpreted as
"mechanical_wear". The tool workshop will only repair "mechanical_wear"
tools. As a bonus, set_RE_wear() will only set the wear bar for
"technic_RE_charge" items: this means developers will notice if they
forget to declare wear_represents, but also means that with no further
changes it's possible to have an RE chargeable item that uses its wear
bar to represent something else.
2014-04-28 11:44:07 +02:00
|
|
|
local itemdef = minetest.registered_items[srcstack:get_name()]
|
2014-05-31 02:58:32 +02:00
|
|
|
if itemdef and
|
2014-05-31 03:13:14 +02:00
|
|
|
(not itemdef.wear_represents or
|
|
|
|
itemdef.wear_represents == "mechanical_wear") and
|
2014-05-31 02:58:32 +02:00
|
|
|
srcstack:get_wear() ~= 0 then
|
Genericise handling of multiple meanings of wear
The tool workshop is meant to repair mechanical damage to tools, so
is at risk of `repairing' tools that use the wear bar to represent
something other than mechanical wear. It had special-case recognition
of the water and lava cans, which use the wear bar to represent how much
content they're carrying, and wouldn't repair them. But it didn't avoid
`repairing' RE chargeable items, which use the wear bar to represent
how much energy they have stored. It would modify the wear bar without
actually affecting the charge, so the wear bar would jump back to the
correct place when the next charging or discharging event occurred.
To genericise, introduce a new item property, "wear_represents", which
indicates how the wear bar is used for this item. Currently defined
values are "mechanical_wear" (straightforward damage to tools that
start out perfect), "technic_RE_charge" (electrical energy, canonically
represented in the meta rather than the wear bar), and "content_level"
(how full a container is). For backcompat, nil is interpreted as
"mechanical_wear". The tool workshop will only repair "mechanical_wear"
tools. As a bonus, set_RE_wear() will only set the wear bar for
"technic_RE_charge" items: this means developers will notice if they
forget to declare wear_represents, but also means that with no further
changes it's possible to have an RE chargeable item that uses its wear
bar to represent something else.
2014-04-28 11:44:07 +02:00
|
|
|
repairable = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not repairable then
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Idle"):format(machine_name))
|
2013-07-17 21:34:35 +02:00
|
|
|
meta:set_int("MV_EU_demand", 0)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if eu_input < demand then
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Unpowered"):format(machine_name))
|
2013-07-17 21:34:35 +02:00
|
|
|
elseif eu_input >= demand then
|
2013-10-30 18:45:32 +01:00
|
|
|
meta:set_string("infotext", S("%s Active"):format(machine_name))
|
2013-07-17 21:34:35 +02:00
|
|
|
srcstack:add_wear(-1000)
|
|
|
|
inv:set_stack("src", 1, srcstack)
|
|
|
|
end
|
|
|
|
meta:set_int("MV_EU_demand", demand)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
technic.register_machine("MV", "technic:tool_workshop", technic.receiver)
|
|
|
|
|