From 48b7191af2dbda2e0782074ae17786b6b3a5f6b4 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 25 May 2018 13:45:41 +0200 Subject: [PATCH] Regularily damage and delete entities in void --- mods/ENTITIES/mcl_void_damage/depends.txt | 2 + mods/ENTITIES/mcl_void_damage/description.txt | 1 + mods/ENTITIES/mcl_void_damage/init.lua | 43 +++++++++++++++++++ mods/ENTITIES/mcl_void_damage/mod.conf | 1 + mods/PLAYER/mcl_death_drop/init.lua | 6 ++- mods/PLAYER/mcl_playerplus/depends.txt | 1 - mods/PLAYER/mcl_playerplus/init.lua | 19 -------- 7 files changed, 51 insertions(+), 22 deletions(-) create mode 100644 mods/ENTITIES/mcl_void_damage/depends.txt create mode 100644 mods/ENTITIES/mcl_void_damage/description.txt create mode 100644 mods/ENTITIES/mcl_void_damage/init.lua create mode 100644 mods/ENTITIES/mcl_void_damage/mod.conf diff --git a/mods/ENTITIES/mcl_void_damage/depends.txt b/mods/ENTITIES/mcl_void_damage/depends.txt new file mode 100644 index 0000000000..e134aeef62 --- /dev/null +++ b/mods/ENTITIES/mcl_void_damage/depends.txt @@ -0,0 +1,2 @@ +mcl_worlds +mcl_death_messages diff --git a/mods/ENTITIES/mcl_void_damage/description.txt b/mods/ENTITIES/mcl_void_damage/description.txt new file mode 100644 index 0000000000..ac7e3d8c40 --- /dev/null +++ b/mods/ENTITIES/mcl_void_damage/description.txt @@ -0,0 +1 @@ +Deal damage to entities stuck in the deep void diff --git a/mods/ENTITIES/mcl_void_damage/init.lua b/mods/ENTITIES/mcl_void_damage/init.lua new file mode 100644 index 0000000000..f8f4578f9d --- /dev/null +++ b/mods/ENTITIES/mcl_void_damage/init.lua @@ -0,0 +1,43 @@ +local voidtimer = 0 + +minetest.register_globalstep(function(dtime) + voidtimer = voidtimer + dtime + if voidtimer > 0.5 then + voidtimer = 0 + local objs = minetest.object_refs + local enable_damage = minetest.settings:get_bool("enable_damage") + for id, obj in pairs(objs) do + local pos = obj:get_pos() + local void, void_deadly = mcl_worlds.is_in_void(pos) + if void_deadly then + local is_player = obj:is_player() + local ent = obj:get_luaentity() + local immortal_val = obj:get_armor_groups().immortal + local is_immortal = false + if immortal_val and immortal_val > 0 then + is_immortal = true + end + if is_immortal or not enable_damage then + if is_player then + -- If damage is disabled, we can't kill players. + -- So we just teleport the player back to spawn. + local spawn = mcl_spawn.get_spawn_pos(obj) + obj:set_pos(spawn) + mcl_worlds.dimension_change(obj, mcl_worlds.pos_to_dimension(spawn)) + minetest.chat_send_player(obj:get_player_name(), "The void is off-limits to you!") + else + obj:remove() + end + elseif enable_damage and not is_immortal then + -- Damage enabled, not immortal: Deal void damage (4 HP / 0.5 seconds) + if obj:get_hp() > 0 then + if is_player then + mcl_death_messages.player_damage(obj, string.format("%s fell into the endless void.", obj:get_player_name())) + end + obj:set_hp(obj:get_hp() - 4) + end + end + end + end + end +end) diff --git a/mods/ENTITIES/mcl_void_damage/mod.conf b/mods/ENTITIES/mcl_void_damage/mod.conf new file mode 100644 index 0000000000..7e0ea4bacc --- /dev/null +++ b/mods/ENTITIES/mcl_void_damage/mod.conf @@ -0,0 +1 @@ +name = mcl_void_damage diff --git a/mods/PLAYER/mcl_death_drop/init.lua b/mods/PLAYER/mcl_death_drop/init.lua index 6d0947e268..1b033bae4d 100644 --- a/mods/PLAYER/mcl_death_drop/init.lua +++ b/mods/PLAYER/mcl_death_drop/init.lua @@ -3,8 +3,10 @@ minetest.register_on_dieplayer(function(player) if keep == false then -- Drop inventory, crafting grid and armor local inv = player:get_inventory() - local pos = player:getpos() + local pos = player:get_pos() local name, player_armor_inv, armor_armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") + -- No item drop if in deep void + local void, void_deadly = mcl_worlds.is_in_void(pos) local lists = { { inv = inv, listname = "main", drop = true }, { inv = inv, listname = "craft", drop = true }, @@ -21,7 +23,7 @@ minetest.register_on_dieplayer(function(player) local z = math.random(0, 9)/3 pos.x = pos.x + x pos.z = pos.z + z - if drop then + if not void_deadly and drop then minetest.add_item(pos, stack) end stack:clear() diff --git a/mods/PLAYER/mcl_playerplus/depends.txt b/mods/PLAYER/mcl_playerplus/depends.txt index 8ff8b857cb..9eb53eaf01 100644 --- a/mods/PLAYER/mcl_playerplus/depends.txt +++ b/mods/PLAYER/mcl_playerplus/depends.txt @@ -1,5 +1,4 @@ mcl_init -mcl_worlds mcl_core mcl_particles mcl_hunger diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index a07b63bec3..4a454adba1 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -141,25 +141,6 @@ minetest.register_globalstep(function(dtime) end end - -- Deal Void damage - local void, void_deadly = mcl_worlds.is_in_void(pos) - if void_deadly then - -- Player is deep into the void, deal void damage - if minetest.settings:get_bool("enable_damage") then - if player:get_hp() > 0 then - mcl_death_messages.player_damage(player, string.format("%s fell into the endless void.", name)) - player:set_hp(player:get_hp() - 4) - end - else - -- If damge is disabled, we can't kill the player. - -- So we just teleport the player back to spawn. - local spawn = mcl_spawn.get_spawn_pos(player) - player:set_pos(spawn) - mcl_worlds.dimension_change(player, mcl_worlds.pos_to_dimension(spawn)) - minetest.chat_send_player(name, "The void is off-limits to you!") - end - end - --[[ Swimming: Cause exhaustion. NOTE: As of 0.4.15, it only counts as swimming when you are with the feet inside the liquid! Head alone does not count. We respect that for now. ]]