From fb681818af514d2102210ef027e9f5b9c15f1c1c Mon Sep 17 00:00:00 2001 From: Vitaliy Olkhin Date: Tue, 30 Jul 2024 20:10:59 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=B7=D1=8B=20=D1=80=D0=B0=D0=B4?= =?UTF-8?q?=D0=B8=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.lua | 97 +++++++++++++++++++++++++++++++++++++++++++++------- init.lua | 19 ++++++---- nodes.lua | 17 ++++++++- 3 files changed, 113 insertions(+), 20 deletions(-) diff --git a/function.lua b/function.lua index c8e610c..a1303ca 100644 --- a/function.lua +++ b/function.lua @@ -123,7 +123,6 @@ surface_effect.technic_forcefield_radiation_protection = function(pos, player) math.round(pos1.y) < range and math.round(pos1.y) > 0 - range and math.round(pos1.z) < range and math.round(pos1.z) > 0 - range then - --minetest.chat_send_all(dump((0 - range))) surface_effect.radiaton_off(player) return true end @@ -193,10 +192,12 @@ su.rediationDomage = function (player, pos) return end - minetest.sound_play("surface_effect_radiaciya",{ - gain = 1.0, - to_player = name, - }) + if surface_effect.detectNuclides(player) == true then + minetest.sound_play("surface_effect_radiaciya",{ + gain = 1.0, + to_player = name, + }) + end persistent_api.add_persistent_effect({ name = "damage_player", -- identifier @@ -242,16 +243,88 @@ end surface_effect.detectNuclides = function (player) local inv = player:get_inventory() - if inv:contains_item("main", "surface_effect:dosimeter") then - return true + if not inv:contains_item("main", "surface_effect:dosimeter") then + return false end - return false - --[[for i=1, inv:get_size("main") do + for i=1, inv:get_size("main") do local stack = inv:get_stack("main", i) if stack:get_name() == "surface_effect:dosimeter" then - use_battery(stack) + local meta = stack:get_meta() + local charge = meta:get_int("technic:charge") + + minetest.log("action", "Detect nuclides, power: " .. charge) + if charge > 0 then + return true + end + end + end + + return false +end + +local function battery_dosimeter(stack) + local meta = stack:get_meta() + local charge = meta:get_int("technic:charge") + + minetest.log("action", "Dosimeter power: " .. charge) + + if charge == -1 then return end + charge = charge - 1 + + if charge < 0 then + technic.set_RE_wear(stack, 0, 65535) + meta:set_int("technic:charge", -1) + return + end + + if charge > 0 then + technic.set_RE_wear(stack, charge, 65535) + meta:set_int("technic:charge", charge) + return + end + + return true +end + +surface_effect.update_inventory = function (player) + local inv = player:get_inventory() + if not inv:contains_item("main", "surface_effect:dosimeter") then + return -- Skip checking every stack + end + + for i=1, inv:get_size("main") do + local stack = inv:get_stack("main", i) + if stack:get_name() == "surface_effect:dosimeter" then + battery_dosimeter(stack) + inv:set_stack("main", i, stack) end - end]] -end \ No newline at end of file + end +end + +surface_effect.technicDetectUranium = function(player) + local pos = player:get_pos() + local radius = 20 + local protectors = minetest.find_nodes_in_area( + {x = pos.x - radius , y = pos.y - radius , z = pos.z - radius}, + {x = pos.x + radius , y = pos.y + radius , z = pos.z + radius}, + {"technic:uranium35_block"}) + + if #protectors > 0 then + local npos = protectors[1] + local meta = minetest.get_meta(npos) + local pos1 = vector.subtract(pos, npos) + + if surface_effect.detectNuclides(player) then + minetest.log("action", "Radiation detect technic " .. surface_effect.dump(protectors[1])) + + minetest.sound_play({name = "radiant_damage_geiger", + --gain = math.min(1, damage/10) + gain = 1.0 + }, { + to_player=player:get_player_name() + }) + end + end +end diff --git a/init.lua b/init.lua index 9277f68..c86bfdd 100644 --- a/init.lua +++ b/init.lua @@ -13,16 +13,18 @@ minetest.register_globalstep(function(dtime) if timer > os.time() then return end - timer = os.time() + 10 + timer = os.time() + 5 for k, player in ipairs(minetest.get_connected_players()) do - surface_effect.mask(player) - local name = player:get_player_name() local object = minetest.env:get_player_by_name(name) - surface_effect.setHud(player) if object then + surface_effect.setHud(player) + surface_effect.mask(player) + surface_effect.update_inventory(player) + surface_effect.technicDetectUranium(player) + local pos = object:get_pos() su.rediationDomage(player, pos) --minetest.chat_send_all(dump(areas:getAreasAtPos(pos))) @@ -33,7 +35,6 @@ end) --Новый игрок minetest.register_on_newplayer(function(player) surface_effect.setHud(player) - surface_effect.showLogo(player) if minetest.get_modpath("hazmat_suit") then @@ -128,7 +129,7 @@ end radiant_damage.register_radiant_damage("radioactive_earth", { interval = 1, - range = 3, + range = 4, --inverse_square_falloff = true, emitted_by = {["surface_effect:radioactive_earth"] = 0.5}, attenuated_by = {['air'] = 0.4, ['default:grass_1'] = 0.5}, @@ -136,6 +137,10 @@ radiant_damage.register_radiant_damage("radioactive_earth", { on_damage = on_radiation_damage, }) -minetest.register_on_player_receive_fields(function(player, formname, fields) +--[[minetest.register_on_player_receive_fields(function(player, formname, fields) + surface_effect.mask(player) +end)]] + +minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info) surface_effect.mask(player) end) \ No newline at end of file diff --git a/nodes.lua b/nodes.lua index e2265e0..4eb6e79 100644 --- a/nodes.lua +++ b/nodes.lua @@ -18,5 +18,20 @@ minetest.register_node("surface_effect:radioactive_earth", { minetest.register_tool("surface_effect:dosimeter", { description = S("Dosimeter"), - inventory_image = "surface_effect_dosimeter.png" + inventory_image = "surface_effect_dosimeter.png", + wear_represents = "technic_RE_charge", + groups = {not_in_creative_inventory = 0}, +}) + +if minetest.get_modpath("technic") then + technic.register_power_tool("surface_effect:dosimeter", 65535) +end + +minetest.register_craft({ + output = 'surface_effect:dosimeter', + recipe = { + {'basic_materials:plastic_sheet', 'technic:chromium_ingot', ''}, + {'technic:control_logic_unit', 'basic_materials:ic', ''}, + {'technic:battery', 'technic:battery', ''}, + } }) \ No newline at end of file