From 0ec78589379871b1e44224cfee3dcf8f72eec95f Mon Sep 17 00:00:00 2001 From: stujones11 Date: Wed, 5 Apr 2017 17:46:09 +0100 Subject: [PATCH] Add punch damage groups and effects --- 3d_armor/README.txt | 48 +++++++++++-- 3d_armor/api.lua | 89 +++++++++++++++++++++++- 3d_armor/armor.lua | 106 ++++++++++++++++++---------- 3d_armor/init.lua | 62 ++++++++--------- shields/init.lua | 163 +++++++++++++++++++++++++++++++++++--------- 5 files changed, 361 insertions(+), 107 deletions(-) diff --git a/3d_armor/README.txt b/3d_armor/README.txt index 8ec9af1..d30538c 100644 --- a/3d_armor/README.txt +++ b/3d_armor/README.txt @@ -69,12 +69,33 @@ armor_water_protect = true -- Enable fire protection (defaults true if using ethereal mod) armor_fire_protect = false +-- Enable punch damage effects (only works for armor with `damage_groups` table) +armor_punch_damage = true + API --- Armor Registration: armor:register_armor(name, def) + +Wrapper function for `minetest.register_tool`, while registering armor as +a tool item is still supported, this may be deprecated in future so new code +should use this method. + +Additional fields supported by 3d_armor: + + texture = + preview = + armor_groups = + damage_groups =
+ reciprocate_damage = + on_equip = + on_unequip = + on_destroy = + on_damage = + on_punch = + armor:register_armor_group(group, base) Example: @@ -86,12 +107,19 @@ armor:register_armor("mod_name:speed_boots", { inventory_image = "mod_name_speed_boots_inv.png", texture = "mod_name_speed_boots.png", preview = "mod_name_speed_boots_preview.png", + groups = {armor_feet=1, armor_use=500}, armor_groups = {fleshy=10, radiation=10}, - groups = {armor_feet=1, physics_speed=0.5, armor_use=2000}, + damage_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1}, + reciprocate_damage = true, on_destroy = function(player, item_name) - minetest.sound_play("mod_name_break_sound", { - to_player = player:get_player_name(), - }) + local pos = player:get_pos() + if pos then + minetest.sound_play({ + name = "mod_name_break_sound", + pos = pos, + gain = 0.5, + }) + end end, }) @@ -109,13 +137,23 @@ Notes: Elements may be modified by dependent mods, eg shields adds armor_shield. Attributes and physics values are 'stackable', durability is determined by the level of armor_use, total uses == approx (65535/armor_use), non-fleshy -damage groups need to be defined in the tool/weapon used against the player +damage groups need to be defined in the tool/weapon used against the player. + +Reciprocal tool damage will be done only by the first armor inventory item + with `reciprocate_damage = true` Item Callbacks: on_equip = func(player, stack) on_unequip = func(player, stack) on_destroy = func(player, stack) +on_damage = func(player, stack) +on_punch = func(player, hitter, time_from_last_punch, tool_capabilities) + +Notes: on_punch is called every time the player takes damage, `hitter`, +`time_from_last_punch` and `tool_capabilities` can be `nil` and will be in the +case of fall damage, etc. Return `false` to override armor damage effects. +When armor is destroyed `stack` will contain a copy of the previous stack. Global Callbacks: diff --git a/3d_armor/api.lua b/3d_armor/api.lua index d7e7bbf..114416a 100644 --- a/3d_armor/api.lua +++ b/3d_armor/api.lua @@ -43,6 +43,7 @@ armor = { on_update = {}, on_equip = {}, on_unequip = {}, + on_damage = {}, on_destroy = {}, }, version = "0.4.8", @@ -67,7 +68,8 @@ armor.config = { material_mithril = true, material_crystal = true, water_protect = true, - fire_protect = minetest.get_modpath("ethereal") ~= nil + fire_protect = minetest.get_modpath("ethereal") ~= nil, + punch_damage = true, } -- Armor Registration @@ -104,6 +106,12 @@ armor.register_on_unequip = function(self, func) end end +armor.register_on_damage = function(self, func) + if type(func) == "function" then + table.insert(self.registered_callbacks.on_damage, func) + end +end + armor.register_on_destroy = function(self, func) if type(func) == "function" then table.insert(self.registered_callbacks.on_destroy, func) @@ -259,6 +267,84 @@ armor.set_player_armor = function(self, player) self:run_callbacks("on_update", player) end +armor.punch = function(self, player, hitter, time_from_last_punch, tool_capabilities) + local name, player_inv = self:get_valid_player(player, "[punch]") + if not name then + return + end + local state = 0 + local count = 0 + local recip = true + local default_groups = {cracky=3, snappy=3, choppy=3, crumbly=3, level=1} + local list = player_inv:get_list("armor") + for i, stack in pairs(list) do + if stack:get_count() == 1 then + local name = stack:get_name() + local use = minetest.get_item_group(name, "armor_use") or 0 + local damage = use > 0 + local def = stack:get_definition() or {} + if type(def.on_punch) == "function" then + damage = def.on_punch(player, hitter, time_from_last_punch, + tool_capabilities) ~= false + end + if damage == true and tool_capabilities then + local damage_groups = def.damage_groups or default_groups + local level = damage_groups.level or 0 + local groupcaps = tool_capabilities.groupcaps or {} + local uses = 0 + damage = false + for group, caps in pairs(groupcaps) do + local maxlevel = caps.maxlevel or 0 + local diff = maxlevel - level + if diff == 0 then + diff = 1 + end + if diff > 0 and caps.times then + local group_level = damage_groups[group] + if group_level then + local time = caps.times[group_level] + if time then + local dt = time_from_last_punch or 0 + if dt > time / diff then + if caps.uses then + uses = caps.uses * math.pow(3, diff) + end + damage = true + break + end + end + end + end + end + if damage == true and recip == true and hitter and + def.reciprocate_damage == true and uses > 0 then + local item = hitter:get_wielded_item() + local wear = 65535 / uses + item:add_wear(wear) + hitter:set_wielded_item(item) + -- reciprocate tool damage only once + recip = false + end + end + if damage == true then + local old_stack = ItemStack(stack) + stack:add_wear(use) + self:set_inventory_stack(player, i, stack) + self:run_callbacks("on_damage", player, stack) + if stack:get_count() == 0 then + self:run_callbacks("on_unequip", player, old_stack) + self:run_callbacks("on_destroy", player, old_stack) + self:set_player_armor(player) + end + end + state = state + stack:get_wear() + count = count + 1 + end + end + self.def[name].state = state + self.def[name].count = items +end + armor.get_player_skin = function(self, name) local skin = nil if self.skin_mod == "skins" or self.skin_mod == "simple_skins" then @@ -363,3 +449,4 @@ armor.drop_armor = function(pos, stack) obj:setvelocity({x=math.random(-1, 1), y=5, z=math.random(-1, 1)}) end end + diff --git a/3d_armor/armor.lua b/3d_armor/armor.lua index c125c83..4cbd789 100644 --- a/3d_armor/armor.lua +++ b/3d_armor/armor.lua @@ -3,11 +3,6 @@ if minetest.global_exists("intllib") then S = intllib.Getter() end -minetest.register_alias("adminboots","3d_armor:boots_admin") -minetest.register_alias("adminhelmet","3d_armor:helmet_admin") -minetest.register_alias("adminchestplate","3d_armor:chestplate_admin") -minetest.register_alias("adminleggings","3d_armor:leggings_admin") - armor:register_armor("3d_armor:helmet_admin", { description = S("Admin Helmet"), inventory_image = "3d_armor_inv_helmet_admin.png", @@ -52,29 +47,38 @@ armor:register_armor("3d_armor:boots_admin", { end, }) +minetest.register_alias("adminboots","3d_armor:boots_admin") +minetest.register_alias("adminhelmet","3d_armor:helmet_admin") +minetest.register_alias("adminchestplate","3d_armor:chestplate_admin") +minetest.register_alias("adminleggings","3d_armor:leggings_admin") + if armor.materials.wood then armor:register_armor("3d_armor:helmet_wood", { description = S("Wood Helmet"), inventory_image = "3d_armor_inv_helmet_wood.png", - armor_groups = {fleshy=5}, groups = {armor_head=1, armor_heal=0, armor_use=2000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, }) armor:register_armor("3d_armor:chestplate_wood", { description = S("Wood Chestplate"), inventory_image = "3d_armor_inv_chestplate_wood.png", - armor_groups = {fleshy=10}, groups = {armor_torso=1, armor_heal=0, armor_use=2000}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, }) armor:register_armor("3d_armor:leggings_wood", { description = S("Wood Leggings"), inventory_image = "3d_armor_inv_leggings_wood.png", - armor_groups = {fleshy=5}, groups = {armor_legs=1, armor_heal=0, armor_use=2000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, }) armor:register_armor("3d_armor:boots_wood", { description = S("Wood Boots"), inventory_image = "3d_armor_inv_boots_wood.png", armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, groups = {armor_feet=1, armor_heal=0, armor_use=2000}, }) end @@ -83,26 +87,30 @@ if armor.materials.cactus then armor:register_armor("3d_armor:helmet_cactus", { description = S("Cactus Helmet"), inventory_image = "3d_armor_inv_helmet_cactus.png", - armor_groups = {fleshy=5}, groups = {armor_head=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, }) armor:register_armor("3d_armor:chestplate_cactus", { description = S("Cactus Chestplate"), inventory_image = "3d_armor_inv_chestplate_cactus.png", - armor_groups = {fleshy=10}, groups = {armor_torso=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, }) armor:register_armor("3d_armor:leggings_cactus", { description = S("Cactus Leggings"), inventory_image = "3d_armor_inv_leggings_cactus.png", - armor_groups = {fleshy=5}, groups = {armor_legs=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, }) armor:register_armor("3d_armor:boots_cactus", { description = S("Cactus Boots"), inventory_image = "3d_armor_inv_boots_cactus.png", - armor_groups = {fleshy=5}, groups = {armor_feet=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, }) end @@ -110,26 +118,30 @@ if armor.materials.steel then armor:register_armor("3d_armor:helmet_steel", { description = S("Steel Helmet"), inventory_image = "3d_armor_inv_helmet_steel.png", + groups = {armor_head=1, armor_heal=0, armor_use=800}, armor_groups = {fleshy=10}, - groups = {armor_head=1, armor_heal=0, armor_use=500}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:chestplate_steel", { description = S("Steel Chestplate"), inventory_image = "3d_armor_inv_chestplate_steel.png", + groups = {armor_torso=1, armor_heal=0, armor_use=800}, armor_groups = {fleshy=15}, - groups = {armor_torso=1, armor_heal=0, armor_use=500}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:leggings_steel", { description = S("Steel Leggings"), inventory_image = "3d_armor_inv_leggings_steel.png", + groups = {armor_legs=1, armor_heal=0, armor_use=800}, armor_groups = {fleshy=15}, - groups = {armor_legs=1, armor_heal=0, armor_use=500}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:boots_steel", { description = S("Steel Boots"), inventory_image = "3d_armor_inv_boots_steel.png", + groups = {armor_feet=1, armor_heal=0, armor_use=800}, armor_groups = {fleshy=10}, - groups = {armor_feet=1, armor_heal=0, armor_use=500}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, }) end @@ -137,26 +149,30 @@ if armor.materials.bronze then armor:register_armor("3d_armor:helmet_bronze", { description = S("Bronze Helmet"), inventory_image = "3d_armor_inv_helmet_bronze.png", + groups = {armor_head=1, armor_heal=6, armor_use=400}, armor_groups = {fleshy=10}, - groups = {armor_head=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:chestplate_bronze", { description = S("Bronze Chestplate"), inventory_image = "3d_armor_inv_chestplate_bronze.png", + groups = {armor_torso=1, armor_heal=6, armor_use=400}, armor_groups = {fleshy=15}, - groups = {armor_torso=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:leggings_bronze", { description = S("Bronze Leggings"), inventory_image = "3d_armor_inv_leggings_bronze.png", + groups = {armor_legs=1, armor_heal=6, armor_use=400}, armor_groups = {fleshy=15}, - groups = {armor_legs=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, }) armor:register_armor("3d_armor:boots_bronze", { description = S("Bronze Boots"), inventory_image = "3d_armor_inv_boots_bronze.png", + groups = {armor_feet=1, armor_heal=6, armor_use=400}, armor_groups = {fleshy=10}, - groups = {armor_feet=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=3, snappy=2, choppy=2, crumbly=1, level=2}, }) end @@ -164,26 +180,30 @@ if armor.materials.diamond then armor:register_armor("3d_armor:helmet_diamond", { description = S("Diamond Helmet"), inventory_image = "3d_armor_inv_helmet_diamond.png", + groups = {armor_head=1, armor_heal=12, armor_use=200}, armor_groups = {fleshy=15}, - groups = {armor_head=1, armor_heal=12, armor_use=100}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, }) armor:register_armor("3d_armor:chestplate_diamond", { description = S("Diamond Chestplate"), inventory_image = "3d_armor_inv_chestplate_diamond.png", + groups = {armor_torso=1, armor_heal=12, armor_use=200}, armor_groups = {fleshy=20}, - groups = {armor_torso=1, armor_heal=12, armor_use=100}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, }) armor:register_armor("3d_armor:leggings_diamond", { description = S("Diamond Leggings"), inventory_image = "3d_armor_inv_leggings_diamond.png", + groups = {armor_legs=1, armor_heal=12, armor_use=200}, armor_groups = {fleshy=20}, - groups = {armor_legs=1, armor_heal=12, armor_use=100}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, }) armor:register_armor("3d_armor:boots_diamond", { description = S("Diamond Boots"), inventory_image = "3d_armor_inv_boots_diamond.png", + groups = {armor_feet=1, armor_heal=12, armor_use=200}, armor_groups = {fleshy=15}, - groups = {armor_feet=1, armor_heal=12, armor_use=100}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, }) end @@ -191,26 +211,30 @@ if armor.materials.gold then armor:register_armor("3d_armor:helmet_gold", { description = S("Gold Helmet"), inventory_image = "3d_armor_inv_helmet_gold.png", + groups = {armor_head=1, armor_heal=6, armor_use=300}, armor_groups = {fleshy=10}, - groups = {armor_head=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, }) armor:register_armor("3d_armor:chestplate_gold", { description = S("Gold Chestplate"), inventory_image = "3d_armor_inv_chestplate_gold.png", + groups = {armor_torso=1, armor_heal=6, armor_use=300}, armor_groups = {fleshy=15}, - groups = {armor_torso=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, }) armor:register_armor("3d_armor:leggings_gold", { description = S("Gold Leggings"), inventory_image = "3d_armor_inv_leggings_gold.png", + groups = {armor_legs=1, armor_heal=6, armor_use=300}, armor_groups = {fleshy=15}, - groups = {armor_legs=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, }) armor:register_armor("3d_armor:boots_gold", { description = S("Gold Boots"), inventory_image = "3d_armor_inv_boots_gold.png", + groups = {armor_feet=1, armor_heal=6, armor_use=300}, armor_groups = {fleshy=10}, - groups = {armor_feet=1, armor_heal=6, armor_use=250}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, }) end @@ -218,26 +242,30 @@ if armor.materials.mithril then armor:register_armor("3d_armor:helmet_mithril", { description = S("Mithril Helmet"), inventory_image = "3d_armor_inv_helmet_mithril.png", + groups = {armor_head=1, armor_heal=12, armor_use=100}, armor_groups = {fleshy=15}, - groups = {armor_head=1, armor_heal=12, armor_use=50}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:chestplate_mithril", { description = S("Mithril Chestplate"), inventory_image = "3d_armor_inv_chestplate_mithril.png", + groups = {armor_torso=1, armor_heal=12, armor_use=100}, armor_groups = {fleshy=20}, - groups = {armor_torso=1, armor_heal=12, armor_use=50}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:leggings_mithril", { description = S("Mithril Leggings"), inventory_image = "3d_armor_inv_leggings_mithril.png", + groups = {armor_legs=1, armor_heal=12, armor_use=100}, armor_groups = {fleshy=20}, - groups = {armor_legs=1, armor_heal=12, armor_use=50}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:boots_mithril", { description = S("Mithril Boots"), inventory_image = "3d_armor_inv_boots_mithril.png", + groups = {armor_feet=1, armor_heal=12, armor_use=100}, armor_groups = {fleshy=15}, - groups = {armor_feet=1, armor_heal=12, armor_use=50}, + damage_groups = {cracky=2, snappy=1, level=3}, }) end @@ -245,27 +273,31 @@ if armor.materials.crystal then armor:register_armor("3d_armor:helmet_crystal", { description = S("Crystal Helmet"), inventory_image = "3d_armor_inv_helmet_crystal.png", + groups = {armor_head=1, armor_heal=12, armor_use=100, armor_fire=1}, armor_groups = {fleshy=15}, - groups = {armor_head=1, armor_heal=12, armor_use=50, armor_fire=1}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:chestplate_crystal", { description = S("Crystal Chestplate"), inventory_image = "3d_armor_inv_chestplate_crystal.png", + groups = {armor_torso=1, armor_heal=12, armor_use=100, armor_fire=1}, armor_groups = {fleshy=20}, - groups = {armor_torso=1, armor_heal=12, armor_use=50, armor_fire=1}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:leggings_crystal", { description = S("Crystal Leggings"), inventory_image = "3d_armor_inv_leggings_crystal.png", + groups = {armor_legs=1, armor_heal=12, armor_use=100, armor_fire=1}, armor_groups = {fleshy=20}, - groups = {armor_legs=1, armor_heal=12, armor_use=50, armor_fire=1}, + damage_groups = {cracky=2, snappy=1, level=3}, }) armor:register_armor("3d_armor:boots_crystal", { description = S("Crystal Boots"), inventory_image = "3d_armor_inv_boots_crystal.png", - armor_groups = {fleshy=15}, - groups = {armor_feet=1, armor_heal=12, armor_use=50, physics_speed=1, + groups = {armor_feet=1, armor_heal=12, armor_use=100, physics_speed=1, physics_jump=0.5, armor_fire=1}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, level=3}, }) end diff --git a/3d_armor/init.lua b/3d_armor/init.lua index f7f646b..6ca4ab0 100644 --- a/3d_armor/init.lua +++ b/3d_armor/init.lua @@ -5,6 +5,7 @@ end local modname = minetest.get_current_modname() local modpath = minetest.get_modpath(modname) local worldpath = minetest.get_worldpath() +local last_punch_time = {} dofile(modpath.."/api.lua") @@ -60,6 +61,14 @@ armor.formspec = armor.formspec.. if armor.config.fire_protect then armor.formspec = armor.formspec.."label[5,2;"..S("Fire")..": armor_fire]" end +armor:register_on_destroy(function(player, stack) + local name = player:get_player_name() + local def = stack:get_definition() + if name and def and def.description then + minetest.chat_send_player(name, S("Your").." "..def.description.." ".. + S("got destroyed").."!") + end +end) dofile(modpath.."/armor.lua") @@ -270,41 +279,30 @@ if armor.config.drop == true or armor.config.destroy == true then end) end +if armor.config.punch_damage == true then + minetest.register_on_punchplayer(function(player, hitter, + time_from_last_punch, tool_capabilities) + armor:punch(player, hitter, time_from_last_punch, tool_capabilities) + local name = player:get_player_name() + if name then + last_punch_time[name] = minetest.get_gametime() + end + end) +end + minetest.register_on_player_hpchange(function(player, hp_change) - local name, player_inv = armor:get_valid_player(player, "[on_hpchange]") - if name and hp_change < 0 then - local heal_max = 0 - local state = 0 - local items = 0 - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - if stack:get_count() > 0 then - local def = stack:get_definition() or {} - local use = def.groups["armor_use"] or 0 - local heal = def.groups["armor_heal"] or 0 - local item = stack:get_name() - stack:add_wear(use) - armor:set_inventory_stack(player, i, stack) - state = state + stack:get_wear() - items = items + 1 - if stack:get_count() == 0 then - local desc = minetest.registered_items[item].description - if desc then - minetest.chat_send_player(name, - S("Your")..desc.." "..S("got destroyed").."!") - end - armor:set_player_armor(player) - armor:run_callbacks("on_unequip", player, stack) - armor:run_callbacks("on_destroy", player, stack) - end - heal_max = heal_max + heal + if player and hp_change < 0 then + local name = player:get_player_name() + if name and armor.def[name] then + local heal = armor.def[name].heal or 0 + if heal >= math.random(100) then + hp_change = 0 end end - armor.def[name].state = state - armor.def[name].count = items - heal_max = heal_max * armor.config.heal_multiplier - if heal_max >= math.random(100) then - hp_change = 0 + -- check if armor damage was handled by on_punchplayer + local time = last_punch_time[name] or 0 + if time == 0 or time + 1 < minetest.get_gametime() then + armor:punch(player) end end return hp_change diff --git a/shields/init.lua b/shields/init.lua index 506ebc0..572b584 100644 --- a/shields/init.lua +++ b/shields/init.lua @@ -3,6 +3,19 @@ if minetest.global_exists("intllib") then S = intllib.Getter() end local use_moreores = minetest.get_modpath("moreores") +local function play_sound_effect(player, name) + if player then + local pos = player:get_pos() + if pos then + minetest.sound_play({ + pos = pos, + name = name, + max_hear_distance = 10, + gain = 0.5, + }) + end + end +end if minetest.global_exists("armor") and armor.elements then table.insert(armor.elements, "shield") @@ -12,25 +25,47 @@ end -- Regisiter Shields -minetest.register_tool("shields:shield_admin", { +armor:register_armor("shields:shield_admin", { description = S("Admin Shield"), inventory_image = "shields_inv_shield_admin.png", groups = {armor_shield=1000, armor_heal=100, armor_use=0, not_in_creative_inventory=1}, - wear = 0, + on_punch = function(player, hitter, time_from_last_punch, tool_capabilities) + if hitter then + hitter:punch(player, time_from_last_punch, tool_capabilities) + play_sound_effect(player, "default_dig_metal") + end + return false + end, }) if armor.materials.wood then - minetest.register_tool("shields:shield_wood", { + armor:register_armor("shields:shield_wood", { description = S("Wooden Shield"), inventory_image = "shields_inv_shield_wood.png", - groups = {armor_shield=5, armor_heal=0, armor_use=2000}, - wear = 0, + groups = {armor_shield=1, armor_heal=0, armor_use=2000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, }) - minetest.register_tool("shields:shield_enhanced_wood", { + armor:register_armor("shields:shield_enhanced_wood", { description = S("Enhanced Wood Shield"), inventory_image = "shields_inv_shield_enhanced_wood.png", - groups = {armor_shield=8, armor_heal=0, armor_use=1000}, - wear = 0, + groups = {armor_shield=1, armor_heal=0, armor_use=2000}, + armor_groups = {fleshy=8}, + damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=2}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, }) minetest.register_craft({ output = "shields:shield_enhanced_wood", @@ -43,17 +78,33 @@ if armor.materials.wood then end if armor.materials.cactus then - minetest.register_tool("shields:shield_cactus", { + armor:register_armor("shields:shield_cactus", { description = S("Cactus Shield"), inventory_image = "shields_inv_shield_cactus.png", - groups = {armor_shield=5, armor_heal=0, armor_use=2000}, - wear = 0, + groups = {armor_shield=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=5}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=1}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_wood_footstep") + end, }) - minetest.register_tool("shields:shield_enhanced_cactus", { + armor:register_armor("shields:shield_enhanced_cactus", { description = S("Enhanced Cactus Shield"), inventory_image = "shields_inv_shield_enhanced_cactus.png", - groups = {armor_shield=8, armor_heal=0, armor_use=1000}, - wear = 0, + groups = {armor_shield=1, armor_heal=0, armor_use=1000}, + armor_groups = {fleshy=8}, + damage_groups = {cracky=3, snappy=3, choppy=2, crumbly=2, level=2}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_dirt_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_dirt_footstep") + end, }) minetest.register_craft({ output = "shields:shield_enhanced_cactus", @@ -66,56 +117,104 @@ if armor.materials.cactus then end if armor.materials.steel then - minetest.register_tool("shields:shield_steel", { + armor:register_armor("shields:shield_steel", { description = S("Steel Shield"), inventory_image = "shields_inv_shield_steel.png", - groups = {armor_shield=10, armor_heal=0, armor_use=500}, - wear = 0, + groups = {armor_shield=1, armor_heal=0, armor_use=800}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_dig_metal") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_dug_metal") + end, }) end if armor.materials.bronze then - minetest.register_tool("shields:shield_bronze", { + armor:register_armor("shields:shield_bronze", { description = S("Bronze Shield"), inventory_image = "shields_inv_shield_bronze.png", - groups = {armor_shield=10, armor_heal=6, armor_use=250}, - wear = 0, + groups = {armor_shield=1, armor_heal=6, armor_use=400}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=2, snappy=3, choppy=2, crumbly=1, level=2}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_dig_metal") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_dug_metal") + end, }) end if armor.materials.diamond then - minetest.register_tool("shields:shield_diamond", { + armor:register_armor("shields:shield_diamond", { description = S("Diamond Shield"), inventory_image = "shields_inv_shield_diamond.png", - groups = {armor_shield=15, armor_heal=12, armor_use=100}, - wear = 0, + groups = {armor_shield=1, armor_heal=12, armor_use=200}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, choppy=1, level=3}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_glass_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_break_glass") + end, }) end if armor.materials.gold then - minetest.register_tool("shields:shield_gold", { + armor:register_armor("shields:shield_gold", { description = S("Gold Shield"), inventory_image = "shields_inv_shield_gold.png", - groups = {armor_shield=10, armor_heal=6, armor_use=250}, - wear = 0, + groups = {armor_shield=1, armor_heal=6, armor_use=300}, + armor_groups = {fleshy=10}, + damage_groups = {cracky=1, snappy=2, choppy=2, crumbly=3, level=2}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_dig_metal") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_dug_metal") + end, }) end if armor.materials.mithril then - minetest.register_tool("shields:shield_mithril", { + armor:register_armor("shields:shield_mithril", { description = S("Mithril Shield"), inventory_image = "shields_inv_shield_mithril.png", - groups = {armor_shield=15, armor_heal=12, armor_use=50}, - wear = 0, + groups = {armor_shield=1, armor_heal=12, armor_use=100}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, level=3}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_glass_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_break_glass") + end, }) end if armor.materials.crystal then - minetest.register_tool("shields:shield_crystal", { + armor:register_armor("shields:shield_crystal", { description = S("Crystal Shield"), inventory_image = "shields_inv_shield_crystal.png", - groups = {armor_shield=15, armor_heal=12, armor_use=50, armor_fire=1}, - wear = 0, + groups = {armor_shield=1, armor_heal=12, armor_use=100, armor_fire=1}, + armor_groups = {fleshy=15}, + damage_groups = {cracky=2, snappy=1, level=3}, + reciprocate_damage = true, + on_damage = function(player, stack) + play_sound_effect(player, "default_glass_footstep") + end, + on_destroy = function(player, stack) + play_sound_effect(player, "default_break_glass") + end, }) end