summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2014-04-28 10:44:07 +0100
committerZefram <zefram@fysh.org>2014-04-30 00:21:55 +0100
commit99fd5dfee5a70b0656e40787168d2c67ba417738 (patch)
treed25ae81f2ca71b7825bb5873ca5dcfb7ec32eec9
parentca69473664d4212aa787e4dca3cd7a918788c724 (diff)
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.
-rw-r--r--technic/items.lua3
-rw-r--r--technic/machines/MV/tool_workshop.lua12
-rw-r--r--technic/machines/register/battery_box.lua1
-rw-r--r--technic/register.lua1
-rw-r--r--technic/tools/cans.lua2
-rw-r--r--technic/tools/chainsaw.lua1
-rw-r--r--technic/tools/flashlight.lua1
-rw-r--r--technic/tools/mining_drill.lua5
-rw-r--r--technic/tools/mining_lasers.lua1
-rw-r--r--technic/tools/sonic_screwdriver.lua1
10 files changed, 24 insertions, 4 deletions
diff --git a/technic/items.lua b/technic/items.lua
index d571917..9149460 100644
--- a/technic/items.lua
+++ b/technic/items.lua
@@ -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 = {
diff --git a/technic/machines/MV/tool_workshop.lua b/technic/machines/MV/tool_workshop.lua
index 9955d5f..b00c3bb 100644
--- a/technic/machines/MV/tool_workshop.lua
+++ b/technic/machines/MV/tool_workshop.lua
@@ -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
diff --git a/technic/machines/register/battery_box.lua b/technic/machines/register/battery_box.lua
index f7bbf1e..8efcb15 100644
--- a/technic/machines/register/battery_box.lua
+++ b/technic/machines/register/battery_box.lua
@@ -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,
diff --git a/technic/register.lua b/technic/register.lua
index 0b55282..09721ff 100644
--- a/technic/register.lua
+++ b/technic/register.lua
@@ -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
diff --git a/technic/tools/cans.lua b/technic/tools/cans.lua
index c1c6713..e75b2db 100644
--- a/technic/tools/cans.lua
+++ b/technic/tools/cans.lua
@@ -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
diff --git a/technic/tools/chainsaw.lua b/technic/tools/chainsaw.lua
index 19ba3e8..273e36d 100644
--- a/technic/tools/chainsaw.lua
+++ b/technic/tools/chainsaw.lua
@@ -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
diff --git a/technic/tools/flashlight.lua b/technic/tools/flashlight.lua
index a2cfe33..7beac5e 100644
--- a/technic/tools/flashlight.lua
+++ b/technic/tools/flashlight.lua
@@ -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({
diff --git a/technic/tools/mining_drill.lua b/technic/tools/mining_drill.lua
index 0471c71..2a7cfe7 100644
--- a/technic/tools/mining_drill.lua
+++ b/technic/tools/mining_drill.lua
@@ -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)
diff --git a/technic/tools/mining_lasers.lua b/technic/tools/mining_lasers.lua
index 4a4ed2f..c6ba57f 100644
--- a/technic/tools/mining_lasers.lua
+++ b/technic/tools/mining_lasers.lua
@@ -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
diff --git a/technic/tools/sonic_screwdriver.lua b/technic/tools/sonic_screwdriver.lua
index a9a52d8..cc4edab 100644
--- a/technic/tools/sonic_screwdriver.lua
+++ b/technic/tools/sonic_screwdriver.lua
@@ -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