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.
| | |
| | | "technic_diamond_block_blue.png", |
| | | "technic_diamond_block_blue.png", |
| | | "technic_diamond_block_blue.png"), |
| | | wear_represents = "technic_RE_charge", |
| | | tool_capabilities = { |
| | | max_drop_level = 0, |
| | | groupcaps = { |
| | |
| | | "technic_diamond_block_green.png", |
| | | "technic_diamond_block_green.png", |
| | | "technic_diamond_block_green.png"), |
| | | wear_represents = "technic_RE_charge", |
| | | tool_capabilities = { |
| | | max_drop_level = 0, |
| | | groupcaps = { |
| | |
| | | "technic_diamond_block_red.png", |
| | | "technic_diamond_block_red.png", |
| | | "technic_diamond_block_red.png"), |
| | | wear_represents = "technic_RE_charge", |
| | | tool_capabilities = { |
| | | max_drop_level = 0, |
| | | groupcaps = { |
| | |
| | | -- Power off automatically if no longer connected to a switching station |
| | | technic.switching_station_timeout_count(pos, "MV") |
| | | |
| | | local repairable = false |
| | | local srcstack = inv:get_stack("src", 1) |
| | | if inv:is_empty("src") or |
| | | srcstack:get_wear() == 0 or |
| | | srcstack:get_name() == "technic:water_can" or |
| | | srcstack:get_name() == "technic:lava_can" then |
| | | if (not srcstack:is_empty("src")) then |
| | | local itemdef = minetest.registered_items[srcstack:get_name()] |
| | | if (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" and srcstack:get_wear() ~= 0 then |
| | | repairable = true |
| | | end |
| | | end |
| | | if not repairable then |
| | | meta:set_string("infotext", S("%s Idle"):format(machine_name)) |
| | | meta:set_int("MV_EU_demand", 0) |
| | | return |
| | |
| | | minetest.register_tool("technic:battery", { |
| | | description = S("RE Battery"), |
| | | inventory_image = "technic_battery.png", |
| | | wear_represents = "technic_RE_charge", |
| | | tool_capabilities = { |
| | | charge = 0, |
| | | max_drop_level = 0, |
| | |
| | | |
| | | -- Wear down a tool depending on the remaining charge. |
| | | function technic.set_RE_wear(itemstack, item_load, max_load) |
| | | if (minetest.registered_items[itemstack:get_name()].wear_represents or "mechanical_wear") ~= "technic_RE_charge" then return itemstack end |
| | | local temp |
| | | if item_load == 0 then |
| | | temp = 0 |
| | |
| | | description = S("Water Can"), |
| | | inventory_image = "technic_water_can.png", |
| | | stack_max = 1, |
| | | wear_represents = "content_level", |
| | | liquids_pointable = true, |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | if pointed_thing.type ~= "node" then |
| | |
| | | description = S("Lava Can"), |
| | | inventory_image = "technic_lava_can.png", |
| | | stack_max = 1, |
| | | wear_represents = "content_level", |
| | | liquids_pointable = true, |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | if pointed_thing.type ~= "node" then |
| | |
| | | description = S("Chainsaw"), |
| | | inventory_image = "technic_chainsaw.png", |
| | | stack_max = 1, |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | if pointed_thing.type ~= "node" then |
| | | return itemstack |
| | |
| | | description = S("Flashlight"), |
| | | inventory_image = "technic_flashlight.png", |
| | | stack_max = 1, |
| | | wear_represents = "technic_RE_charge", |
| | | }) |
| | | |
| | | minetest.register_craft({ |
| | |
| | | description = S("Mining Drill Mk%d"):format(1), |
| | | inventory_image = "technic_mining_drill.png", |
| | | stack_max = 1, |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | if pointed_thing.type ~= "node" then |
| | | return itemstack |
| | |
| | | minetest.register_tool("technic:mining_drill_mk2", { |
| | | description = S("Mining Drill Mk%d"):format(2), |
| | | inventory_image = "technic_mining_drill_mk2.png", |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | mining_drill_mk2_handler(itemstack, user, pointed_thing) |
| | | return itemstack |
| | |
| | | description = S("Mining Drill Mk%d Mode %d"):format(2, i), |
| | | inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png", |
| | | wield_image = "technic_mining_drill_mk2.png", |
| | | wear_represents = "technic_RE_charge", |
| | | groups = {not_in_creative_inventory=1}, |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | mining_drill_mk2_handler(itemstack, user, pointed_thing) |
| | |
| | | minetest.register_tool("technic:mining_drill_mk3", { |
| | | description = S("Mining Drill Mk%d"):format(3), |
| | | inventory_image = "technic_mining_drill_mk3.png", |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | mining_drill_mk3_handler(itemstack,user,pointed_thing) |
| | | return itemstack |
| | |
| | | description = S("Mining Drill Mk%d Mode %d"):format(3, i), |
| | | inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png", |
| | | wield_image = "technic_mining_drill_mk3.png", |
| | | wear_represents = "technic_RE_charge", |
| | | groups = {not_in_creative_inventory=1}, |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | mining_drill_mk3_handler(itemstack,user,pointed_thing) |
| | |
| | | description = S("Mining Laser Mk%d"):format(m[1]), |
| | | inventory_image = "technic_mining_laser_mk"..m[1]..".png", |
| | | stack_max = 1, |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user) |
| | | local meta = minetest.deserialize(itemstack:get_metadata()) |
| | | if not meta or not meta.charge then |
| | |
| | | minetest.register_tool("technic:sonic_screwdriver", { |
| | | description = S("Sonic Screwdriver"), |
| | | inventory_image = "technic_sonic_screwdriver.png", |
| | | wear_represents = "technic_RE_charge", |
| | | on_use = function(itemstack, user, pointed_thing) |
| | | -- Must be pointing to facedir applicable node |
| | | if pointed_thing.type ~= "node" then |