From 3bedc8106883284b23db0de9de2f9b8213b65270 Mon Sep 17 00:00:00 2001 From: AFCMS Date: Fri, 28 May 2021 00:07:06 +0200 Subject: [PATCH] fix some code style issues in lightning --- mods/ENTITIES/mcl_item_entity/init.lua | 21 +++++++++++---------- mods/ENVIRONMENT/lightning/init.lua | 25 +++++++++++++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index a73f586e9c..7886664f8c 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -363,6 +363,17 @@ if not time_to_live then time_to_live = 300 end +local function cxcz(o, cw, one, zero) + if cw < 0 then + table.insert(o, { [one]=1, y=0, [zero]=0 }) + table.insert(o, { [one]=-1, y=0, [zero]=0 }) + else + table.insert(o, { [one]=-1, y=0, [zero]=0 }) + table.insert(o, { [one]=1, y=0, [zero]=0 }) + end + return o +end + minetest.register_entity(":__builtin:item", { initial_properties = { hp_max = 1, @@ -642,16 +653,6 @@ minetest.register_entity(":__builtin:item", { -- 1st: closest -- 2nd: other direction -- 3rd and 4th: other axis - local cxcz = function(o, cw, one, zero) - if cw < 0 then - table.insert(o, { [one]=1, y=0, [zero]=0 }) - table.insert(o, { [one]=-1, y=0, [zero]=0 }) - else - table.insert(o, { [one]=-1, y=0, [zero]=0 }) - table.insert(o, { [one]=1, y=0, [zero]=0 }) - end - return o - end if math.abs(cx) < math.abs(cz) then order = cxcz(order, cx, "x", "z") order = cxcz(order, cz, "z", "x") diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 2b79bf5ce4..3d5955d6e2 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -1,6 +1,7 @@ --[[ Copyright (C) 2016 - Auke Kok +Adapted by MineClone2 contributors "lightning" is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -9,7 +10,7 @@ of the license, or (at your option) any later version. --]] -local S = minetest.get_translator("lightning") +local S = minetest.get_translator(minetest.get_current_modname()) local get_connected_players = minetest.get_connected_players local line_of_sight = minetest.line_of_sight @@ -22,22 +23,22 @@ local add_entity = minetest.add_entity local get_objects_inside_radius = minetest.get_objects_inside_radius local get_item_group = minetest.get_item_group -lightning = {} - -lightning.interval_low = 17 -lightning.interval_high = 503 -lightning.range_h = 100 -lightning.range_v = 50 -lightning.size = 100 --- disable this to stop lightning mod from striking -lightning.auto = true +lightning = { + interval_low = 17, + interval_high = 503, + range_h = 100, + range_v = 50, + size = 100, + -- disable this to stop lightning mod from striking + auto = true, +} local rng = PcgRandom(32321123312123) local ps = {} local ttl = -1 -local revertsky = function(dtime) +local function revertsky(dtime) if ttl == 0 then return end @@ -96,7 +97,7 @@ end -- lightning strike API -- * pos: optional, if not given a random pos will be chosen -- * returns: bool - success if a strike happened -lightning.strike = function(pos) +function lightning.strike(pos) if lightning.auto then after(rng:next(lightning.interval_low, lightning.interval_high), lightning.strike) end