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.
This commit is contained in:
Zefram 2014-04-28 10:44:07 +01:00
parent ca69473664
commit 99fd5dfee5
10 changed files with 24 additions and 4 deletions

View File

@ -32,6 +32,7 @@ minetest.register_tool("technic:blue_energy_crystal", {
"technic_diamond_block_blue.png", "technic_diamond_block_blue.png",
"technic_diamond_block_blue.png", "technic_diamond_block_blue.png",
"technic_diamond_block_blue.png"), "technic_diamond_block_blue.png"),
wear_represents = "technic_RE_charge",
tool_capabilities = { tool_capabilities = {
max_drop_level = 0, max_drop_level = 0,
groupcaps = { groupcaps = {
@ -46,6 +47,7 @@ minetest.register_tool("technic:green_energy_crystal", {
"technic_diamond_block_green.png", "technic_diamond_block_green.png",
"technic_diamond_block_green.png", "technic_diamond_block_green.png",
"technic_diamond_block_green.png"), "technic_diamond_block_green.png"),
wear_represents = "technic_RE_charge",
tool_capabilities = { tool_capabilities = {
max_drop_level = 0, max_drop_level = 0,
groupcaps = { groupcaps = {
@ -60,6 +62,7 @@ minetest.register_tool("technic:red_energy_crystal", {
"technic_diamond_block_red.png", "technic_diamond_block_red.png",
"technic_diamond_block_red.png", "technic_diamond_block_red.png",
"technic_diamond_block_red.png"), "technic_diamond_block_red.png"),
wear_represents = "technic_RE_charge",
tool_capabilities = { tool_capabilities = {
max_drop_level = 0, max_drop_level = 0,
groupcaps = { groupcaps = {

View File

@ -60,11 +60,15 @@ minetest.register_abm({
-- Power off automatically if no longer connected to a switching station -- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV") technic.switching_station_timeout_count(pos, "MV")
local repairable = false
local srcstack = inv:get_stack("src", 1) local srcstack = inv:get_stack("src", 1)
if inv:is_empty("src") or if (not srcstack:is_empty("src")) then
srcstack:get_wear() == 0 or local itemdef = minetest.registered_items[srcstack:get_name()]
srcstack:get_name() == "technic:water_can" or if (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" and srcstack:get_wear() ~= 0 then
srcstack:get_name() == "technic:lava_can" then repairable = true
end
end
if not repairable then
meta:set_string("infotext", S("%s Idle"):format(machine_name)) meta:set_string("infotext", S("%s Idle"):format(machine_name))
meta:set_int("MV_EU_demand", 0) meta:set_int("MV_EU_demand", 0)
return return

View File

@ -18,6 +18,7 @@ minetest.register_craft({
minetest.register_tool("technic:battery", { minetest.register_tool("technic:battery", {
description = S("RE Battery"), description = S("RE Battery"),
inventory_image = "technic_battery.png", inventory_image = "technic_battery.png",
wear_represents = "technic_RE_charge",
tool_capabilities = { tool_capabilities = {
charge = 0, charge = 0,
max_drop_level = 0, max_drop_level = 0,

View File

@ -44,6 +44,7 @@ end
-- Wear down a tool depending on the remaining charge. -- Wear down a tool depending on the remaining charge.
function technic.set_RE_wear(itemstack, item_load, max_load) 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 local temp
if item_load == 0 then if item_load == 0 then
temp = 0 temp = 0

View File

@ -26,6 +26,7 @@ minetest.register_tool("technic:water_can", {
description = S("Water Can"), description = S("Water Can"),
inventory_image = "technic_water_can.png", inventory_image = "technic_water_can.png",
stack_max = 1, stack_max = 1,
wear_represents = "content_level",
liquids_pointable = true, liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
@ -75,6 +76,7 @@ minetest.register_tool("technic:lava_can", {
description = S("Lava Can"), description = S("Lava Can"),
inventory_image = "technic_lava_can.png", inventory_image = "technic_lava_can.png",
stack_max = 1, stack_max = 1,
wear_represents = "content_level",
liquids_pointable = true, liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then

View File

@ -255,6 +255,7 @@ minetest.register_tool("technic:chainsaw", {
description = S("Chainsaw"), description = S("Chainsaw"),
inventory_image = "technic_chainsaw.png", inventory_image = "technic_chainsaw.png",
stack_max = 1, stack_max = 1,
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack

View File

@ -13,6 +13,7 @@ minetest.register_tool("technic:flashlight", {
description = S("Flashlight"), description = S("Flashlight"),
inventory_image = "technic_flashlight.png", inventory_image = "technic_flashlight.png",
stack_max = 1, stack_max = 1,
wear_represents = "technic_RE_charge",
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -326,6 +326,7 @@ minetest.register_tool("technic:mining_drill", {
description = S("Mining Drill Mk%d"):format(1), description = S("Mining Drill Mk%d"):format(1),
inventory_image = "technic_mining_drill.png", inventory_image = "technic_mining_drill.png",
stack_max = 1, stack_max = 1,
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -349,6 +350,7 @@ minetest.register_tool("technic:mining_drill", {
minetest.register_tool("technic:mining_drill_mk2", { minetest.register_tool("technic:mining_drill_mk2", {
description = S("Mining Drill Mk%d"):format(2), description = S("Mining Drill Mk%d"):format(2),
inventory_image = "technic_mining_drill_mk2.png", inventory_image = "technic_mining_drill_mk2.png",
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
mining_drill_mk2_handler(itemstack, user, pointed_thing) mining_drill_mk2_handler(itemstack, user, pointed_thing)
return itemstack return itemstack
@ -363,6 +365,7 @@ for i = 1, 4 do
description = S("Mining Drill Mk%d Mode %d"):format(2, i), description = S("Mining Drill Mk%d Mode %d"):format(2, i),
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png", inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
wield_image = "technic_mining_drill_mk2.png", wield_image = "technic_mining_drill_mk2.png",
wear_represents = "technic_RE_charge",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
mining_drill_mk2_handler(itemstack, user, pointed_thing) mining_drill_mk2_handler(itemstack, user, pointed_thing)
@ -374,6 +377,7 @@ end
minetest.register_tool("technic:mining_drill_mk3", { minetest.register_tool("technic:mining_drill_mk3", {
description = S("Mining Drill Mk%d"):format(3), description = S("Mining Drill Mk%d"):format(3),
inventory_image = "technic_mining_drill_mk3.png", inventory_image = "technic_mining_drill_mk3.png",
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
mining_drill_mk3_handler(itemstack,user,pointed_thing) mining_drill_mk3_handler(itemstack,user,pointed_thing)
return itemstack return itemstack
@ -388,6 +392,7 @@ for i=1,5,1 do
description = S("Mining Drill Mk%d Mode %d"):format(3, i), description = S("Mining Drill Mk%d Mode %d"):format(3, i),
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png", inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
wield_image = "technic_mining_drill_mk3.png", wield_image = "technic_mining_drill_mk3.png",
wear_represents = "technic_RE_charge",
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
mining_drill_mk3_handler(itemstack,user,pointed_thing) mining_drill_mk3_handler(itemstack,user,pointed_thing)

View File

@ -168,6 +168,7 @@ for _, m in pairs(mining_lasers_list) do
description = S("Mining Laser Mk%d"):format(m[1]), description = S("Mining Laser Mk%d"):format(m[1]),
inventory_image = "technic_mining_laser_mk"..m[1]..".png", inventory_image = "technic_mining_laser_mk"..m[1]..".png",
stack_max = 1, stack_max = 1,
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user) on_use = function(itemstack, user)
local meta = minetest.deserialize(itemstack:get_metadata()) local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then if not meta or not meta.charge then

View File

@ -7,6 +7,7 @@ technic.register_power_tool("technic:sonic_screwdriver", sonic_screwdriver_max_c
minetest.register_tool("technic:sonic_screwdriver", { minetest.register_tool("technic:sonic_screwdriver", {
description = S("Sonic Screwdriver"), description = S("Sonic Screwdriver"),
inventory_image = "technic_sonic_screwdriver.png", inventory_image = "technic_sonic_screwdriver.png",
wear_represents = "technic_RE_charge",
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to facedir applicable node -- Must be pointing to facedir applicable node
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then