From 14e61a59589657557d68cd9f706df5dd0fb97d2d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 22 Feb 2017 02:38:41 +0100 Subject: [PATCH] Falling anvils now hurt players Also fix depends of mcl_wip --- mods/ITEMS/mcl_anvils/falling_anvil.lua | 62 +++++++++++++++++++++++++ mods/ITEMS/mcl_anvils/init.lua | 4 +- mods/MISC/mcl_wip/depends.txt | 2 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 mods/ITEMS/mcl_anvils/falling_anvil.lua diff --git a/mods/ITEMS/mcl_anvils/falling_anvil.lua b/mods/ITEMS/mcl_anvils/falling_anvil.lua new file mode 100644 index 0000000000..2bf559d0c7 --- /dev/null +++ b/mods/ITEMS/mcl_anvils/falling_anvil.lua @@ -0,0 +1,62 @@ +-- Hurt players hit by an anvil + +local falling_node = minetest.registered_entities["__builtin:falling_node"] +local on_step_old = falling_node.on_step +local on_step_add = function(self, dtime) + if minetest.get_item_group(self.node.name, "anvil") == 0 then + return + end + local kill + local pos = self.object:getpos() + if not self._startpos then + self._startpos = pos + end + local objs = minetest.get_objects_inside_radius(pos, 1) + for _,v in ipairs(objs) do + local hp = v:get_hp() + if v:is_player() and hp ~= 0 then + if not self.hit_players then + self.hit_players = {} + end + local name = v:get_player_name() + local hit = false + for _,v in ipairs(self.hit_players) do + if name == v then + hit = true + end + end + if not hit then + table.insert(self.hit_players, name) + local way = self._startpos.y - pos.y + local damage = (way - 1) * 2 + damage = math.min(40, math.max(0, damage)) + if damage >= 1 then + hp = hp - damage + if hp < 0 then + hp = 0 + end + v:set_hp(hp) + if hp == 0 then + kill = true + end + end + end + end + end + if kill then + local pos = self.object:getpos() + local pos = {x = pos.x, y = pos.y + 0.3, z = pos.z} + if minetest.registered_nodes[self.node.name] then + minetest.add_node(pos, self.node) + end + self.object:remove() + core.check_for_falling(pos) + end +end +local on_step_table = {on_step_old, on_step_add} +local on_step_new = table.copy(on_step_table) +falling_node.on_step = function(self, dtime) + for _,v in ipairs(on_step_new) do + v(self, dtime) + end +end diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index eae860c3dc..75b620823d 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -1,5 +1,5 @@ local anvildef = { - groups = {cracky=1, falling_node=1, deco_block=1}, + groups = {cracky=1, falling_node=1, deco_block=1, anvil=1}, tiles = {"mcl_anvils_anvil_top_damaged_0.png^[transformR90", "mcl_anvils_anvil_base.png"}, paramtype = "light", sunlight_propagates = true, @@ -42,3 +42,5 @@ minetest.register_craft({ { "mcl_core:iron_ingot", "mcl_core:iron_ingot", "mcl_core:iron_ingot" }, } }) + +dofile(minetest.get_modpath(minetest.get_current_modname()).."/falling_anvil.lua") diff --git a/mods/MISC/mcl_wip/depends.txt b/mods/MISC/mcl_wip/depends.txt index b639ba5d16..3b569aaf2f 100644 --- a/mods/MISC/mcl_wip/depends.txt +++ b/mods/MISC/mcl_wip/depends.txt @@ -10,4 +10,4 @@ mcl_minecarts mcl_sponges gemalde signs -mesecons_observers +mcl_observers