From c71bd9588dd9a6af2f82bc193cefc35fb565f5c9 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 5 Feb 2018 19:01:54 +0100 Subject: [PATCH] Generalize anvil damage --- GROUPS.md | 1 + mods/ENTITIES/mcl_falling_nodes/init.lua | 16 ++++++++++++---- mods/HELP/mcl_doc/init.lua | 8 ++++++++ mods/ITEMS/mcl_anvils/init.lua | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/GROUPS.md b/GROUPS.md index a50234cf..a62fb2f0 100644 --- a/GROUPS.md +++ b/GROUPS.md @@ -30,6 +30,7 @@ Please read to learn how digging times ### Groups for interactions * `crush_after_fall=1`: For falling nodes. These will crush whatever they hit after falling, not dropping as an item +* `falling_node_damage=1`: For falling nodes. Hurts any objects it hits while falling. Damage is based on anvils * `dig_by_water=1`: Blocks with this group will drop when they are near flowing water * `destroy_by_lava_flow=1`: Blocks with this group will be destroyed by flowing lava * `dig_by_piston=1`: Blocks which will drop as an item when pushed by a piston. They also cannot be pulled by sticky pistons diff --git a/mods/ENTITIES/mcl_falling_nodes/init.lua b/mods/ENTITIES/mcl_falling_nodes/init.lua index 60f028bc..fc0aac24 100644 --- a/mods/ENTITIES/mcl_falling_nodes/init.lua +++ b/mods/ENTITIES/mcl_falling_nodes/init.lua @@ -1,4 +1,6 @@ -local on_anvil_step = function(self, dtime) +local on_damage_step = function(self, dtime) + -- Cause damage to everything it hits. + -- Algorithm based on MC anvils. local pos = self.object:get_pos() if not self._startpos then self._startpos = pos @@ -28,7 +30,13 @@ local on_anvil_step = function(self, dtime) hp = 0 end if v:is_player() then - mcl_death_messages.player_damage(v, string.format("%s was smashed by a falling anvil.", v:get_player_name())) + local msg + if minetest.get_item_group(self.node.name, "anvil") ~= 0 then + msg = "%s was smashed by a falling anvil." + else + msg = "%s was smashed by a falling block." + end + mcl_death_messages.player_damage(v, string.format(msg, v:get_player_name())) mcl_hunger.exhaust(v:get_player_name(), mcl_hunger.EXHAUST_DAMAGE) end v:set_hp(hp) @@ -210,8 +218,8 @@ minetest.register_entity(":__builtin:falling_node", { end end - if minetest.get_item_group(self.node, "anvil") ~= 0 then - on_anvil_step(self, dtime) + if minetest.get_item_group(self.node.name, "falling_node_damage") ~= 0 then + on_damage_step(self, dtime) end end }) diff --git a/mods/HELP/mcl_doc/init.lua b/mods/HELP/mcl_doc/init.lua index 55eadcc2..c7421509 100644 --- a/mods/HELP/mcl_doc/init.lua +++ b/mods/HELP/mcl_doc/init.lua @@ -159,6 +159,14 @@ doc.sub.items.register_factoid("nodes", "gravity", function(itemstring, def) return s end) +doc.sub.items.register_factoid("nodes", "gravity", function(itemstring, def) + local s = "" + if minetest.get_item_group(itemstring, "crush_after_fall") == 1 then + s = s .. "When this block falls deeper than 1 block, it causes damage to anything it hits. The damage dealt is B×2−2 hit points with B = number of blocks fallen. The damage can never be more than 40 HP." + end + return s +end) + -- Mining, hardness and all that doc.sub.items.register_factoid("nodes", "mining", function(itemstring, def) local pickaxey = { "Diamond Pickaxe", "Iron Pickaxe", "Stone Pickaxe", "Golden Pickaxe", "Wooden Pickaxe" } diff --git a/mods/ITEMS/mcl_anvils/init.lua b/mods/ITEMS/mcl_anvils/init.lua index 936b2a1c..465a5009 100644 --- a/mods/ITEMS/mcl_anvils/init.lua +++ b/mods/ITEMS/mcl_anvils/init.lua @@ -234,7 +234,7 @@ local function damage_anvil(pos) end local anvildef = { - groups = {pickaxey=1, falling_node=1, crush_after_fall=1, deco_block=1, anvil=1}, + groups = {pickaxey=1, falling_node=1, falling_node_damage=1, crush_after_fall=1, deco_block=1, anvil=1}, tiles = {"mcl_anvils_anvil_top_damaged_0.png^[transformR90", "mcl_anvils_anvil_base.png", "mcl_anvils_anvil_side.png"}, paramtype = "light", sunlight_propagates = true,