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"),
wear_represents = "technic_RE_charge",
tool_capabilities = {
max_drop_level = 0,
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"),
wear_represents = "technic_RE_charge",
tool_capabilities = {
max_drop_level = 0,
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"),
wear_represents = "technic_RE_charge",
tool_capabilities = {
max_drop_level = 0,
groupcaps = {

View File

@ -60,11 +60,15 @@ minetest.register_abm({
-- 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

View File

@ -18,6 +18,7 @@ minetest.register_craft({
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,

View File

@ -44,6 +44,7 @@ end
-- 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

View File

@ -26,6 +26,7 @@ minetest.register_tool("technic:water_can", {
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
@ -75,6 +76,7 @@ minetest.register_tool("technic:lava_can", {
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

View File

@ -255,6 +255,7 @@ minetest.register_tool("technic:chainsaw", {
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

View File

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

View File

@ -326,6 +326,7 @@ minetest.register_tool("technic:mining_drill", {
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
@ -349,6 +350,7 @@ minetest.register_tool("technic:mining_drill", {
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
@ -363,6 +365,7 @@ for i = 1, 4 do
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)
@ -374,6 +377,7 @@ end
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
@ -388,6 +392,7 @@ for i=1,5,1 do
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)

View File

@ -168,6 +168,7 @@ for _, m in pairs(mining_lasers_list) do
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

View File

@ -7,6 +7,7 @@ technic.register_power_tool("technic:sonic_screwdriver", sonic_screwdriver_max_c
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