From a2049a0b77c2658ef901788f8fb378b2b9f142c4 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Thu, 3 Jan 2019 18:50:07 +0100 Subject: [PATCH] Each block supporting the "defect" state can now be set to "defect" by means of the Tubelib End Wrench (for Controller program testing purposes) --- tubelib/node_states.lua | 3 ++- tubelib/repairkit.lua | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tubelib/node_states.lua b/tubelib/node_states.lua index 0961949..48b80e8 100644 --- a/tubelib/node_states.lua +++ b/tubelib/node_states.lua @@ -307,7 +307,8 @@ function NodeStates:keep_running(pos, meta, val, num_items) if self.aging_level1 then local cnt = meta:get_int("tubelib_aging") + num_items meta:set_int("tubelib_aging", cnt) - if cnt > (self.aging_level1) and math.random(self.aging_level2/num_items) == 1 then + if (cnt > (self.aging_level1) and math.random(self.aging_level2/num_items) == 1) + or cnt >= 999999 then self:defect(pos, meta) end end diff --git a/tubelib/repairkit.lua b/tubelib/repairkit.lua index 7d6f126..52704d0 100644 --- a/tubelib/repairkit.lua +++ b/tubelib/repairkit.lua @@ -16,6 +16,14 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P = minetest.string_to_pos local M = minetest.get_meta +local function destroy_node(itemstack, placer, pointed_thing) + if pointed_thing.type == "node" then + local pos = pointed_thing.under + if not minetest.is_protected(pos, placer:get_player_name()) then + M(pos):set_int("tubelib_aging", 999999) + end + end +end local function repair_node(itemstack, user, pointed_thing) local pos = pointed_thing.under @@ -55,11 +63,12 @@ minetest.register_craftitem("tubelib:repairkit", { minetest.register_node("tubelib:end_wrench", { - description = "Tubelib End Wrench", + description = "Tubelib End Wrench (use = read status, place = destroy)", inventory_image = "tubelib_end_wrench.png", wield_image = "tubelib_end_wrench.png", groups = {cracky=1, book=1}, on_use = read_state, + on_place = destroy_node, node_placement_prediction = "", })