diff --git a/mods/CORE/mcl_damage/init.lua b/mods/CORE/mcl_damage/init.lua new file mode 100644 index 0000000000..983b82b49d --- /dev/null +++ b/mods/CORE/mcl_damage/init.lua @@ -0,0 +1,164 @@ +mcl_damage = { + modifiers = {}, + damage_callbacks = {}, + death_callbacks = {}, + types = { + in_fire = {is_fire = true}, + lightning_bolt = {is_lightning = true}, + on_fire = {is_fire = true, bypasses_armor = true}, + lava = {is_fire = true}, + hot_floor = {is_fire = true}, + in_wall = {bypasses_armor = true}, + drown = {bypasses_armor = true}, + starve = {bypasses_armor = true, bypasses_magic = true}, + cactus = {}, + fall = {bypasses_armor = true}, + fly_into_wall = {bypasses_armor = true}, -- unused + out_of_world = {bypasses_armor = true, bypasses_magic = true, bypasses_invulnerability = true}, + generic = {bypasses_armor = true}, + magic = {is_magic = true, bypasses_armor = true}, + dragon_breath = {is_magic = true, bypasses_armor = true}, -- this is only used for dragon fireball; dragon fireball does not actually deal impact damage tho, so this is unreachable + wither = {bypasses_armor = true}, -- unused + wither_skull = {is_magic = true, is_explosion = true}, -- this is non-MC but a workaround to get the proper death message + anvil = {}, + falling_node = {}, -- this is falling_block in MC + mob = {}, + player = {}, + arrow = {is_projectile = true}, + fireball = {is_projectile = true, is_fire = true}, + thorns = {is_magic = true}, + explosion = {is_explosion = true}, + cramming = {bypasses_armor = true}, -- unused + fireworks = {is_explosion = true}, -- unused + } +} + +function mcl_damage.register_modifier(func, priority) + table.insert(mcl_damage.modifiers, {func = func, priority = priority or 0}) +end + +function mcl_damage.register_on_damage(func) + table.insert(mcl_damage.damage_callbacks, func) +end + +function mcl_damage.register_on_death(func) + table.insert(mcl_damage.death_callbacks, func) +end + +function mcl_damage.run_modifiers(obj, damage, reason) + for _, modf in ipairs(mcl_damage.modifiers) do + damage = modf.func(obj, damage, reason) or damage + if damage == 0 then + return 0 + end + end + + return damage +end + +local function run_callbacks(funcs, ...) + for _, func in pairs(funcs) do + func(...) + end +end + +function mcl_damage.run_damage_callbacks(obj, damage, reason) + run_callbacks(mcl_damage.damage_callbacks, obj, damage, reason) +end + +function mcl_damage.run_death_callbacks(obj, reason) + run_callbacks(mcl_damage.death_callbacks, obj, reason) +end + +function mcl_damage.from_punch(mcl_reason, object) + mcl_reason.direct = object + local luaentity = mcl_reason.direct:get_luaentity() + if luaentity then + if luaentity._is_arrow then + mcl_reason.type = "arrow" + elseif luaentity._is_fireball then + mcl_reason.type = "fireball" + elseif luaentity._cmi_is_mob then + mcl_reason.type = "mob" + end + mcl_reason.source = mcl_reason.source or luaentity._source_object + else + mcl_reason.type = "player" + end +end + +function mcl_damage.finish_reason(mcl_reason) + mcl_reason.source = mcl_reason.source or mcl_reason.direct + mcl_reason.flags = mcl_damage.types[mcl_reason.type] +end + +function mcl_damage.from_mt(mt_reason) + if mt_reason._mcl_chached_reason then + return mt_reason._mcl_chached_reason + end + + local mcl_reason + + if mt_reason._mcl_reason then + mcl_reason = mt_reason._mcl_reason + else + mcl_reason = {type = "generic"} + + if mt_reason._mcl_type then + mcl_reason.type = mt_reason._mcl_type + elseif mt_reason.type == "fall" then + mcl_reason.type = "fall" + elseif mt_reason.type == "drown" then + mcl_reason.type = "drown" + elseif mt_reason.type == "punch" then + mcl_damage.from_punch(mcl_reason, mt_reason.object) + elseif mt_reason.type == "node_damage" and mt_reason.node then + if minetest.get_item_group(mt_reason.node, "fire") > 0 then + mcl_reason.type = "in_fire" + end + if minetest.get_item_group(mt_reason.node, "lava") > 0 then + mcl_reason.type = "lava" + end + end + + for key, value in pairs(mt_reason) do + if key:find("_mcl_") == 1 then + mcl_reason[key:sub(6, #key)] = value + end + end + end + + mcl_damage.finish_reason(mcl_reason) + mt_reason._mcl_cached_reason = mcl_reason + + return mcl_reason +end + +function mcl_damage.register_type(name, def) + mcl_damage.types[name] = def +end + +minetest.register_on_player_hpchange(function(player, hp_change, mt_reason) + if hp_change < 0 then + if player:get_hp() <= 0 then + return 0 + end + hp_change = -mcl_damage.run_modifiers(player, -hp_change, mcl_damage.from_mt(mt_reason)) + end + return hp_change +end, true) + +minetest.register_on_player_hpchange(function(player, hp_change, mt_reason) + if hp_change < 0 then + mcl_damage.run_damage_callbacks(player, -hp_change, mcl_damage.from_mt(mt_reason)) + end +end, false) + +minetest.register_on_dieplayer(function(player, mt_reason) + mcl_damage.run_death_callbacks(player, mcl_damage.from_mt(mt_reason)) +end) + +minetest.register_on_mods_loaded(function() + table.sort(mcl_damage.modifiers, function(a, b) return a.priority < b.priority end) +end) + diff --git a/mods/CORE/mcl_damage/mod.conf b/mods/CORE/mcl_damage/mod.conf new file mode 100644 index 0000000000..c7d96395ea --- /dev/null +++ b/mods/CORE/mcl_damage/mod.conf @@ -0,0 +1,3 @@ +name = mcl_damage +author = Fleckenstein +description = Minecraft-like damage reason system diff --git a/mods/CORE/mcl_explosions/init.lua b/mods/CORE/mcl_explosions/init.lua index cd16aa879d..e59e3ea123 100644 --- a/mods/CORE/mcl_explosions/init.lua +++ b/mods/CORE/mcl_explosions/init.lua @@ -12,7 +12,6 @@ under the LGPLv2.1 license. mcl_explosions = {} -local mod_death_messages = minetest.get_modpath("mcl_death_messages") ~= nil local mod_fire = minetest.get_modpath("mcl_fire") ~= nil local CONTENT_FIRE = minetest.get_content_id("mcl_fire:fire") @@ -150,7 +149,8 @@ end -- raydirs - The directions for each ray -- radius - The maximum distance each ray will go -- info - Table containing information about explosion --- puncher - object that punches other objects (optional) +-- direct - direct source object of the damage (optional) +-- source - indirect source object of the damage (optional) -- -- Values in info: -- drop_chance - The chance that destroyed nodes will drop their items @@ -165,7 +165,7 @@ end -- Note that this function has been optimized, it contains code which has been -- inlined to avoid function calls and unnecessary table creation. This was -- measured to give a significant performance increase. -local function trace_explode(pos, strength, raydirs, radius, info, puncher) +local function trace_explode(pos, strength, raydirs, radius, info, direct, source) local vm = get_voxel_manip() local emin, emax = vm:read_from_map(vector.subtract(pos, radius), @@ -247,7 +247,7 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) local ent = obj:get_luaentity() -- Ignore items to lower lag - if obj:is_player() or (ent and ent.name ~= '__builtin.item') then + if (obj:is_player() or (ent and ent.name ~= '__builtin.item')) and obj:get_hp() > 0 then local opos = obj:get_pos() local collisionbox = nil @@ -321,7 +321,6 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) impact = 0 end local damage = math.floor((impact * impact + impact) * 7 * strength + 1) - local source = puncher or obj local sleep_formspec_doesnt_close_mt53 = false if obj:is_player() then @@ -333,26 +332,22 @@ local function trace_explode(pos, strength, raydirs, radius, info, puncher) sleep_formspec_doesnt_close_mt53 = true end end - if mod_death_messages then - mcl_death_messages.player_damage(obj, S("@1 was caught in an explosion.", name)) - end - if rawget(_G, "armor") and armor.last_damage_types then - armor.last_damage_types[name] = "explosion" - end end if sleep_formspec_doesnt_close_mt53 then - minetest.after(0.3, function(obj, damage, impact, punch_dir) -- 0.2 is minimum delay for closing old formspec and open died formspec -- TODO: REMOVE THIS IN THE FUTURE - if not obj then return end - obj:punch(obj, 10, { damage_groups = { full_punch_interval = 1, fleshy = damage, knockback = impact * 20.0 } }, punch_dir) - obj:add_velocity(vector.multiply(punch_dir, impact * 20)) - end, obj, damage, impact, vector.new(punch_dir)) - else - obj:punch(source, 10, { damage_groups = { full_punch_interval = 1, fleshy = damage, knockback = impact * 20.0 } }, punch_dir) + minetest.after(0.3, function() -- 0.2 is minimum delay for closing old formspec and open died formspec -- TODO: REMOVE THIS IN THE FUTURE + if not obj:is_player() then + return + end + + mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) - if obj:is_player() then obj:add_velocity(vector.multiply(punch_dir, impact * 20)) - elseif ent.tnt_knockback then + end) + else + mcl_util.deal_damage(obj, damage, {type = "explosion", direct = direct, source = source}) + + if obj:is_player() or ent.tnt_knockback then obj:add_velocity(vector.multiply(punch_dir, impact * 20)) end end @@ -422,7 +417,8 @@ end -- pos - The position where the explosion originates from -- strength - The blast strength of the explosion (a TNT explosion uses 4) -- info - Table containing information about explosion --- puncher - object that is reported as source of punches/damage (optional) +-- direct - direct source object of the damage (optional) +-- source - indirect source object of the damage (optional) -- -- Values in info: -- drop_chance - If specified becomes the drop chance of all nodes in the @@ -436,7 +432,7 @@ end -- griefing - If true, the explosion will destroy nodes (default: true) -- grief_protected - If true, the explosion will also destroy nodes which have -- been protected (default: false) -function mcl_explosions.explode(pos, strength, info, puncher) +function mcl_explosions.explode(pos, strength, info, direct, source) if info == nil then info = {} end @@ -465,7 +461,7 @@ function mcl_explosions.explode(pos, strength, info, puncher) info.drop_chance = 0 end - trace_explode(pos, strength, shape, radius, info, puncher) + trace_explode(pos, strength, shape, radius, info, direct, source) if info.particles then add_particles(pos, radius) diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_sponge1.png b/mods/CORE/mcl_particles/textures/mcl_particles_sponge1.png new file mode 100644 index 0000000000..e8099a41a9 Binary files /dev/null and b/mods/CORE/mcl_particles/textures/mcl_particles_sponge1.png differ diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_sponge2.png b/mods/CORE/mcl_particles/textures/mcl_particles_sponge2.png new file mode 100644 index 0000000000..0004ce4db5 Binary files /dev/null and b/mods/CORE/mcl_particles/textures/mcl_particles_sponge2.png differ diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_sponge3.png b/mods/CORE/mcl_particles/textures/mcl_particles_sponge3.png new file mode 100644 index 0000000000..62ae83a860 Binary files /dev/null and b/mods/CORE/mcl_particles/textures/mcl_particles_sponge3.png differ diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_sponge4.png b/mods/CORE/mcl_particles/textures/mcl_particles_sponge4.png new file mode 100644 index 0000000000..7ee00cbf59 Binary files /dev/null and b/mods/CORE/mcl_particles/textures/mcl_particles_sponge4.png differ diff --git a/mods/CORE/mcl_particles/textures/mcl_particles_sponge5.png b/mods/CORE/mcl_particles/textures/mcl_particles_sponge5.png new file mode 100644 index 0000000000..5278caff34 Binary files /dev/null and b/mods/CORE/mcl_particles/textures/mcl_particles_sponge5.png differ diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index ac913de390..f976457c0b 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -418,3 +418,124 @@ function mcl_util.get_color(colorstr) return colorstr, hex end end + +function mcl_util.call_on_rightclick(itemstack, player, pointed_thing) + -- Call on_rightclick if the pointed node defines it + if pointed_thing and pointed_thing.type == "node" then + local pos = pointed_thing.under + local node = minetest.get_node(pos) + if player and not player:get_player_control().sneak then + local nodedef = minetest.registered_nodes[node.name] + local on_rightclick = nodedef and nodedef.on_rightclick + if on_rightclick then + return on_rightclick(pos, node, player, itemstack, pointed_thing) or itemstack + end + end + end +end + +function mcl_util.calculate_durability(itemstack) + local unbreaking_level = mcl_enchanting.get_enchantment(itemstack, "unbreaking") + local armor_uses = minetest.get_item_group(itemstack:get_name(), "mcl_armor_uses") + + local uses + + if armor_uses > 0 then + uses = armor_uses + if unbreaking_level > 0 then + uses = uses / (0.6 + 0.4 / (unbreaking_level + 1)) + end + else + local def = itemstack:get_definition() + if def then + local fixed_uses = def._mcl_uses + if fixed_uses then + uses = fixed_uses + if unbreaking_level > 0 then + uses = uses * (unbreaking_level + 1) + end + end + end + if not uses then + local toolcaps = itemstack:get_tool_capabilities() + local groupcaps = toolcaps.groupcaps + for _, v in pairs(groupcaps) do + uses = v.uses + break + end + end + end + + return uses or 0 +end + +function mcl_util.use_item_durability(itemstack, n) + local uses = mcl_util.calculate_durability(itemstack) + itemstack:add_wear(65535 / uses * n) +end + +function mcl_util.deal_damage(target, damage, mcl_reason) + local luaentity = target:get_luaentity() + + if luaentity then + if luaentity.deal_damage then + luaentity:deal_damage(damage, mcl_reason or {type = "generic"}) + return + elseif luaentity._cmi_is_mob then + -- local puncher = mcl_reason and mcl_reason.direct or target + -- target:punch(puncher, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy = damage}}, vector.direction(puncher:get_pos(), target:get_pos()), damage) + luaentity.health = luaentity.health - damage + return + end + end + + target:set_hp(target:get_hp() - damage, {_mcl_reason = mcl_reason}) +end + +function mcl_util.get_hp(obj) + local luaentity = obj:get_luaentity() + + if luaentity and luaentity._cmi_is_mob then + return luaentity.health + else + return obj:get_hp() + end +end + +function mcl_util.get_inventory(object, create) + if object:is_player() then + return object:get_inventory() + else + local luaentity = object:get_luaentity() + local inventory = luaentity.inventory + + if create and not inventory and luaentity.create_inventory then + inventory = luaentity:create_inventory() + end + + return inventory + end +end + +function mcl_util.get_wielded_item(object) + if object:is_player() then + return object:get_wielded_item() + else + -- ToDo: implement getting wielditems from mobs as soon as mobs have wielditems + return ItemStack() + end +end + +function mcl_util.get_object_name(object) + if object:is_player() then + return object:get_player_name() + else + local luaentity = object:get_luaentity() + + if not luaentity then + return "" + end + + return luaentity.nametag and luaentity.nametag ~= "" and luaentity.nametag or luaentity.description or luaentity.name + end +end diff --git a/mods/ENTITIES/mcl_burning/api.lua b/mods/ENTITIES/mcl_burning/api.lua index d2567f6b2e..78814a2c7d 100644 --- a/mods/ENTITIES/mcl_burning/api.lua +++ b/mods/ENTITIES/mcl_burning/api.lua @@ -35,7 +35,7 @@ function mcl_burning.get_touching_nodes(obj, nodenames, storage) return nodes end -function mcl_burning.set_on_fire(obj, burn_time, reason) +function mcl_burning.set_on_fire(obj, burn_time) if obj:get_hp() < 0 then return end @@ -47,27 +47,27 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) return end - local max_fire_prot_lvl = 0 + if obj:is_player() and minetest.is_creative_enabled(obj:get_player_name()) then + burn_time = 0 + else + local max_fire_prot_lvl = 0 + local inv = mcl_util.get_inventory(obj) + local armor_list = inv and inv:get_list("armor") - if obj:is_player() then - if minetest.is_creative_enabled(obj:get_player_name()) then - burn_time = burn_time / 100 + if armor_list then + for _, stack in pairs(armor_list) do + local fire_prot_lvl = mcl_enchanting.get_enchantment(stack, "fire_protection") + if fire_prot_lvl > max_fire_prot_lvl then + max_fire_prot_lvl = fire_prot_lvl + end + end end - local inv = obj:get_inventory() - - for i = 2, 5 do - local stack = inv:get_stack("armor", i) - - local fire_prot_lvl = mcl_enchanting.get_enchantment(stack, "fire_protection") - max_fire_prot_lvl = math.max(max_fire_prot_lvl, fire_prot_lvl) + if max_fire_prot_lvl > 0 then + burn_time = burn_time - math.floor(burn_time * max_fire_prot_lvl * 0.15) end end - if max_fire_prot_lvl > 0 then - burn_time = burn_time - math.floor(burn_time * max_fire_prot_lvl * 0.15) - end - if not storage.burn_time or burn_time >= storage.burn_time then if obj:is_player() and not storage.fire_hud_id then storage.fire_hud_id = obj:hud_add({ @@ -79,7 +79,6 @@ function mcl_burning.set_on_fire(obj, burn_time, reason) }) end storage.burn_time = burn_time - storage.burn_reason = reason storage.fire_damage_timer = 0 local fire_entity = minetest.add_entity(obj:get_pos(), "mcl_burning:fire") @@ -120,7 +119,6 @@ function mcl_burning.extinguish(obj) mcl_burning.storage[obj] = {} else storage.burn_time = nil - storage.burn_reason = nil storage.fire_damage_timer = nil end end @@ -140,36 +138,9 @@ function mcl_burning.tick(obj, dtime, storage) storage.fire_damage_timer = 0 local luaentity = obj:get_luaentity() - local is_mob = luaentity and luaentity._cmi_is_mob - local hp = is_mob and luaentity.health or obj:get_hp() - if hp > 0 then - local do_damage = true - - if obj:is_player() then - if mcl_potions.player_has_effect(obj, "fire_proof") then - do_damage = false - else - local name = obj:get_player_name() - armor.last_damage_types[name] = "fire" - local deathmsg = S("@1 burned to death.", name) - if storage.reason then - deathmsg = S("@1 was burned by @2.", name, storage.reason) - end - mcl_death_messages.player_damage(obj, deathmsg) - end - elseif luaentity.fire_damage_resistant then - do_damage = false - end - - if do_damage then - local new_hp = hp - 1 - if is_mob then - luaentity.health = new_hp - else - obj:set_hp(new_hp) - end - end + if not luaentity or not luaentity.fire_damage_resistant then + mcl_util.deal_damage(obj, 1, {type = "on_fire"}) end end end diff --git a/mods/ENTITIES/mcl_falling_nodes/init.lua b/mods/ENTITIES/mcl_falling_nodes/init.lua index 6e69f89112..af2c06703d 100644 --- a/mods/ENTITIES/mcl_falling_nodes/init.lua +++ b/mods/ENTITIES/mcl_falling_nodes/init.lua @@ -1,9 +1,6 @@ local S = minetest.get_translator("mcl_falling_nodes") -local dmes = minetest.get_modpath("mcl_death_messages") ~= nil local has_mcl_armor = minetest.get_modpath("mcl_armor") -local is_creative_enabled = minetest.is_creative_enabled - local get_falling_depth = function(self) if not self._startpos then -- Fallback @@ -23,80 +20,31 @@ local deal_falling_damage = function(self, dtime) -- Fallback self._startpos = pos end - local objs = minetest.get_objects_inside_radius(pos, 1) - for _,v in ipairs(objs) do - if v:is_player() then - local hp = v:get_hp() - local name = v:get_player_name() - if hp ~= 0 then - if not self._hit_players then - self._hit_players = {} - end - local hit = false - for _,v in ipairs(self._hit_players) do - if name == v then - hit = true + self._hit = self._hit or {} + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 1)) do + if mcl_util.get_hp(obj) > 0 and not self._hit[obj] then + self._hit[obj] = true + local way = self._startpos.y - pos.y + local damage = (way - 1) * 2 + damage = math.min(40, math.max(0, damage)) + if damage >= 1 then + -- Reduce damage if wearing a helmet + local inv = mcl_util.get_inventory(obj) + if inv then + local helmet = inv:get_stack("armor", 2) + if minetest.get_item_group(helmet:get_name(), "combat_armor") > 0 then + damage = damage / 4 * 3 + mcl_util.use_item_durability(helmet, 1) + inv:set_stack("armor", 2, helmet) 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 - -- Reduce damage if wearing a helmet - local inv = v:get_inventory() - local helmet = inv:get_stack("armor", 2) - if has_mcl_armor and not helmet:is_empty() then - hp = hp/4*3 - if not is_creative_enabled(name) then - helmet:add_wear(65535/helmet:get_definition().groups.mcl_armor_uses) --TODO: be sure damage is exactly like mc (informations are missing in the mc wiki) - inv:set_stack("armor", 2, helmet) - end - end - local msg - if minetest.get_item_group(self.node.name, "anvil") ~= 0 then - msg = S("@1 was smashed by a falling anvil.", v:get_player_name()) - else - msg = S("@1 was smashed by a falling block.", v:get_player_name()) - end - if dmes then - mcl_death_messages.player_damage(v, msg) - end - v:set_hp(hp, { type = "punch", from = "mod" }) - end - end - end - else - local hp = v:get_luaentity().health - if hp and hp ~= 0 then - if not self._hit_mobs then - self._hit_mobs = {} - end - local hit = false - for _,mob in ipairs(self._hit_mobs) do - if v == mob then - hit = true - end - end - --TODO: reduce damage for mobs then they will be able to wear armor - if not hit then - table.insert(self._hit_mobs, v) - 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:get_luaentity().health = hp - end + local deathmsg, dmg_type + if minetest.get_item_group(self.node.name, "anvil") ~= 0 then + dmg_type = "anvil" + else + dmg_type = "falling_node" end + mcl_util.deal_damage(obj, damage, {type = dmg_type}) end end end @@ -166,7 +114,7 @@ minetest.register_entity(":__builtin:falling_node", { on_activate = function(self, staticdata) self.object:set_armor_groups({immortal = 1}) - + local ds = minetest.deserialize(staticdata) if ds then self._startpos = ds._startpos @@ -200,7 +148,7 @@ minetest.register_entity(":__builtin:falling_node", { local np = {x = pos.x, y = pos.y + 0.3, z = pos.z} local n2 = minetest.get_node(np) if n2.name == "mcl_portals:portal_end" then - -- TODO: Teleport falling node. + -- TODO: Teleport falling node. self.object:remove() return end @@ -239,7 +187,7 @@ minetest.register_entity(":__builtin:falling_node", { end local nd = minetest.registered_nodes[n2.name] if n2.name == "mcl_portals:portal_end" then - -- TODO: Teleport falling node. + -- TODO: Teleport falling node. elseif (nd and nd.buildable_to == true) or minetest.get_item_group(self.node.name, "crush_after_fall") ~= 0 then -- Replace destination node if it's buildable to diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index eda74aeb42..2d8cef5b0e 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -502,20 +502,6 @@ and damages any entity caught inside the blast radius. Protection will limit node destruction but not entity damage. -mobs:capture_mob ----------------- - -mobs:capture_mob(...) - -Does nothing and returns false. - -This function is provided for compability with Mobs Redo for an attempt to -capture a mob. -Mobs cannot be captured in MineClone 2. - -In Mobs Redo, this is generally called inside the on_rightclick section of the mob -api code, it provides a chance of capturing the mob. See Mobs Redo documentation -of parameters. Feeding and Taming/Breeding --------------------------- @@ -535,19 +521,6 @@ Will return true when mob is fed with item it likes. them up -Protecting Mobs ---------------- - -mobs:protect(self, clicker) - -This function can be used to right-click any tamed mob with mobs:protector item, -this will protect the mob from harm inside of a protected area from other -players. Will return true when mob right-clicked with mobs:protector item. - - 'self' mob information - 'clicker' player information - - Riding Mobs ----------- @@ -605,7 +578,7 @@ Note: animation names above are from the pre-defined animation lists inside mob registry without extensions. -mobs:set_animation(self, name) +mobs.set_mob_animation(self, name) This function sets the current animation for mob, defaulting to "stand" if not found. @@ -781,8 +754,5 @@ mobs:register_mob("mob_horse:horse", { inv:remove_item("main", "mobs:saddle") end end - - -- used to capture horse with magic lasso - mobs:capture_mob(self, clicker, 0, 0, 80, false, nil) end }) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua new file mode 100644 index 0000000000..d413bae72e --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -0,0 +1,761 @@ +-- API for Mobs Redo: MineClone 2 Delux 2.0 DRM Free Early Access Super Extreme Edition + +-- mobs library +mobs = {} + +-- lua locals - can grab from this to easily plop them into the api lua files + +--localize minetest functions +local minetest_settings = minetest.settings +local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius +local minetest_get_modpath = minetest.get_modpath +local minetest_registered_nodes = minetest.registered_nodes +local minetest_get_node = minetest.get_node +local minetest_get_item_group = minetest.get_item_group +local minetest_registered_entities = minetest.registered_entities +local minetest_line_of_sight = minetest.line_of_sight +local minetest_after = minetest.after +local minetest_sound_play = minetest.sound_play +local minetest_add_particlespawner = minetest.add_particlespawner +local minetest_registered_items = minetest.registered_items +local minetest_set_node = minetest.set_node +local minetest_add_item = minetest.add_item +local minetest_get_craft_result = minetest.get_craft_result +local minetest_find_path = minetest.find_path +local minetest_is_protected = minetest.is_protected +local minetest_is_creative_enabled = minetest.is_creative_enabled +local minetest_find_node_near = minetest.find_node_near +local minetest_find_nodes_in_area_under_air = minetest.find_nodes_in_area_under_air +local minetest_raycast = minetest.raycast +local minetest_get_us_time = minetest.get_us_time +local minetest_add_entity = minetest.add_entity +local minetest_get_natural_light = minetest.get_natural_light +local minetest_get_node_or_nil = minetest.get_node_or_nil + +-- localize math functions +local math_pi = math.pi +local math_sin = math.sin +local math_cos = math.cos +local math_abs = math.abs +local math_min = math.min +local math_max = math.max +local math_atan = math.atan +local math_random = math.random +local math_floor = math.floor + +-- localize vector functions +local vector_new = vector.new +local vector_add = vector.add +local vector_length = vector.length +local vector_direction = vector.direction +local vector_normalize = vector.normalize +local vector_multiply = vector.multiply +local vector_divide = vector.divide + +-- mob constants +local BREED_TIME = 30 +local BREED_TIME_AGAIN = 300 +local CHILD_GROW_TIME = 60*20 +local DEATH_DELAY = 0.5 +local DEFAULT_FALL_SPEED = -10 +local FLOP_HEIGHT = 5.0 +local FLOP_HOR_SPEED = 1.5 +local GRAVITY = minetest_settings:get("movement_gravity")-- + 9.81 + + +local MOB_CAP = {} +MOB_CAP.hostile = 70 +MOB_CAP.passive = 10 +MOB_CAP.ambient = 15 +MOB_CAP.water = 15 + +-- Load main settings +local damage_enabled = minetest_settings:get_bool("enable_damage") +local disable_blood = minetest_settings:get_bool("mobs_disable_blood") +local mobs_drop_items = minetest_settings:get_bool("mobs_drop_items") ~= false +local mobs_griefing = minetest_settings:get_bool("mobs_griefing") ~= false +local spawn_protected = minetest_settings:get_bool("mobs_spawn_protected") ~= false +local remove_far = true +local difficulty = tonumber(minetest_settings:get("mob_difficulty")) or 1.0 +local show_health = false +local max_per_block = tonumber(minetest_settings:get("max_objects_per_block") or 64) +local mobs_spawn_chance = tonumber(minetest_settings:get("mobs_spawn_chance") or 2.5) + +-- pathfinding settings +local enable_pathfinding = true +local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching +local stuck_path_timeout = 10 -- how long will mob follow path before giving up + +-- default nodes +local node_ice = "mcl_core:ice" +local node_snowblock = "mcl_core:snowblock" +local node_snow = "mcl_core:snow" +mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt" + +local mod_weather = minetest_get_modpath("mcl_weather") ~= nil +local mod_explosions = minetest_get_modpath("mcl_explosions") ~= nil +local mod_mobspawners = minetest_get_modpath("mcl_mobspawners") ~= nil +local mod_hunger = minetest_get_modpath("mcl_hunger") ~= nil +local mod_worlds = minetest_get_modpath("mcl_worlds") ~= nil +local mod_armor = minetest_get_modpath("mcl_armor") ~= nil +local mod_experience = minetest_get_modpath("mcl_experience") ~= nil + + +-- random locals I found +local los_switcher = false +local height_switcher = false + +-- Get translator +local S = minetest.get_translator("mcl_mobs") + +-- CMI support check +local use_cmi = minetest.global_exists("cmi") + + +-- Invisibility mod check +mobs.invis = {} +if minetest.global_exists("invisibility") then + mobs.invis = invisibility +end + + +-- creative check +function mobs.is_creative(name) + return minetest_is_creative_enabled(name) +end + + +local atan = function(x) + if not x or x ~= x then + return 0 + else + return math_atan(x) + end +end + + + + +-- Shows helpful debug info above each mob +local mobs_debug = minetest_settings:get_bool("mobs_debug", false) + +-- Peaceful mode message so players will know there are no monsters +if minetest_settings:get_bool("only_peaceful_mobs", false) then + minetest.register_on_joinplayer(function(player) + minetest.chat_send_player(player:get_player_name(), + S("Peaceful mode active! No monsters will spawn.")) + end) +end + + +local api_path = minetest.get_modpath(minetest.get_current_modname()).."/api/mob_functions/" + +--ignite all parts of the api +dofile(api_path .. "ai.lua") +dofile(api_path .. "animation.lua") +dofile(api_path .. "collision.lua") +dofile(api_path .. "environment.lua") +dofile(api_path .. "interaction.lua") +dofile(api_path .. "movement.lua") +dofile(api_path .. "set_up.lua") +dofile(api_path .. "attack_type_instructions.lua") +dofile(api_path .. "sound_handling.lua") +dofile(api_path .. "death_logic.lua") +dofile(api_path .. "mob_effects.lua") +dofile(api_path .. "projectile_handling.lua") +dofile(api_path .. "breeding.lua") +dofile(api_path .. "head_logic.lua") + + +mobs.spawning_mobs = {} + + + + +-- register mob entity +function mobs:register_mob(name, def) + + local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25} + + -- Workaround for : + -- Increase upper Y limit to avoid mobs glitching through solid nodes. + -- FIXME: Remove workaround if it's no longer needed. + + if collisionbox[5] < 0.79 then + collisionbox[5] = 0.79 + end + + mobs.spawning_mobs[name] = true + + local function scale_difficulty(value, default, min, special) + if (not value) or (value == default) or (value == special) then + return default + else + return math_max(min, value * difficulty) + end + end + + minetest.register_entity(name, { + description = def.description, + use_texture_alpha = def.use_texture_alpha, + stepheight = def.stepheight or 0.6, + stepheight_backup = def.stepheight or 0.6, + name = name, + type = def.type, + attack_type = def.attack_type, + fly = def.fly, + fly_in = def.fly_in or {"air", "__airlike"}, + owner = def.owner or "", + order = def.order or "", + on_die = def.on_die, + spawn_small_alternative = def.spawn_small_alternative, + do_custom = def.do_custom, + jump_height = def.jump_height or 4, -- was 6 + rotate = def.rotate or 0, -- 0=front, 90=side, 180=back, 270=side2 + hp_min = scale_difficulty(def.hp_min, 5, 1), + hp_max = scale_difficulty(def.hp_max, 10, 1), + xp_min = def.xp_min or 1, + xp_max = def.xp_max or 5, + breath_max = def.breath_max or 6, + breathes_in_water = def.breathes_in_water or false, + physical = true, + collisionbox = collisionbox, + collide_with_objects = def.collide_with_objects or false, + selectionbox = def.selectionbox or def.collisionbox, + visual = def.visual, + visual_size = def.visual_size or {x = 1, y = 1}, + mesh = def.mesh, + makes_footstep_sound = def.makes_footstep_sound or false, + view_range = def.view_range or 16, + walk_velocity = def.walk_velocity or 1, + run_velocity = def.run_velocity or 2, + damage = scale_difficulty(def.damage, 0, 0), + light_damage = def.light_damage or 0, + sunlight_damage = def.sunlight_damage or 0, + water_damage = def.water_damage or 0, + lava_damage = def.lava_damage or 8, + fire_damage = def.fire_damage or 1, + suffocation = def.suffocation or true, + fall_damage = def.fall_damage or 1, + fall_speed = def.fall_speed or DEFAULT_FALL_SPEED, -- must be lower than -2 + drops = def.drops or {}, + armor = def.armor or 100, + on_rightclick = mobs.create_mob_on_rightclick(def.on_rightclick), + arrow = def.arrow, + shoot_interval = def.shoot_interval, + sounds = def.sounds or {}, + animation = def.animation, + jump = def.jump ~= false, + walk_chance = def.walk_chance or 50, + attacks_monsters = def.attacks_monsters or false, + group_attack = def.group_attack or false, + passive = def.passive or false, + knock_back = def.knock_back ~= false, + shoot_offset = def.shoot_offset or 0, + floats = def.floats or 1, -- floats in water by default + floats_on_lava = def.floats_on_lava or 0, + replace_rate = def.replace_rate, + replace_what = def.replace_what, + replace_with = def.replace_with, + replace_offset = def.replace_offset or 0, + on_replace = def.on_replace, + timer = 0, + state_timer = 0, + env_damage_timer = 0, + tamed = false, + pause_timer = 0, + gotten = false, + reach = def.reach or 3, + htimer = 0, + texture_list = def.textures, + child_texture = def.child_texture, + docile_by_day = def.docile_by_day or false, + time_of_day = 0.5, + fear_height = def.fear_height or 0, + runaway = def.runaway, + runaway_timer = 0, + pathfinding = def.pathfinding, + immune_to = def.immune_to or {}, + explosion_radius = def.explosion_radius, -- LEGACY + explosion_damage_radius = def.explosion_damage_radius, -- LEGACY + explosiontimer_reset_radius = def.explosiontimer_reset_radius, + explosion_timer = def.explosion_timer or 3, + allow_fuse_reset = def.allow_fuse_reset ~= false, + stop_to_explode = def.stop_to_explode ~= false, + custom_attack = def.custom_attack, + double_melee_attack = def.double_melee_attack, + dogshoot_switch = def.dogshoot_switch, + dogshoot_count = 0, + dogshoot_count_max = def.dogshoot_count_max or 5, + dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5), + attack_animals = def.attack_animals or false, + specific_attack = def.specific_attack, + runaway_from = def.runaway_from, + owner_loyal = def.owner_loyal, + facing_fence = false, + + _cmi_is_mob = true, + + pushable = def.pushable or true, + + --j4i stuff + yaw = 0, + automatic_face_movement_dir = def.rotate or 0, -- 0=front, 90=side, 180=back, 270=side2 + automatic_face_movement_max_rotation_per_sec = 360, --degrees + backface_culling = true, + walk_timer = 0, + stand_timer = 0, + current_animation = "", + gravity = GRAVITY, + swim = def.swim, + swim_in = def.swim_in or {mobs_mc.items.water_source, "mcl_core:water_flowing", mobs_mc.items.river_water_source}, + pitch_switch = "static", + jump_only = def.jump_only, + hostile = def.hostile, + neutral = def.neutral, + attacking = nil, + visual_size_origin = def.visual_size or {x = 1, y = 1, z = 1}, + punch_timer_cooloff = def.punch_timer_cooloff or 0.5, + death_animation_timer = 0, + hostile_cooldown = def.hostile_cooldown or 15, + tilt_fly = def.tilt_fly, + tilt_swim = def.tilt_swim, + fall_slow = def.fall_slow, + projectile_cooldown_min = def.projectile_cooldown_min or 2, + projectile_cooldown_max = def.projectile_cooldown_max or 6, + skittish = def.skittish, + + minimum_follow_distance = def.minimum_follow_distance or 0.5, --make mobs not freak out when underneath + + memory = 0, -- memory timer if chasing/following + fly_random_while_attack = def.fly_random_while_attack, + + --for spiders + always_climb = def.always_climb, + + --despawn mechanic variables + lifetimer_reset = 30, --30 seconds + lifetimer = 30, --30 seconds + + --breeding stuff + breed_timer = 0, + breed_lookout_timer = 0, + breed_distance = def.breed_distance or 1.5, --how far away mobs have to be to begin actual breeding + breed_lookout_timer_goal = 30, --30 seconds (this timer is for how long the mob looks for a mate) + breed_timer_cooloff = 5*60, -- 5 minutes (this timer is for how long the mob has to wait before being bred again) + bred = false, + follow = def.follow, --this item is also used for the breeding mechanism + follow_distance = def.follow_distance or 2, + baby_size = def.baby_size or 0.5, + baby = false, + grow_up_timer = 0, + grow_up_goal = 20*60, --in 20 minutes the mob grows up + special_breed_timer = 0, --this is used for the AHEM AHEM part of breeding + + backup_visual_size = def.visual_size, + backup_collisionbox = collisionbox, + backup_selectionbox = def.selectionbox or def.collisionbox, + + + --fire timer + burn_timer = 0, + + ignores_cobwebs = def.ignores_cobwebs, + breath = def.breath_max or 6, + + random_sound_timer_min = 3, + random_sound_timer_max = 10, + + + --head code variables + --defaults are for the cow's default + --because I don't know what else to set them + --to :P + + has_head = def.has_head or false, + head_bone = def.head_bone, + + --you must use these to adjust the mob's head positions + + --has_head is used as a logic gate (quick easy check) + has_head = def.has_head or false, + --head_bone is the actual bone in the model which the head + --is attached to for animation + head_bone = def.head_bone or "head", + + --this part controls the base position of the head calculations + --localized to the mob's visual yaw when gotten (self.object:get_yaw()) + --you can enable the debug in /mob_functions/head_logic.lua by uncommenting the + --particle spawner code + head_height_offset = def.head_height_offset or 1.0525, + head_direction_offset = def.head_direction_offset or 0.5, + + --this part controls the visual of the head + head_bone_pos_y = def.head_bone_pos_y or 3.6, + head_bone_pos_z = def.head_bone_pos_z or -0.6, + head_pitch_modifier = def.head_pitch_modifier or 0, + + --these variables are switches in case the model + --moves the wrong way + swap_y_with_x = def.swap_y_with_x or false, + reverse_head_yaw = def.reverse_head_yaw or false, + + --END HEAD CODE VARIABLES + + --end j4i stuff + + -- MCL2 extensions + teleport = mobs.teleport, + do_teleport = def.do_teleport, + spawn_class = def.spawn_class, + ignores_nametag = def.ignores_nametag or false, + rain_damage = def.rain_damage or 0, + glow = def.glow, + --can_despawn = can_despawn, + child = def.child or false, + texture_mods = {}, + shoot_arrow = def.shoot_arrow, + sounds_child = def.sounds_child, + explosion_strength = def.explosion_strength, + suffocation_timer = 0, + follow_velocity = def.follow_velocity or 2.4, + instant_death = def.instant_death or false, + fire_resistant = def.fire_resistant or false, + fire_damage_resistant = def.fire_damage_resistant or false, + ignited_by_sunlight = def.ignited_by_sunlight or false, + eye_height = def.eye_height or 1.5, + defuse_reach = def.defuse_reach or 4, + -- End of MCL2 extensions + + on_spawn = def.on_spawn, + + --on_blast = def.on_blast or do_tnt, + + on_step = mobs.mob_step, + + --do_punch = def.do_punch, + + on_punch = mobs.mob_punch, + + --on_breed = def.on_breed, + + --on_grown = def.on_grown, + + --on_detach_child = mob_detach_child, + + on_activate = function(self, staticdata, dtime) + self.object:set_acceleration(vector_new(0,-GRAVITY, 0)) + return mobs.mob_activate(self, staticdata, def, dtime) + end, + + get_staticdata = function(self) + return mobs.mob_staticdata(self) + end, + + --harmed_by_heal = def.harmed_by_heal, + }) + + if minetest_get_modpath("doc_identifier") ~= nil then + doc.sub.identifier.register_object(name, "basics", "mobs") + end + +end -- END mobs:register_mob function + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-- register arrow for shoot attack +function mobs:register_arrow(name, def) + + -- errorcheck + if not name or not def then + print("failed to register arrow entity") + return + end + + minetest.register_entity(name.."_entity", { + + physical = false, + visual = def.visual, + visual_size = def.visual_size, + textures = def.textures, + velocity = def.velocity, + hit_player = def.hit_player, + hit_node = def.hit_node, + hit_mob = def.hit_mob, + hit_object = def.hit_object, + drop = def.drop or false, -- drops arrow as registered item when true + collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows + timer = 0, + switch = 0, + owner_id = def.owner_id, + rotate = def.rotate, + speed = def.speed or nil, + on_step = function(self) + + local vel = self.object:get_velocity() + + local pos = self.object:get_pos() + + if self.timer > 150 + or not mobs.within_limits(pos, 0) then + mcl_burning.extinguish(self.object) + self.object:remove(); + return + end + + -- does arrow have a tail (fireball) + if def.tail + and def.tail == 1 + and def.tail_texture then + + --do this to prevent clipping through main entity sprite + local pos_adjustment = vector_multiply(vector_normalize(vel), -1) + local divider = def.tail_distance_divider or 1 + pos_adjustment = vector_divide(pos_adjustment, divider) + local new_pos = vector_add(pos, pos_adjustment) + minetest.add_particle({ + pos = new_pos, + velocity = {x = 0, y = 0, z = 0}, + acceleration = {x = 0, y = 0, z = 0}, + expirationtime = def.expire or 0.25, + collisiondetection = false, + texture = def.tail_texture, + size = def.tail_size or 5, + glow = def.glow or 0, + }) + end + + if self.hit_node then + + local node = minetest_get_node(pos).name + + if minetest_registered_nodes[node].walkable then + + self.hit_node(self, pos, node) + + if self.drop == true then + + pos.y = pos.y + 1 + + self.lastpos = (self.lastpos or pos) + + minetest_add_item(self.lastpos, self.object:get_luaentity().name) + end + + self.object:remove(); + + return + end + end + + if self.hit_player or self.hit_mob or self.hit_object then + + for _,player in pairs(minetest_get_objects_inside_radius(pos, 1.5)) do + + if self.hit_player + and player:is_player() then + + if self.hit_player then + self.hit_player(self, player) + else + mobs.arrow_hit(self, player) + end + + self.object:remove(); + return + end + + --[[ + local entity = player:get_luaentity() + + if entity + and self.hit_mob + and entity._cmi_is_mob == true + and tostring(player) ~= self.owner_id + and entity.name ~= self.object:get_luaentity().name + and (self._shooter and entity.name ~= self._shooter:get_luaentity().name) then + + --self.hit_mob(self, player) + self.object:remove(); + return + end + ]]-- + + --[[ + if entity + and self.hit_object + and (not entity._cmi_is_mob) + and tostring(player) ~= self.owner_id + and entity.name ~= self.object:get_luaentity().name + and (self._shooter and entity.name ~= self._shooter:get_luaentity().name) then + + --self.hit_object(self, player) + self.object:remove(); + return + end + ]]-- + end + end + + self.lastpos = pos + end + }) +end + +-- Register spawn eggs + +-- Note: This also introduces the “spawn_egg” group: +-- * spawn_egg=1: Spawn egg (generic mob, no metadata) +-- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata) +function mobs:register_egg(mob, desc, background, addegg, no_creative) + + local grp = {spawn_egg = 1} + + -- do NOT add this egg to creative inventory (e.g. dungeon master) + if no_creative == true then + grp.not_in_creative_inventory = 1 + end + + local invimg = background + + if addegg == 1 then + invimg = "mobs_chicken_egg.png^(" .. invimg .. + "^[mask:mobs_chicken_egg_overlay.png)" + end + + -- register old stackable mob egg + minetest.register_craftitem(mob, { + + description = desc, + inventory_image = invimg, + groups = grp, + + _doc_items_longdesc = S("This allows you to place a single mob."), + _doc_items_usagehelp = S("Just place it where you want the mob to appear. Animals will spawn tamed, unless you hold down the sneak key while placing. If you place this on a mob spawner, you change the mob it spawns."), + + on_place = function(itemstack, placer, pointed_thing) + + local pos = pointed_thing.above + + -- am I clicking on something with existing on_rightclick function? + local under = minetest_get_node(pointed_thing.under) + local def = minetest_registered_nodes[under.name] + if def and def.on_rightclick then + return def.on_rightclick(pointed_thing.under, under, placer, itemstack) + end + + if pos + --and within_limits(pos, 0) + and not minetest_is_protected(pos, placer:get_player_name()) then + + local name = placer:get_player_name() + local privs = minetest.get_player_privs(name) + if mod_mobspawners and under.name == "mcl_mobspawners:spawner" then + if minetest_is_protected(pointed_thing.under, name) then + minetest.record_protection_violation(pointed_thing.under, name) + return itemstack + end + if not privs.maphack then + minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner.")) + return itemstack + end + mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name()) + if not mobs.is_creative(name) then + itemstack:take_item() + end + return itemstack + end + + if not minetest_registered_entities[mob] then + return itemstack + end + + if minetest_settings:get_bool("only_peaceful_mobs", false) + and minetest_registered_entities[mob].type == "monster" then + minetest.chat_send_player(name, S("Only peaceful mobs allowed!")) + return itemstack + end + + local mob = minetest_add_entity(pos, mob) + minetest.log("action", "Mob spawned: "..name.." at "..minetest.pos_to_string(pos)) + local ent = mob:get_luaentity() + + -- don't set owner if monster or sneak pressed + --[[ + if ent.type ~= "monster" + and not placer:get_player_control().sneak then + ent.owner = placer:get_player_name() + ent.tamed = true + end + ]]-- + + -- set nametag + local nametag = itemstack:get_meta():get_string("name") + if nametag ~= "" then + if string.len(nametag) > MAX_MOB_NAME_LENGTH then + nametag = string.sub(nametag, 1, MAX_MOB_NAME_LENGTH) + end + ent.nametag = nametag + update_tag(ent) + end + + -- if not in creative then take item + if not mobs.is_creative(placer:get_player_name()) then + itemstack:take_item() + end + end + + return itemstack + end, + }) + +end + + diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua new file mode 100644 index 0000000000..eda7e88711 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -0,0 +1,1153 @@ +local math_random = math.random +local math_pi = math.pi +local math_floor = math.floor +local math_round = math.round + +local vector_multiply = vector.multiply +local vector_add = vector.add +local vector_new = vector.new +local vector_distance = vector.distance + +local minetest_yaw_to_dir = minetest.yaw_to_dir +local minetest_get_item_group = minetest.get_item_group +local minetest_get_node = minetest.get_node +local minetest_line_of_sight = minetest.line_of_sight +local minetest_get_node_light = minetest.get_node_light + +local DOUBLE_PI = math.pi * 2 +local THIRTY_SECONDTH_PI = DOUBLE_PI * 0.03125 + + +--a simple helper function which is too small to move into movement.lua +local quick_rotate = function(self,dtime) + self.yaw = self.yaw + THIRTY_SECONDTH_PI + if self.yaw > DOUBLE_PI then + self.yaw = self.yaw - DOUBLE_PI + end +end + +--a simple helper function for rounding +--http://lua-users.org/wiki/SimpleRound +function round2(num, numDecimalPlaces) + return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num)) +end + + +--[[ + _ _ +| | | | +| | __ _ _ __ __| | +| | / _` | '_ \ / _` | +| |___| (_| | | | | (_| | +\_____/\__,_|_| |_|\__,_| +]]-- + +--this is basically reverse jump_check +local cliff_check = function(self,dtime) + --mobs will flip out if they are falling without this + if self.object:get_velocity().y ~= 0 then + return false + end + + local pos = self.object:get_pos() + local dir = minetest_yaw_to_dir(self.yaw) + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + dir = vector_multiply(dir,radius) + + local free_fall, blocker = minetest_line_of_sight( + {x = pos.x + dir.x, y = pos.y, z = pos.z + dir.z}, + {x = pos.x + dir.x, y = pos.y - self.fear_height, z = pos.z + dir.z}) + + return free_fall +end + + +-- state switching logic (stand, walk, run, attacks) +local land_state_list_wandering = {"stand", "walk"} + +local land_state_switch = function(self, dtime) + + --do math before sure not attacking, following, or running away so continue + --doing random walking for mobs if all states are not met + self.state_timer = self.state_timer - dtime + + --only run away + if self.skittish and self.state == "run" then + self.run_timer = self.run_timer - dtime + if self.run_timer > 0 then + return + end + --continue + end + + --ignore everything else if breeding + if self.breed_lookout_timer and self.breed_lookout_timer > 0 then + self.state = "breed" + return + --reset the state timer to get the mob out of + --the breed state + elseif self.state == "breed" then + self.state_timer = 0 + end + + --ignore everything else if following + if mobs.check_following(self) and + (not self.breed_lookout_timer or (self.breed_lookout_timer and self.breed_lookout_timer == 0)) and + (not self.breed_timer or (self.breed_timer and self.breed_timer == 0)) then + self.state = "follow" + return + --reset the state timer to get the mob out of + --the follow state - not the cleanest option + --but the easiest + elseif self.state == "follow" then + self.state_timer = 0 + end + + --only attack + if self.hostile and self.attacking then + self.state = "attack" + return + end + + --if finally reached here then do random wander + if self.state_timer <= 0 then + self.state_timer = math.random(4,10) + math.random() + self.state = land_state_list_wandering[math.random(1,#land_state_list_wandering)] + end + +end + +-- states are executed here +local land_state_execution = function(self,dtime) + + --[[ -- this is a debug which shows the timer and makes mobs breed 100 times faster + print(self.breed_timer) + if self.breed_timer > 0 then + self.breed_timer = self.breed_timer - (dtime * 100) + if self.breed_timer <= 0 then + self.breed_timer = 0 + end + end + ]]-- + + --no collisionbox exception + if not self.object:get_properties() then + return + end + + + --timer to time out looking for mate + if self.breed_lookout_timer and self.breed_lookout_timer > 0 then + self.breed_lookout_timer = self.breed_lookout_timer - dtime + --looking for mate failed + if self.breed_lookout_timer <= 0 then + self.breed_lookout_timer = 0 + end + end + + --cool off after breeding + if self.breed_timer and self.breed_timer > 0 then + self.breed_timer = self.breed_timer - dtime + --do this to skip the first check, using as switch + if self.breed_timer <= 0 then + self.breed_timer = 0 + end + end + + + local pos = self.object:get_pos() + local collisionbox = self.object:get_properties().collisionbox + --get the center of the mob + pos.y = pos.y + (collisionbox[2] + collisionbox[5] / 2) + local current_node = minetest_get_node(pos).name + local float_now = false + + --recheck if in water or lava + if minetest_get_item_group(current_node, "water") ~= 0 or minetest_get_item_group(current_node, "lava") ~= 0 then + float_now = true + end + + --make slow falling mobs fall slow + if self.fall_slow then + local velocity = self.object:get_velocity() + if velocity then + if velocity.y < 0 then + --lua is acting really weird so we have to help it + if round2(self.object:get_acceleration().y, 1) == -self.gravity then + self.object:set_acceleration(vector_new(0,0,0)) + mobs.mob_fall_slow(self) + end + else + if round2(self.object:get_acceleration().y, 1) == 0 then + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end + end + end + end + + --calculate fall damage + if self.fall_damage then + mobs.calculate_fall_damage(self) + end + + if self.state == "stand" then + + --do animation + mobs.set_mob_animation(self, "stand") + + --set the velocity of the mob + mobs.set_velocity(self,0) + + --animation fixes for explosive mobs + if self.attack_type == "explode" then + mobs.reverse_explosion_animation(self,dtime) + end + + mobs.lock_yaw(self) + elseif self.state == "follow" then + + --always look at players + mobs.set_yaw_while_following(self) + + --check distance + local distance_from_follow_person = vector_distance(self.object:get_pos(), self.following_person:get_pos()) + local distance_2d = mobs.get_2d_distance(self.object:get_pos(), self.following_person:get_pos()) + + --don't push the player if too close + --don't spin around randomly + if self.follow_distance < distance_from_follow_person and self.minimum_follow_distance < distance_2d then + mobs.set_mob_animation(self, "run") + mobs.set_velocity(self,self.run_velocity) + + if mobs.jump_check(self) == 1 then + mobs.jump(self) + end + else + mobs.set_mob_animation(self, "stand") + mobs.set_velocity(self,0) + end + + elseif self.state == "walk" then + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + end + + --do animation + mobs.set_mob_animation(self, "walk") + + --enable rotation locking + mobs.movement_rotation_lock(self) + + --check for nodes to jump over + local node_in_front_of = mobs.jump_check(self) + + if node_in_front_of == 1 then + + mobs.jump(self) + + --turn if on the edge of cliff + --(this is written like this because unlike + --jump_check which simply tells the mob to jump + --this requires a mob to turn, removing the + --ease of a full implementation for it in a single + --function) + elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then + --turn 45 degrees if so + quick_rotate(self,dtime) + --stop the mob so it doesn't fall off + mobs.set_velocity(self,0) + end + + --only move forward if path is clear + if node_in_front_of == 0 or node_in_front_of == 1 then + --set the velocity of the mob + mobs.set_velocity(self,self.walk_velocity) + end + + --animation fixes for explosive mobs + if self.attack_type == "explode" then + mobs.reverse_explosion_animation(self,dtime) + end + + elseif self.state == "run" then + + --do animation + mobs.set_mob_animation(self, "run") + + --enable rotation locking + mobs.movement_rotation_lock(self) + + --check for nodes to jump over + local node_in_front_of = mobs.jump_check(self) + + if node_in_front_of == 1 then + + mobs.jump(self) + + --turn if on the edge of cliff + --(this is written like this because unlike + --jump_check which simply tells the mob to jump + --this requires a mob to turn, removing the + --ease of a full implementation for it in a single + --function) + elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then + --turn 45 degrees if so + quick_rotate(self,dtime) + --stop the mob so it doesn't fall off + mobs.set_velocity(self,0) + end + + --only move forward if path is clear + if node_in_front_of == 0 or node_in_front_of == 1 then + --set the velocity of the mob + mobs.set_velocity(self,self.run_velocity) + end + + elseif self.state == "attack" then + + --execute mob attack type + if self.attack_type == "explode" then + + mobs.explode_attack_walk(self, dtime) + + elseif self.attack_type == "punch" then + + mobs.punch_attack_walk(self,dtime) + + elseif self.attack_type == "projectile" then + + mobs.projectile_attack_walk(self,dtime) + + end + elseif self.state == "breed" then + + mobs.breeding_effect(self) + + local mate = mobs.look_for_mate(self) + + --found a mate + if mate then + mobs.set_yaw_while_breeding(self,mate) + mobs.set_velocity(self, self.walk_velocity) + + --smoosh together basically + if vector_distance(self.object:get_pos(), mate:get_pos()) <= self.breed_distance then + mobs.set_mob_animation(self, "stand") + if self.special_breed_timer == 0 then + self.special_breed_timer = 2 --breeding takes 2 seconds + end + + self.special_breed_timer = self.special_breed_timer - dtime + if self.special_breed_timer <= 0 then + + --pop a baby out, it's a miracle! + local baby_pos = vector.divide(vector.add(self.object:get_pos(), mate:get_pos()), 2) + local baby_mob = minetest.add_entity(pos, self.name, minetest.serialize({baby = true, grow_up_timer = self.grow_up_goal, bred = true})) + + mobs.play_sound_specific(self,"item_drop_pickup") + + self.special_breed_timer = 0 + self.breed_lookout_timer = 0 + self.breed_timer = self.breed_timer_cooloff + + mate:get_luaentity().special_breed_timer = 0 + mate:get_luaentity().breed_lookout_timer = 0 + mate:get_luaentity().breed_timer = self.breed_timer_cooloff -- can reuse because it's the same mob + end + else + mobs.set_mob_animation(self, "walk") + end + --couldn't find a mate, just stand there until the player pushes it towards one + --or the timer runs out + else + mobs.set_mob_animation(self, "stand") + mobs.set_velocity(self,0) + end + + end + + if float_now then + mobs.float(self) + else + local acceleration = self.object:get_acceleration() + if acceleration and acceleration.y == 0 then + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end + end +end + + + + +--[[ + _____ _ +/ ___| (_) +\ `--.__ ___ _ __ ___ + `--. \ \ /\ / / | '_ ` _ \ +/\__/ /\ V V /| | | | | | | +\____/ \_/\_/ |_|_| |_| |_| +]]-- + + + +-- state switching logic (stand, walk, run, attacks) +local swim_state_list_wandering = {"stand", "swim"} + +local swim_state_switch = function(self, dtime) + self.state_timer = self.state_timer - dtime + if self.state_timer <= 0 then + self.state_timer = math.random(4,10) + math.random() + self.state = swim_state_list_wandering[math.random(1,#swim_state_list_wandering)] + end +end + + +--check if a mob needs to turn while swimming +local swim_turn_check = function(self,dtime) + + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local dir = minetest_yaw_to_dir(self.yaw) + + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + vector_multiply(dir, radius) + + local test_dir = vector.add(pos,dir) + + local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 + + return(green_flag_1) +end + +--this is to swap the built in engine acceleration modifier +local swim_physics_swapper = function(self,inside_swim_node) + + --should be swimming, gravity is applied, switch to floating + if inside_swim_node and self.object:get_acceleration().y ~= 0 then + self.object:set_acceleration(vector_new(0,0,0)) + --not be swim, gravity isn't applied, switch to falling + elseif not inside_swim_node and self.object:get_acceleration().y == 0 then + self.pitch = 0 + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end +end + + +local random_pitch_multiplier = {-1,1} +-- states are executed here +local swim_state_execution = function(self,dtime) + + local pos = self.object:get_pos() + + pos.y = pos.y + self.object:get_properties().collisionbox[5] + local current_node = minetest_get_node(pos).name + local inside_swim_node = false + + --quick scan everything to see if inside swim node + for _,id in pairs(self.swim_in) do + if id == current_node then + inside_swim_node = true + break + end + end + + --turn gravity on or off + swim_physics_swapper(self,inside_swim_node) + + --swim properly if inside swim node + if inside_swim_node then + + if self.state == "stand" then + + --do animation + mobs.set_mob_animation(self, "stand") + + mobs.set_swim_velocity(self,0) + + if self.tilt_swim then + mobs.set_static_pitch(self) + end + + mobs.lock_yaw(self) + + elseif self.state == "swim" then + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + + --create a truly random pitch, since there is no easy access to pitch math that I can find + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] + end + + --do animation + mobs.set_mob_animation(self, "walk") + + --do a quick turn to make mob continuously move + --if in a fish tank or something + if swim_turn_check(self,dtime) then + quick_rotate(self,dtime) + end + + mobs.set_swim_velocity(self,self.walk_velocity) + + --only enable tilt swimming if enabled + if self.tilt_swim then + mobs.set_dynamic_pitch(self) + end + + --enable rotation locking + mobs.movement_rotation_lock(self) + end + --flop around if not inside swim node + else + --do animation + mobs.set_mob_animation(self, "stand") + + mobs.flop(self) + + if self.tilt_swim then + mobs.set_static_pitch(self) + end + end + +end + + +--[[ +______ _ +| ___| | +| |_ | |_ _ +| _| | | | | | +| | | | |_| | +\_| |_|\__, | + __/ | + |___/ +]]-- + +-- state switching logic (stand, walk, run, attacks) +local fly_state_list_wandering = {"stand", "fly"} + +local fly_state_switch = function(self, dtime) + + if self.hostile and self.attacking then + self.state = "attack" + return + end + + self.state_timer = self.state_timer - dtime + if self.state_timer <= 0 then + self.state_timer = math.random(4,10) + math.random() + self.state = fly_state_list_wandering[math.random(1,#fly_state_list_wandering)] + end +end + + +--check if a mob needs to turn while flying +local fly_turn_check = function(self,dtime) + + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local dir = minetest_yaw_to_dir(self.yaw) + + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + vector_multiply(dir, radius) + + local test_dir = vector.add(pos,dir) + + local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 + + return(green_flag_1) +end + +--this is to swap the built in engine acceleration modifier +local fly_physics_swapper = function(self,inside_fly_node) + + --should be flyming, gravity is applied, switch to floating + if inside_fly_node and self.object:get_acceleration().y ~= 0 then + self.object:set_acceleration(vector_new(0,0,0)) + --not be fly, gravity isn't applied, switch to falling + elseif not inside_fly_node and self.object:get_acceleration().y == 0 then + self.pitch = 0 + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end +end + + +local random_pitch_multiplier = {-1,1} +-- states are executed here +local fly_state_execution = function(self,dtime) + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local current_node = minetest_get_node(pos).name + local inside_fly_node = minetest_get_item_group(current_node, "solid") == 0 + + local float_now = false + --recheck if in water or lava + if minetest_get_item_group(current_node, "water") ~= 0 or minetest_get_item_group(current_node, "lava") ~= 0 then + inside_fly_node = false + float_now = true + end + + --turn gravity on or off + fly_physics_swapper(self,inside_fly_node) + + --fly properly if inside fly node + if inside_fly_node then + if self.state == "stand" then + + --do animation + mobs.set_mob_animation(self, "stand") + + mobs.set_fly_velocity(self,0) + + if self.tilt_fly then + mobs.set_static_pitch(self) + end + + mobs.lock_yaw(self) + + elseif self.state == "fly" then + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + + --create a truly random pitch, since there is no easy access to pitch math that I can find + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] + end + + --do animation + mobs.set_mob_animation(self, "walk") + + --do a quick turn to make mob continuously move + --if in a bird cage or something + if fly_turn_check(self,dtime) then + quick_rotate(self,dtime) + end + + if self.tilt_fly then + mobs.set_dynamic_pitch(self) + end + + mobs.set_fly_velocity(self,self.walk_velocity) + + --enable rotation locking + mobs.movement_rotation_lock(self) + + elseif self.state == "attack" then + + --execute mob attack type + --if self.attack_type == "explode" then + + --mobs.explode_attack_fly(self, dtime) + + --elseif self.attack_type == "punch" then + + --mobs.punch_attack_fly(self,dtime) + + if self.attack_type == "projectile" then + + mobs.projectile_attack_fly(self,dtime) + + end + end + else + --make the mob float + if self.floats and float_now then + mobs.set_velocity(self, 0) + + mobs.float(self) + + if self.tilt_fly then + mobs.set_static_pitch(self) + end + end + end +end + + +--[[ + ___ + |_ | + | |_ _ _ __ ___ _ __ + | | | | | '_ ` _ \| '_ \ +/\__/ / |_| | | | | | | |_) | +\____/ \__,_|_| |_| |_| .__/ + | | + |_| +]]-- + + +--check if a mob needs to turn while jumping +local jump_turn_check = function(self,dtime) + + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local dir = minetest_yaw_to_dir(self.yaw) + + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + vector_multiply(dir, radius) + + local test_dir = vector.add(pos,dir) + + local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 + + return(green_flag_1) +end + +-- state switching logic (stand, jump, run, attacks) +local jump_state_list_wandering = {"stand", "jump"} + +local jump_state_switch = function(self, dtime) + self.state_timer = self.state_timer - dtime + if self.state_timer <= 0 then + self.state_timer = math.random(4,10) + math.random() + self.state = jump_state_list_wandering[math.random(1,#jump_state_list_wandering)] + end +end + +-- states are executed here +local jump_state_execution = function(self,dtime) + + local pos = self.object:get_pos() + local collisionbox = self.object:get_properties().collisionbox + --get the center of the mob + pos.y = pos.y + (collisionbox[2] + collisionbox[5] / 2) + local current_node = minetest_get_node(pos).name + + local float_now = false + + --recheck if in water or lava + if minetest_get_item_group(current_node, "water") ~= 0 or minetest_get_item_group(current_node, "lava") ~= 0 then + float_now = true + end + + if self.state == "stand" then + + --do animation + mobs.set_mob_animation(self, "stand") + + --set the velocity of the mob + mobs.set_velocity(self,0) + + mobs.lock_yaw(self) + + elseif self.state == "jump" then + + self.walk_timer = self.walk_timer - dtime + + --reset the jump timer + if self.walk_timer <= 0 then + + --re-randomize the jump timer + self.walk_timer = math.random(1,6) + math.random() + + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + end + + --do animation + mobs.set_mob_animation(self, "walk") + + --enable rotation locking + mobs.movement_rotation_lock(self) + + --jumping mobs are more loosey goosey + if node_in_front_of == 1 then + quick_rotate(self,dtime) + end + + --only move forward if path is clear + mobs.jump_move(self,self.walk_velocity) + + elseif self.state == "run" then + + print("run") + + elseif self.state == "attack" then + + print("attack") + + end + + if float_now then + mobs.float(self) + end +end + + + + +--[[ +___ ___ _ _ _ +| \/ | (_) | | (_) +| . . | __ _ _ _ __ | | ___ __ _ _ ___ +| |\/| |/ _` | | '_ \ | | / _ \ / _` | |/ __| +| | | | (_| | | | | | | |___| (_) | (_| | | (__ +\_| |_/\__,_|_|_| |_| \_____/\___/ \__, |_|\___| + __/ | + |___/ +]]-- + +--the main loop +mobs.mob_step = function(self, dtime) + + --do not continue if non-existent + if not self or not self.object or not self.object:get_luaentity() then + self.object:remove() + return false + end + + + --DEBUG TIME! + --REMEMBER TO MOVE THIS AFTER DEATH CHECK + + --if self.has_head then + -- mobs.do_head_logic(self,dtime) + --end + + + + --if true then--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG + -- return + --end + + --despawn mechanism + --don't despawned tamed or bred mobs + if not self.tamed and not self.bred then + self.lifetimer = self.lifetimer - dtime + if self.lifetimer <= 0 then + self.lifetimer = self.lifetimer_reset + if not mobs.check_for_player_within_area(self, 64) then + --print("removing in MAIN LOGIC!") + self.object:remove() + return + end + end + end + + --color modifier which coincides with the pause_timer + if self.old_health and self.health < self.old_health then + self.object:set_texture_mod("^[colorize:red:120") + --fix double death sound + if self.health > 0 then + mobs.play_sound(self,"damage") + end + end + self.old_health = self.health + + --do death logic (animation, poof, explosion, etc) + if self.health <= 0 or self.dead then + --play death sound once + if not self.played_death_sound then + self.dead = true + mobs.play_sound(self,"death") + self.played_death_sound = true + end + + mobs.death_logic(self, dtime) + + --this is here because the mob must continue to move + --while stunned before coming to a complete halt even during + --the death tilt + if self.pause_timer > 0 then + self.pause_timer = self.pause_timer - dtime + --perfectly reset pause_timer + if self.pause_timer < 0 then + self.pause_timer = 0 + end + end + + return + end + + mobs.random_sound_handling(self,dtime) + + --mobs drowning mechanic + if not self.breathes_in_water then + + local pos = self.object:get_pos() + + pos.y = pos.y + self.eye_height + + local node = minetest_get_node(pos).name + + if minetest_get_item_group(node, "water") ~= 0 then + self.breath = self.breath - dtime + + --reset breath when drowning + if self.breath <= 0 then + self.health = self.health - 4 + self.breath = 1 + self.pause_timer = 0.5 + end + + elseif self.breath < self.breath_max then + self.breath = self.breath + dtime + + --clean timer reset + if self.breath > self.breath_max then + self.breath = self.breath_max + end + end + end + + --set mobs on fire when burned by sunlight + if self.ignited_by_sunlight then + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + + if self.burn_timer > 0 then + self.burn_timer = self.burn_timer - dtime + + if self.burn_timer <= 0 then + self.health = self.health - 4 + self.burn_timer = 0 + end + end + + if self.burn_timer == 0 and minetest_get_node_light(pos) > 12 and minetest_get_node_light(pos, 0.5) == 15 then + mcl_burning.set_on_fire(self.object, 1) + self.burn_timer = 1 --1.7 seconds + self.pause_timer = 0.4 + end + end + + + + + + --baby grows up + if self.baby then + --print(self.grow_up_timer) + --catch missing timer + if not self.grow_up_timer then + self.grow_up_timer = self.grow_up_goal + end + + self.grow_up_timer = self.grow_up_timer - dtime + + --baby grows up! + if self.grow_up_timer <= 0 then + self.grow_up_timer = 0 + mobs.baby_grow_up(self) + end + end + + + + --do custom mob instructions + if self.do_custom then + -- when false skip going any further + if self.do_custom(self, dtime) == false then + --this needs to be here or the mob becomes immortal + if self.pause_timer > 0 then + self.pause_timer = self.pause_timer - dtime + --perfectly reset pause_timer + if self.pause_timer <= 0 then + self.pause_timer = 0 + self.object:set_texture_mod("") + end + end + --this overrides internal lua collision detection + return + end + end + + local attacking = nil + + --scan for players within eyesight + if self.hostile then + --true for line_of_sight is debug + attacking = mobs.detect_closest_player_within_radius(self,true,self.view_range,self.eye_height) + + --go get the closest player + if attacking then + + self.memory = 6 --6 seconds of memory + + --set initial punch timer + if self.attacking == nil then + if self.attack_type == "punch" then + self.punch_timer = -1 + end + end + self.attacking = attacking + + --no player in area + elseif self.memory > 0 then + --try to remember + self.memory = self.memory - dtime + --get if memory player is within viewing range + if self.attacking and self.attacking:is_player() then + local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + if distance > self.view_range then + self.memory = 0 + end + --out of viewing range, forget em + else + self.memory = 0 + end + + if self.memory <= 0 then + + --reset states when coming out of hostile state + if self.attacking ~= nil then + self.state_timer = -1 + end + + self.attacking = nil + self.memory = 0 + end + end + end + + --count down hostile cooldown timer when no players in range + if self.neutral and self.hostile and not attacking and self.hostile_cooldown_timer then + + self.hostile_cooldown_timer = self.hostile_cooldown_timer - dtime + + if self.hostile_cooldown_timer <= 0 then + self.hostile = false + self.hostile_cooldown_timer = 0 + end + end + + --mob is stunned after being hit + if self.pause_timer > 0 then + self.pause_timer = self.pause_timer - dtime + --don't break eye contact + if self.hostile and self.attacking then + mobs.set_yaw_while_attacking(self) + end + + --perfectly reset pause_timer + if self.pause_timer <= 0 then + self.pause_timer = 0 + self.object:set_texture_mod("") + end + + --stop walking mobs from falling through the water + if not self.jump_only and not self.swim and not self.fly then + local pos = self.object:get_pos() + local collisionbox = self.object:get_properties().collisionbox + --get the center of the mob + pos.y = pos.y + (collisionbox[2] + collisionbox[5] / 2) + local current_node = minetest_get_node(pos).name + + --recheck if in water or lava + if minetest_get_item_group(current_node, "water") ~= 0 or minetest_get_item_group(current_node, "lava") ~= 0 then + mobs.float(self) + end + end + + --stop projectile mobs from being completely disabled while stunned + if self.projectile_timer and self.projectile_timer > 0.01 then + self.projectile_timer = self.projectile_timer - dtime + if self.projectile_timer < 0.01 then + self.projectile_timer = 0.01 + end + end + + return -- don't allow collision detection + --do normal ai + else + --jump only (like slimes) + if self.jump_only then + jump_state_switch(self, dtime) + jump_state_execution(self, dtime) + --swimming + elseif self.swim then + swim_state_switch(self, dtime) + swim_state_execution(self, dtime) + --flying + elseif self.fly then + fly_state_switch(self, dtime) + fly_state_execution(self,dtime) + --regular mobs that walk around + else + land_state_switch(self, dtime) + land_state_execution(self,dtime) + end + end + + --do not continue if non-existent + if not self or not self.object or not self.object:get_luaentity() then + self.object:remove() + return false + end + + --make it so mobs do not glitch out when walking around/jumping + mobs.swap_auto_step_height_adjust(self) + + + -- can mob be pushed, if so calculate direction -- do this last (overrides everything) + if self.pushable then + mobs.collision(self) + end + + --overrides absolutely everything + --mobs get stuck in cobwebs like players + if not self.ignores_cobwebs then + + local pos = self.object:get_pos() + local node = pos and minetest_get_node(pos).name + + if node == "mcl_core:cobweb" then + + --fight the rest of the api + if self.object:get_acceleration().y ~= 0 then + self.object:set_acceleration(vector_new(0,0,0)) + end + + mobs.stick_in_cobweb(self) + + self.was_stuck_in_cobweb = true + + else + --do not override other functions + if self.was_stuck_in_cobweb == true then + --return the mob back to normal + self.was_stuck_in_cobweb = nil + if self.object:get_acceleration().y == 0 and not self.swim and not self.fly then + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end + end + end + end + + self.old_velocity = self.object:get_velocity() + self.old_pos = self.object:get_pos() +end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua new file mode 100644 index 0000000000..c26d330897 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua @@ -0,0 +1,259 @@ +local math_pi = math.pi +local math_floor = math.floor +local math_random = math.random +local HALF_PI = math_pi/2 + + +local vector_direction = vector.direction +local vector_distance = vector.distance +local vector_new = vector.new + +local minetest_dir_to_yaw = minetest.dir_to_yaw + +-- set defined animation +mobs.set_mob_animation = function(self, anim, fixed_frame) + + if not self.animation or not anim then + return + end + + if self.state == "die" and anim ~= "die" and anim ~= "stand" then + return + end + + + if (not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"]) then + return + end + + --animations break if they are constantly set + --so we put this return gate to check if it is + --already at the animation we are trying to implement + if self.current_animation == anim then + return + end + + local a_start = self.animation[anim .. "_start"] + local a_end + + if fixed_frame then + a_end = a_start + else + a_end = self.animation[anim .. "_end"] + end + + self.object:set_animation({ + x = a_start, + y = a_end}, + self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, + 0, self.animation[anim .. "_loop"] ~= false) + + + self.current_animation = anim +end + + + + +mobs.death_effect = function(pos, yaw, collisionbox, rotate) + local min, max + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + else + min = { x = -0.5, y = 0, z = -0.5 } + max = { x = 0.5, y = 0.5, z = 0.5 } + end + if rotate then + min = vector.rotate(min, {x=0, y=yaw, z=math_pi/2}) + max = vector.rotate(max, {x=0, y=yaw, z=math_pi/2}) + min, max = vector.sort(min, max) + min = vector.multiply(min, 0.5) + max = vector.multiply(max, 0.5) + end + + minetest_add_particlespawner({ + amount = 50, + time = 0.001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector_new(-5,-5,-5), + maxvel = vector_new(5,5,5), + minexptime = 1.1, + maxexptime = 1.5, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "mcl_particles_mob_death.png^[colorize:#000000:255", + }) + + minetest_sound_play("mcl_mobs_mob_poof", { + pos = pos, + gain = 1.0, + max_hear_distance = 8, + }, true) +end + + +--this allows auto facedir rotation while making it so mobs +--don't look like wet noodles flopping around +mobs.movement_rotation_lock = function(self) + + local current_engine_yaw = self.object:get_yaw() + local current_lua_yaw = self.yaw + + if current_engine_yaw > math.pi * 2 then + current_engine_yaw = current_engine_yaw - (math.pi * 2) + end + + if math.abs(current_engine_yaw - current_lua_yaw) <= 0.05 and self.object:get_properties().automatic_face_movement_dir then + self.object:set_properties{automatic_face_movement_dir = false} + elseif math.abs(current_engine_yaw - current_lua_yaw) > 0.05 and self.object:get_properties().automatic_face_movement_dir == false then + self.object:set_properties{automatic_face_movement_dir = self.rotate} + end +end + + +--this is used when a mob is chasing a player +mobs.set_yaw_while_attacking = function(self) + + if self.object:get_properties().automatic_face_movement_dir then + self.object:set_properties{automatic_face_movement_dir = false} + end + + --turn positions into pseudo 2d vectors + local pos1 = self.object:get_pos() + pos1.y = 0 + + local pos2 = self.attacking:get_pos() + pos2.y = 0 + + local new_direction = vector_direction(pos1,pos2) + local new_yaw = minetest_dir_to_yaw(new_direction) + + self.object:set_yaw(new_yaw) + self.yaw = new_yaw +end + +--this is used to unlock a mob's yaw after attacking +mobs.unlock_yaw = function(self) + if self.object:get_properties().automatic_face_movement_dir == false then + self.object:set_properties{automatic_face_movement_dir = self.rotate} + end +end + +--this is used to lock a mob's yaw when they're standing +mobs.lock_yaw = function(self) + if self.object:get_properties().automatic_face_movement_dir then + self.object:set_properties{automatic_face_movement_dir = false} + end +end + + +local calculate_pitch = function(self) + local pos = self.object:get_pos() + local pos2 = self.old_pos + + if pos == nil or pos2 == nil then + return false + end + + return(minetest_dir_to_yaw(vector_new(vector_distance(vector_new(pos.x,0,pos.z),vector_new(pos2.x,0,pos2.z)),0,pos.y - pos2.y)) + HALF_PI) +end + +--this is a helper function used to make mobs pitch rotation dynamically flow when flying/swimming +mobs.set_dynamic_pitch = function(self) + local pitch = calculate_pitch(self) + + if not pitch then + return + end + + local current_rotation = self.object:get_rotation() + + current_rotation.x = pitch + + self.object:set_rotation(current_rotation) + + self.pitch_switch = "dynamic" +end + +--this is a helper function used to make mobs pitch rotation reset when flying/swimming +mobs.set_static_pitch = function(self) + + if self.pitch_switch == "static" then + return + end + + local current_rotation = self.object:get_rotation() + + current_rotation.x = 0 + + self.object:set_rotation(current_rotation) + self.pitch_switch = "static" +end + +--this is a helper function for mobs explosion animation +mobs.handle_explosion_animation = function(self) + + --secondary catch-all + if not self.explosion_animation then + self.explosion_animation = 0 + end + + --the timer works from 0 for sense of a 0 based counting + --but this just bumps it up so it's usable in here + local explosion_timer_adjust = self.explosion_animation + 1 + + + local visual_size_modified = table.copy(self.visual_size_origin) + + visual_size_modified.x = visual_size_modified.x * (explosion_timer_adjust ^ 3) + visual_size_modified.y = visual_size_modified.y * explosion_timer_adjust + + self.object:set_properties({visual_size = visual_size_modified}) +end + + +--this is used when a mob is following player +mobs.set_yaw_while_following = function(self) + + if self.object:get_properties().automatic_face_movement_dir then + self.object:set_properties{automatic_face_movement_dir = false} + end + + --turn positions into pseudo 2d vectors + local pos1 = self.object:get_pos() + pos1.y = 0 + + local pos2 = self.following_person:get_pos() + pos2.y = 0 + + local new_direction = vector_direction(pos1,pos2) + local new_yaw = minetest_dir_to_yaw(new_direction) + + self.object:set_yaw(new_yaw) + self.yaw = new_yaw +end + +--this is used for when mobs breed +mobs.set_yaw_while_breeding = function(self, mate) + + if self.object:get_properties().automatic_face_movement_dir then + self.object:set_properties{automatic_face_movement_dir = false} + end + + --turn positions into pseudo 2d vectors + local pos1 = self.object:get_pos() + pos1.y = 0 + + local pos2 = mate:get_pos() + pos2.y = 0 + + local new_direction = vector_direction(pos1,pos2) + local new_yaw = minetest_dir_to_yaw(new_direction) + + self.object:set_yaw(new_yaw) + self.yaw = new_yaw +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua new file mode 100644 index 0000000000..c973f3d1b3 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/attack_type_instructions.lua @@ -0,0 +1,351 @@ +local vector_direction = vector.direction +local minetest_dir_to_yaw = minetest.dir_to_yaw +local vector_distance = vector.distance +local vector_multiply = vector.multiply +local math_random = math.random + +--[[ + _ _ _ _ +| | | | | | | | +| | | | __ _ _ __ __| | | | +| | | | / _` | '_ \ / _` | | | +|_| | |___| (_| | | | | (_| | |_| +(_) \_____/\__,_|_| |_|\__,_| (_) +]]-- + + + +--[[ + _____ _ _ +| ___| | | | | +| |____ ___ __ | | ___ __| | ___ +| __\ \/ / '_ \| |/ _ \ / _` |/ _ \ +| |___> <| |_) | | (_) | (_| | __/ +\____/_/\_\ .__/|_|\___/ \__,_|\___| + | | + |_| +]]-- + +mobs.explode_attack_walk = function(self,dtime) + + --this needs an exception + if self.attacking == nil or not self.attacking:is_player() then + self.attacking = nil + return + end + + mobs.set_yaw_while_attacking(self) + + local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + + --make mob walk up to player within 2 nodes distance then start exploding + if distance_from_attacking >= self.reach and + --don't allow explosion to cancel unless out of the reach boundary + not (self.explosion_animation ~= nil and self.explosion_animation > 0 and distance_from_attacking <= self.defuse_reach) then + + mobs.set_velocity(self, self.run_velocity) + mobs.set_mob_animation(self,"run") + + mobs.reverse_explosion_animation(self,dtime) + else + mobs.set_velocity(self,0) + + --this is the only way I can reference this without dumping extra data on all mobs + if not self.explosion_animation then + self.explosion_animation = 0 + end + + --play ignite sound + if self.explosion_animation == 0 then + mobs.play_sound(self,"attack") + end + + mobs.set_mob_animation(self,"stand") + + mobs.handle_explosion_animation(self) + + self.explosion_animation = self.explosion_animation + (dtime/2.5) + end + + --make explosive mobs jump + --check for nodes to jump over + --explosive mobs will just ride against walls for now + local node_in_front_of = mobs.jump_check(self) + if node_in_front_of == 1 then + mobs.jump(self) + end + + + --do biggening explosion thing + if self.explosion_animation and self.explosion_animation > self.explosion_timer then + mcl_explosions.explode(self.object:get_pos(), self.explosion_strength,{ drop_chance = 1.0 }) + self.object:remove() + end +end + + +--this is a small helper function to make working with explosion animations easier +mobs.reverse_explosion_animation = function(self,dtime) + + --if explosion animation was greater than 0 then reverse it + if self.explosion_animation ~= nil and self.explosion_animation > 0 then + self.explosion_animation = self.explosion_animation - dtime + if self.explosion_animation < 0 then + self.explosion_animation = 0 + end + end + + mobs.handle_explosion_animation(self) +end + + + + +--[[ +______ _ +| ___ \ | | +| |_/ / _ _ __ ___| |__ +| __/ | | | '_ \ / __| '_ \ +| | | |_| | | | | (__| | | | +\_| \__,_|_| |_|\___|_| |_| +]]-- + + + +mobs.punch_attack_walk = function(self,dtime) + + --this needs an exception + if self.attacking == nil or not self.attacking:is_player() then + self.attacking = nil + return + end + + local distance_from_attacking = mobs.get_2d_distance(self.object:get_pos(), self.attacking:get_pos()) + + if distance_from_attacking >= self.minimum_follow_distance then + mobs.set_velocity(self, self.run_velocity) + mobs.set_mob_animation(self, "run") + else + mobs.set_velocity(self, 0) + mobs.set_mob_animation(self, "stand") + end + + mobs.set_yaw_while_attacking(self) + + --make punchy mobs jump + --check for nodes to jump over + --explosive mobs will just ride against walls for now + local node_in_front_of = mobs.jump_check(self) + + if node_in_front_of == 1 then + mobs.jump(self) + end + + --mobs that can climb over stuff + if self.always_climb and node_in_front_of > 0 then + mobs.climb(self) + end + + + --auto reset punch_timer + if not self.punch_timer then + self.punch_timer = 0 + end + + if self.punch_timer > 0 then + self.punch_timer = self.punch_timer - dtime + end +end + +mobs.punch_attack = function(self) + + self.attacking:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self.damage} + }, nil) + + self.punch_timer = self.punch_timer_cooloff + + + --knockback + local pos1 = self.object:get_pos() + pos1.y = 0 + local pos2 = self.attacking:get_pos() + pos2.y = 0 + local dir = vector_direction(pos1,pos2) + + dir = vector_multiply(dir,3) + + if self.attacking:get_velocity().y <= 1 then + dir.y = 5 + end + + self.attacking:add_velocity(dir) +end + + + + +--[[ +______ _ _ _ _ +| ___ \ (_) | | (_) | +| |_/ / __ ___ _ ___ ___| |_ _| | ___ +| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \ +| | | | | (_) | | __/ (__| |_| | | __/ +\_| |_| \___/| |\___|\___|\__|_|_|\___| + _/ | + |__/ +]]-- + + +mobs.projectile_attack_walk = function(self,dtime) + + --this needs an exception + if self.attacking == nil or not self.attacking:is_player() then + self.attacking = nil + return + end + + mobs.set_yaw_while_attacking(self) + + local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + + + if distance_from_attacking >= self.reach then + mobs.set_velocity(self, self.run_velocity) + mobs.set_mob_animation(self,"run") + else + mobs.set_velocity(self,0) + mobs.set_mob_animation(self,"stand") + end + + --do this to not load data into other mobs + if not self.projectile_timer then + self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) + end + + --run projectile timer + if self.projectile_timer > 0 then + self.projectile_timer = self.projectile_timer - dtime + + --shoot + if self.projectile_timer <= 0 then + --reset timer + self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) + mobs.shoot_projectile(self) + end + end + + --make shooty mobs jump + --check for nodes to jump over + --explosive mobs will just ride against walls for now + local node_in_front_of = mobs.jump_check(self) + if node_in_front_of == 1 then + mobs.jump(self) + end + +end + + + + + + + + + +--[[ + _ ______ _ _ +| | | ___| | | | +| | | |_ | |_ _ | | +| | | _| | | | | | | | +|_| | | | | |_| | |_| +(_) \_| |_|\__, | (_) + __/ | + |___/ +]]-- + + + + +--[[ +______ _ _ _ _ +| ___ \ (_) | | (_) | +| |_/ / __ ___ _ ___ ___| |_ _| | ___ +| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \ +| | | | | (_) | | __/ (__| |_| | | __/ +\_| |_| \___/| |\___|\___|\__|_|_|\___| + _/ | + |__/ +]]-- + +local random_pitch_multiplier = {-1,1} + +mobs.projectile_attack_fly = function(self, dtime) + + --this needs an exception + if self.attacking == nil or not self.attacking:is_player() then + self.attacking = nil + return + end + + --this is specifically for random ghast movement + if self.fly_random_while_attack then + + --enable rotation locking + mobs.movement_rotation_lock(self) + + self.walk_timer = self.walk_timer - dtime + + --reset the walk timer + if self.walk_timer <= 0 then + --re-randomize the walk timer + self.walk_timer = math.random(1,6) + math.random() + --set the mob into a random direction + self.yaw = (math_random() * (math.pi * 2)) + --create a truly random pitch, since there is no easy access to pitch math that I can find + self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)] + end + + mobs.set_fly_velocity(self, self.run_velocity) + + else + + mobs.set_yaw_while_attacking(self) + + local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos()) + + if distance_from_attacking >= self.reach then + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, self.run_velocity) + mobs.set_mob_animation(self,"run") + else + mobs.set_pitch_while_attacking(self) + mobs.set_fly_velocity(self, 0) + mobs.set_mob_animation(self,"stand") + end + end + + + --do this to not load data into other mobs + if not self.projectile_timer then + self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) + end + + --run projectile timer + if self.projectile_timer > 0 then + self.projectile_timer = self.projectile_timer - dtime + + --shoot + if self.projectile_timer <= 0 then + + if self.fly_random_while_attack then + mobs.set_yaw_while_attacking(self) + self.walk_timer = 0 + end + --reset timer + self.projectile_timer = math_random(self.projectile_cooldown_min, self.projectile_cooldown_max) + mobs.shoot_projectile(self) + end + end +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua similarity index 55% rename from mods/ENTITIES/mcl_mobs/api.lua rename to mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua index 3f635ece0e..c7c4ad27c0 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/backup_code_api.lua @@ -1,118 +1,3 @@ - --- API for Mobs Redo: MineClone 2 Edition (MRM) - -mobs = {} -mobs.mod = "mrm" -mobs.version = "20210106" -- don't rely too much on this, rarely updated, if ever - -local MAX_MOB_NAME_LENGTH = 30 -local HORNY_TIME = 30 -local HORNY_AGAIN_TIME = 300 -local CHILD_GROW_TIME = 60*20 -local DEATH_DELAY = 0.5 -local DEFAULT_FALL_SPEED = -10 -local FLOP_HEIGHT = 5.0 -local FLOP_HOR_SPEED = 1.5 - -local MOB_CAP = {} -MOB_CAP.hostile = 70 -MOB_CAP.passive = 10 -MOB_CAP.ambient = 15 -MOB_CAP.water = 15 - --- Localize -local S = minetest.get_translator("mcl_mobs") - --- CMI support check -local use_cmi = minetest.global_exists("cmi") - - --- Invisibility mod check -mobs.invis = {} -if minetest.global_exists("invisibility") then - mobs.invis = invisibility -end - - --- creative check -function mobs.is_creative(name) - return minetest.is_creative_enabled(name) -end - - --- localize math functions -local pi = math.pi -local sin = math.sin -local cos = math.cos -local abs = math.abs -local min = math.min -local max = math.max -local atann = math.atan -local random = math.random -local floor = math.floor -local atan = function(x) - if not x or x ~= x then - return 0 - else - return atann(x) - end -end - - --- Load settings -local damage_enabled = minetest.settings:get_bool("enable_damage") -local disable_blood = minetest.settings:get_bool("mobs_disable_blood") -local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false -local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false -local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false -local remove_far = true -local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0 -local show_health = false -local max_per_block = tonumber(minetest.settings:get("max_objects_per_block") or 64) -local mobs_spawn_chance = tonumber(minetest.settings:get("mobs_spawn_chance") or 2.5) - --- Shows helpful debug info above each mob -local mobs_debug = minetest.settings:get_bool("mobs_debug", false) - --- Peaceful mode message so players will know there are no monsters -if minetest.settings:get_bool("only_peaceful_mobs", false) then - minetest.register_on_joinplayer(function(player) - minetest.chat_send_player(player:get_player_name(), - S("Peaceful mode active! No monsters will spawn.")) - end) -end - --- pathfinding settings -local enable_pathfinding = true -local stuck_timeout = 3 -- how long before mob gets stuck in place and starts searching -local stuck_path_timeout = 10 -- how long will mob follow path before giving up - --- default nodes -local node_ice = "mcl_core:ice" -local node_snowblock = "mcl_core:snowblock" -local node_snow = "mcl_core:snow" -mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt" - -local mod_weather = minetest.get_modpath("mcl_weather") ~= nil -local mod_explosions = minetest.get_modpath("mcl_explosions") ~= nil -local mod_mobspawners = minetest.get_modpath("mcl_mobspawners") ~= nil -local mod_hunger = minetest.get_modpath("mcl_hunger") ~= nil -local mod_worlds = minetest.get_modpath("mcl_worlds") ~= nil -local mod_armor = minetest.get_modpath("mcl_armor") ~= nil -local mod_experience = minetest.get_modpath("mcl_experience") ~= nil - -----For Water Flowing: -local enable_physics = function(object, luaentity, ignore_check) - if luaentity.physical_state == false or ignore_check == true then - luaentity.physical_state = true - object:set_properties({ - physical = true - }) - object:set_velocity({x=0,y=0,z=0}) - object:set_acceleration({x=0,y=-9.81,z=0}) - end -end - local disable_physics = function(object, luaentity, ignore_check, reset_movement) if luaentity.physical_state == true or ignore_check == true then luaentity.physical_state = false @@ -126,629 +11,912 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement end end - --- play sound -local mob_sound = function(self, soundname, is_opinion, fixed_pitch) - - local soundinfo - if self.sounds_child and self.child then - soundinfo = self.sounds_child - elseif self.sounds then - soundinfo = self.sounds +----For Water Flowing: +local enable_physics = function(object, luaentity, ignore_check) + if luaentity.physical_state == false or ignore_check == true then + luaentity.physical_state = true + object:set_properties({ + physical = true + }) + object:set_velocity({x=0,y=0,z=0}) + object:set_acceleration({x=0,y=-9.81,z=0}) end - if not soundinfo then - return - end - local sound = soundinfo[soundname] - if sound then - if is_opinion and self.opinion_sound_cooloff > 0 then - return - end - local pitch - if not fixed_pitch then - local base_pitch = soundinfo.base_pitch - if not base_pitch then - base_pitch = 1 +end + +--[[ +local timer = 0 +minetest.register_globalstep(function(dtime) + timer = timer + dtime + if timer < 1 then return end + for _, player in pairs(minetest.get_connected_players()) do + local pos = player:get_pos() + for _, obj in pairs(minetest_get_objects_inside_radius(pos, 47)) do + local lua = obj:get_luaentity() + if lua and lua._cmi_is_mob then + lua.lifetimer = math.max(20, lua.lifetimer) + lua.despawn_immediately = false end - if self.child and (not self.sounds_child) then - -- Children have higher pitch - pitch = base_pitch * 1.5 - else - pitch = base_pitch + end + end + timer = 0 +end) +]]-- + +-- compatibility function for old entities to new modpack entities +function mobs:alias_mob(old_name, new_name) + + -- spawn egg + minetest.register_alias(old_name, new_name) + + -- entity + minetest.register_entity(":" .. old_name, { + + physical = false, + + on_step = function(self) + + if minetest_registered_entities[new_name] then + minetest_add_entity(self.object:get_pos(), new_name) end - -- randomize the pitch a bit - pitch = pitch + math.random(-10, 10) * 0.005 + + self.object:remove() end - minetest.sound_play(sound, { - object = self.object, - gain = 1.0, - max_hear_distance = self.sounds.distance, - pitch = pitch, - }, true) - self.opinion_sound_cooloff = 1 - end -end - --- Return true if object is in view_range -local function object_in_range(self, object) - if not object then - return false - end - local factor - -- Apply view range reduction for special player armor - if object:is_player() and mod_armor then - factor = armor:get_mob_view_range_factor(object, self.name) - end - -- Distance check - local dist - if factor and factor == 0 then - return false - elseif factor then - dist = self.view_range * factor - else - dist = self.view_range - end - - local p1, p2 = self.object:get_pos(), object:get_pos() - return p1 and p2 and (vector.distance(p1, p2) <= dist) -end - --- attack player/mob -local do_attack = function(self, player) - - if self.state == "attack" or self.state == "die" then - return - end - - self.attack = player - self.state = "attack" - - -- TODO: Implement war_cry sound without being annoying - --if random(0, 100) < 90 then - --mob_sound(self, "war_cry", true) - --end -end - - --- collision function borrowed amended from jordan4ibanez open_ai mod -local collision = function(self) - - local pos = self.object:get_pos() - local vel = self.object:get_velocity() - local x = 0 - local z = 0 - local width = -self.collisionbox[1] + self.collisionbox[4] + 0.5 - - for _,object in pairs(minetest.get_objects_inside_radius(pos, width)) do - - if object:is_player() - or (object:get_luaentity()._cmi_is_mob == true and object ~= self.object) then - - local pos2 = object:get_pos() - local vec = {x = pos.x - pos2.x, z = pos.z - pos2.z} - local force = (width + 0.5) - vector.distance( - {x = pos.x, y = 0, z = pos.z}, - {x = pos2.x, y = 0, z = pos2.z}) - - x = x + (vec.x * force) - z = z + (vec.z * force) - end - end - - return({x,z}) -end - --- move mob in facing direction -local set_velocity = function(self, v) - - local c_x, c_y = 0, 0 - - -- can mob be pushed, if so calculate direction - if self.pushable then - c_x, c_y = unpack(collision(self)) - end - - -- halt mob if it has been ordered to stay - if self.order == "stand" then - self.object:set_velocity({x = 0, y = 0, z = 0}) - return - end - - local yaw = (self.object:get_yaw() or 0) + self.rotate - - self.object:set_velocity({ - x = (sin(yaw) * -v) + c_x, - y = self.object:get_velocity().y, - z = (cos(yaw) * v) + c_y, }) end - - --- calculate mob velocity -local get_velocity = function(self) - - local v = self.object:get_velocity() - if v then - return (v.x * v.x + v.z * v.z) ^ 0.5 - end - - return 0 -end - -local function update_roll(self) - local is_Fleckenstein = self.nametag == "Fleckenstein" - local was_Fleckenstein = false - - local rot = self.object:get_rotation() - rot.z = is_Fleckenstein and pi or 0 - self.object:set_rotation(rot) - - local cbox = table.copy(self.collisionbox) - local acbox = self.object:get_properties().collisionbox - - if math.abs(cbox[2] - acbox[2]) > 0.1 then - was_Fleckenstein = true - end - - if is_Fleckenstein ~= was_Fleckenstein then - local pos = self.object:get_pos() - pos.y = pos.y + (acbox[2] + acbox[5]) - self.object:set_pos(pos) - end - - if is_Fleckenstein then - cbox[2], cbox[5] = -cbox[5], -cbox[2] - end - - self.object:set_properties({collisionbox = cbox}) -end - --- set and return valid yaw -local set_yaw = function(self, yaw, delay, dtime) - - if not yaw or yaw ~= yaw then - yaw = 0 - end - - delay = delay or 0 - - if delay == 0 then - if self.shaking and dtime then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime - end - self.object:set_yaw(yaw) - update_roll(self) - return yaw - end - - self.target_yaw = yaw - self.delay = delay - - return self.target_yaw -end - --- global function to set mob yaw -function mobs:yaw(self, yaw, delay, dtime) - set_yaw(self, yaw, delay, dtime) -end - -local add_texture_mod = function(self, mod) - local full_mod = "" - local already_added = false - for i=1, #self.texture_mods do - if mod == self.texture_mods[i] then - already_added = true - end - full_mod = full_mod .. self.texture_mods[i] - end - if not already_added then - full_mod = full_mod .. mod - table.insert(self.texture_mods, mod) - end - self.object:set_texture_mod(full_mod) -end -local remove_texture_mod = function(self, mod) - local full_mod = "" - local remove = {} - for i=1, #self.texture_mods do - if self.texture_mods[i] ~= mod then - full_mod = full_mod .. self.texture_mods[i] - else - table.insert(remove, i) - end - end - for i=#remove, 1 do - table.remove(self.texture_mods, remove[i]) - end - self.object:set_texture_mod(full_mod) -end - --- set defined animation -local set_animation = function(self, anim, fixed_frame) - if not self.animation or not anim then - return - end - if self.state == "die" and anim ~= "die" and anim ~= "stand" then +-- Spawn a child +function mobs:spawn_child(pos, mob_type) + local child = minetest_add_entity(pos, mob_type) + if not child then return end - self.animation.current = self.animation.current or "" + local ent = child:get_luaentity() + effect(pos, 15, "mcl_particles_smoke.png", 1, 2, 2, 15, 5) - if (anim == self.animation.current - or not self.animation[anim .. "_start"] - or not self.animation[anim .. "_end"]) and self.state ~= "die" then - return + ent.child = true + + local textures + -- using specific child texture (if found) + if ent.child_texture then + textures = ent.child_texture[1] end - self.animation.current = anim + -- and resize to half height + child:set_properties({ + textures = textures, + visual_size = { + x = ent.base_size.x * .5, + y = ent.base_size.y * .5, + }, + collisionbox = { + ent.base_colbox[1] * .5, + ent.base_colbox[2] * .5, + ent.base_colbox[3] * .5, + ent.base_colbox[4] * .5, + ent.base_colbox[5] * .5, + ent.base_colbox[6] * .5, + }, + selectionbox = { + ent.base_selbox[1] * .5, + ent.base_selbox[2] * .5, + ent.base_selbox[3] * .5, + ent.base_selbox[4] * .5, + ent.base_selbox[5] * .5, + ent.base_selbox[6] * .5, + }, + }) - local a_start = self.animation[anim .. "_start"] - local a_end - if fixed_frame then - a_end = a_start - else - a_end = self.animation[anim .. "_end"] - end - - self.object:set_animation({ - x = a_start, - y = a_end}, - self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, - 0, self.animation[anim .. "_loop"] ~= false) + return child end --- above function exported for mount.lua -function mobs:set_animation(self, anim) - set_animation(self, anim) -end --- Returns true is node can deal damage to self -local is_node_dangerous = function(self, nodename) - local nn = nodename - if self.lava_damage > 0 then - if minetest.get_item_group(nn, "lava") ~= 0 then - return true - end - end - if self.fire_damage > 0 then - if minetest.get_item_group(nn, "fire") ~= 0 then - return true - end - end - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].damage_per_second and minetest.registered_nodes[nn].damage_per_second > 0 then - return true - end - return false -end - - --- Returns true if node is a water hazard -local is_node_waterhazard = function(self, nodename) - local nn = nodename - if self.water_damage > 0 then - if minetest.get_item_group(nn, "water") ~= 0 then - return true - end - end - if minetest.registered_nodes[nn] and minetest.registered_nodes[nn].drowning and minetest.registered_nodes[nn].drowning > 0 then - if self.breath_max ~= -1 then - -- check if the mob is water-breathing _and_ the block is water; only return true if neither is the case - -- this will prevent water-breathing mobs to classify water or e.g. sand below them as dangerous - if not self.breathes_in_water and minetest.get_item_group(nn, "water") ~= 0 then - return true - end - end - end - return false -end - - --- check line of sight (BrunoMine) -local line_of_sight = function(self, pos1, pos2, stepsize) - - stepsize = stepsize or 1 - - local s, pos = minetest.line_of_sight(pos1, pos2, stepsize) - - -- normal walking and flying mobs can see you through air - if s == true then - return true - end - - -- New pos1 to be analyzed - local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} - - local r, pos = minetest.line_of_sight(npos1, pos2, stepsize) - - -- Checks the return - if r == true then return true end - - -- Nodename found - local nn = minetest.get_node(pos).name - - -- Target Distance (td) to travel - local td = vector.distance(pos1, pos2) - - -- Actual Distance (ad) traveled - local ad = 0 - - -- It continues to advance in the line of sight in search of a real - -- obstruction which counts as 'normal' nodebox. - while minetest.registered_nodes[nn] - and minetest.registered_nodes[nn].walkable == false do - - -- Check if you can still move forward - if td < ad + stepsize then - return true -- Reached the target - end - - -- Moves the analyzed pos - local d = vector.distance(pos1, pos2) - - npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x - npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y - npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z - - -- NaN checks - if d == 0 - or npos1.x ~= npos1.x - or npos1.y ~= npos1.y - or npos1.z ~= npos1.z then - return false - end - - ad = ad + stepsize - - -- scan again - r, pos = minetest.line_of_sight(npos1, pos2, stepsize) - - if r == true then return true end - - -- New Nodename found - nn = minetest.get_node(pos).name - - end - - return false -end - - --- are we flying in what we are suppose to? (taikedz) -local flight_check = function(self) - - local nod = self.standing_in - local def = minetest.registered_nodes[nod] - - if not def then return false end -- nil check - - local fly_in - if type(self.fly_in) == "string" then - fly_in = { self.fly_in } - elseif type(self.fly_in) == "table" then - fly_in = self.fly_in - else +-- feeding, taming and breeding (thanks blert2112) +function mobs:feed_tame(self, clicker, feed_count, breed, tame) + if not self.follow then return false end - for _,checknode in pairs(fly_in) do - if nod == checknode then - return true - elseif checknode == "__airlike" and def.walkable == false and - (def.liquidtype == "none" or minetest.get_item_group(nod, "fake_liquid") == 1) then - return true + -- can eat/tame with item in hand + if follow_holding(self, clicker) then + + -- if not in creative then take item + if not mobs.is_creative(clicker:get_player_name()) then + + local item = clicker:get_wielded_item() + + item:take_item() + + clicker:set_wielded_item(item) end - end - return false -end + mob_sound(self, "eat", nil, true) + -- increase health + self.health = self.health + 4 --- custom particle effects -local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow, go_down) + if self.health >= self.hp_max then - radius = radius or 2 - min_size = min_size or 0.5 - max_size = max_size or 1 - gravity = gravity or -10 - glow = glow or 0 - go_down = go_down or false + self.health = self.hp_max - local ym - if go_down then - ym = 0 - else - ym = -radius - end - - minetest.add_particlespawner({ - amount = amount, - time = 0.25, - minpos = pos, - maxpos = pos, - minvel = {x = -radius, y = ym, z = -radius}, - maxvel = {x = radius, y = radius, z = radius}, - minacc = {x = 0, y = gravity, z = 0}, - maxacc = {x = 0, y = gravity, z = 0}, - minexptime = 0.1, - maxexptime = 1, - minsize = min_size, - maxsize = max_size, - texture = texture, - glow = glow, - }) -end - -local damage_effect = function(self, damage) - -- damage particles - if (not disable_blood) and damage > 0 then - - local amount_large = math.floor(damage / 2) - local amount_small = damage % 2 - - local pos = self.object:get_pos() - - pos.y = pos.y + (self.collisionbox[5] - self.collisionbox[2]) * .5 - - local texture = "mobs_blood.png" - -- full heart damage (one particle for each 2 HP damage) - if amount_large > 0 then - effect(pos, amount_large, texture, 2, 2, 1.75, 0, nil, true) - end - -- half heart damage (one additional particle if damage is an odd number) - if amount_small > 0 then - -- TODO: Use "half heart" - effect(pos, amount_small, texture, 1, 1, 1.75, 0, nil, true) - end - end -end - -mobs.death_effect = function(pos, yaw, collisionbox, rotate) - local min, max - if collisionbox then - min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} - max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} - else - min = { x = -0.5, y = 0, z = -0.5 } - max = { x = 0.5, y = 0.5, z = 0.5 } - end - if rotate then - min = vector.rotate(min, {x=0, y=yaw, z=pi/2}) - max = vector.rotate(max, {x=0, y=yaw, z=pi/2}) - min, max = vector.sort(min, max) - min = vector.multiply(min, 0.5) - max = vector.multiply(max, 0.5) - end - - minetest.add_particlespawner({ - amount = 50, - time = 0.001, - minpos = vector.add(pos, min), - maxpos = vector.add(pos, max), - minvel = vector.new(-5,-5,-5), - maxvel = vector.new(5,5,5), - minexptime = 1.1, - maxexptime = 1.5, - minsize = 1, - maxsize = 2, - collisiondetection = false, - vertical = false, - texture = "mcl_particles_mob_death.png^[colorize:#000000:255", - }) - - minetest.sound_play("mcl_mobs_mob_poof", { - pos = pos, - gain = 1.0, - max_hear_distance = 8, - }, true) -end - -local update_tag = function(self) - local tag - if mobs_debug then - tag = "nametag = '"..tostring(self.nametag).."'\n".. - "state = '"..tostring(self.state).."'\n".. - "order = '"..tostring(self.order).."'\n".. - "attack = "..tostring(self.attack).."\n".. - "health = "..tostring(self.health).."\n".. - "breath = "..tostring(self.breath).."\n".. - "gotten = "..tostring(self.gotten).."\n".. - "tamed = "..tostring(self.tamed).."\n".. - "horny = "..tostring(self.horny).."\n".. - "hornytimer = "..tostring(self.hornytimer).."\n".. - "runaway_timer = "..tostring(self.runaway_timer).."\n".. - "following = "..tostring(self.following) - else - tag = self.nametag - end - self.object:set_properties({ - nametag = tag, - }) - - update_roll(self) -end - --- drop items -local item_drop = function(self, cooked, looting_level) - - -- no drops if disabled by setting - if not mobs_drop_items then return end - - looting_level = looting_level or 0 - - -- no drops for child mobs (except monster) - if (self.child and self.type ~= "monster") then - return - end - - local obj, item, num - local pos = self.object:get_pos() - - self.drops = self.drops or {} -- nil check - - for n = 1, #self.drops do - local dropdef = self.drops[n] - local chance = 1 / dropdef.chance - local looting_type = dropdef.looting - - if looting_level > 0 then - local chance_function = dropdef.looting_chance_function - if chance_function then - chance = chance_function(looting_level) - elseif looting_type == "rare" then - chance = chance + (dropdef.looting_factor or 0.01) * looting_level + if self.htimer < 1 then + self.htimer = 5 end end - local num = 0 - local do_common_looting = (looting_level > 0 and looting_type == "common") - if random() < chance then - num = random(dropdef.min or 1, dropdef.max or 1) - elseif not dropdef.looting_ignore_chance then - do_common_looting = false + self.object:set_hp(self.health) + + update_tag(self) + + -- make children grow quicker + if self.child == true then + + -- deduct 10% of the time to adulthood + self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1) + + return true end - if do_common_looting then - num = num + math.floor(math.random(0, looting_level) + 0.5) - end + -- feed and tame + self.food = (self.food or 0) + 1 + if self.food >= feed_count then - if num > 0 then - item = dropdef.name + self.food = 0 - -- cook items when true - if cooked then + if breed and self.hornytimer == 0 then + self.horny = true + end - local output = minetest.get_craft_result({ - method = "cooking", width = 1, items = {item}}) + if tame then - if output and output.item and not output.item:is_empty() then - item = output.item:get_name() + self.tamed = true + + if not self.owner or self.owner == "" then + self.owner = clicker:get_player_name() end end - -- add item if it exists - for x = 1, num do - obj = minetest.add_item(pos, ItemStack(item .. " " .. 1)) + -- make sound when fed so many times + mob_sound(self, "random", true) + end + + return true + end + + return false +end + +-- no damage to nodes explosion +function mobs:safe_boom(self, pos, strength) + minetest_sound_play(self.sounds and self.sounds.explode or "tnt_explode", { + pos = pos, + gain = 1.0, + max_hear_distance = self.sounds and self.sounds.distance or 32 + }, true) + local radius = strength + entity_physics(pos, radius) + effect(pos, 32, "mcl_particles_smoke.png", radius * 3, radius * 5, radius, 1, 0) +end + + +-- make explosion with protection and tnt mod check +function mobs:boom(self, pos, strength, fire) + self.object:remove() + if mod_explosions then + if mobs_griefing and not minetest_is_protected(pos, "") then + mcl_explosions.explode(pos, strength, { drop_chance = 1.0, fire = fire }, self.object) + else + mobs:safe_boom(self, pos, strength) + end + else + mobs:safe_boom(self, pos, strength) + end +end + +-- falling and fall damage +-- returns true if mob died +local falling = function(self, pos) + + if self.fly and self.state ~= "die" then + return + end + + if mcl_portals ~= nil then + if mcl_portals.nether_portal_cooloff(self.object) then + return false -- mob has teleported through Nether portal - it's 99% not falling + end + end + + -- floating in water (or falling) + local v = self.object:get_velocity() + + if v.y > 0 then + + -- apply gravity when moving up + self.object:set_acceleration({ + x = 0, + y = -10, + z = 0 + }) + + elseif v.y <= 0 and v.y > self.fall_speed then + + -- fall downwards at set speed + self.object:set_acceleration({ + x = 0, + y = self.fall_speed, + z = 0 + }) + else + -- stop accelerating once max fall speed hit + self.object:set_acceleration({x = 0, y = 0, z = 0}) + end + + if minetest_registered_nodes[node_ok(pos).name].groups.lava then + + if self.floats_on_lava == 1 then + + self.object:set_acceleration({ + x = 0, + y = -self.fall_speed / (max(1, v.y) ^ 2), + z = 0 + }) + end + end + + -- in water then float up + if minetest_registered_nodes[node_ok(pos).name].groups.water then + + if self.floats == 1 then + + self.object:set_acceleration({ + x = 0, + y = -self.fall_speed / (math_max(1, v.y) ^ 2), + z = 0 + }) + end + else + + end +end + + + + +-- find someone to runaway from +local runaway_from = function(self) + + if not self.runaway_from and self.state ~= "flop" then + return + end + + local s = self.object:get_pos() + local p, sp, dist + local player, obj, min_player + local type, name = "", "" + local min_dist = self.view_range + 1 + local objs = minetest_get_objects_inside_radius(s, self.view_range) + + for n = 1, #objs do + + if objs[n]:is_player() then + + if mobs.invis[ objs[n]:get_player_name() ] + or self.owner == objs[n]:get_player_name() + or (not object_in_range(self, objs[n])) then + type = "" + else + player = objs[n] + type = "player" + name = "player" end + else + obj = objs[n]:get_luaentity() - if obj and obj:get_luaentity() then + if obj then + player = obj.object + type = obj.type + name = obj.name or "" + end + end - obj:set_velocity({ - x = random(-10, 10) / 9, - y = 6, - z = random(-10, 10) / 9, - }) - elseif obj then - obj:remove() -- item does not exist + -- find specific mob to runaway from + if name ~= "" and name ~= self.name + and specific_runaway(self.runaway_from, name) then + + p = player:get_pos() + sp = s + + -- aim higher to make looking up hills more realistic + p.y = p.y + 1 + sp.y = sp.y + 1 + + dist = vector.distance(p, s) + + + -- choose closest player/mpb to runaway from + if dist < min_dist + and line_of_sight(self, sp, p, 2) == true then + min_dist = dist + min_player = player end end end - self.drops = {} + if min_player then + + local lp = player:get_pos() + local vec = { + x = lp.x - s.x, + y = lp.y - s.y, + z = lp.z - s.z + } + + local yaw = (atan(vec.z / vec.x) + 3 * math_pi / 2) - self.rotate + + if lp.x > s.x then + yaw = yaw + math_pi + end + + yaw = set_yaw(self, yaw, 4) + self.state = "runaway" + self.runaway_timer = 3 + self.following = nil + end end +-- specific runaway +local specific_runaway = function(list, what) + + -- no list so do not run + if list == nil then + return false + end + + -- found entity on list to attack? + for no = 1, #list do + + if list[no] == what then + return true + end + end + + return false +end + + +-- follow player if owner or holding item, if fish outta water then flop +local follow_flop = function(self) + + -- find player to follow + if (self.follow ~= "" + or self.order == "follow") + and not self.following + and self.state ~= "attack" + and self.order ~= "sit" + and self.state ~= "runaway" then + + local s = self.object:get_pos() + local players = minetest.get_connected_players() + + for n = 1, #players do + + if (object_in_range(self, players[n])) + and not mobs.invis[ players[n]:get_player_name() ] then + + self.following = players[n] + + break + end + end + end + + if self.type == "npc" + and self.order == "follow" + and self.state ~= "attack" + and self.order ~= "sit" + and self.owner ~= "" then + + -- npc stop following player if not owner + if self.following + and self.owner + and self.owner ~= self.following:get_player_name() then + self.following = nil + end + else + -- stop following player if not holding specific item, + -- mob is horny, fleeing or attacking + if self.following + and self.following:is_player() + and (follow_holding(self, self.following) == false or + self.horny or self.state == "runaway") then + self.following = nil + end + + end + + -- follow that thing + if self.following then + + local s = self.object:get_pos() + local p + + if self.following:is_player() then + + p = self.following:get_pos() + + elseif self.following.object then + + p = self.following.object:get_pos() + end + + if p then + + local dist = vector.distance(p, s) + + -- dont follow if out of range + if (not object_in_range(self, self.following)) then + self.following = nil + else + local vec = { + x = p.x - s.x, + z = p.z - s.z + } + + local yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate + + if p.x > s.x then yaw = yaw + math_pi end + + set_yaw(self, yaw, 2.35) + + -- anyone but standing npc's can move along + if dist > 3 + and self.order ~= "stand" then + + set_velocity(self, self.follow_velocity) + + if self.walk_chance ~= 0 then + set_animation(self, "run") + end + else + set_velocity(self, 0) + set_animation(self, "stand") + end + + return + end + end + end + + -- swimmers flop when out of their element, and swim again when back in + if self.fly then + local s = self.object:get_pos() + if not flight_check(self, s) then + + self.state = "flop" + self.object:set_acceleration({x = 0, y = DEFAULT_FALL_SPEED, z = 0}) + + local sdef = minetest_registered_nodes[self.standing_on] + -- Flop on ground + if sdef and sdef.walkable then + mob_sound(self, "flop") + self.object:set_velocity({ + x = math_random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + y = FLOP_HEIGHT, + z = math_random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), + }) + end + + set_animation(self, "stand", true) + + return + elseif self.state == "flop" then + self.state = "stand" + self.object:set_acceleration({x = 0, y = 0, z = 0}) + set_velocity(self, 0) + end + end +end + + +-- npc, find closest monster to attack +local npc_attack = function(self) + + if self.type ~= "npc" + or not self.attacks_monsters + or self.state == "attack" then + return + end + + local p, sp, obj, min_player + local s = self.object:get_pos() + local min_dist = self.view_range + 1 + local objs = minetest_get_objects_inside_radius(s, self.view_range) + + for n = 1, #objs do + + obj = objs[n]:get_luaentity() + + if obj and obj.type == "monster" then + + p = obj.object:get_pos() + sp = s + + local dist = vector.distance(p, s) + + -- aim higher to make looking up hills more realistic + p.y = p.y + 1 + sp.y = sp.y + 1 + + if dist < min_dist + and line_of_sight(self, sp, p, 2) == true then + min_dist = dist + min_player = obj.object + end + end + end + + if min_player then + do_attack(self, min_player) + end +end + + +-- monster find someone to attack +local monster_attack = function(self) + + if self.type ~= "monster" + or not damage_enabled + or minetest_is_creative_enabled("") + or self.passive + or self.state == "attack" + or day_docile(self) then + return + end + + local s = self.object:get_pos() + local p, sp, dist + local player, obj, min_player + local type, name = "", "" + local min_dist = self.view_range + 1 + local objs = minetest_get_objects_inside_radius(s, self.view_range) + + for n = 1, #objs do + + if objs[n]:is_player() then + + if mobs.invis[ objs[n]:get_player_name() ] or (not object_in_range(self, objs[n])) then + type = "" + else + player = objs[n] + type = "player" + name = "player" + end + else + obj = objs[n]:get_luaentity() + + if obj then + player = obj.object + type = obj.type + name = obj.name or "" + end + end + + -- find specific mob to attack, failing that attack player/npc/animal + if specific_attack(self.specific_attack, name) + and (type == "player" or type == "npc" + or (type == "animal" and self.attack_animals == true)) then + + p = player:get_pos() + sp = s + + dist = vector.distance(p, s) + + -- aim higher to make looking up hills more realistic + p.y = p.y + 1 + sp.y = sp.y + 1 + + + -- choose closest player to attack + if dist < min_dist + and line_of_sight(self, sp, p, 2) == true then + min_dist = dist + min_player = player + end + end + end + + -- attack player + if min_player then + do_attack(self, min_player) + end +end + + +-- specific attacks +local specific_attack = function(list, what) + + -- no list so attack default (player, animals etc.) + if list == nil then + return true + end + + -- found entity on list to attack? + for no = 1, #list do + + if list[no] == what then + return true + end + end + + return false +end + + +-- dogfight attack switch and counter function +local dogswitch = function(self, dtime) + + -- switch mode not activated + if not self.dogshoot_switch + or not dtime then + return 0 + end + + self.dogshoot_count = self.dogshoot_count + dtime + + if (self.dogshoot_switch == 1 + and self.dogshoot_count > self.dogshoot_count_max) + or (self.dogshoot_switch == 2 + and self.dogshoot_count > self.dogshoot_count2_max) then + + self.dogshoot_count = 0 + + if self.dogshoot_switch == 1 then + self.dogshoot_switch = 2 + else + self.dogshoot_switch = 1 + end + end + + return self.dogshoot_switch +end + +-- path finding and smart mob routine by rnd, line_of_sight and other edits by Elkien3 +local smart_mobs = function(self, s, p, dist, dtime) + + local s1 = self.path.lastpos + + local target_pos = self.attack:get_pos() + + -- is it becoming stuck? + if math_abs(s1.x - s.x) + math_abs(s1.z - s.z) < .5 then + self.path.stuck_timer = self.path.stuck_timer + dtime + else + self.path.stuck_timer = 0 + end + + self.path.lastpos = {x = s.x, y = s.y, z = s.z} + + local use_pathfind = false + local has_lineofsight = minetest_line_of_sight( + {x = s.x, y = (s.y) + .5, z = s.z}, + {x = target_pos.x, y = (target_pos.y) + 1.5, z = target_pos.z}, .2) + + -- im stuck, search for path + if not has_lineofsight then + + if los_switcher == true then + use_pathfind = true + los_switcher = false + end -- cannot see target! + else + if los_switcher == false then + + los_switcher = true + use_pathfind = false + + minetest_after(1, function(self) + if not self.object:get_luaentity() then + return + end + if has_lineofsight then self.path.following = false end + end, self) + end -- can see target! + end + + if (self.path.stuck_timer > stuck_timeout and not self.path.following) then + + use_pathfind = true + self.path.stuck_timer = 0 + + minetest_after(1, function(self) + if not self.object:get_luaentity() then + return + end + if has_lineofsight then self.path.following = false end + end, self) + end + + if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then + + use_pathfind = true + self.path.stuck_timer = 0 + + minetest_after(1, function(self) + if not self.object:get_luaentity() then + return + end + if has_lineofsight then self.path.following = false end + end, self) + end + + if math_abs(vector.subtract(s,target_pos).y) > self.stepheight then + + if height_switcher then + use_pathfind = true + height_switcher = false + end + else + if not height_switcher then + use_pathfind = false + height_switcher = true + end + end + + if use_pathfind then + -- lets try find a path, first take care of positions + -- since pathfinder is very sensitive + local sheight = self.collisionbox[5] - self.collisionbox[2] + + -- round position to center of node to avoid stuck in walls + -- also adjust height for player models! + s.x = math_floor(s.x + 0.5) + s.z = math_floor(s.z + 0.5) + + local ssight, sground = minetest_line_of_sight(s, { + x = s.x, y = s.y - 4, z = s.z}, 1) + + -- determine node above ground + if not ssight then + s.y = sground.y + 1 + end + + local p1 = self.attack:get_pos() + + p1.x = math_floor(p1.x + 0.5) + p1.y = math_floor(p1.y + 0.5) + p1.z = math_floor(p1.z + 0.5) + + local dropheight = 12 + if self.fear_height ~= 0 then dropheight = self.fear_height end + local jumpheight = 0 + if self.jump and self.jump_height >= 4 then + jumpheight = math.min(math.ceil(self.jump_height / 4), 4) + elseif self.stepheight > 0.5 then + jumpheight = 1 + end + self.path.way = minetest_find_path(s, p1, 16, jumpheight, dropheight, "A*_noprefetch") + + self.state = "" + do_attack(self, self.attack) + + -- no path found, try something else + if not self.path.way then + + self.path.following = false + + -- lets make way by digging/building if not accessible + if self.pathfinding == 2 and mobs_griefing then + + -- is player higher than mob? + if s.y < p1.y then + + -- build upwards + if not minetest_is_protected(s, "") then + + local ndef1 = minetest_registered_nodes[self.standing_in] + + if ndef1 and (ndef1.buildable_to or ndef1.groups.liquid) then + + minetest_set_node(s, {name = mobs.fallback_node}) + end + end + + local sheight = math.ceil(self.collisionbox[5]) + 1 + + -- assume mob is 2 blocks high so it digs above its head + s.y = s.y + sheight + + -- remove one block above to make room to jump + if not minetest_is_protected(s, "") then + + local node1 = node_ok(s, "air").name + local ndef1 = minetest_registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest_set_node(s, {name = "air"}) + minetest_add_item(s, ItemStack(node1)) + + end + end + + s.y = s.y - sheight + self.object:set_pos({x = s.x, y = s.y + 2, z = s.z}) + + else -- dig 2 blocks to make door toward player direction + + local yaw1 = self.object:get_yaw() + math_pi / 2 + local p1 = { + x = s.x + math_cos(yaw1), + y = s.y, + z = s.z + math_sin(yaw1) + } + + if not minetest_is_protected(p1, "") then + + local node1 = node_ok(p1, "air").name + local ndef1 = minetest_registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest_add_item(p1, ItemStack(node1)) + minetest_set_node(p1, {name = "air"}) + end + + p1.y = p1.y + 1 + node1 = node_ok(p1, "air").name + ndef1 = minetest_registered_nodes[node1] + + if node1 ~= "air" + and node1 ~= "ignore" + and ndef1 + and not ndef1.groups.level + and not ndef1.groups.unbreakable + and not ndef1.groups.liquid then + + minetest_add_item(p1, ItemStack(node1)) + minetest_set_node(p1, {name = "air"}) + end + + end + end + end + + -- will try again in 2 seconds + self.path.stuck_timer = stuck_timeout - 2 + elseif s.y < p1.y and (not self.fly) then + do_jump(self) --add jump to pathfinding + self.path.following = true + -- Yay, I found path! + -- TODO: Implement war_cry sound without being annoying + --mob_sound(self, "war_cry", true) + else + set_velocity(self, self.walk_velocity) + + -- follow path now that it has it + self.path.following = true + end + end +end + + + + + + -- check if mob is dead or only hurt local check_for_death = function(self, cause, cmi_cause) @@ -775,7 +943,7 @@ local check_for_death = function(self, cause, cmi_cause) -- play damage sound if health was reduced and make mob flash red. if damaged then add_texture_mod(self, "^[colorize:red:130") - minetest.after(.2, function(self) + minetest_after(.2, function(self) if self and self.object then remove_texture_mod(self, "^[colorize:red:130") end @@ -818,8 +986,8 @@ local check_for_death = function(self, cause, cmi_cause) local looting = mcl_enchanting.get_enchantment(wielditem, "looting") item_drop(self, cooked, looting) - if mod_experience and ((not self.child) or self.type ~= "animal") and (minetest.get_us_time() - self.xp_timestamp <= 5000000) then - mcl_experience.throw_experience(self.object:get_pos(), math.random(self.xp_min, self.xp_max)) + if mod_experience and ((not self.child) or self.type ~= "animal") and (minetest_get_us_time() - self.xp_timestamp <= 5000000) then + mcl_experience.throw_experience(self.object:get_pos(), math_random(self.xp_min, self.xp_max)) end end end @@ -884,7 +1052,7 @@ local check_for_death = function(self, cause, cmi_cause) set_animation(self, "die") else local rot = self.object:get_rotation() - rot.z = pi/2 + rot.z = math_pi/2 self.object:set_rotation(rot) length = 1 + DEATH_DELAY set_animation(self, "stand", true) @@ -911,34 +1079,366 @@ local check_for_death = function(self, cause, cmi_cause) if length <= 0 then kill(self) else - minetest.after(length, kill, self) + minetest_after(length, kill, self) end return true end +local damage_effect = function(self, damage) + -- damage particles + if (not disable_blood) and damage > 0 then --- check if within physical map limits (-30911 to 30927) -local within_limits, wmin, wmax = nil, -30913, 30928 -within_limits = function(pos, radius) - if mcl_vars then - if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then - wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max - within_limits = function(pos, radius) - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax + local amount_large = math_floor(damage / 2) + local amount_small = damage % 2 + + local pos = self.object:get_pos() + + pos.y = pos.y + (self.collisionbox[5] - self.collisionbox[2]) * .5 + + local texture = "mobs_blood.png" + -- full heart damage (one particle for each 2 HP damage) + if amount_large > 0 then + effect(pos, amount_large, texture, 2, 2, 1.75, 0, nil, true) + end + -- half heart damage (one additional particle if damage is an odd number) + if amount_small > 0 then + -- TODO: Use "half heart" + effect(pos, amount_small, texture, 1, 1, 1.75, 0, nil, true) + end + end +end + + +-- custom particle effects +local effect = function(pos, amount, texture, min_size, max_size, radius, gravity, glow, go_down) + + radius = radius or 2 + min_size = min_size or 0.5 + max_size = max_size or 1 + gravity = gravity or -10 + glow = glow or 0 + go_down = go_down or false + + local ym + if go_down then + ym = 0 + else + ym = -radius + end + + minetest_add_particlespawner({ + amount = amount, + time = 0.25, + minpos = pos, + maxpos = pos, + minvel = {x = -radius, y = ym, z = -radius}, + maxvel = {x = radius, y = radius, z = radius}, + minacc = {x = 0, y = gravity, z = 0}, + maxacc = {x = 0, y = gravity, z = 0}, + minexptime = 0.1, + maxexptime = 1, + minsize = min_size, + maxsize = max_size, + texture = texture, + glow = glow, + }) +end + + +-- are we flying in what we are suppose to? (taikedz) +local flight_check = function(self) + + local nod = self.standing_in + local def = minetest_registered_nodes[nod] + + if not def then return false end -- nil check + + local fly_in + if type(self.fly_in) == "string" then + fly_in = { self.fly_in } + elseif type(self.fly_in) == "table" then + fly_in = self.fly_in + else + return false + end + + for _,checknode in pairs(fly_in) do + if nod == checknode then + return true + elseif checknode == "__airlike" and def.walkable == false and + (def.liquidtype == "none" or minetest_get_item_group(nod, "fake_liquid") == 1) then + return true + end + end + + return false +end + + +-- check line of sight (BrunoMine) +local line_of_sight = function(self, pos1, pos2, stepsize) + + stepsize = stepsize or 1 + + local s, pos = minetest_line_of_sight(pos1, pos2, stepsize) + + -- normal walking and flying mobs can see you through air + if s == true then + return true + end + + -- New pos1 to be analyzed + local npos1 = {x = pos1.x, y = pos1.y, z = pos1.z} + + local r, pos = minetest_line_of_sight(npos1, pos2, stepsize) + + -- Checks the return + if r == true then return true end + + -- Nodename found + local nn = minetest_get_node(pos).name + + -- Target Distance (td) to travel + local td = vector.distance(pos1, pos2) + + -- Actual Distance (ad) traveled + local ad = 0 + + -- It continues to advance in the line of sight in search of a real + -- obstruction which counts as 'normal' nodebox. + while minetest_registered_nodes[nn] + and minetest_registered_nodes[nn].walkable == false do + + -- Check if you can still move forward + if td < ad + stepsize then + return true -- Reached the target + end + + -- Moves the analyzed pos + local d = vector.distance(pos1, pos2) + + npos1.x = ((pos2.x - pos1.x) / d * stepsize) + pos1.x + npos1.y = ((pos2.y - pos1.y) / d * stepsize) + pos1.y + npos1.z = ((pos2.z - pos1.z) / d * stepsize) + pos1.z + + -- NaN checks + if d == 0 + or npos1.x ~= npos1.x + or npos1.y ~= npos1.y + or npos1.z ~= npos1.z then + return false + end + + ad = ad + stepsize + + -- scan again + r, pos = minetest_line_of_sight(npos1, pos2, stepsize) + + if r == true then return true end + + -- New Nodename found + nn = minetest_get_node(pos).name + + end + + return false +end + +-- Returns true if node is a water hazard +local is_node_waterhazard = function(self, nodename) + local nn = nodename + if self.water_damage > 0 then + if minetest_get_item_group(nn, "water") ~= 0 then + return true + end + end + if minetest_registered_nodes[nn] and minetest_registered_nodes[nn].drowning and minetest_registered_nodes[nn].drowning > 0 then + if self.breath_max ~= -1 then + -- check if the mob is water-breathing _and_ the block is water; only return true if neither is the case + -- this will prevent water-breathing mobs to classify water or e.g. sand below them as dangerous + if not self.breathes_in_water and minetest_get_item_group(nn, "water") ~= 0 then + return true end end end - return pos - and (pos.x - radius) > wmin and (pos.x + radius) < wmax - and (pos.y - radius) > wmin and (pos.y + radius) < wmax - and (pos.z - radius) > wmin and (pos.z + radius) < wmax + return false end +-- Returns true is node can deal damage to self +local is_node_dangerous = function(self, nodename) + local nn = nodename + if self.lava_damage > 0 then + if minetest_get_item_group(nn, "lava") ~= 0 then + return true + end + end + if self.fire_damage > 0 then + if minetest_get_item_group(nn, "fire") ~= 0 then + return true + end + end + if minetest_registered_nodes[nn] and minetest_registered_nodes[nn].damage_per_second and minetest_registered_nodes[nn].damage_per_second > 0 then + return true + end + return false +end + + +local add_texture_mod = function(self, mod) + local full_mod = "" + local already_added = false + for i=1, #self.texture_mods do + if mod == self.texture_mods[i] then + already_added = true + end + full_mod = full_mod .. self.texture_mods[i] + end + if not already_added then + full_mod = full_mod .. mod + table.insert(self.texture_mods, mod) + end + self.object:set_texture_mod(full_mod) +end + + +local remove_texture_mod = function(self, mod) + local full_mod = "" + local remove = {} + for i=1, #self.texture_mods do + if self.texture_mods[i] ~= mod then + full_mod = full_mod .. self.texture_mods[i] + else + table.insert(remove, i) + end + end + for i=#remove, 1 do + table.remove(self.texture_mods, remove[i]) + end + self.object:set_texture_mod(full_mod) +end + + +-- Return true if object is in view_range +local function object_in_range(self, object) + if not object then + return false + end + local factor + -- Apply view range reduction for special player armor + if not object then + return false + end + local factor + -- Apply view range reduction for special player armor + if object:is_player() and mod_armor then + local factors = mcl_armor.player_view_range_factors[object] + factor = factors and factors[self.name] + end + -- Distance check + local dist + if factor and factor == 0 then + return false + elseif factor then + dist = self.view_range * factor + else + dist = self.view_range + end + + local p1, p2 = self.object:get_pos(), object:get_pos() + return p1 and p2 and (vector.distance(p1, p2) <= dist) +end + +-- attack player/mob +local do_attack = function(self, player) + + if self.state == "attack" or self.state == "die" then + return + end + + self.attack = player + self.state = "attack" + + -- TODO: Implement war_cry sound without being annoying + --if math_random(0, 100) < 90 then + --mob_sound(self, "war_cry", true) + --end +end + + +-- play sound +local mob_sound = function(self, soundname, is_opinion, fixed_pitch) + local soundinfo + if self.sounds_child and self.child then + soundinfo = self.sounds_child + elseif self.sounds then + soundinfo = self.sounds + end + if not soundinfo then + return + end + local sound = soundinfo[soundname] + if sound then + if is_opinion and self.opinion_sound_cooloff > 0 then + return + end + local pitch + if not fixed_pitch then + local base_pitch = soundinfo.base_pitch + if not base_pitch then + base_pitch = 1 + end + if self.child and (not self.sounds_child) then + -- Children have higher pitch + pitch = base_pitch * 1.5 + else + pitch = base_pitch + end + -- randomize the pitch a bit + pitch = pitch + math_random(-10, 10) * 0.005 + end + minetest_sound_play(sound, { + object = self.object, + gain = 1.0, + max_hear_distance = self.sounds.distance, + pitch = pitch, + }, true) + self.opinion_sound_cooloff = 1 + end +end + + +local function update_roll(self) + local is_Fleckenstein = self.nametag == "Fleckenstein" + local was_Fleckenstein = false + + local rot = self.object:get_rotation() + rot.z = is_Fleckenstein and math_pi or 0 + self.object:set_rotation(rot) + + local cbox = table.copy(self.collisionbox) + local acbox = self.object:get_properties().collisionbox + + if math_abs(cbox[2] - acbox[2]) > 0.1 then + was_Fleckenstein = true + end + + if is_Fleckenstein ~= was_Fleckenstein then + local pos = self.object:get_pos() + pos.y = pos.y + (acbox[2] + acbox[5]) + self.object:set_pos(pos) + end + + if is_Fleckenstein then + cbox[2], cbox[5] = -cbox[5], -cbox[2] + end + + self.object:set_properties({collisionbox = cbox}) +end + + + -- is mob facing a cliff or danger local is_at_cliff_or_danger = function(self) @@ -950,23 +1450,23 @@ local is_at_cliff_or_danger = function(self) return false end local yaw = self.object:get_yaw() - local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) - local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + local dir_x = -math_sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = math_cos(yaw) * (self.collisionbox[4] + 0.5) local pos = self.object:get_pos() local ypos = pos.y + self.collisionbox[2] -- just above floor - local free_fall, blocker = minetest.line_of_sight( + local free_fall, blocker = minetest_line_of_sight( {x = pos.x + dir_x, y = ypos, z = pos.z + dir_z}, {x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}) if free_fall then return true else - local bnode = minetest.get_node(blocker) + local bnode = minetest_get_node(blocker) local danger = is_node_dangerous(self, bnode.name) if danger then return true else - local def = minetest.registered_nodes[bnode.name] + local def = minetest_registered_nodes[bnode.name] if def and def.walkable then return false end @@ -985,18 +1485,18 @@ local is_at_water_danger = function(self) return false end local yaw = self.object:get_yaw() - local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) - local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + local dir_x = -math_sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = math_cos(yaw) * (self.collisionbox[4] + 0.5) local pos = self.object:get_pos() local ypos = pos.y + self.collisionbox[2] -- just above floor - local free_fall, blocker = minetest.line_of_sight( + local free_fall, blocker = minetest_line_of_sight( {x = pos.x + dir_x, y = ypos, z = pos.z + dir_z}, {x = pos.x + dir_x, y = ypos - 3, z = pos.z + dir_z}) if free_fall then return true else - local bnode = minetest.get_node(blocker) + local bnode = minetest_get_node(blocker) local waterdanger = is_node_waterhazard(self, bnode.name) if waterdanger and (is_node_waterhazard(self, self.standing_in) or is_node_waterhazard(self, self.standing_on)) then @@ -1004,7 +1504,7 @@ local is_at_water_danger = function(self) elseif waterdanger and (is_node_waterhazard(self, self.standing_in) or is_node_waterhazard(self, self.standing_on)) == false then return true else - local def = minetest.registered_nodes[bnode.name] + local def = minetest_registered_nodes[bnode.name] if def and def.walkable then return false end @@ -1014,21 +1514,6 @@ local is_at_water_danger = function(self) return false end - --- get node but use fallback for nil or unknown -local node_ok = function(pos, fallback) - - fallback = fallback or mobs.fallback_node - - local node = minetest.get_node_or_nil(pos) - - if node and minetest.registered_nodes[node.name] then - return node - end - - return minetest.registered_nodes[fallback] -end - local function get_light(pos, tod) if minetest.get_node_or_nil(pos) then local lightfunc = minetest.get_natural_light or minetest.get_node_light @@ -1120,7 +1605,7 @@ local do_env_damage = function(self) self.object:set_velocity({x = 0, y = 0, z = 0}) end - local nodef = minetest.registered_nodes[self.standing_in] + local nodef = minetest_registered_nodes[self.standing_in] -- rain if self.rain_damage > 0 and mod_weather then @@ -1161,6 +1646,8 @@ local do_env_damage = function(self) self.health = self.health - self.lava_damage + mcl_burning.set_on_fire(self.object, 15) + effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil) if check_for_death(self, "lava", {type = "environment", @@ -1177,6 +1664,8 @@ local do_env_damage = function(self) self.health = self.health - self.fire_damage + mcl_burning.set_on_fire(self.object, 8) + effect(pos, 5, "fire_basic_flame.png", nil, nil, 1, nil) if check_for_death(self, "fire", {type = "environment", @@ -1202,7 +1691,7 @@ local do_env_damage = function(self) if self.breath_max ~= -1 then local drowning = false if self.breathes_in_water then - if minetest.get_item_group(self.standing_in, "water") == 0 then + if minetest_get_item_group(self.standing_in, "water") == 0 then drowning = true end elseif nodef.drowning > 0 then @@ -1210,7 +1699,7 @@ local do_env_damage = function(self) end if drowning then - self.breath = math.max(0, self.breath - 1) + self.breath = math_max(0, self.breath - 1) effect(pos, 2, "bubble.png", nil, nil, 1, nil) if self.breath <= 0 then @@ -1228,7 +1717,7 @@ local do_env_damage = function(self) return true end else - self.breath = math.min(self.breath_max, self.breath + 1) + self.breath = math_min(self.breath_max, self.breath + 1) end end @@ -1294,13 +1783,13 @@ local do_jump = function(self) local nod = node_ok(pos) - if minetest.registered_nodes[nod.name].walkable == false then + if minetest_registered_nodes[nod.name].walkable == false then return false end -- where is front - local dir_x = -sin(yaw) * (self.collisionbox[4] + 0.5) - local dir_z = cos(yaw) * (self.collisionbox[4] + 0.5) + local dir_x = -math_sin(yaw) * (self.collisionbox[4] + 0.5) + local dir_z = math_cos(yaw) * (self.collisionbox[4] + 0.5) -- what is in front of mob? nod = node_ok({ @@ -1318,7 +1807,7 @@ local do_jump = function(self) }, "air") -- we don't attempt to jump if there's a stack of blocks blocking - if minetest.registered_nodes[nodTop.name].walkable == true then + if minetest_registered_nodes[nodTop.name].walkable == true then return false end @@ -1328,11 +1817,11 @@ local do_jump = function(self) end if self.walk_chance == 0 - or minetest.registered_items[nod.name].walkable then + or minetest_registered_items[nod.name].walkable then - if minetest.get_item_group(nod.name, "fence") == 0 - and minetest.get_item_group(nod.name, "fence_gate") == 0 - and minetest.get_item_group(nod.name, "wall") == 0 then + if minetest_get_item_group(nod.name, "fence") == 0 + and minetest_get_item_group(nod.name, "fence_gate") == 0 + and minetest_get_item_group(nod.name, "wall") == 0 then local v = self.object:get_velocity() @@ -1343,7 +1832,7 @@ local do_jump = function(self) self.object:set_velocity(v) -- when in air move forward - minetest.after(0.3, function(self, v) + minetest_after(0.3, function(self, v) if (not self.object) or (not self.object:get_luaentity()) or (self.state == "die") then return end @@ -1390,7 +1879,7 @@ local entity_physics = function(pos, radius) radius = radius * 2 - local objs = minetest.get_objects_inside_radius(pos, radius) + local objs = minetest_get_objects_inside_radius(pos, radius) local obj_pos, dist for n = 1, #objs do @@ -1400,7 +1889,7 @@ local entity_physics = function(pos, radius) dist = vector.distance(pos, obj_pos) if dist < 1 then dist = 1 end - local damage = floor((4 / dist) * radius) + local damage = math_floor((4 / dist) * radius) local ent = objs[n]:get_luaentity() -- punches work on entities AND players @@ -1480,14 +1969,14 @@ local breed = function(self) return end - -- horny animal can mate for HORNY_TIME seconds, - -- afterwards horny animal cannot mate again for HORNY_AGAIN_TIME seconds + -- horny animal can mate for BREED_TIME seconds, + -- afterwards horny animal cannot mate again for BREED_TIME_AGAIN seconds if self.horny == true - and self.hornytimer < HORNY_TIME + HORNY_AGAIN_TIME then + and self.hornytimer < BREED_TIME + BREED_TIME_AGAIN then self.hornytimer = self.hornytimer + 1 - if self.hornytimer >= HORNY_TIME + HORNY_AGAIN_TIME then + if self.hornytimer >= BREED_TIME + BREED_TIME_AGAIN then self.hornytimer = 0 self.horny = false end @@ -1495,13 +1984,13 @@ local breed = function(self) -- find another same animal who is also horny and mate if nearby if self.horny == true - and self.hornytimer <= HORNY_TIME then + and self.hornytimer <= BREED_TIME then local pos = self.object:get_pos() effect({x = pos.x, y = pos.y + 1, z = pos.z}, 8, "heart.png", 3, 4, 1, 0.1) - local objs = minetest.get_objects_inside_radius(pos, 3) + local objs = minetest_get_objects_inside_radius(pos, 3) local num = 0 local ent = nil @@ -1534,18 +2023,18 @@ local breed = function(self) if ent and canmate == true and ent.horny == true - and ent.hornytimer <= HORNY_TIME then + and ent.hornytimer <= BREED_TIME then num = num + 1 end -- found your mate? then have a baby if num > 1 then - self.hornytimer = HORNY_TIME + 1 - ent.hornytimer = HORNY_TIME + 1 + self.hornytimer = BREED_TIME + 1 + ent.hornytimer = BREED_TIME + 1 -- spawn baby - minetest.after(5, function(parent1, parent2, pos) + minetest_after(5, function(parent1, parent2, pos) if not parent1.object:get_luaentity() then return end @@ -1555,7 +2044,7 @@ local breed = function(self) -- Give XP if mod_experience then - mcl_experience.throw_experience(pos, math.random(1, 7)) + mcl_experience.throw_experience(pos, math_random(1, 7)) end -- custom breed function @@ -1572,7 +2061,7 @@ local breed = function(self) -- Use texture of one of the parents - local p = math.random(1, 2) + local p = math_random(1, 2) if p == 1 then ent_c.base_texture = parent1.base_texture else @@ -1595,7 +2084,6 @@ local breed = function(self) end end - -- find and replace what mob is looking for (grass, wheat etc.) local replace = function(self, pos) @@ -1603,7 +2091,7 @@ local replace = function(self, pos) or not self.replace_what or self.child == true or self.object:get_velocity().y ~= 0 - or random(1, self.replace_rate) > 1 then + or math_random(1, self.replace_rate) > 1 then return end @@ -1611,7 +2099,7 @@ local replace = function(self, pos) if type(self.replace_what[1]) == "table" then - local num = random(#self.replace_what) + local num = math_random(#self.replace_what) what = self.replace_what[num][1] or "" with = self.replace_what[num][2] or "" @@ -1624,7 +2112,7 @@ local replace = function(self, pos) pos.y = pos.y + y_offset - local node = minetest.get_node(pos) + local node = minetest_get_node(pos) if node.name == what then local oldnode = {name = what, param2 = node.param2} @@ -1638,7 +2126,7 @@ local replace = function(self, pos) if on_replace_return ~= false then if mobs_griefing then - minetest.set_node(pos, newnode) + minetest_set_node(pos, newnode) end end @@ -1662,650 +2150,24 @@ local day_docile = function(self) end -local los_switcher = false -local height_switcher = false --- path finding and smart mob routine by rnd, line_of_sight and other edits by Elkien3 -local smart_mobs = function(self, s, p, dist, dtime) +local mob_detach_child = function(self, child) - local s1 = self.path.lastpos - - local target_pos = self.attack:get_pos() - - -- is it becoming stuck? - if abs(s1.x - s.x) + abs(s1.z - s.z) < .5 then - self.path.stuck_timer = self.path.stuck_timer + dtime - else - self.path.stuck_timer = 0 + if self.driver == child then + self.driver = nil end - self.path.lastpos = {x = s.x, y = s.y, z = s.z} - - local use_pathfind = false - local has_lineofsight = minetest.line_of_sight( - {x = s.x, y = (s.y) + .5, z = s.z}, - {x = target_pos.x, y = (target_pos.y) + 1.5, z = target_pos.z}, .2) - - -- im stuck, search for path - if not has_lineofsight then - - if los_switcher == true then - use_pathfind = true - los_switcher = false - end -- cannot see target! - else - if los_switcher == false then - - los_switcher = true - use_pathfind = false - - minetest.after(1, function(self) - if not self.object:get_luaentity() then - return - end - if has_lineofsight then self.path.following = false end - end, self) - end -- can see target! - end - - if (self.path.stuck_timer > stuck_timeout and not self.path.following) then - - use_pathfind = true - self.path.stuck_timer = 0 - - minetest.after(1, function(self) - if not self.object:get_luaentity() then - return - end - if has_lineofsight then self.path.following = false end - end, self) - end - - if (self.path.stuck_timer > stuck_path_timeout and self.path.following) then - - use_pathfind = true - self.path.stuck_timer = 0 - - minetest.after(1, function(self) - if not self.object:get_luaentity() then - return - end - if has_lineofsight then self.path.following = false end - end, self) - end - - if math.abs(vector.subtract(s,target_pos).y) > self.stepheight then - - if height_switcher then - use_pathfind = true - height_switcher = false - end - else - if not height_switcher then - use_pathfind = false - height_switcher = true - end - end - - if use_pathfind then - -- lets try find a path, first take care of positions - -- since pathfinder is very sensitive - local sheight = self.collisionbox[5] - self.collisionbox[2] - - -- round position to center of node to avoid stuck in walls - -- also adjust height for player models! - s.x = floor(s.x + 0.5) - s.z = floor(s.z + 0.5) - - local ssight, sground = minetest.line_of_sight(s, { - x = s.x, y = s.y - 4, z = s.z}, 1) - - -- determine node above ground - if not ssight then - s.y = sground.y + 1 - end - - local p1 = self.attack:get_pos() - - p1.x = floor(p1.x + 0.5) - p1.y = floor(p1.y + 0.5) - p1.z = floor(p1.z + 0.5) - - local dropheight = 12 - if self.fear_height ~= 0 then dropheight = self.fear_height end - local jumpheight = 0 - if self.jump and self.jump_height >= 4 then - jumpheight = math.min(math.ceil(self.jump_height / 4), 4) - elseif self.stepheight > 0.5 then - jumpheight = 1 - end - self.path.way = minetest.find_path(s, p1, 16, jumpheight, dropheight, "A*_noprefetch") - - self.state = "" - do_attack(self, self.attack) - - -- no path found, try something else - if not self.path.way then - - self.path.following = false - - -- lets make way by digging/building if not accessible - if self.pathfinding == 2 and mobs_griefing then - - -- is player higher than mob? - if s.y < p1.y then - - -- build upwards - if not minetest.is_protected(s, "") then - - local ndef1 = minetest.registered_nodes[self.standing_in] - - if ndef1 and (ndef1.buildable_to or ndef1.groups.liquid) then - - minetest.set_node(s, {name = mobs.fallback_node}) - end - end - - local sheight = math.ceil(self.collisionbox[5]) + 1 - - -- assume mob is 2 blocks high so it digs above its head - s.y = s.y + sheight - - -- remove one block above to make room to jump - if not minetest.is_protected(s, "") then - - local node1 = node_ok(s, "air").name - local ndef1 = minetest.registered_nodes[node1] - - if node1 ~= "air" - and node1 ~= "ignore" - and ndef1 - and not ndef1.groups.level - and not ndef1.groups.unbreakable - and not ndef1.groups.liquid then - - minetest.set_node(s, {name = "air"}) - minetest.add_item(s, ItemStack(node1)) - - end - end - - s.y = s.y - sheight - self.object:set_pos({x = s.x, y = s.y + 2, z = s.z}) - - else -- dig 2 blocks to make door toward player direction - - local yaw1 = self.object:get_yaw() + pi / 2 - local p1 = { - x = s.x + cos(yaw1), - y = s.y, - z = s.z + sin(yaw1) - } - - if not minetest.is_protected(p1, "") then - - local node1 = node_ok(p1, "air").name - local ndef1 = minetest.registered_nodes[node1] - - if node1 ~= "air" - and node1 ~= "ignore" - and ndef1 - and not ndef1.groups.level - and not ndef1.groups.unbreakable - and not ndef1.groups.liquid then - - minetest.add_item(p1, ItemStack(node1)) - minetest.set_node(p1, {name = "air"}) - end - - p1.y = p1.y + 1 - node1 = node_ok(p1, "air").name - ndef1 = minetest.registered_nodes[node1] - - if node1 ~= "air" - and node1 ~= "ignore" - and ndef1 - and not ndef1.groups.level - and not ndef1.groups.unbreakable - and not ndef1.groups.liquid then - - minetest.add_item(p1, ItemStack(node1)) - minetest.set_node(p1, {name = "air"}) - end - - end - end - end - - -- will try again in 2 seconds - self.path.stuck_timer = stuck_timeout - 2 - elseif s.y < p1.y and (not self.fly) then - do_jump(self) --add jump to pathfinding - self.path.following = true - -- Yay, I found path! - -- TODO: Implement war_cry sound without being annoying - --mob_sound(self, "war_cry", true) - else - set_velocity(self, self.walk_velocity) - - -- follow path now that it has it - self.path.following = true - end - end end - --- specific attacks -local specific_attack = function(list, what) - - -- no list so attack default (player, animals etc.) - if list == nil then - return true - end - - -- found entity on list to attack? - for no = 1, #list do - - if list[no] == what then - return true - end - end - - return false -end - --- monster find someone to attack -local monster_attack = function(self) - - if self.type ~= "monster" - or not damage_enabled - or minetest.is_creative_enabled("") - or self.passive - or self.state == "attack" - or day_docile(self) then - return - end - - local s = self.object:get_pos() - local p, sp, dist - local player, obj, min_player - local type, name = "", "" - local min_dist = self.view_range + 1 - local objs = minetest.get_objects_inside_radius(s, self.view_range) - - for n = 1, #objs do - - if objs[n]:is_player() then - - if mobs.invis[ objs[n]:get_player_name() ] or (not object_in_range(self, objs[n])) then - type = "" - else - player = objs[n] - type = "player" - name = "player" - end - else - obj = objs[n]:get_luaentity() - - if obj then - player = obj.object - type = obj.type - name = obj.name or "" - end - end - - -- find specific mob to attack, failing that attack player/npc/animal - if specific_attack(self.specific_attack, name) - and (type == "player" or type == "npc" - or (type == "animal" and self.attack_animals == true)) then - - p = player:get_pos() - sp = s - - dist = vector.distance(p, s) - - -- aim higher to make looking up hills more realistic - p.y = p.y + 1 - sp.y = sp.y + 1 - - - -- choose closest player to attack - if dist < min_dist - and line_of_sight(self, sp, p, 2) == true then - min_dist = dist - min_player = player - end - end - end - - -- attack player - if min_player then - do_attack(self, min_player) - end -end - - --- npc, find closest monster to attack -local npc_attack = function(self) - - if self.type ~= "npc" - or not self.attacks_monsters - or self.state == "attack" then - return - end - - local p, sp, obj, min_player - local s = self.object:get_pos() - local min_dist = self.view_range + 1 - local objs = minetest.get_objects_inside_radius(s, self.view_range) - - for n = 1, #objs do - - obj = objs[n]:get_luaentity() - - if obj and obj.type == "monster" then - - p = obj.object:get_pos() - sp = s - - local dist = vector.distance(p, s) - - -- aim higher to make looking up hills more realistic - p.y = p.y + 1 - sp.y = sp.y + 1 - - if dist < min_dist - and line_of_sight(self, sp, p, 2) == true then - min_dist = dist - min_player = obj.object - end - end - end - - if min_player then - do_attack(self, min_player) - end -end - - --- specific runaway -local specific_runaway = function(list, what) - - -- no list so do not run - if list == nil then - return false - end - - -- found entity on list to attack? - for no = 1, #list do - - if list[no] == what then - return true - end - end - - return false -end - - --- find someone to runaway from -local runaway_from = function(self) - - if not self.runaway_from and self.state ~= "flop" then - return - end - - local s = self.object:get_pos() - local p, sp, dist - local player, obj, min_player - local type, name = "", "" - local min_dist = self.view_range + 1 - local objs = minetest.get_objects_inside_radius(s, self.view_range) - - for n = 1, #objs do - - if objs[n]:is_player() then - - if mobs.invis[ objs[n]:get_player_name() ] - or self.owner == objs[n]:get_player_name() - or (not object_in_range(self, objs[n])) then - type = "" - else - player = objs[n] - type = "player" - name = "player" - end - else - obj = objs[n]:get_luaentity() - - if obj then - player = obj.object - type = obj.type - name = obj.name or "" - end - end - - -- find specific mob to runaway from - if name ~= "" and name ~= self.name - and specific_runaway(self.runaway_from, name) then - - p = player:get_pos() - sp = s - - -- aim higher to make looking up hills more realistic - p.y = p.y + 1 - sp.y = sp.y + 1 - - dist = vector.distance(p, s) - - - -- choose closest player/mpb to runaway from - if dist < min_dist - and line_of_sight(self, sp, p, 2) == true then - min_dist = dist - min_player = player - end - end - end - - if min_player then - - local lp = player:get_pos() - local vec = { - x = lp.x - s.x, - y = lp.y - s.y, - z = lp.z - s.z - } - - local yaw = (atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate - - if lp.x > s.x then - yaw = yaw + pi - end - - yaw = set_yaw(self, yaw, 4) - self.state = "runaway" - self.runaway_timer = 3 - self.following = nil - end -end - - --- follow player if owner or holding item, if fish outta water then flop -local follow_flop = function(self) - - -- find player to follow - if (self.follow ~= "" - or self.order == "follow") - and not self.following - and self.state ~= "attack" - and self.order ~= "sit" - and self.state ~= "runaway" then - - local s = self.object:get_pos() - local players = minetest.get_connected_players() - - for n = 1, #players do - - if (object_in_range(self, players[n])) - and not mobs.invis[ players[n]:get_player_name() ] then - - self.following = players[n] - - break - end - end - end - - if self.type == "npc" - and self.order == "follow" - and self.state ~= "attack" - and self.order ~= "sit" - and self.owner ~= "" then - - -- npc stop following player if not owner - if self.following - and self.owner - and self.owner ~= self.following:get_player_name() then - self.following = nil - end - else - -- stop following player if not holding specific item, - -- mob is horny, fleeing or attacking - if self.following - and self.following:is_player() - and (follow_holding(self, self.following) == false or - self.horny or self.state == "runaway") then - self.following = nil - end - - end - - -- follow that thing - if self.following then - - local s = self.object:get_pos() - local p - - if self.following:is_player() then - - p = self.following:get_pos() - - elseif self.following.object then - - p = self.following.object:get_pos() - end - - if p then - - local dist = vector.distance(p, s) - - -- dont follow if out of range - if (not object_in_range(self, self.following)) then - self.following = nil - else - local vec = { - x = p.x - s.x, - z = p.z - s.z - } - - local yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate - - if p.x > s.x then yaw = yaw + pi end - - set_yaw(self, yaw, 2.35) - - -- anyone but standing npc's can move along - if dist > 3 - and self.order ~= "stand" then - - set_velocity(self, self.follow_velocity) - - if self.walk_chance ~= 0 then - set_animation(self, "run") - end - else - set_velocity(self, 0) - set_animation(self, "stand") - end - - return - end - end - end - - -- swimmers flop when out of their element, and swim again when back in - if self.fly then - local s = self.object:get_pos() - if not flight_check(self, s) then - - self.state = "flop" - self.object:set_acceleration({x = 0, y = DEFAULT_FALL_SPEED, z = 0}) - - local sdef = minetest.registered_nodes[self.standing_on] - -- Flop on ground - if sdef and sdef.walkable then - mob_sound(self, "flop") - self.object:set_velocity({ - x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), - y = FLOP_HEIGHT, - z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED), - }) - end - - set_animation(self, "stand", true) - - return - elseif self.state == "flop" then - self.state = "stand" - self.object:set_acceleration({x = 0, y = 0, z = 0}) - set_velocity(self, 0) - end - end -end - - --- dogshoot attack switch and counter function -local dogswitch = function(self, dtime) - - -- switch mode not activated - if not self.dogshoot_switch - or not dtime then - return 0 - end - - self.dogshoot_count = self.dogshoot_count + dtime - - if (self.dogshoot_switch == 1 - and self.dogshoot_count > self.dogshoot_count_max) - or (self.dogshoot_switch == 2 - and self.dogshoot_count > self.dogshoot_count2_max) then - - self.dogshoot_count = 0 - - if self.dogshoot_switch == 1 then - self.dogshoot_switch = 2 - else - self.dogshoot_switch = 1 - end - end - - return self.dogshoot_switch -end - --- execute current state (stand, walk, run, attacks) --- returns true if mob has died -local do_states = function(self, dtime) - - local yaw = self.object:get_yaw() or 0 +function do_states(self) if self.state == "stand" then - if random(1, 4) == 1 then + if math_random(1, 4) == 1 then local lp = nil local s = self.object:get_pos() - local objs = minetest.get_objects_inside_radius(s, 3) + local objs = minetest_get_objects_inside_radius(s, 3) for n = 1, #objs do @@ -2323,11 +2185,11 @@ local do_states = function(self, dtime) z = lp.z - s.z } - yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate - if lp.x > s.x then yaw = yaw + pi end + if lp.x > s.x then yaw = yaw + math_pi end else - yaw = yaw + random(-0.5, 0.5) + yaw = yaw + math_random(-0.5, 0.5) end yaw = set_yaw(self, yaw, 8) @@ -2342,7 +2204,7 @@ local do_states = function(self, dtime) if self.walk_chance ~= 0 and self.facing_fence ~= true - and random(1, 100) <= self.walk_chance + and math_random(1, 100) <= self.walk_chance and is_at_cliff_or_danger(self) == false then set_velocity(self, self.walk_velocity) @@ -2361,19 +2223,19 @@ local do_states = function(self, dtime) and self.lava_damage > 0) or self.breath_max ~= -1 then - lp = minetest.find_node_near(s, 1, {"group:water", "group:lava"}) + lp = minetest_find_node_near(s, 1, {"group:water", "group:lava"}) elseif self.water_damage > 0 then - lp = minetest.find_node_near(s, 1, {"group:water"}) + lp = minetest_find_node_near(s, 1, {"group:water"}) elseif self.lava_damage > 0 then - lp = minetest.find_node_near(s, 1, {"group:lava"}) + lp = minetest_find_node_near(s, 1, {"group:lava"}) elseif self.fire_damage > 0 then - lp = minetest.find_node_near(s, 1, {"group:fire"}) + lp = minetest_find_node_near(s, 1, {"group:fire"}) end @@ -2387,12 +2249,12 @@ local do_states = function(self, dtime) -- If mob in or on dangerous block, look for land if is_in_danger then -- Better way to find shore - copied from upstream - lp = minetest.find_nodes_in_area_under_air( + lp = minetest_find_nodes_in_area_under_air( {x = s.x - 5, y = s.y - 0.5, z = s.z - 5}, {x = s.x + 5, y = s.y + 1, z = s.z + 5}, {"group:solid"}) - lp = #lp > 0 and lp[random(#lp)] + lp = #lp > 0 and lp[math_random(#lp)] -- did we find land? if lp then @@ -2402,10 +2264,10 @@ local do_states = function(self, dtime) z = lp.z - s.z } - yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate - if lp.x > s.x then yaw = yaw + pi end + if lp.x > s.x then yaw = yaw + math_pi end -- look towards land and move in that direction yaw = set_yaw(self, yaw, 6) @@ -2418,8 +2280,8 @@ local do_states = function(self, dtime) else -- Randomly turn - if random(1, 100) <= 30 then - yaw = yaw + random(-0.5, 0.5) + if math_random(1, 100) <= 30 then + yaw = yaw + math_random(-0.5, 0.5) yaw = set_yaw(self, yaw, 8) end end @@ -2427,9 +2289,9 @@ local do_states = function(self, dtime) yaw = set_yaw(self, yaw, 8) -- otherwise randomly turn - elseif random(1, 100) <= 30 then + elseif math_random(1, 100) <= 30 then - yaw = yaw + random(-0.5, 0.5) + yaw = yaw + math_random(-0.5, 0.5) yaw = set_yaw(self, yaw, 8) end @@ -2440,7 +2302,7 @@ local do_states = function(self, dtime) end if self.facing_fence == true or cliff_or_danger - or random(1, 100) <= 30 then + or math_random(1, 100) <= 30 then set_velocity(self, 0) self.state = "stand" @@ -2515,9 +2377,9 @@ local do_states = function(self, dtime) z = p.z - s.z } - yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate - if p.x > s.x then yaw = yaw + pi end + if p.x > s.x then yaw = yaw + math_pi end yaw = set_yaw(self, yaw, 0, dtime) @@ -2583,10 +2445,10 @@ local do_states = function(self, dtime) local pos = self.object:get_pos() if mod_explosions then - if mobs_griefing and not minetest.is_protected(pos, "") then + if mobs_griefing and not minetest_is_protected(pos, "") then mcl_explosions.explode(mcl_util.get_object_center(self.object), self.explosion_strength, { drop_chance = 1.0 }, self.object) else - minetest.sound_play(self.sounds.explode, { + minetest_sound_play(self.sounds.explode, { pos = pos, gain = 1.0, max_hear_distance = self.sounds.distance or 32 @@ -2611,9 +2473,9 @@ local do_states = function(self, dtime) and dist > self.reach then local p1 = s - local me_y = floor(p1.y) + local me_y = math_floor(p1.y) local p2 = p - local p_y = floor(p2.y + 1) + local p_y = math_floor(p2.y + 1) local v = self.object:get_velocity() if flight_check(self, s) then @@ -2674,7 +2536,7 @@ local do_states = function(self, dtime) return end - if abs(p1.x-s.x) + abs(p1.z - s.z) < 0.6 then + if math_abs(p1.x-s.x) + math_abs(p1.z - s.z) < 0.6 then -- reached waypoint, remove it from queue table.remove(self.path.way, 1) end @@ -2688,9 +2550,9 @@ local do_states = function(self, dtime) z = p.z - s.z } - yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate - if p.x > s.x then yaw = yaw + pi end + if p.x > s.x then yaw = yaw + math_pi end yaw = set_yaw(self, yaw, 0, dtime) @@ -2740,7 +2602,7 @@ local do_states = function(self, dtime) self.timer = 0 if self.double_melee_attack - and random(1, 2) == 1 then + and math_random(1, 2) == 1 then set_animation(self, "punch2") else set_animation(self, "punch") @@ -2793,9 +2655,9 @@ local do_states = function(self, dtime) z = p.z - s.z } - yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate + yaw = (atan(vec.z / vec.x) + math_pi / 2) - self.rotate - if p.x > s.x then yaw = yaw + pi end + if p.x > s.x then yaw = yaw + math_pi end yaw = set_yaw(self, yaw, 0, dtime) @@ -2806,8 +2668,8 @@ local do_states = function(self, dtime) if self.shoot_interval and self.timer > self.shoot_interval - and not minetest.raycast(p, self.attack:get_pos(), false, false):next() - and random(1, 100) <= 60 then + and not minetest_raycast(p, self.attack:get_pos(), false, false):next() + and math_random(1, 100) <= 60 then self.timer = 0 set_animation(self, "shoot") @@ -2816,16 +2678,16 @@ local do_states = function(self, dtime) mob_sound(self, "shoot_attack") -- Shoot arrow - if minetest.registered_entities[self.arrow] then + if minetest_registered_entities[self.arrow] then local arrow, ent local v = 1 if not self.shoot_arrow then self.firing = true - minetest.after(1, function() + minetest_after(1, function() self.firing = false end) - arrow = minetest.add_entity(p, self.arrow) + arrow = minetest_add_entity(p, self.arrow) ent = arrow:get_luaentity() if ent.velocity then v = ent.velocity @@ -2853,851 +2715,48 @@ local do_states = function(self, dtime) end --- falling and fall damage --- returns true if mob died -local falling = function(self, pos) - if self.fly and self.state ~= "die" then + +-- above function exported for mount.lua +function mobs:set_animation(self, anim) + set_animation(self, anim) +end + + +-- set defined animation +local set_animation = function(self, anim, fixed_frame) + if not self.animation or not anim then + return + end + if self.state == "die" and anim ~= "die" and anim ~= "stand" then return end - if mcl_portals ~= nil then - if mcl_portals.nether_portal_cooloff(self.object) then - return false -- mob has teleported through Nether portal - it's 99% not falling - end + self.animation.current = self.animation.current or "" + + if (anim == self.animation.current + or not self.animation[anim .. "_start"] + or not self.animation[anim .. "_end"]) and self.state ~= "die" then + return end - -- floating in water (or falling) - local v = self.object:get_velocity() + self.animation.current = anim - if v.y > 0 then - - -- apply gravity when moving up - self.object:set_acceleration({ - x = 0, - y = -10, - z = 0 - }) - - elseif v.y <= 0 and v.y > self.fall_speed then - - -- fall downwards at set speed - self.object:set_acceleration({ - x = 0, - y = self.fall_speed, - z = 0 - }) + local a_start = self.animation[anim .. "_start"] + local a_end + if fixed_frame then + a_end = a_start else - -- stop accelerating once max fall speed hit - self.object:set_acceleration({x = 0, y = 0, z = 0}) + a_end = self.animation[anim .. "_end"] end - if minetest.registered_nodes[node_ok(pos).name].groups.lava then - - if self.floats_on_lava == 1 then - - self.object:set_acceleration({ - x = 0, - y = -self.fall_speed / (max(1, v.y) ^ 2), - z = 0 - }) - end - end - - -- in water then float up - if minetest.registered_nodes[node_ok(pos).name].groups.water then - - if self.floats == 1 then - - self.object:set_acceleration({ - x = 0, - y = -self.fall_speed / (max(1, v.y) ^ 2), - z = 0 - }) - end - else - - -- fall damage onto solid ground - if self.fall_damage == 1 - and self.object:get_velocity().y == 0 then - - local d = (self.old_y or 0) - self.object:get_pos().y - - if d > 5 then - - local add = minetest.get_item_group(self.standing_on, "fall_damage_add_percent") - local damage = d - 5 - if add ~= 0 then - damage = damage + damage * (add/100) - end - damage = floor(damage) - if damage > 0 then - self.health = self.health - damage - - effect(pos, 5, "mcl_particles_smoke.png", 1, 2, 2, nil) - - if check_for_death(self, "fall", {type = "fall"}) then - return true - end - end - end - - self.old_y = self.object:get_pos().y - end - end + self.object:set_animation({ + x = a_start, + y = a_end}, + self.animation[anim .. "_speed"] or self.animation.speed_normal or 15, + 0, self.animation[anim .. "_loop"] ~= false) end -local teleport = function(self, target) - if self.do_teleport then - if self.do_teleport(self, target) == false then - return - end - end -end - - --- deal damage and effects when mob punched -local mob_punch = function(self, hitter, tflp, tool_capabilities, dir) - - -- custom punch function - if self.do_punch then - - -- when false skip going any further - if self.do_punch(self, hitter, tflp, tool_capabilities, dir) == false then - return - end - end - - -- error checking when mod profiling is enabled - if not tool_capabilities then - minetest.log("warning", "[mobs] Mod profiling enabled, damage not enabled") - return - end - - local is_player = hitter:is_player() - - if is_player then - -- is mob protected? - if self.protected and minetest.is_protected(self.object:get_pos(), hitter:get_player_name()) then - return - end - - -- set/update 'drop xp' timestamp if hitted by player - self.xp_timestamp = minetest.get_us_time() - end - - - -- punch interval - local weapon = hitter:get_wielded_item() - local punch_interval = 1.4 - - -- exhaust attacker - if mod_hunger and is_player then - mcl_hunger.exhaust(hitter:get_player_name(), mcl_hunger.EXHAUST_ATTACK) - end - - -- calculate mob damage - local damage = 0 - local armor = self.object:get_armor_groups() or {} - local tmp - - -- quick error check incase it ends up 0 (serialize.h check test) - if tflp == 0 then - tflp = 0.2 - end - - if use_cmi then - damage = cmi.calculate_damage(self.object, hitter, tflp, tool_capabilities, dir) - else - - for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do - - tmp = tflp / (tool_capabilities.full_punch_interval or 1.4) - - if tmp < 0 then - tmp = 0.0 - elseif tmp > 1 then - tmp = 1.0 - end - - damage = damage + (tool_capabilities.damage_groups[group] or 0) - * tmp * ((armor[group] or 0) / 100.0) - end - end - - if weapon then - local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect") - if fire_aspect_level > 0 then - mcl_burning.set_on_fire(self.object, fire_aspect_level * 4) - end - end - - -- check for tool immunity or special damage - for n = 1, #self.immune_to do - - if self.immune_to[n][1] == weapon:get_name() then - - damage = self.immune_to[n][2] or 0 - break - end - end - - -- healing - if damage <= -1 then - self.health = self.health - floor(damage) - return - end - - if use_cmi then - - local cancel = cmi.notify_punch(self.object, hitter, tflp, tool_capabilities, dir, damage) - - if cancel then return end - end - - if tool_capabilities then - punch_interval = tool_capabilities.full_punch_interval or 1.4 - end - - -- add weapon wear manually - -- Required because we have custom health handling ("health" property) - if minetest.is_creative_enabled("") ~= true - and tool_capabilities then - if tool_capabilities.punch_attack_uses then - -- Without this delay, the wear does not work. Quite hacky ... - minetest.after(0, function(name) - local player = minetest.get_player_by_name(name) - if not player then return end - local weapon = hitter:get_wielded_item(player) - local def = weapon:get_definition() - if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then - local wear = floor(65535/tool_capabilities.punch_attack_uses) - weapon:add_wear(wear) - hitter:set_wielded_item(weapon) - end - end, hitter:get_player_name()) - end - end - - local die = false - - -- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately. - if damage >= 0.1 then - - -- weapon sounds - if weapon:get_definition().sounds ~= nil then - - local s = random(0, #weapon:get_definition().sounds) - - minetest.sound_play(weapon:get_definition().sounds[s], { - object = self.object, --hitter, - max_hear_distance = 8 - }, true) - else - minetest.sound_play("default_punch", { - object = self.object, - max_hear_distance = 5 - }, true) - end - - damage_effect(self, damage) - - -- do damage - self.health = self.health - damage - - -- skip future functions if dead, except alerting others - if check_for_death(self, "hit", {type = "punch", puncher = hitter}) then - die = true - end - - -- knock back effect (only on full punch) - if not die - and self.knock_back - and tflp >= punch_interval then - - local v = self.object:get_velocity() - local r = 1.4 - min(punch_interval, 1.4) - local kb = r * 2.0 - local up = 2 - - -- if already in air then dont go up anymore when hit - if v.y ~= 0 - or self.fly then - up = 0 - end - - -- direction error check - dir = dir or {x = 0, y = 0, z = 0} - - -- check if tool already has specific knockback value - if tool_capabilities.damage_groups["knockback"] then - kb = tool_capabilities.damage_groups["knockback"] - else - kb = kb * 1.5 - end - - - local luaentity - if hitter then - luaentity = hitter:get_luaentity() - end - if hitter and is_player then - local wielditem = hitter:get_wielded_item() - kb = kb + 3 * mcl_enchanting.get_enchantment(wielditem, "knockback") - elseif luaentity and luaentity._knockback then - kb = kb + luaentity._knockback - end - - self.object:set_velocity({ - x = dir.x * kb, - y = dir.y * kb + up * 2, - z = dir.z * kb - }) - - self.pause_timer = 0.25 - end - end -- END if damage - - -- if skittish then run away - if not die and self.runaway == true and self.state ~= "flop" then - - local lp = hitter:get_pos() - local s = self.object:get_pos() - local vec = { - x = lp.x - s.x, - y = lp.y - s.y, - z = lp.z - s.z - } - - local yaw = (atan(vec.z / vec.x) + 3 * pi / 2) - self.rotate - - if lp.x > s.x then - yaw = yaw + pi - end - - yaw = set_yaw(self, yaw, 6) - self.state = "runaway" - self.runaway_timer = 0 - self.following = nil - end - - local name = hitter:get_player_name() or "" - - -- attack puncher and call other mobs for help - if self.passive == false - and self.state ~= "flop" - and (self.child == false or self.type == "monster") - and hitter:get_player_name() ~= self.owner - and not mobs.invis[ name ] then - - if not die then - -- attack whoever punched mob - self.state = "" - do_attack(self, hitter) - end - - -- alert others to the attack - local objs = minetest.get_objects_inside_radius(hitter:get_pos(), self.view_range) - local obj = nil - - for n = 1, #objs do - - obj = objs[n]:get_luaentity() - - if obj then - - -- only alert members of same mob or friends - if obj.group_attack - and obj.state ~= "attack" - and obj.owner ~= name then - if obj.name == self.name then - do_attack(obj, hitter) - elseif type(obj.group_attack) == "table" then - for i=1, #obj.group_attack do - if obj.name == obj.group_attack[i] then - do_attack(obj, hitter) - break - end - end - end - end - - -- have owned mobs attack player threat - if obj.owner == name and obj.owner_loyal then - do_attack(obj, self.object) - end - end - end - end -end - -local mob_detach_child = function(self, child) - - if self.driver == child then - self.driver = nil - end - -end - --- get entity staticdata -local mob_staticdata = function(self) - ---[[ - -- remove mob when out of range unless tamed - if remove_far - and self.can_despawn - and self.remove_ok - and ((not self.nametag) or (self.nametag == "")) - and self.lifetimer <= 20 then - - minetest.log("action", "Mob "..name.." despawns in mob_staticdata at "..minetest.pos_to_string(self.object.get_pos(), 1)) - mcl_burning.extinguish(self.object) - self.object:remove() - - return ""-- nil - end ---]] - self.remove_ok = true - self.attack = nil - self.following = nil - self.state = "stand" - - if use_cmi then - self.serialized_cmi_components = cmi.serialize_components(self._cmi_components) - end - - local tmp = {} - - for _,stat in pairs(self) do - - local t = type(stat) - - if t ~= "function" - and t ~= "nil" - and t ~= "userdata" - and _ ~= "_cmi_components" then - tmp[_] = self[_] - end - end - - return minetest.serialize(tmp) -end - - --- activate mob and reload settings -local mob_activate = function(self, staticdata, def, dtime) - - -- remove monsters in peaceful mode - if self.type == "monster" - and minetest.settings:get_bool("only_peaceful_mobs", false) then - mcl_burning.extinguish(self.object) - self.object:remove() - - return - end - - -- load entity variables - local tmp = minetest.deserialize(staticdata) - - if tmp then - for _,stat in pairs(tmp) do - self[_] = stat - end - end - - -- select random texture, set model and size - if not self.base_texture then - - -- compatiblity with old simple mobs textures - if type(def.textures[1]) == "string" then - def.textures = {def.textures} - end - - self.base_texture = def.textures[random(1, #def.textures)] - self.base_mesh = def.mesh - self.base_size = self.visual_size - self.base_colbox = self.collisionbox - self.base_selbox = self.selectionbox - end - - -- for current mobs that dont have this set - if not self.base_selbox then - self.base_selbox = self.selectionbox or self.base_colbox - end - - -- set texture, model and size - local textures = self.base_texture - local mesh = self.base_mesh - local vis_size = self.base_size - local colbox = self.base_colbox - local selbox = self.base_selbox - - -- specific texture if gotten - if self.gotten == true - and def.gotten_texture then - textures = def.gotten_texture - end - - -- specific mesh if gotten - if self.gotten == true - and def.gotten_mesh then - mesh = def.gotten_mesh - end - - -- set child objects to half size - if self.child == true then - - vis_size = { - x = self.base_size.x * .5, - y = self.base_size.y * .5, - } - - if def.child_texture then - textures = def.child_texture[1] - end - - colbox = { - self.base_colbox[1] * .5, - self.base_colbox[2] * .5, - self.base_colbox[3] * .5, - self.base_colbox[4] * .5, - self.base_colbox[5] * .5, - self.base_colbox[6] * .5 - } - selbox = { - self.base_selbox[1] * .5, - self.base_selbox[2] * .5, - self.base_selbox[3] * .5, - self.base_selbox[4] * .5, - self.base_selbox[5] * .5, - self.base_selbox[6] * .5 - } - end - - if self.health == 0 then - self.health = random (self.hp_min, self.hp_max) - end - if self.breath == nil then - self.breath = self.breath_max - end - - -- pathfinding init - self.path = {} - self.path.way = {} -- path to follow, table of positions - self.path.lastpos = {x = 0, y = 0, z = 0} - self.path.stuck = false - self.path.following = false -- currently following path? - self.path.stuck_timer = 0 -- if stuck for too long search for path - - -- Armor groups - -- immortal=1 because we use custom health - -- handling (using "health" property) - local armor - if type(self.armor) == "table" then - armor = table.copy(self.armor) - armor.immortal = 1 - else - armor = {immortal=1, fleshy = self.armor} - end - self.object:set_armor_groups(armor) - self.old_y = self.object:get_pos().y - self.old_health = self.health - self.sounds.distance = self.sounds.distance or 10 - self.textures = textures - self.mesh = mesh - self.collisionbox = colbox - self.selectionbox = selbox - self.visual_size = vis_size - self.standing_in = "ignore" - self.standing_on = "ignore" - self.jump_sound_cooloff = 0 -- used to prevent jump sound from being played too often in short time - self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types - - self.texture_mods = {} - self.object:set_texture_mod("") - - self.v_start = false - self.timer = 0 - self.blinktimer = 0 - self.blinkstatus = false - - -- check existing nametag - if not self.nametag then - self.nametag = def.nametag - end - - -- set anything changed above - self.object:set_properties(self) - set_yaw(self, (random(0, 360) - 180) / 180 * pi, 6) - update_tag(self) - set_animation(self, "stand") - - -- run on_spawn function if found - if self.on_spawn and not self.on_spawn_run then - if self.on_spawn(self) then - self.on_spawn_run = true -- if true, set flag to run once only - end - end - - -- run after_activate - if def.after_activate then - def.after_activate(self, staticdata, def, dtime) - end - - if use_cmi then - self._cmi_components = cmi.activate_components(self.serialized_cmi_components) - cmi.notify_activate(self.object, dtime) - end -end - - --- main mob function -local mob_step = function(self, dtime) - - if not self.fire_resistant then - mcl_burning.tick(self.object, dtime, self) - end - - if use_cmi then - cmi.notify_step(self.object, dtime) - end - - local pos = self.object:get_pos() - local yaw = 0 - - if mobs_debug then - update_tag(self) - end - - if self.state == "die" then - return - end - - if self.jump_sound_cooloff > 0 then - self.jump_sound_cooloff = self.jump_sound_cooloff - dtime - end - if self.opinion_sound_cooloff > 0 then - self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime - end - if falling(self, pos) then - -- Return if mob died after falling - return - end - - -- smooth rotation by ThomasMonroe314 - - if self.delay and self.delay > 0 then - - local yaw = self.object:get_yaw() or 0 - - if self.delay == 1 then - yaw = self.target_yaw - else - local dif = abs(yaw - self.target_yaw) - - if yaw > self.target_yaw then - - if dif > pi then - dif = 2 * pi - dif -- need to add - yaw = yaw + dif / self.delay - else - yaw = yaw - dif / self.delay -- need to subtract - end - - elseif yaw < self.target_yaw then - - if dif > pi then - dif = 2 * pi - dif - yaw = yaw - dif / self.delay -- need to subtract - else - yaw = yaw + dif / self.delay -- need to add - end - end - - if yaw > (pi * 2) then yaw = yaw - (pi * 2) end - if yaw < 0 then yaw = yaw + (pi * 2) end - end - - self.delay = self.delay - 1 - if self.shaking then - yaw = yaw + (math.random() * 2 - 1) * 5 * dtime - end - self.object:set_yaw(yaw) - update_roll(self) - end - - -- end rotation - - -- run custom function (defined in mob lua file) - if self.do_custom then - - -- when false skip going any further - if self.do_custom(self, dtime) == false then - return - end - end - - -- knockback timer - if self.pause_timer > 0 then - - self.pause_timer = self.pause_timer - dtime - - return - end - - -- attack timer - self.timer = self.timer + dtime - - if self.state ~= "attack" then - - if self.timer < 1 then - return - end - - self.timer = 0 - end - - -- never go over 100 - if self.timer > 100 then - self.timer = 1 - end - - -- mob plays random sound at times - if random(1, 70) == 1 then - mob_sound(self, "random", true) - end - - -- environmental damage timer (every 1 second) - self.env_damage_timer = self.env_damage_timer + dtime - - if (self.state == "attack" and self.env_damage_timer > 1) - or self.state ~= "attack" then - - self.env_damage_timer = 0 - - -- check for environmental damage (water, fire, lava etc.) - if do_env_damage(self) then - return - end - - -- node replace check (cow eats grass etc.) - replace(self, pos) - end - - monster_attack(self) - - npc_attack(self) - - breed(self) - - if do_states(self, dtime) then - return - end - - if not self.object:get_luaentity() then - return false - end - - do_jump(self) - - runaway_from(self) - - if is_at_water_danger(self) and self.state ~= "attack" then - if random(1, 10) <= 6 then - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") - yaw = yaw + random(-0.5, 0.5) - yaw = set_yaw(self, yaw, 8) - end - end - - -- Add water flowing for mobs from mcl_item_entity - local p, node, nn, def - p = self.object:get_pos() - node = minetest.get_node_or_nil(p) - if node then - nn = node.name - def = minetest.registered_nodes[nn] - end - - -- Move item around on flowing liquids - if def and def.liquidtype == "flowing" then - - --[[ Get flowing direction (function call from flowlib), if there's a liquid. - NOTE: According to Qwertymine, flowlib.quickflow is only reliable for liquids with a flowing distance of 7. - Luckily, this is exactly what we need if we only care about water, which has this flowing distance. ]] - local vec = flowlib.quick_flow(p, node) - -- Just to make sure we don't manipulate the speed for no reason - if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then - -- Minecraft Wiki: Flowing speed is "about 1.39 meters per second" - local f = 1.39 - -- Set new item moving speed into the direciton of the liquid - local newv = vector.multiply(vec, f) - self.object:set_acceleration({x = 0, y = 0, z = 0}) - self.object:set_velocity({x = newv.x, y = -0.22, z = newv.z}) - - self.physical_state = true - self._flowing = true - self.object:set_properties({ - physical = true - }) - return - end - elseif self._flowing == true then - -- Disable flowing physics if not on/in flowing liquid - self._flowing = false - enable_physics(self.object, self, true) - return - end - - --Mob following code. - follow_flop(self) - - if is_at_cliff_or_danger(self) then - set_velocity(self, 0) - self.state = "stand" - set_animation(self, "stand") - local yaw = self.object:get_yaw() or 0 - yaw = set_yaw(self, yaw + 0.78, 8) - end - - -- Despawning: when lifetimer expires, remove mob - if remove_far - and self.can_despawn == true - and ((not self.nametag) or (self.nametag == "")) - and self.state ~= "attack" - and self.following == nil then - - self.lifetimer = self.lifetimer - dtime - if self.despawn_immediately or self.lifetimer <= 0 then - minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) - mcl_burning.extinguish(self.object) - self.object:remove() - elseif self.lifetimer <= 10 then - if math.random(10) < 4 then - self.despawn_immediately = true - else - self.lifetimer = 20 - end - end - end -end - - --- default function when mobs are blown up with TNT -local do_tnt = function(obj, damage) - - obj.object:punch(obj.object, 1.0, { - full_punch_interval = 1.0, - damage_groups = {fleshy = damage}, - }, nil) - - return false, true, {} -end - - -mobs.spawning_mobs = {} -- Code to execute before custom on_rightclick handling local on_rightclick_prefix = function(self, clicker) @@ -3735,642 +2794,201 @@ local create_mob_on_rightclick = function(on_rightclick) end end --- register mob entity -function mobs:register_mob(name, def) +-- set and return valid yaw +local set_yaw = function(self, yaw, delay, dtime) - mobs.spawning_mobs[name] = true - -local can_despawn -if def.can_despawn ~= nil then - can_despawn = def.can_despawn -elseif def.spawn_class == "passive" then - can_despawn = false -else - can_despawn = true -end - -local function scale_difficulty(value, default, min, special) - if (not value) or (value == default) or (value == special) then - return default - else - return max(min, value * difficulty) - end -end - -local collisionbox = def.collisionbox or {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25} --- Workaround for : --- Increase upper Y limit to avoid mobs glitching through solid nodes. --- FIXME: Remove workaround if it's no longer needed. -if collisionbox[5] < 0.79 then - collisionbox[5] = 0.79 -end - -minetest.register_entity(name, { - - use_texture_alpha = def.use_texture_alpha, - stepheight = def.stepheight or 0.6, - name = name, - type = def.type, - attack_type = def.attack_type, - fly = def.fly, - fly_in = def.fly_in or {"air", "__airlike"}, - owner = def.owner or "", - order = def.order or "", - on_die = def.on_die, - spawn_small_alternative = def.spawn_small_alternative, - do_custom = def.do_custom, - jump_height = def.jump_height or 4, -- was 6 - rotate = math.rad(def.rotate or 0), -- 0=front, 90=side, 180=back, 270=side2 - lifetimer = def.lifetimer or 57.73, - hp_min = scale_difficulty(def.hp_min, 5, 1), - hp_max = scale_difficulty(def.hp_max, 10, 1), - xp_min = def.xp_min or 0, - xp_max = def.xp_max or 0, - xp_timestamp = 0, - breath_max = def.breath_max or 15, - breathes_in_water = def.breathes_in_water or false, - physical = true, - collisionbox = collisionbox, - selectionbox = def.selectionbox or def.collisionbox, - visual = def.visual, - visual_size = def.visual_size or {x = 1, y = 1}, - mesh = def.mesh, - makes_footstep_sound = def.makes_footstep_sound or false, - view_range = def.view_range or 16, - walk_velocity = def.walk_velocity or 1, - run_velocity = def.run_velocity or 2, - damage = scale_difficulty(def.damage, 0, 0), - light_damage = def.light_damage or 0, - sunlight_damage = def.sunlight_damage or 0, - water_damage = def.water_damage or 0, - lava_damage = def.lava_damage or 8, - fire_damage = def.fire_damage or 1, - suffocation = def.suffocation or true, - fall_damage = def.fall_damage or 1, - fall_speed = def.fall_speed or DEFAULT_FALL_SPEED, -- must be lower than -2 - drops = def.drops or {}, - armor = def.armor or 100, - on_rightclick = create_mob_on_rightclick(def.on_rightclick), - arrow = def.arrow, - shoot_interval = def.shoot_interval, - sounds = def.sounds or {}, - animation = def.animation, - follow = def.follow, - jump = def.jump ~= false, - walk_chance = def.walk_chance or 50, - attacks_monsters = def.attacks_monsters or false, - group_attack = def.group_attack or false, - passive = def.passive or false, - knock_back = def.knock_back ~= false, - shoot_offset = def.shoot_offset or 0, - floats = def.floats or 1, -- floats in water by default - floats_on_lava = def.floats_on_lava or 0, - replace_rate = def.replace_rate, - replace_what = def.replace_what, - replace_with = def.replace_with, - replace_offset = def.replace_offset or 0, - on_replace = def.on_replace, - timer = 0, - env_damage_timer = 0, - tamed = false, - pause_timer = 0, - horny = false, - hornytimer = 0, - gotten = false, - health = 0, - reach = def.reach or 3, - htimer = 0, - texture_list = def.textures, - child_texture = def.child_texture, - docile_by_day = def.docile_by_day or false, - time_of_day = 0.5, - fear_height = def.fear_height or 0, - runaway = def.runaway, - runaway_timer = 0, - pathfinding = def.pathfinding, - immune_to = def.immune_to or {}, - explosion_radius = def.explosion_radius, -- LEGACY - explosion_damage_radius = def.explosion_damage_radius, -- LEGACY - explosiontimer_reset_radius = def.explosiontimer_reset_radius, - explosion_timer = def.explosion_timer or 3, - allow_fuse_reset = def.allow_fuse_reset ~= false, - stop_to_explode = def.stop_to_explode ~= false, - custom_attack = def.custom_attack, - double_melee_attack = def.double_melee_attack, - dogshoot_switch = def.dogshoot_switch, - dogshoot_count = 0, - dogshoot_count_max = def.dogshoot_count_max or 5, - dogshoot_count2_max = def.dogshoot_count2_max or (def.dogshoot_count_max or 5), - attack_animals = def.attack_animals or false, - specific_attack = def.specific_attack, - runaway_from = def.runaway_from, - owner_loyal = def.owner_loyal, - facing_fence = false, - _cmi_is_mob = true, - pushable = def.pushable or true, - - - -- MCL2 extensions - teleport = teleport, - do_teleport = def.do_teleport, - spawn_class = def.spawn_class, - ignores_nametag = def.ignores_nametag or false, - rain_damage = def.rain_damage or 0, - glow = def.glow, - can_despawn = can_despawn, - child = def.child or false, - texture_mods = {}, - shoot_arrow = def.shoot_arrow, - sounds_child = def.sounds_child, - explosion_strength = def.explosion_strength, - suffocation_timer = 0, - follow_velocity = def.follow_velocity or 2.4, - instant_death = def.instant_death or false, - fire_resistant = def.fire_resistant or false, - fire_damage_resistant = def.fire_damage_resistant or false, - ignited_by_sunlight = def.ignited_by_sunlight or false, - -- End of MCL2 extensions - - on_spawn = def.on_spawn, - - on_blast = def.on_blast or do_tnt, - - on_step = mob_step, - - do_punch = def.do_punch, - - on_punch = mob_punch, - - on_breed = def.on_breed, - - on_grown = def.on_grown, - - on_detach_child = mob_detach_child, - - on_activate = function(self, staticdata, dtime) - --this is a temporary hack so mobs stop - --glitching and acting really weird with the - --default built in engine collision detection - self.object:set_properties({ - collide_with_objects = false, - }) - return mob_activate(self, staticdata, def, dtime) - end, - - get_staticdata = function(self) - return mob_staticdata(self) - end, - - harmed_by_heal = def.harmed_by_heal, - -}) - -if minetest.get_modpath("doc_identifier") ~= nil then - doc.sub.identifier.register_object(name, "basics", "mobs") -end - -end -- END mobs:register_mob function - - --- register arrow for shoot attack -function mobs:register_arrow(name, def) - - if not name or not def then return end -- errorcheck - - minetest.register_entity(name, { - - physical = false, - visual = def.visual, - visual_size = def.visual_size, - textures = def.textures, - velocity = def.velocity, - hit_player = def.hit_player, - hit_node = def.hit_node, - hit_mob = def.hit_mob, - hit_object = def.hit_object, - drop = def.drop or false, -- drops arrow as registered item when true - collisionbox = {0, 0, 0, 0, 0, 0}, -- remove box around arrows - timer = 0, - switch = 0, - owner_id = def.owner_id, - rotate = def.rotate, - on_punch = function(self) - local vel = self.object:get_velocity() - self.object:set_velocity({x=vel.x * -1, y=vel.y * -1, z=vel.z * -1}) - end, - collisionbox = def.collisionbox or {0, 0, 0, 0, 0, 0}, - automatic_face_movement_dir = def.rotate - and (def.rotate - (pi / 180)) or false, - - on_activate = def.on_activate, - - on_step = def.on_step or function(self, dtime) - - self.timer = self.timer + 1 - - local pos = self.object:get_pos() - - if self.switch == 0 - or self.timer > 150 - or not within_limits(pos, 0) then - mcl_burning.extinguish(self.object) - self.object:remove(); - - return - end - - -- does arrow have a tail (fireball) - if def.tail - and def.tail == 1 - and def.tail_texture then - - minetest.add_particle({ - pos = pos, - velocity = {x = 0, y = 0, z = 0}, - acceleration = {x = 0, y = 0, z = 0}, - expirationtime = def.expire or 0.25, - collisiondetection = false, - texture = def.tail_texture, - size = def.tail_size or 5, - glow = def.glow or 0, - }) - end - - if self.hit_node then - - local node = node_ok(pos).name - - if minetest.registered_nodes[node].walkable then - - self.hit_node(self, pos, node) - - if self.drop == true then - - pos.y = pos.y + 1 - - self.lastpos = (self.lastpos or pos) - - minetest.add_item(self.lastpos, self.object:get_luaentity().name) - end - - self.object:remove(); - - return - end - end - - if self.hit_player or self.hit_mob or self.hit_object then - - for _,player in pairs(minetest.get_objects_inside_radius(pos, 1.5)) do - - if self.hit_player - and player:is_player() then - - self.hit_player(self, player) - self.object:remove(); - return - end - - local entity = player:get_luaentity() - - if entity - and self.hit_mob - and entity._cmi_is_mob == true - and tostring(player) ~= self.owner_id - and entity.name ~= self.object:get_luaentity().name then - self.hit_mob(self, player) - self.object:remove(); - return - end - - if entity - and self.hit_object - and (not entity._cmi_is_mob) - and tostring(player) ~= self.owner_id - and entity.name ~= self.object:get_luaentity().name then - self.hit_object(self, player) - self.object:remove(); - return - end - end - end - - self.lastpos = pos - end - }) -end - - --- no damage to nodes explosion -function mobs:safe_boom(self, pos, strength) - minetest.sound_play(self.sounds and self.sounds.explode or "tnt_explode", { - pos = pos, - gain = 1.0, - max_hear_distance = self.sounds and self.sounds.distance or 32 - }, true) - local radius = strength - entity_physics(pos, radius) - effect(pos, 32, "mcl_particles_smoke.png", radius * 3, radius * 5, radius, 1, 0) -end - - --- make explosion with protection and tnt mod check -function mobs:boom(self, pos, strength, fire) - self.object:remove() - if mod_explosions then - if mobs_griefing and not minetest.is_protected(pos, "") then - mcl_explosions.explode(pos, strength, { drop_chance = 1.0, fire = fire }, self.object) - else - mobs:safe_boom(self, pos, strength) - end - else - mobs:safe_boom(self, pos, strength) - end -end - - --- Register spawn eggs - --- Note: This also introduces the “spawn_egg” group: --- * spawn_egg=1: Spawn egg (generic mob, no metadata) --- * spawn_egg=2: Spawn egg (captured/tamed mob, metadata) -function mobs:register_egg(mob, desc, background, addegg, no_creative) - - local grp = {spawn_egg = 1} - - -- do NOT add this egg to creative inventory (e.g. dungeon master) - if no_creative == true then - grp.not_in_creative_inventory = 1 + if not yaw or yaw ~= yaw then + yaw = 0 end - local invimg = background + delay = delay or 0 - if addegg == 1 then - invimg = "mobs_chicken_egg.png^(" .. invimg .. - "^[mask:mobs_chicken_egg_overlay.png)" + if delay == 0 then + if self.shaking and dtime then + yaw = yaw + (math_random() * 2 - 1) * 5 * dtime + end + self.yaw(yaw) + update_roll(self) + return yaw end - -- register old stackable mob egg - minetest.register_craftitem(mob, { - - description = desc, - inventory_image = invimg, - groups = grp, - - _doc_items_longdesc = S("This allows you to place a single mob."), - _doc_items_usagehelp = S("Just place it where you want the mob to appear. Animals will spawn tamed, unless you hold down the sneak key while placing. If you place this on a mob spawner, you change the mob it spawns."), - - on_place = function(itemstack, placer, pointed_thing) - - local pos = pointed_thing.above - - -- am I clicking on something with existing on_rightclick function? - local under = minetest.get_node(pointed_thing.under) - local def = minetest.registered_nodes[under.name] - if def and def.on_rightclick then - return def.on_rightclick(pointed_thing.under, under, placer, itemstack) - end - - if pos - and within_limits(pos, 0) - and not minetest.is_protected(pos, placer:get_player_name()) then - - local name = placer:get_player_name() - local privs = minetest.get_player_privs(name) - if mod_mobspawners and under.name == "mcl_mobspawners:spawner" then - if minetest.is_protected(pointed_thing.under, name) then - minetest.record_protection_violation(pointed_thing.under, name) - return itemstack - end - if not privs.maphack then - minetest.chat_send_player(name, S("You need the “maphack” privilege to change the mob spawner.")) - return itemstack - end - mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name()) - if not mobs.is_creative(name) then - itemstack:take_item() - end - return itemstack - end - - if not minetest.registered_entities[mob] then - return itemstack - end - - if minetest.settings:get_bool("only_peaceful_mobs", false) - and minetest.registered_entities[mob].type == "monster" then - minetest.chat_send_player(name, S("Only peaceful mobs allowed!")) - return itemstack - end - - pos.y = pos.y - 0.5 - - local mob = minetest.add_entity(pos, mob) - minetest.log("action", "Mob spawned: "..name.." at "..minetest.pos_to_string(pos)) - local ent = mob:get_luaentity() - - -- don't set owner if monster or sneak pressed - if ent.type ~= "monster" - and not placer:get_player_control().sneak then - ent.owner = placer:get_player_name() - ent.tamed = true - end - - -- set nametag - local nametag = itemstack:get_meta():get_string("name") - if nametag ~= "" then - if string.len(nametag) > MAX_MOB_NAME_LENGTH then - nametag = string.sub(nametag, 1, MAX_MOB_NAME_LENGTH) - end - ent.nametag = nametag - update_tag(ent) - end - - -- if not in creative then take item - if not mobs.is_creative(placer:get_player_name()) then - itemstack:take_item() - end - end - - return itemstack - end, - }) + self.target_yaw = yaw + self.delay = delay + return self.target_yaw end --- No-op in MCL2 (capturing mobs is not possible). --- Provided for compability with Mobs Redo -function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith) - return false +-- global function to set mob yaw +function mobs:yaw(self, yaw, delay, dtime) + set_yaw(self, yaw, delay, dtime) end --- No-op in MCL2 (protecting mobs is not possible). -function mobs:protect(self, clicker) - return false -end +mob_step = function() + + --if self.state == "die" then + -- print("need custom die stop moving thing") + -- return + --end + + --if not self.fire_resistant then + -- mcl_burning.tick(self.object, dtime, self) + --end + + --if use_cmi then + --cmi.notify_step(self.object, dtime) + --end + + --local pos = self.object:get_pos() + --local yaw = 0 + + --if mobs_debug then + --update_tag(self) + --end --- feeding, taming and breeding (thanks blert2112) -function mobs:feed_tame(self, clicker, feed_count, breed, tame) - if not self.follow then - return false + + --if self.jump_sound_cooloff > 0 then + -- self.jump_sound_cooloff = self.jump_sound_cooloff - dtime + --end + + --if self.opinion_sound_cooloff > 0 then + -- self.opinion_sound_cooloff = self.opinion_sound_cooloff - dtime + --end + + --if falling(self, pos) then + -- Return if mob died after falling + -- return + --end + + + -- run custom function (defined in mob lua file) + --if self.do_custom then + + -- when false skip going any further + --if self.do_custom(self, dtime) == false then + -- return + --end + --end + + -- knockback timer + --if self.pause_timer > 0 then + + -- self.pause_timer = self.pause_timer - dtime + + -- return + --end + + -- attack timer + --self.timer = self.timer + dtime + + --[[ + if self.state ~= "attack" then + + if self.timer < 1 then + print("returning>>error code 1") + return + end + + self.timer = 0 end + ]]-- - -- can eat/tame with item in hand - if follow_holding(self, clicker) then + -- never go over 100 + --if self.timer > 100 then + -- self.timer = 1 + --end - -- if not in creative then take item - if not mobs.is_creative(clicker:get_player_name()) then + -- mob plays random sound at times + --if math_random(1, 70) == 1 then + -- mob_sound(self, "random", true) + --end - local item = clicker:get_wielded_item() + -- environmental damage timer (every 1 second) + --self.env_damage_timer = self.env_damage_timer + dtime - item:take_item() + --if (self.state == "attack" and self.env_damage_timer > 1) + --or self.state ~= "attack" then + -- + -- self.env_damage_timer = 0 + -- + -- -- check for environmental damage (water, fire, lava etc.) + -- if do_env_damage(self) then + -- return + -- end + -- + -- node replace check (cow eats grass etc.) + -- replace(self, pos) + --end - clicker:set_wielded_item(item) - end + --monster_attack(self) - mob_sound(self, "eat", nil, true) + --npc_attack(self) - -- increase health - self.health = self.health + 4 + --breed(self) - if self.health >= self.hp_max then + --do_jump(self) - self.health = self.hp_max + --runaway_from(self) - if self.htimer < 1 then - self.htimer = 5 - end - end - self.object:set_hp(self.health) + --if is_at_water_danger(self) and self.state ~= "attack" then + -- if math_random(1, 10) <= 6 then + -- set_velocity(self, 0) + -- self.state = "stand" + -- set_animation(self, "stand") + -- yaw = yaw + math_random(-0.5, 0.5) + -- yaw = set_yaw(self, yaw, 8) + -- end + --end - update_tag(self) - -- make children grow quicker - if self.child == true then - - -- deduct 10% of the time to adulthood - self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1) - - return true - end - - -- feed and tame - self.food = (self.food or 0) + 1 - if self.food >= feed_count then - - self.food = 0 - - if breed and self.hornytimer == 0 then - self.horny = true - end - - if tame then - - self.tamed = true - - if not self.owner or self.owner == "" then - self.owner = clicker:get_player_name() - end - end - - -- make sound when fed so many times - mob_sound(self, "random", true) - end - - return true - end - - return false -end - --- Spawn a child -function mobs:spawn_child(pos, mob_type) - local child = minetest.add_entity(pos, mob_type) - if not child then + -- Add water flowing for mobs from mcl_item_entity + --[[ + local p, node, nn, def + p = self.object:get_pos() + node = minetest_get_node_or_nil(p) + if node then + nn = node.name + def = minetest_registered_nodes[nnenable_physicss if not on/in flowing liquid + self._flowing = false + enable_physics(self.object, self, true) return end - local ent = child:get_luaentity() - effect(pos, 15, "mcl_particles_smoke.png", 1, 2, 2, 15, 5) + --Mob following code. + follow_flop(self) - ent.child = true - local textures - -- using specific child texture (if found) - if ent.child_texture then - textures = ent.child_texture[1] + if is_at_cliff_or_danger(self) then + set_velocity(self, 0) + self.state = "stand" + set_animation(self, "stand") + local yaw = self.object:get_yaw() or 0 + yaw = set_yaw(self, yaw + 0.78, 8) end - -- and resize to half height - child:set_properties({ - textures = textures, - visual_size = { - x = ent.base_size.x * .5, - y = ent.base_size.y * .5, - }, - collisionbox = { - ent.base_colbox[1] * .5, - ent.base_colbox[2] * .5, - ent.base_colbox[3] * .5, - ent.base_colbox[4] * .5, - ent.base_colbox[5] * .5, - ent.base_colbox[6] * .5, - }, - selectionbox = { - ent.base_selbox[1] * .5, - ent.base_selbox[2] * .5, - ent.base_selbox[3] * .5, - ent.base_selbox[4] * .5, - ent.base_selbox[5] * .5, - ent.base_selbox[6] * .5, - }, - }) - - return child -end - - --- compatibility function for old entities to new modpack entities -function mobs:alias_mob(old_name, new_name) - - -- spawn egg - minetest.register_alias(old_name, new_name) - - -- entity - minetest.register_entity(":" .. old_name, { - - physical = false, - - on_step = function(self) - - if minetest.registered_entities[new_name] then - minetest.add_entity(self.object:get_pos(), new_name) - end + -- Despawning: when lifetimer expires, remove mob + if remove_far + and self.can_despawn == true + and ((not self.nametag) or (self.nametag == "")) + and self.state ~= "attack" + and self.following == nil then + self.lifetimer = self.lifetimer - dtime + if self.despawn_immediately or self.lifetimer <= 0 then + minetest.log("action", "Mob "..self.name.." despawns in mob_step at "..minetest.pos_to_string(pos, 1)) + mcl_burning.extinguish(self.object) self.object:remove() - end - }) - -end - - -local timer = 0 -minetest.register_globalstep(function(dtime) - timer = timer + dtime - if timer < 1 then return end - for _, player in pairs(minetest.get_connected_players()) do - local pos = player:get_pos() - for _, obj in pairs(minetest.get_objects_inside_radius(pos, 47)) do - local lua = obj:get_luaentity() - if lua and lua._cmi_is_mob then - lua.lifetimer = math.max(20, lua.lifetimer) - lua.despawn_immediately = false + elseif self.lifetimer <= 10 then + if math_random(10) < 4 then + self.despawn_immediately = true + else + self.lifetimer = 20 end end end - timer = 0 -end) + ]]-- + +end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua new file mode 100644 index 0000000000..5dc0b8884a --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/breeding.lua @@ -0,0 +1,184 @@ +local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius + +local vector_distance = vector.distance + +--check to see if someone nearby has some tasty food +mobs.check_following = function(self) -- returns true or false + + --ignore + if not self.follow then + self.following_person = nil + return(false) + end + + --hey look, this thing works for passive mobs too! + local follower = mobs.detect_closest_player_within_radius(self,true,self.view_range,self.eye_height) + + --check if the follower is a player incase they log out + if follower and follower:is_player() then + local stack = follower:get_wielded_item() + --safety check + if not stack then + self.following_person = nil + return(false) + end + + local item_name = stack:get_name() + --all checks have passed, that guy has some good looking food + if item_name == self.follow then + self.following_person = follower + return(true) + end + end + + --everything failed + self.following_person = nil + return(false) +end + +--a function which attempts to make mobs enter +--the breeding state +mobs.enter_breed_state = function(self,clicker) + + --do not breed if baby + if self.baby then + return(false) + end + + --do not do anything if looking for mate or + --if cooling off from breeding + if self.breed_lookout_timer > 0 or self.breed_timer > 0 then + return(false) + end + + --if this is caught, that means something has gone + --seriously wrong + if not clicker or not clicker:is_player() then + return(false) + end + + local stack = clicker:get_wielded_item() + --safety check + if not stack then + return(false) + end + + local item_name = stack:get_name() + --all checks have passed, that guy has some good looking food + if item_name == self.follow then + if not minetest.is_creative_enabled(clicker:get_player_name()) then + stack:take_item() + clicker:set_wielded_item(stack) + end + self.breed_lookout_timer = self.breed_lookout_timer_goal + self.bred = true + mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic") + return(true) + end + + --everything failed + return(false) +end + + +--find the closest mate in the area +mobs.look_for_mate = function(self) + + local pos1 = self.object:get_pos() + pos1.y = pos1.y + self.eye_height + + local mates_in_area = {} + local winner_mate = nil + local mates_detected = 0 + local radius = self.view_range + + --get mates in radius + for _,mate in pairs(minetest_get_objects_inside_radius(pos1, radius)) do + + --look for a breeding mate + if mate and mate:get_luaentity() + and mate:get_luaentity()._cmi_is_mob + and mate:get_luaentity().name == self.name + and mate:get_luaentity().breed_lookout_timer > 0 + and mate:get_luaentity() ~= self then + + local pos2 = mate:get_pos() + + local distance = vector_distance(pos1,pos2) + + if distance <= radius then + if line_of_sight then + --must add eye height or stuff breaks randomly because of + --seethrough nodes being a blocker (like grass) + if minetest_line_of_sight( + vector_new(pos1.x, pos1.y, pos1.z), + vector_new(pos2.x, pos2.y + mate:get_properties().eye_height, pos2.z) + ) then + mates_detected = mates_detected + 1 + mates_in_area[mate] = distance + end + else + mates_detected = mates_detected + 1 + mates_in_area[mate] = distance + end + end + end + end + + + --return if there's no one near by + if mates_detected <= 0 then --handle negative numbers for some crazy error that could possibly happen + return nil + end + + --do a default radius max + local shortest_distance = radius + 1 + + --sort through mates and find the closest mate + for mate,distance in pairs(mates_in_area) do + if distance < shortest_distance then + shortest_distance = distance + winner_mate = mate + end + end + + return(winner_mate) + +end + +--make the baby grow up +mobs.baby_grow_up = function(self) + self.baby = nil + self.visual_size = self.backup_visual_size + self.collisionbox = self.backup_collisionbox + self.selectionbox = self.backup_selectionbox + self.object:set_properties(self) +end + +--makes the baby grow up faster with diminishing returns +mobs.make_baby_grow_faster = function(self,clicker) + if clicker and clicker:is_player() then + local stack = clicker:get_wielded_item() + --safety check + if not stack then + return(false) + end + + local item_name = stack:get_name() + --all checks have passed, that guy has some good looking food + if item_name == self.follow then + self.grow_up_timer = self.grow_up_timer - (self.grow_up_timer * 0.10) --take 10 percent off - diminishing returns + + if not minetest.is_creative_enabled(clicker:get_player_name()) then + stack:take_item() + clicker:set_wielded_item(stack) + end + + mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic") + + return(true) + end + end + + return(false) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua new file mode 100644 index 0000000000..44f43f20f0 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua @@ -0,0 +1,140 @@ +local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius + +local math_random = math.random +local vector_multiply = vector.multiply + +local vector_direction = vector.direction + +local integer_test = {-1,1} + +mobs.collision = function(self) + + local pos = self.object:get_pos() + + + if not self or not self.object or not self.object:get_luaentity() then + return + end + + --do collision detection from the base of the mob + local collisionbox = self.object:get_properties().collisionbox + + pos.y = pos.y + collisionbox[2] + + local collision_boundary = collisionbox[4] + + local radius = collision_boundary + + if collisionbox[5] > collision_boundary then + radius = collisionbox[5] + end + + local collision_count = 0 + + + local check_for_attack = false + + if self.attack_type == "punch" and self.hostile and self.attacking then + check_for_attack = true + end + + for _,object in ipairs(minetest_get_objects_inside_radius(pos, radius*1.25)) do + if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true and object:get_luaentity().health > 0)) and + --don't collide with rider, rider don't collide with thing + (not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and + (not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then + --stop infinite loop + collision_count = collision_count + 1 + --mob cramming + if collision_count > 30 then + self.health = -20 + break + end + + local pos2 = object:get_pos() + + local object_collisionbox = object:get_properties().collisionbox + + pos2.y = pos2.y + object_collisionbox[2] + + local object_collision_boundary = object_collisionbox[4] + + + --this is checking the difference of the object collided with's possision + --if positive top of other object is inside (y axis) of current object + local y_base_diff = (pos2.y + object_collisionbox[5]) - pos.y + + local y_top_diff = (pos.y + collisionbox[5]) - pos2.y + + + local distance = vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)) + + if distance <= collision_boundary + object_collision_boundary and y_base_diff >= 0 and y_top_diff >= 0 then + + local dir = vector.direction(pos,pos2) + + dir.y = 0 + + --eliminate mob being stuck in corners + if dir.x == 0 and dir.z == 0 then + --slightly adjust mob position to prevent equal length + --corner/wall sticking + dir.x = dir.x + ((math_random()/10)*integer_test[math.random(1,2)]) + dir.z = dir.z + ((math_random()/10)*integer_test[math.random(1,2)]) + end + + local velocity = dir + + --0.5 is the max force multiplier + local force = 0.5 - (0.5 * distance / (collision_boundary + object_collision_boundary)) + + local vel1 = vector.multiply(velocity, -1.5) + local vel2 = vector.multiply(velocity, 1.5) + + vel1 = vector.multiply(vel1, force * 10) + vel2 = vector.multiply(vel2, force) + + if object:is_player() then + vel2 = vector_multiply(vel2, 2.5) + + --integrate mob punching into collision detection + if check_for_attack and self.punch_timer <= 0 then + if object == self.attacking then + mobs.punch_attack(self) + end + end + end + + self.object:add_velocity(vel1) + object:add_velocity(vel2) + end + + end + end +end + + +--this is used for arrow collisions +mobs.arrow_hit = function(self, player) + + player:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self._damage} + }, nil) + + + --knockback + local pos1 = self.object:get_pos() + pos1.y = 0 + local pos2 = player:get_pos() + pos2.y = 0 + local dir = vector_direction(pos1,pos2) + + dir = vector_multiply(dir,3) + + if player:get_velocity().y <= 1 then + dir.y = 5 + end + + player:add_velocity(dir) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua new file mode 100644 index 0000000000..fd95b60ef2 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua @@ -0,0 +1,154 @@ +local minetest_add_item = minetest.add_item +local minetest_sound_play = minetest.sound_play + +local math_pi = math.pi +local math_random = math.random +local math_floor = math.floor +local HALF_PI = math_pi / 2 + +local vector_new = vector.new + + +-- drop items +local item_drop = function(self, cooked, looting_level) + + looting_level = looting_level or 0 + + -- no drops for child mobs (except monster) + if (self.child and self.type ~= "monster") then + return + end + + local obj, item, num + local pos = self.object:get_pos() + + self.drops = self.drops or {} -- nil check + + for n = 1, #self.drops do + local dropdef = self.drops[n] + local chance = 1 / dropdef.chance + local looting_type = dropdef.looting + + if looting_level > 0 then + local chance_function = dropdef.looting_chance_function + if chance_function then + chance = chance_function(looting_level) + elseif looting_type == "rare" then + chance = chance + (dropdef.looting_factor or 0.01) * looting_level + end + end + + local num = 0 + local do_common_looting = (looting_level > 0 and looting_type == "common") + if math_random() < chance then + num = math_random(dropdef.min or 1, dropdef.max or 1) + elseif not dropdef.looting_ignore_chance then + do_common_looting = false + end + + if do_common_looting then + num = num + math_floor(math_random(0, looting_level) + 0.5) + end + + if num > 0 then + item = dropdef.name + + -- cook items when true + if cooked then + + local output = minetest_get_craft_result({ + method = "cooking", width = 1, items = {item}}) + + if output and output.item and not output.item:is_empty() then + item = output.item:get_name() + end + end + + -- add item if it exists + for x = 1, num do + obj = minetest_add_item(pos, ItemStack(item .. " " .. 1)) + end + + if obj and obj:get_luaentity() then + + obj:set_velocity({ + x = math_random(-10, 10) / 9, + y = 6, + z = math_random(-10, 10) / 9, + }) + elseif obj then + obj:remove() -- item does not exist + end + end + end + + self.drops = {} +end + + +mobs.death_logic = function(self, dtime) + self.death_animation_timer = self.death_animation_timer + dtime + + --get all attached entities and sort through them + local attached_entities = self.object:get_children() + if #attached_entities > 0 then + for _,entity in pairs(attached_entities) do + --kick the player off + if entity:is_player() then + mobs.detach(entity) + --kick mobs off + --if there is scaling issues, this needs an additional check + else + entity:set_detach() + end + end + end + + --stop mob from getting in the way of other mobs you're fighting + if self.object:get_properties().pointable then + self.object:set_properties({pointable = false}) + end + + --the final POOF of a mob despawning + if self.death_animation_timer >= 1.25 then + + item_drop(self,false,1) + + mobs.death_effect(self) + + mcl_experience.throw_experience(self.object:get_pos(), math_random(self.xp_min, self.xp_max)) + + self.object:remove() + + return + end + + --I'm sure there's a more efficient way to do this + --but this is the easiest, easier to work with 1 variable synced + --this is also not smooth + local death_animation_roll = self.death_animation_timer * 2 -- * 2 to make it faster + if death_animation_roll > 1 then + death_animation_roll = 1 + end + + local rot = self.object:get_rotation() --(no pun intended) + + rot.z = death_animation_roll * HALF_PI + + self.object:set_rotation(rot) + + mobs.set_mob_animation(self,"stand", true) + + + --flying and swimming mobs just fall down + if self.fly or self.swim then + if self.object:get_acceleration().y ~= -self.gravity then + self.object:set_acceleration(vector_new(0,-self.gravity,0)) + end + end + + --when landing allow mob to slow down and just fall if in air + if self.pause_timer <= 0 then + mobs.set_velocity(self,0) + end +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua new file mode 100644 index 0000000000..7c709c09e6 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/environment.lua @@ -0,0 +1,260 @@ +local minetest_line_of_sight = minetest.line_of_sight +local minetest_dir_to_yaw = minetest.dir_to_yaw +local minetest_yaw_to_dir = minetest.yaw_to_dir +local minetest_get_node = minetest.get_node +local minetest_get_item_group = minetest.get_item_group +local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius +local minetest_get_node_or_nil = minetest.get_node_or_nil +local minetest_registered_nodes = minetest.registered_nodes +local minetest_get_connected_players = minetest.get_connected_players + +local vector_new = vector.new +local vector_add = vector.add +local vector_multiply = vector.multiply +local vector_distance = vector.distance + +local table_copy = table.copy + +local math_abs = math.abs + +-- default function when mobs are blown up with TNT +local do_tnt = function(obj, damage) + + obj.object:punch(obj.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = damage}, + }, nil) + + return false, true, {} +end + +--a fast function to be able to detect only players without using objects_in_radius +mobs.detect_closest_player_within_radius = function(self, line_of_sight, radius, object_height_adder) + + local pos1 = self.object:get_pos() + local players_in_area = {} + local winner_player = nil + local players_detected = 0 + + --get players in radius + for _,player in pairs(minetest.get_connected_players()) do + if player and player:get_hp() > 0 then + + local pos2 = player:get_pos() + + local distance = vector_distance(pos1,pos2) + + if distance <= radius then + if line_of_sight then + --must add eye height or stuff breaks randomly because of + --seethrough nodes being a blocker (like grass) + if minetest_line_of_sight( + vector_new(pos1.x, pos1.y + object_height_adder, pos1.z), + vector_new(pos2.x, pos2.y + player:get_properties().eye_height, pos2.z) + ) then + players_detected = players_detected + 1 + players_in_area[player] = distance + end + else + players_detected = players_detected + 1 + players_in_area[player] = distance + end + end + end + end + + + --return if there's no one near by + if players_detected <= 0 then --handle negative numbers for some crazy error that could possibly happen + return nil + end + + --do a default radius max + local shortest_distance = radius + 1 + + --sort through players and find the closest player + for player,distance in pairs(players_in_area) do + if distance < shortest_distance then + shortest_distance = distance + winner_player = player + end + end + + return(winner_player) +end + + +--check if a mob needs to jump +mobs.jump_check = function(self,dtime) + + local pos = self.object:get_pos() + pos.y = pos.y + 0.1 + local dir = minetest_yaw_to_dir(self.yaw) + + local collisionbox = self.object:get_properties().collisionbox + local radius = collisionbox[4] + 0.5 + + vector_multiply(dir, radius) + + --only jump if there's a node and a non-solid node above it + local test_dir = vector_add(pos,dir) + + local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0 + + test_dir.y = test_dir.y + 1 + + local green_flag_2 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") == 0 + + if green_flag_1 and green_flag_2 then + --can jump over node + return(1) + elseif green_flag_1 and not green_flag_2 then + --wall in front of mob + return(2) + end + + --nothing to jump over + return(0) +end + +-- a helper function to quickly turn neutral passive mobs hostile +local turn_hostile = function(self,detected_mob) + --drop in variables for attacking (stops crash) + detected_mob.punch_timer = 0 + --set to hostile + detected_mob.hostile = true + --hostile_cooldown timer is initialized here + detected_mob.hostile_cooldown_timer = detected_mob.hostile_cooldown + --set target to the same + detected_mob.attacking = self.attacking +end + +--allow hostile mobs to signal to other mobs +--to switch from neutal passive to neutral hostile +mobs.group_attack_initialization = function(self) + + --get basic data + local friends_list + + if self.group_attack == true then + friends_list = {self.name} + else + friends_list = table_copy(self.group_attack) + end + + local objects_in_area = minetest_get_objects_inside_radius(self.object:get_pos(), self.view_range) + + --get the player's name + local name = self.attacking:get_player_name() + + --re-use local variable + local detected_mob + + --run through mobs in viewing distance + for _,object in pairs(objects_in_area) do + if object and object:get_luaentity() then + detected_mob = object:get_luaentity() + -- only alert members of same mob or friends + if detected_mob._cmi_is_mob and detected_mob.state ~= "attack" and detected_mob.owner ~= name then + if detected_mob.name == self.name then + turn_hostile(self,detected_mob) + else + for _,id in pairs(friends_list) do + if detected_mob.name == id then + turn_hostile(self,detected_mob) + break + end + end + end + end + + --THIS NEEDS TO BE RE-IMPLEMENTED AS A GLOBAL HIT IN MOB_PUNCH!! + -- have owned mobs attack player threat + --if obj.owner == name and obj.owner_loyal then + -- do_attack(obj, self.object) + --end + end + end +end + +-- check if within physical map limits (-30911 to 30927) +-- within_limits, wmin, wmax = nil, -30913, 30928 +mobs.within_limits = function(pos, radius) + if mcl_vars then + if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then + wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max + within_limits = function(pos, radius) + return pos + and (pos.x - radius) > wmin and (pos.x + radius) < wmax + and (pos.y - radius) > wmin and (pos.y + radius) < wmax + and (pos.z - radius) > wmin and (pos.z + radius) < wmax + end + end + end + return pos + and (pos.x - radius) > wmin and (pos.x + radius) < wmax + and (pos.y - radius) > wmin and (pos.y + radius) < wmax + and (pos.z - radius) > wmin and (pos.z + radius) < wmax +end + +-- get node but use fallback for nil or unknown +mobs.node_ok = function(pos, fallback) + + fallback = fallback or mobs.fallback_node + + local node = minetest_get_node_or_nil(pos) + + if node and minetest_registered_nodes[node.name] then + return node + end + + return minetest_registered_nodes[fallback] +end + + +--a teleport functoin +mobs.teleport = function(self, target) + if self.do_teleport then + if self.do_teleport(self, target) == false then + return + end + end +end + +--a function used for despawning mobs +mobs.check_for_player_within_area = function(self, radius) + local pos1 = self.object:get_pos() + --get players in radius + for _,player in pairs(minetest_get_connected_players()) do + if player and player:get_hp() > 0 then + local pos2 = player:get_pos() + local distance = vector_distance(pos1,pos2) + if distance < radius then + --found a player + return(true) + end + end + end + --did not find a player + return(false) +end + + +--a simple helper function for mobs following +mobs.get_2d_distance = function(pos1,pos2) + pos1.y = 0 + pos2.y = 0 + return(vector_distance(pos1, pos2)) +end + +-- fall damage onto solid ground +mobs.calculate_fall_damage = function(self) + if self.old_velocity and self.old_velocity.y < -7 and self.object:get_velocity().y == 0 then + local vel = self.object:get_velocity() + if vel then + local damage = math_abs(self.old_velocity.y + 7) * 2 + self.pause_timer = 0.4 + self.health = self.health - damage + end + end +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua new file mode 100644 index 0000000000..0fc94ffe68 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/head_logic.lua @@ -0,0 +1,112 @@ +local vector_new = vector.new + + +--converts yaw to degrees +local degrees = function(yaw) + return(yaw*180.0/math.pi) +end + + +mobs.do_head_logic = function(self,dtime) + + local player = minetest.get_player_by_name("singleplayer") + + local look_at = player:get_pos() + look_at.y = look_at.y + player:get_properties().eye_height + + + + + local pos = self.object:get_pos() + + local body_yaw = self.object:get_yaw() + + local body_dir = minetest.yaw_to_dir(body_yaw) + + + pos.y = pos.y + self.head_height_offset + + local head_offset = vector.multiply(body_dir, self.head_direction_offset) + + pos = vector.add(pos, head_offset) + + + + + minetest.add_particle({ + pos = pos, + velocity = {x=0, y=0, z=0}, + acceleration = {x=0, y=0, z=0}, + expirationtime = 0.2, + size = 1, + texture = "default_dirt.png", + }) + + + local bone_pos = vector_new(0,0,0) + + + --(horizontal) + bone_pos.y = self.head_bone_pos_y + + --(vertical) + bone_pos.z = self.head_bone_pos_z + + --print(yaw) + + --local _, bone_rot = self.object:get_bone_position("head") + + --bone_rot.x = bone_rot.x + (dtime * 10) + --bone_rot.z = bone_rot.z + (dtime * 10) + + + local head_yaw + head_yaw = minetest.dir_to_yaw(vector.direction(pos,look_at)) - body_yaw + + if self.reverse_head_yaw then + head_yaw = head_yaw * -1 + end + + --over rotation protection + --stops radians from going out of spec + if head_yaw > math.pi then + head_yaw = head_yaw - (math.pi * 2) + elseif head_yaw < -math.pi then + head_yaw = head_yaw + (math.pi * 2) + end + + + local check_failed = false + --upper check + 90 degrees or upper math.radians (3.14/2) + if head_yaw > math.pi - (math.pi/2) then + head_yaw = 0 + check_failed = true + --lower check - 90 degrees or lower negative math.radians (-3.14/2) + elseif head_yaw < -math.pi + (math.pi/2) then + head_yaw = 0 + check_failed = true + end + + local head_pitch = 0 + + --DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG + --head_yaw = 0 + --DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG + + if not check_failed then + head_pitch = minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(look_at.x,0,look_at.z)),0,pos.y-look_at.y))+(math.pi/2) + end + + if self.head_pitch_modifier then + head_pitch = head_pitch + self.head_pitch_modifier + end + + if self.swap_y_with_x then + self.object:set_bone_position(self.head_bone, bone_pos, vector_new(degrees(head_pitch),degrees(head_yaw),0)) + else + self.object:set_bone_position(self.head_bone, bone_pos, vector_new(degrees(head_pitch),0,degrees(head_yaw))) + end + + + --set_bone_position([bone, position, rotation]) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua new file mode 100644 index 0000000000..6b23d2fe7d --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua @@ -0,0 +1,291 @@ +local minetest_after = minetest.after +local minetest_sound_play = minetest.sound_play +local minetest_dir_to_yaw = minetest.dir_to_yaw + +local math_floor = math.floor +local math_min = math.min +local math_random = math.random + +local vector_direction = vector.direction +local vector_multiply = vector.multiply + +local MAX_MOB_NAME_LENGTH = 30 + +mobs.feed_tame = function(self) + return nil +end + +-- Code to execute before custom on_rightclick handling +local on_rightclick_prefix = function(self, clicker) + + local item = clicker:get_wielded_item() + + -- Name mob with nametag + if not self.ignores_nametag and item:get_name() == "mcl_mobs:nametag" then + + local tag = item:get_meta():get_string("name") + if tag ~= "" then + if string.len(tag) > MAX_MOB_NAME_LENGTH then + tag = string.sub(tag, 1, MAX_MOB_NAME_LENGTH) + end + self.nametag = tag + + mobs.update_tag(self) + + if not mobs.is_creative(clicker:get_player_name()) then + item:take_item() + clicker:set_wielded_item(item) + end + return true + end + + end + return false +end + +-- I have no idea what this does +mobs.create_mob_on_rightclick = function(on_rightclick) + return function(self, clicker) + --don't allow rightclicking dead mobs + if self.health <= 0 then + return + end + local stop = on_rightclick_prefix(self, clicker) + if (not stop) and (on_rightclick) then + on_rightclick(self, clicker) + end + end +end + + +-- deal damage and effects when mob punched +mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) + + --don't do anything if the mob is already dead + if self.health <= 0 then + return + end + + --neutral passive mobs switch to neutral hostile + if self.neutral then + --drop in variables for attacking (stops crash) + self.attacking = hitter + self.punch_timer = 0 + self.hostile = true + --hostile_cooldown timer is initialized here + self.hostile_cooldown_timer = self.hostile_cooldown + + --initialize the group attack (check for other mobs in area, make them neutral hostile) + if self.group_attack then + mobs.group_attack_initialization(self) + end + end + + --turn skittish mobs away and RUN + if self.skittish then + + self.state = "run" + + self.run_timer = 5 --arbitrary 5 seconds + + local pos1 = self.object:get_pos() + pos1.y = 0 + local pos2 = hitter:get_pos() + pos2.y = 0 + + + local dir = vector_direction(pos2,pos1) + + local yaw = minetest_dir_to_yaw(dir) + + self.yaw = yaw + end + + + -- custom punch function + if self.do_punch then + -- when false skip going any further + if self.do_punch(self, hitter, tflp, tool_capabilities, dir) == false then + return + end + end + + --don't do damage until pause timer resets + if self.pause_timer > 0 then + return + end + + + -- error checking when mod profiling is enabled + if not tool_capabilities then + minetest.log("warning", "[mobs_mc] Mod profiling enabled, damage not enabled") + return + end + + + local is_player = hitter:is_player() + + + -- punch interval + local weapon = hitter:get_wielded_item() + + local punch_interval = 1.4 + + -- exhaust attacker + if mod_hunger and is_player then + mcl_hunger.exhaust(hitter:get_player_name(), mcl_hunger.EXHAUST_ATTACK) + end + + -- calculate mob damage + local damage = 0 + local armor = self.object:get_armor_groups() or {} + local tmp + + --calculate damage groups + for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do + damage = damage + (tool_capabilities.damage_groups[group] or 0) * ((armor[group] or 0) / 100.0) + end + + if weapon then + local fire_aspect_level = mcl_enchanting.get_enchantment(weapon, "fire_aspect") + if fire_aspect_level > 0 then + mcl_burning.set_on_fire(self.object, fire_aspect_level * 4) + end + end + + -- check for tool immunity or special damage + for n = 1, #self.immune_to do + if self.immune_to[n][1] == weapon:get_name() then + damage = self.immune_to[n][2] or 0 + break + end + end + + -- healing + if damage <= -1 then + self.health = self.health - math_floor(damage) + return + end + + if tool_capabilities then + punch_interval = tool_capabilities.full_punch_interval or 1.4 + end + + -- add weapon wear manually + -- Required because we have custom health handling ("health" property) + --minetest_is_creative_enabled("") ~= true --removed for now + if tool_capabilities then + if tool_capabilities.punch_attack_uses then + -- Without this delay, the wear does not work. Quite hacky ... + minetest_after(0, function(name) + local player = minetest.get_player_by_name(name) + if not player then return end + local weapon = hitter:get_wielded_item(player) + local def = weapon:get_definition() + if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then + local wear = math_floor(65535/tool_capabilities.punch_attack_uses) + weapon:add_wear(wear) + hitter:set_wielded_item(weapon) + end + end, hitter:get_player_name()) + end + end + + + --if player is falling multiply damage by 1.5 + --critical hit + if hitter:get_velocity().y < 0 then + damage = damage * 1.5 + mobs.critical_effect(self) + end + + + -- only play hit sound and show blood effects if damage is 1 or over; lower to 0.1 to ensure armor works appropriately. + if damage >= 0.1 then + + minetest_sound_play("default_punch", { + object = self.object, + max_hear_distance = 16 + }, true) + + -- do damage + self.health = self.health - damage + + + --0.4 seconds until you can hurt the mob again + self.pause_timer = 0.4 + + --don't do knockback from a rider + for _,obj in pairs(self.object:get_children()) do + if obj == hitter then + return + end + end + + -- knock back effect + local velocity = self.object:get_velocity() + + --2d direction + local pos1 = self.object:get_pos() + pos1.y = 0 + local pos2 = hitter:get_pos() + pos2.y = 0 + + local dir = vector.direction(pos2,pos1) + + local up = 3 + + -- if already in air then dont go up anymore when hit + if velocity.y ~= 0 then + up = 0 + end + + + --0.75 for perfect distance to not be too easy, and not be too hard + local multiplier = 0.75 + + -- check if tool already has specific knockback value + local knockback_enchant = mcl_enchanting.get_enchantment(hitter:get_wielded_item(), "knockback") + if knockback_enchant and knockback_enchant > 0 then + multiplier = knockback_enchant + 1 --(starts from 1, 1 would be no change) + end + + --do this to sure you can punch a mob back when + --it's coming for you + if self.hostile then + multiplier = multiplier + 2 + end + + dir = vector_multiply(dir,multiplier) + + dir.y = up + + --add the velocity + self.object:add_velocity(dir) + + end +end + +--do internal per mob projectile calculations +mobs.shoot_projectile = function(self) + + local pos1 = self.object:get_pos() + --add mob eye height + pos1.y = pos1.y + self.eye_height + + local pos2 = self.attacking:get_pos() + --add player eye height + pos2.y = pos2.y + self.attacking:get_properties().eye_height + + --get direction + local dir = vector_direction(pos1,pos2) + + --call internal shoot_arrow function + self.shoot_arrow(self,pos1,dir) +end + +mobs.update_tag = function(self) + self.object:set_properties({ + nametag = self.nametag, + }) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua new file mode 100644 index 0000000000..847315ff18 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua @@ -0,0 +1,152 @@ +local minetest_add_particlespawner = minetest.add_particlespawner + +mobs.death_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 50, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-0.5,0.5,-0.5), + maxvel = vector.new(0.5,1,0.5), + minexptime = 1.1, + maxexptime = 1.5, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "mcl_particles_mob_death.png", -- this particle looks strange + }) +end + +mobs.critical_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 10, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png^[colorize:black:255", + }) +end + +--when feeding a mob +mobs.feed_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 10, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png^[colorize:gray:255", + }) +end + +--hearts when tamed +mobs.tamed_effect = function(self) + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 30, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png", + }) +end + +--hearts when breeding +mobs.breeding_effect = function(self) + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 2, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png", + }) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua new file mode 100644 index 0000000000..9a5fd9ea10 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/movement.lua @@ -0,0 +1,391 @@ +local math_pi = math.pi +local math_sin = math.sin +local math_cos = math.cos +local math_random = math.random +local HALF_PI = math_pi / 2 +local DOUBLE_PI = math_pi * 2 + +-- localize vector functions +local vector_new = vector.new +local vector_length = vector.length +local vector_multiply = vector.multiply +local vector_distance = vector.distance +local vector_normalize = vector.normalize + +local minetest_yaw_to_dir = minetest.yaw_to_dir +local minetest_dir_to_yaw = minetest.dir_to_yaw + +local DEFAULT_JUMP_HEIGHT = 5 +local DEFAULT_FLOAT_SPEED = 4 +local DEFAULT_CLIMB_SPEED = 3 + + +mobs.stick_in_cobweb = function(self) + local current_velocity = self.object:get_velocity() + + local goal_velocity = vector_multiply(vector_normalize(current_velocity), 0.4) + + goal_velocity.y = -0.5 + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + +--this is a generic float function +mobs.float = function(self) + + if self.object:get_acceleration().y ~= 0 then + self.object:set_acceleration(vector_new(0,0,0)) + end + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = 0, + y = DEFAULT_FLOAT_SPEED, + z = 0, + } + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + new_velocity_addition.x = 0 + new_velocity_addition.z = 0 + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + +--this is a generic climb function +mobs.climb = function(self) + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = 0, + y = DEFAULT_CLIMB_SPEED, + z = 0, + } + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + new_velocity_addition.x = 0 + new_velocity_addition.z = 0 + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + + + +--[[ + _ _ +| | | | +| | __ _ _ __ __| | +| | / _` | '_ \ / _` | +| |___| (_| | | | | (_| | +\_____/\__,_|_| |_|\__,_| +]] + + +-- move mob in facing direction +--this has been modified to be internal +--internal = lua (self.yaw) +--engine = c++ (self.object:get_yaw()) +mobs.set_velocity = function(self, v) + + local yaw = (self.yaw or 0) + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = (math_sin(yaw) * -v), + y = 0, + z = (math_cos(yaw) * v), + } + + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + if vector_length(new_velocity_addition) > vector_length(goal_velocity) then + vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition))) + end + + new_velocity_addition.y = 0 + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + + + +-- calculate mob velocity +mobs.get_velocity = function(self) + + local v = self.object:get_velocity() + + v.y = 0 + + if v then + return vector_length(v) + end + + return 0 +end + +--make mobs jump +mobs.jump = function(self, velocity) + + if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then + return + end + + --fallback velocity to allow modularity + velocity = velocity or DEFAULT_JUMP_HEIGHT + + self.object:add_velocity(vector_new(0,velocity,0)) +end + +--make mobs fall slowly +mobs.mob_fall_slow = function(self) + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = 0, + y = -2, + z = 0, + } + + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + new_velocity_addition.x = 0 + new_velocity_addition.z = 0 + + if vector_length(new_velocity_addition) > vector_length(goal_velocity) then + vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition))) + end + + new_velocity_addition.x = 0 + new_velocity_addition.z = 0 + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end + +end + + +--[[ + _____ _ +/ ___| (_) +\ `--.__ ___ _ __ ___ + `--. \ \ /\ / / | '_ ` _ \ +/\__/ /\ V V /| | | | | | | +\____/ \_/\_/ |_|_| |_| |_| +]]-- + + + + +--make mobs flop +mobs.flop = function(self, velocity) + + if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then + return false + end + + mobs.set_velocity(self, 0) + + --fallback velocity to allow modularity + velocity = velocity or DEFAULT_JUMP_HEIGHT + + --create a random direction (2d yaw) + local dir = DOUBLE_PI * math_random() + + --create a random force value + local force = math_random(0,3) + math_random() + + --convert the yaw to a direction vector then multiply it times the force + local final_additional_force = vector_multiply(minetest_yaw_to_dir(dir), force) + + --place in the "flop" velocity to make the mob flop + final_additional_force.y = velocity + + self.object:add_velocity(final_additional_force) + + return true +end + + + +-- move mob in facing direction +--this has been modified to be internal +--internal = lua (self.yaw) +--engine = c++ (self.object:get_yaw()) +mobs.set_swim_velocity = function(self, v) + + local yaw = (self.yaw or 0) + local pitch = (self.pitch or 0) + + if v == 0 then + pitch = 0 + end + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = (math_sin(yaw) * -v), + y = pitch, + z = (math_cos(yaw) * v), + } + + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + if vector_length(new_velocity_addition) > vector_length(goal_velocity) then + vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition))) + end + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + +--[[ +______ _ +| ___| | +| |_ | |_ _ +| _| | | | | | +| | | | |_| | +\_| |_|\__, | + __/ | + |___/ +]]-- + +-- move mob in facing direction +--this has been modified to be internal +--internal = lua (self.yaw) +--engine = c++ (self.object:get_yaw()) +mobs.set_fly_velocity = function(self, v) + + local yaw = (self.yaw or 0) + local pitch = (self.pitch or 0) + + if v == 0 then + pitch = 0 + end + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = (math_sin(yaw) * -v), + y = pitch, + z = (math_cos(yaw) * v), + } + + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + if vector_length(new_velocity_addition) > vector_length(goal_velocity) then + vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition))) + end + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + +--a quick and simple pitch calculation between two vector positions +mobs.calculate_pitch = function(pos1, pos2) + + if pos1 == nil or pos2 == nil then + return false + end + + return(minetest_dir_to_yaw(vector_new(vector_distance(vector_new(pos1.x,0,pos1.z),vector_new(pos2.x,0,pos2.z)),0,pos1.y - pos2.y)) + HALF_PI) +end + +--make mobs fly up or down based on their y difference +mobs.set_pitch_while_attacking = function(self) + local pos1 = self.object:get_pos() + local pos2 = self.attacking:get_pos() + + local pitch = mobs.calculate_pitch(pos2,pos1) + + self.pitch = pitch +end + + + +--[[ + ___ + |_ | + | |_ _ _ __ ___ _ __ + | | | | | '_ ` _ \| '_ \ +/\__/ / |_| | | | | | | |_) | +\____/ \__,_|_| |_| |_| .__/ + | | + |_| +]]-- + +--special mob jump movement +mobs.jump_move = function(self, velocity) + + if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then + return + end + + --make the mob stick for a split second + mobs.set_velocity(self,0) + + --fallback velocity to allow modularity + jump_height = DEFAULT_JUMP_HEIGHT + + local yaw = (self.yaw or 0) + + local current_velocity = self.object:get_velocity() + + local goal_velocity = { + x = (math_sin(yaw) * -velocity), + y = jump_height, + z = (math_cos(yaw) * velocity), + } + + + local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) + + if vector_length(new_velocity_addition) > vector_length(goal_velocity) then + vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition))) + end + + --smooths out mobs a bit + if vector_length(new_velocity_addition) >= 0.0001 then + self.object:add_velocity(new_velocity_addition) + end +end + +--make it so mobs do not glitch out and freak out +--when moving around over nodes +mobs.swap_auto_step_height_adjust = function(self) + local y_vel = self.object:get_velocity().y + + if y_vel == 0 and self.stepheight ~= self.stepheight_backup then + self.stepheight = self.stepheight_backup + elseif y_vel ~= 0 and self.stepheight ~= 0 then + self.stepheight = 0 + end +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua new file mode 100644 index 0000000000..e7ae6ffbe4 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/projectile_handling.lua @@ -0,0 +1,44 @@ +local GRAVITY = minetest.settings:get("movement_gravity")-- + 9.81 + +mobs.shoot_projectile_handling = function(arrow_item, pos, dir, yaw, shooter, power, damage, is_critical, bow_stack, collectable, gravity) + local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, arrow_item.."_entity") + if power == nil then + power = 19 + end + if damage == nil then + damage = 3 + end + + gravity = gravity or -GRAVITY + + local knockback + if bow_stack then + local enchantments = mcl_enchanting.get_enchantments(bow_stack) + if enchantments.power then + damage = damage + (enchantments.power + 1) / 4 + end + if enchantments.punch then + knockback = enchantments.punch * 3 + end + if enchantments.flame then + mcl_burning.set_on_fire(obj, math.huge) + end + end + obj:set_velocity({x=dir.x*power, y=dir.y*power, z=dir.z*power}) + obj:set_acceleration({x=0, y=gravity, z=0}) + obj:set_yaw(yaw-math.pi/2) + local le = obj:get_luaentity() + le._shooter = shooter + le._damage = damage + le._is_critical = is_critical + le._startpos = pos + le._knockback = knockback + le._collectable = collectable + + --play custom shoot sound + if shooter ~= nil and shooter.shoot_sound then + minetest.sound_play(shooter.shoot_sound, {pos=pos, max_hear_distance=16}, true) + end + + return obj +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/set_up.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/set_up.lua new file mode 100644 index 0000000000..dfef98ee81 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/set_up.lua @@ -0,0 +1,226 @@ +local math_random = math.random + +local minetest_settings = minetest.settings + +-- get entity staticdata +mobs.mob_staticdata = function(self) + + --despawn mechanism + --don't despawned tamed or bred mobs + if not self.tamed and not self.bred then + if not mobs.check_for_player_within_area(self, 64) then + --print("removing SERIALIZED!") + self.object:remove() + return + end + end + + self.remove_ok = true + self.attack = nil + self.following = nil + + if use_cmi then + self.serialized_cmi_components = cmi.serialize_components(self._cmi_components) + end + + local tmp = {} + + for _,stat in pairs(self) do + + local t = type(stat) + + if t ~= "function" + and t ~= "nil" + and t ~= "userdata" + and _ ~= "_cmi_components" then + tmp[_] = self[_] + end + end + + return minetest.serialize(tmp) +end + + +-- activate mob and reload settings +mobs.mob_activate = function(self, staticdata, def, dtime) + + -- remove monsters in peaceful mode + if self.type == "monster" and minetest_settings:get_bool("only_peaceful_mobs", false) then + mcl_burning.extinguish(self.object) + self.object:remove() + return + end + + -- load entity variables + local tmp = minetest.deserialize(staticdata) + + if tmp then + for _,stat in pairs(tmp) do + self[_] = stat + end + end + + --set up wandering + if not self.wandering then + self.wandering = true + end + + --clear animation + self.current_animation = nil + + -- select random texture, set model and size + if not self.base_texture then + + -- compatiblity with old simple mobs textures + if type(def.textures[1]) == "string" then + def.textures = {def.textures} + end + + self.base_texture = def.textures[math_random(1, #def.textures)] + self.base_mesh = def.mesh + self.base_size = self.visual_size + self.base_colbox = self.collisionbox + self.base_selbox = self.selectionbox + end + + -- for current mobs that dont have this set + if not self.base_selbox then + self.base_selbox = self.selectionbox or self.base_colbox + end + + -- set texture, model and size + local textures = self.base_texture + local mesh = self.base_mesh + local vis_size = self.base_size + local colbox = self.base_colbox + local selbox = self.base_selbox + + -- specific texture if gotten + if self.gotten == true + and def.gotten_texture then + textures = def.gotten_texture + end + + -- specific mesh if gotten + if self.gotten == true + and def.gotten_mesh then + mesh = def.gotten_mesh + end + + -- set baby mobs to half size + if self.baby == true then + + vis_size = { + x = self.base_size.x * self.baby_size, + y = self.base_size.y * self.baby_size, + } + + if def.child_texture then + textures = def.child_texture[1] + end + + colbox = { + self.base_colbox[1] * self.baby_size, + self.base_colbox[2] * self.baby_size, + self.base_colbox[3] * self.baby_size, + self.base_colbox[4] * self.baby_size, + self.base_colbox[5] * self.baby_size, + self.base_colbox[6] * self.baby_size + } + selbox = { + self.base_selbox[1] * self.baby_size, + self.base_selbox[2] * self.baby_size, + self.base_selbox[3] * self.baby_size, + self.base_selbox[4] * self.baby_size, + self.base_selbox[5] * self.baby_size, + self.base_selbox[6] * self.baby_size + } + end + + --stop mobs from reviving + if not self.dead and not self.health then + self.health = math_random (self.hp_min, self.hp_max) + end + + + + if not self.random_sound_timer then + self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max) + end + + if self.breath == nil then + self.breath = self.breath_max + end + + -- pathfinding init + self.path = {} + self.path.way = {} -- path to follow, table of positions + self.path.lastpos = {x = 0, y = 0, z = 0} + self.path.stuck = false + self.path.following = false -- currently following path? + self.path.stuck_timer = 0 -- if stuck for too long search for path + + -- Armor groups + -- immortal=1 because we use custom health + -- handling (using "health" property) + local armor + if type(self.armor) == "table" then + armor = table.copy(self.armor) + armor.immortal = 1 + else + armor = {immortal=1, fleshy = self.armor} + end + self.object:set_armor_groups(armor) + self.old_y = self.object:get_pos().y + self.old_health = self.health + self.sounds.distance = self.sounds.distance or 10 + self.textures = textures + self.mesh = mesh + self.collisionbox = colbox + self.selectionbox = selbox + self.visual_size = vis_size + self.standing_in = "ignore" + self.standing_on = "ignore" + self.jump_sound_cooloff = 0 -- used to prevent jump sound from being played too often in short time + self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types + + self.texture_mods = {} + + + self.v_start = false + self.timer = 0 + self.blinktimer = 0 + self.blinkstatus = false + + + --continue mob effect on server restart + if self.dead or self.health <= 0 then + self.object:set_texture_mod("^[colorize:red:120") + else + self.object:set_texture_mod("") + end + + + -- set anything changed above + self.object:set_properties(self) + + --update_tag(self) + --mobs.set_animation(self, "stand") + + -- run on_spawn function if found + if self.on_spawn and not self.on_spawn_run then + if self.on_spawn(self) then + self.on_spawn_run = true -- if true, set flag to run once only + end + end + + -- run after_activate + if def.after_activate then + def.after_activate(self, staticdata, def, dtime) + end + + if use_cmi then + self._cmi_components = cmi.activate_components(self.serialized_cmi_components) + cmi.notify_activate(self.object, dtime) + end +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua new file mode 100644 index 0000000000..98d2644e80 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/sound_handling.lua @@ -0,0 +1,59 @@ +local math_random = math.random + + +--generic call for sound handler for mobs (data access) +mobs.play_sound = function(self,sound) + local soundinfo = self.sounds + + if not soundinfo then + return + end + + local play_sound = soundinfo[sound] + + if not play_sound then + return + end + + mobs.play_sound_handler(self, play_sound) +end + + +--generic sound handler for mobs +mobs.play_sound_handler = function(self, sound) + local pitch = (100 + math_random(-15,15) + math_random()) / 100 + local distance = self.sounds.distance or 16 + + minetest.sound_play(sound, { + object = self.object, + gain = 1.0, + max_hear_distance = distance, + pitch = pitch, + }, true) +end + + +--random sound timing handler +mobs.random_sound_handling = function(self,dtime) + + self.random_sound_timer = self.random_sound_timer - dtime + + --play sound and reset timer + if self.random_sound_timer <= 0 then + mobs.play_sound(self,"random") + self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max) + end +end + +--used for playing a non-mob internal sound at random pitches +mobs.play_sound_specific = function(self,soundname) + local pitch = (100 + math_random(-15,15) + math_random()) / 100 + local distance = self.sounds.distance or 16 + + minetest.sound_play(soundname, { + object = self.object, + gain = 1.0, + max_hear_distance = distance, + pitch = pitch, + }, true) +end \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/mount.lua b/mods/ENTITIES/mcl_mobs/api/mount.lua similarity index 92% rename from mods/ENTITIES/mcl_mobs/mount.lua rename to mods/ENTITIES/mcl_mobs/api/mount.lua index 9383ee067c..8ee45f299c 100644 --- a/mods/ENTITIES/mcl_mobs/mount.lua +++ b/mods/ENTITIES/mcl_mobs/api/mount.lua @@ -206,21 +206,30 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) -- move forwards if ctrl.up then - entity.v = entity.v + entity.accel / 10 + mobs.set_velocity(entity, entity.run_velocity) + + mobs.set_mob_animation(entity, moving_anim) -- move backwards elseif ctrl.down then - if entity.max_speed_reverse == 0 and entity.v == 0 then - return - end + mobs.set_velocity(entity, -entity.run_velocity) - entity.v = entity.v - entity.accel / 10 + mobs.set_mob_animation(entity, moving_anim) + + --halt + else + + mobs.set_velocity(entity, 0) + + mobs.set_mob_animation(entity, stand_anim) end - -- fix mob rotation + -- mob rotation entity.object:set_yaw(entity.driver:get_look_horizontal() - entity.rotate) + entity.yaw = entity.driver:get_look_horizontal() - entity.rotate + --[[ if can_fly then -- fly up @@ -244,32 +253,21 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) end else + ]]-- - -- jump - if ctrl.jump then + -- jump + if ctrl.jump then - if velo.y == 0 then - velo.y = velo.y + entity.jump_height - acce_y = acce_y + (acce_y * 3) + 1 - end - end - - end - end - - -- if not moving then set animation and return - if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then - - if stand_anim then - mobs:set_animation(entity, stand_anim) + mobs.jump(entity) end - return + --end end + --[[ -- set moving animation if moving_anim then - mobs:set_animation(entity, moving_anim) + mobs:set_mob_animation(entity, moving_anim) end -- Stop! @@ -383,6 +381,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) end entity.v2 = v + ]]-- end @@ -390,6 +389,10 @@ end function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim) + if true then + print("succ") + return + end local ctrl = entity.driver:get_player_control() local velo = entity.object:get_velocity() local dir = entity.driver:get_look_dir() @@ -440,9 +443,9 @@ function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim) -- change animation if stopped if velo.x == 0 and velo.y == 0 and velo.z == 0 then - mobs:set_animation(entity, stand_anim) + mobs:set_mob_animation(entity, stand_anim) else -- moving animation - mobs:set_animation(entity, moving_anim) + mobs:set_mob_animation(entity, moving_anim) end end diff --git a/mods/ENTITIES/mcl_mobs/spawning.lua b/mods/ENTITIES/mcl_mobs/api/spawning.lua similarity index 67% rename from mods/ENTITIES/mcl_mobs/spawning.lua rename to mods/ENTITIES/mcl_mobs/api/spawning.lua index 210c6b9c67..ca4dc1e4fc 100644 --- a/mods/ENTITIES/mcl_mobs/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/api/spawning.lua @@ -1,17 +1,30 @@ --lua locals -local get_node = minetest.get_node -local get_item_group = minetest.get_item_group -local get_node_light = minetest.get_node_light +local get_node = minetest.get_node +local get_item_group = minetest.get_item_group +local get_node_light = minetest.get_node_light local find_nodes_in_area_under_air = minetest.find_nodes_in_area_under_air -local new_vector = vector.new +local get_biome_name = minetest.get_biome_name +local get_objects_inside_radius = minetest.get_objects_inside_radius + + local math_random = math.random -local get_biome_name = minetest.get_biome_name +local math_floor = math.floor local max = math.max -local get_objects_inside_radius = minetest.get_objects_inside_radius + local vector_distance = vector.distance +local vector_new = vector.new +local vector_floor = vector.floor + +local table_copy = table.copy +local table_remove = table.remove + -- range for mob count -local aoc_range = 32 +local aoc_range = 48 + +--do mobs spawn? +local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false + --[[ THIS IS THE BIG LIST OF ALL BIOMES - used for programming/updating mobs @@ -153,28 +166,14 @@ Overworld regular: - -local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false --- count how many mobs of one type are inside an area - -local count_mobs = function(pos,mobtype) +-- count how many mobs are in an area +local count_mobs = function(pos) local num = 0 - local objs = get_objects_inside_radius(pos, aoc_range) - for n = 1, #objs do - local obj = objs[n]:get_luaentity() - if obj and obj.name and obj._cmi_is_mob then - -- count hostile mobs only - if mobtype == "hostile" then - if obj.spawn_class == "hostile" then - num = num + 1 - end - -- count passive mobs only - else - num = num + 1 - end + for _,object in pairs(get_objects_inside_radius(pos, aoc_range)) do + if object and object:get_luaentity() and object:get_luaentity()._cmi_is_mob then + num = num + 1 end end - return num end @@ -484,23 +483,23 @@ end local axis --inner and outer part of square donut radius -local inner = 1 -local outer = 65 +local inner = 15 +local outer = 64 local int = {-1,1} local position_calculation = function(pos) - pos = vector.floor(pos) + pos = vector_floor(pos) --this is used to determine the axis buffer from the player - axis = math.random(0,1) + axis = math_random(0,1) --cast towards the direction if axis == 0 then --x - pos.x = pos.x + math.random(inner,outer)*int[math.random(1,2)] - pos.z = pos.z + math.random(-outer,outer) + pos.x = pos.x + math_random(inner,outer)*int[math_random(1,2)] + pos.z = pos.z + math_random(-outer,outer) else --z - pos.z = pos.z + math.random(inner,outer)*int[math.random(1,2)] - pos.x = pos.x + math.random(-outer,outer) + pos.z = pos.z + math_random(inner,outer)*int[math_random(1,2)] + pos.x = pos.x + math_random(-outer,outer) end return(pos) end @@ -516,7 +515,7 @@ local decypher_limits_dictionary = { local function decypher_limits(posy) --local min_max_table = decypher_limits_dictionary[dimension] --return min_max_table[1],min_max_table[2] - posy = math.floor(posy) + posy = math_floor(posy) return posy - 32, posy + 32 end @@ -539,108 +538,169 @@ if mobs_spawn then local timer = 0 minetest.register_globalstep(function(dtime) timer = timer + dtime - if timer >= 8 then + if timer >= 10 then timer = 0 for _,player in pairs(minetest.get_connected_players()) do - for i = 1,math_random(3,8) do - repeat -- after this line each "break" means "continue" - local player_pos = player:get_pos() + -- after this line each "break" means "continue" + local do_mob_spawning = true + repeat + --don't need to get these variables more than once + --they happen in a single server step - local _,dimension = mcl_worlds.y_to_layer(player_pos.y) + local player_pos = player:get_pos() + local _,dimension = mcl_worlds.y_to_layer(player_pos.y) - if dimension == "void" or dimension == "default" then - break -- ignore void and unloaded area - end + if dimension == "void" or dimension == "default" then + break -- ignore void and unloaded area + end - local min,max = decypher_limits(player_pos.y) + local min,max = decypher_limits(player_pos.y) - local goal_pos = position_calculation(player_pos) + for i = 1,math_random(1,4) do + -- after this line each "break" means "continue" + local do_mob_algorithm = true + repeat - local spawning_position_list = find_nodes_in_area_under_air(new_vector(goal_pos.x,min,goal_pos.z), vector.new(goal_pos.x,max,goal_pos.z), {"group:solid", "group:water", "group:lava"}) + local goal_pos = position_calculation(player_pos) + + local spawning_position_list = find_nodes_in_area_under_air(vector_new(goal_pos.x,min,goal_pos.z), vector_new(goal_pos.x,max,goal_pos.z), {"group:solid", "group:water", "group:lava"}) + + --couldn't find node + if #spawning_position_list <= 0 then + break + end + + local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)] + + --Prevent strange behavior --- this is commented out: /too close to player --fixed with inner circle + if not spawning_position then -- or vector_distance(player_pos, spawning_position) < 15 + break + end + + --hard code mob limit in area to 5 for now + if count_mobs(spawning_position) >= 5 then + break + end + + local gotten_node = get_node(spawning_position).name + + if not gotten_node or gotten_node == "air" then --skip air nodes + break + end + + local gotten_biome = minetest.get_biome_data(spawning_position) + + if not gotten_biome then + break --skip if in unloaded area + end + + gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with + + --add this so mobs don't spawn inside nodes + spawning_position.y = spawning_position.y + 1 + + --only need to poll for node light if everything else worked + local gotten_light = get_node_light(spawning_position) + + local is_water = get_item_group(gotten_node, "water") ~= 0 + local is_lava = get_item_group(gotten_node, "lava") ~= 0 + + local mob_def = nil + + --create a disconnected clone of the spawn dictionary + --prevents memory leak + local mob_library_worker_table = table_copy(spawn_dictionary) + + --grab mob that fits into the spawning location + --randomly grab a mob, don't exclude any possibilities + local repeat_mob_search = true + repeat + + --do not infinite loop + if #mob_library_worker_table <= 0 then + --print("breaking infinite loop") + break + end + + local skip = false + + --use this for removing table elements of mobs that do not match + local temp_index = math_random(1,#mob_library_worker_table) + + local temp_def = mob_library_worker_table[temp_index] + + --skip if something ridiculous happens (nil mob def) + --something truly horrible has happened if skip gets + --activated at this point + if not temp_def then + skip = true + end + + if not skip and (spawning_position.y < temp_def.min_height or spawning_position.y > temp_def.max_height) then + skip = true + end + + --skip if not correct dimension + if not skip and (temp_def.dimension ~= dimension) then + skip = true + end + + --skip if not in correct biome + if not skip and (not biome_check(temp_def.biomes, gotten_biome)) then + skip = true + end + + --don't spawn if not in light limits + if not skip and (gotten_light < temp_def.min_light or gotten_light > temp_def.max_light) then + skip = true + end + + --skip if not in correct spawning type + if not skip and (temp_def.type_of_spawning == "ground" and is_water) then + skip = true + end + + if not skip and (temp_def.type_of_spawning == "ground" and is_lava) then + skip = true + end + + --found a mob, exit out of loop + if not skip then + --minetest.log("warning", "found mob:"..temp_def.name) + --print("found mob:"..temp_def.name) + mob_def = table_copy(temp_def) + break + else + --minetest.log("warning", "deleting temp index "..temp_index) + --print("deleting temp index") + table_remove(mob_library_worker_table, temp_index) + end + + until repeat_mob_search == false --this is needed to sort through mobs randomly + + + --catch if went through all mobs and something went horribly wrong + --could not find a valid mob to spawn that fits the environment + if not mob_def then + break + end + + --adjust the position for water and lava mobs + if mob_def.type_of_spawning == "water" or mob_def.type_of_spawning == "lava" then + spawning_position.y = spawning_position.y - 1 + end + + --print("spawning: " .. mob_def.name) + + --everything is correct, spawn mob + minetest.add_entity(spawning_position, mob_def.name) - --couldn't find node - if #spawning_position_list <= 0 then break - end + until do_mob_algorithm == false --this is a safety catch + end - local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)] - - --Prevent strange behavior/too close to player - if not spawning_position or vector_distance(player_pos, spawning_position) < 15 then - break - end - - local gotten_node = get_node(spawning_position).name - - if not gotten_node or gotten_node == "air" then --skip air nodes - break - end - - local gotten_biome = minetest.get_biome_data(spawning_position) - - if not gotten_biome then - break --skip if in unloaded area - end - - gotten_biome = get_biome_name(gotten_biome.biome) --makes it easier to work with - - --grab random mob - local mob_def = spawn_dictionary[math.random(1,#spawn_dictionary)] - - if not mob_def then - break --skip if something ridiculous happens (nil mob def) - end - - --skip if not correct dimension - if mob_def.dimension ~= dimension then - break - end - - --skip if not in correct biome - if not biome_check(mob_def.biomes, gotten_biome) then - break - end - - --add this so mobs don't spawn inside nodes - spawning_position.y = spawning_position.y + 1 - - if spawning_position.y < mob_def.min_height or spawning_position.y > mob_def.max_height then - break - end - - --only need to poll for node light if everything else worked - local gotten_light = get_node_light(spawning_position) - - --don't spawn if not in light limits - if gotten_light < mob_def.min_light or gotten_light > mob_def.max_light then - break - end - - local is_water = get_item_group(gotten_node, "water") ~= 0 - local is_lava = get_item_group(gotten_node, "lava") ~= 0 - - if mob_def.type_of_spawning == "ground" and is_water then - break - end - - if mob_def.type_of_spawning == "ground" and is_lava then - break - end - - --finally do the heavy check (for now) of mobs in area - if count_mobs(spawning_position, mob_def.spawn_class) >= mob_def.aoc then - break - end - - --adjust the position for water and lava mobs - if mob_def.type_of_spawning == "water" or mob_def.type_of_spawning == "lava" then - spawning_position.y = spawning_position.y - 1 - end - - --everything is correct, spawn mob - minetest.add_entity(spawning_position, mob_def.name) - until true --this is a safety catch - end + break + until do_mob_spawning == false --this is a performance catch end end end) diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index 69246b4706..b0daba2c4b 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -1,14 +1,16 @@ local path = minetest.get_modpath(minetest.get_current_modname()) +local api_path = path.."/api" + -- Mob API -dofile(path .. "/api.lua") +dofile(api_path .. "/api.lua") -- Spawning Algorithm -dofile(path .. "/spawning.lua") +dofile(api_path .. "/spawning.lua") -- Rideable Mobs -dofile(path .. "/mount.lua") +dofile(api_path .. "/mount.lua") -- Mob Items dofile(path .. "/crafts.lua") \ No newline at end of file diff --git a/mods/ENTITIES/mcl_mobs/lucky_block.lua b/mods/ENTITIES/mcl_mobs/lucky_block.lua deleted file mode 100644 index ea90de74ac..0000000000 --- a/mods/ENTITIES/mcl_mobs/lucky_block.lua +++ /dev/null @@ -1,8 +0,0 @@ - -if minetest.get_modpath("lucky_block") then - - lucky_block:add_blocks({ - {"dro", {"mcl_mobs:nametag"}, 1}, - {"lig"}, - }) -end diff --git a/mods/ENTITIES/mcl_mobs/sounds/attributes.txt b/mods/ENTITIES/mcl_mobs/sounds/attributes.txt new file mode 100644 index 0000000000..1228dd9d7d --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/sounds/attributes.txt @@ -0,0 +1,4 @@ + +default_punch.1 = https://freesound.org/people/Merrick079/sounds/566436/ +default_punch.2 = https://freesound.org/people/Merrick079/sounds/566435/ +default_punch.3 = https://freesound.org/people/Merrick079/sounds/566434/ diff --git a/mods/ENTITIES/mcl_mobs/sounds/default_punch.1.ogg b/mods/ENTITIES/mcl_mobs/sounds/default_punch.1.ogg new file mode 100644 index 0000000000..4d7ba8015e Binary files /dev/null and b/mods/ENTITIES/mcl_mobs/sounds/default_punch.1.ogg differ diff --git a/mods/ENTITIES/mcl_mobs/sounds/default_punch.2.ogg b/mods/ENTITIES/mcl_mobs/sounds/default_punch.2.ogg new file mode 100644 index 0000000000..c022d94f87 Binary files /dev/null and b/mods/ENTITIES/mcl_mobs/sounds/default_punch.2.ogg differ diff --git a/mods/ENTITIES/mcl_mobs/sounds/default_punch.3.ogg b/mods/ENTITIES/mcl_mobs/sounds/default_punch.3.ogg new file mode 100644 index 0000000000..4c5e3f9b30 Binary files /dev/null and b/mods/ENTITIES/mcl_mobs/sounds/default_punch.3.ogg differ diff --git a/mods/ENTITIES/mcl_mobs/sounds/default_punch.ogg b/mods/ENTITIES/mcl_mobs/sounds/default_punch.ogg deleted file mode 100644 index 28a500bf57..0000000000 Binary files a/mods/ENTITIES/mcl_mobs/sounds/default_punch.ogg and /dev/null differ diff --git a/mods/ENTITIES/mcl_mobs/todo.txt b/mods/ENTITIES/mcl_mobs/todo.txt new file mode 100644 index 0000000000..7598b14ed8 --- /dev/null +++ b/mods/ENTITIES/mcl_mobs/todo.txt @@ -0,0 +1 @@ +--use vector.distance to count down mob despawn timer \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/0_gameconfig.lua b/mods/ENTITIES/mobs_mc/0_gameconfig.lua index c92ccbba52..3476bee4c7 100644 --- a/mods/ENTITIES/mobs_mc/0_gameconfig.lua +++ b/mods/ENTITIES/mobs_mc/0_gameconfig.lua @@ -81,7 +81,9 @@ mobs_mc.items = { gunpowder = "tnt:gunpowder", flint_and_steel = "fire:flint_and_steel", water_source = "default:water_source", + water_flowing = "default:water_flowing", river_water_source = "default:river_water_source", + water_flowing = "default:river_water_flowing", black_dye = "dye:black", poppy = "flowers:rose", dandelion = "flowers:dandelion_yellow", diff --git a/mods/ENTITIES/mobs_mc/1_items_default.lua b/mods/ENTITIES/mobs_mc/1_items_default.lua index b4abd4f9cc..bdadbfdc56 100644 --- a/mods/ENTITIES/mobs_mc/1_items_default.lua +++ b/mods/ENTITIES/mobs_mc/1_items_default.lua @@ -516,8 +516,6 @@ end -- Evoker if c("totem") then - local hud_totem = {} - -- Totem of Undying minetest.register_craftitem("mobs_mc:totem", { description = S("Totem of Undying"), @@ -527,66 +525,8 @@ if c("totem") then inventory_image = "mcl_totems_totem.png", wield_image = "mcl_totems_totem.png", stack_max = 1, + groups = {combat_item=1}, }) - - minetest.register_on_leaveplayer(function(player) - hud_totem[player:get_player_name()] = nil - end) - - -- Save the player from death when holding totem of undying in hand - minetest.register_on_player_hpchange(function(player, hp_change) - local hp = player:get_hp() - -- Fatal damage? - if hp + hp_change <= 0 then - local wield = player:get_wielded_item() - if wield:get_name() == "mobs_mc:totem" then - local ppos = player:get_pos() - local pnname = minetest.get_node(ppos).name - -- Some exceptions when _not_ to save the player - for n=1, #mobs_mc.misc.totem_fail_nodes do - if pnname == mobs_mc.misc.totem_fail_nodes[n] then - return hp_change - end - end - -- Reset breath as well - if player:get_breath() < 11 then - player:set_breath(10) - end - if not minetest.is_creative_enabled(player:get_player_name()) then - wield:take_item() - player:set_wielded_item(wield) - end - -- Effects - minetest.sound_play({name = "mcl_totems_totem", gain=1}, {pos=ppos, max_hear_distance=16}, true) - - -- Big totem overlay - if not hud_totem[player:get_player_name()] then - hud_totem[player:get_player_name()] = player:hud_add({ - hud_elem_type = "image", - text = "mcl_totems_totem.png", - position = { x=0.5, y=1 }, - scale = { x=17, y=17 }, - offset = { x=0, y=-178 }, - z_index = 100, - }) - minetest.after(3, function(name) - local player = minetest.get_player_by_name(name) - if player and player:is_player() then - local name = player:get_player_name() - if hud_totem[name] then - player:hud_remove(hud_totem[name]) - hud_totem[name] = nil - end - end - end, player:get_player_name()) - end - - -- Set HP to exactly 1 - return -hp + 1 - end - end - return hp_change - end, true) end -- Rotten flesh diff --git a/mods/ENTITIES/mobs_mc/bat.lua b/mods/ENTITIES/mobs_mc/bat.lua index 677b96aad3..70e084ee29 100644 --- a/mods/ENTITIES/mobs_mc/bat.lua +++ b/mods/ENTITIES/mobs_mc/bat.lua @@ -3,10 +3,14 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:bat", { + description = S("Bat"), type = "animal", spawn_class = "ambient", can_despawn = true, passive = true, + rotate = 270, + tilt_fly = true, + fly = true, hp_min = 6, hp_max = 6, collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.89, 0.25}, @@ -44,9 +48,7 @@ mobs:register_mob("mobs_mc:bat", { fall_damage = 0, view_range = 16, fear_height = 0, - jump = false, - fly = true, makes_footstep_sound = false, }) diff --git a/mods/ENTITIES/mobs_mc/blaze.lua b/mods/ENTITIES/mobs_mc/blaze.lua index 847e2f4a53..146e8da705 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -11,12 +11,16 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:blaze", { + description = S("Blaze"), type = "monster", spawn_class = "hostile", hp_min = 20, hp_max = 20, xp_min = 10, xp_max = 10, + tilt_fly = false, + hostile = true, + rotate = 270, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.79, 0.3}, rotate = -180, visual = "mesh", @@ -35,7 +39,7 @@ mobs:register_mob("mobs_mc:blaze", { walk_velocity = .8, run_velocity = 1.6, damage = 6, - reach = 2, + reach = 4, -- don't want blaze getting too close pathfinding = 1, drops = { {name = mobs_mc.items.blaze_rod, @@ -63,7 +67,7 @@ mobs:register_mob("mobs_mc:blaze", { fall_speed = -2.25, light_damage = 0, view_range = 16, - attack_type = "dogshoot", + attack_type = "projectile", arrow = "mobs_mc:blaze_fireball", shoot_interval = 3.5, shoot_offset = 1.0, @@ -75,9 +79,18 @@ mobs:register_mob("mobs_mc:blaze", { fear_height = 0, glow = 14, fire_resistant = true, + eye_height = 0.75, + projectile_cooldown_min = 2, + projectile_cooldown_max = 3, + shoot_arrow = function(self, pos, dir) + -- 2-4 damage per arrow + local dmg = math.random(2,4) + mobs.shoot_projectile_handling("mobs_mc:blaze_fireball", pos, dir, self.object:get_yaw(), self.object, 7, dmg,nil,nil,nil,-0.4) + end, + do_custom = function(self) - if self.state == "attack" and vector.distance(self.object:get_pos(), self.attack:get_pos()) < 1.2 then - mcl_burning.set_on_fire(self.attack, 5) + if self.attacking and self.state == "attack" and vector.distance(self.object:get_pos(), self.attacking:get_pos()) < 1.2 then + mcl_burning.set_on_fire(self.attacking, 5) end local pos = self.object:get_pos() minetest.add_particle({ @@ -147,16 +160,19 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { visual_size = {x = 0.3, y = 0.3}, textures = {"mcl_fire_fire_charge.png"}, velocity = 15, + speed = 5, + tail = 1, + tail_texture = "mobs_mc_spit.png^[colorize:black:255", --repurpose spit texture + tail_size = 2, + tail_distance_divider = 3, + _is_fireball = true, -- Direct hit, no fire... just plenty of pain hit_player = function(self, player) - if rawget(_G, "armor") and armor.last_damage_types then - armor.last_damage_types[player:get_player_name()] = "fireball" - end - mcl_burning.set_on_fire(player, 5, "blaze") + mcl_burning.set_on_fire(player, 5) player:punch(self.object, 1.0, { full_punch_interval = 1.0, - damage_groups = {fleshy = 5}, + damage_groups = {fleshy = self._damage}, }, nil) end, @@ -164,7 +180,7 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { mcl_burning.set_on_fire(mob, 5) mob:punch(self.object, 1.0, { full_punch_interval = 1.0, - damage_groups = {fleshy = 5}, + damage_groups = {fleshy = self._damage}, }, nil) end, @@ -179,7 +195,9 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { -- Node hit, make fire hit_node = function(self, pos, node) - if node.name == "air" then + if node.name ~= "air" then + local pos_above = table.copy(pos) + pos_above.y = pos_above.y + 1 minetest.set_node(pos_above, {name=mobs_mc.items.fire}) else local v = self.object:get_velocity() diff --git a/mods/ENTITIES/mobs_mc/chicken.lua b/mods/ENTITIES/mobs_mc/chicken.lua index 246bf216ac..9146a012f1 100644 --- a/mods/ENTITIES/mobs_mc/chicken.lua +++ b/mods/ENTITIES/mobs_mc/chicken.lua @@ -9,6 +9,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:chicken", { + description = S("Chicken"), type = "animal", spawn_class = "passive", @@ -17,7 +18,8 @@ mobs:register_mob("mobs_mc:chicken", { xp_min = 1, xp_max = 3, collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2}, - runaway = true, + skittish = true, + fall_slow = true, floats = 1, visual = "mesh", mesh = "mobs_mc_chicken.b3d", @@ -25,9 +27,10 @@ mobs:register_mob("mobs_mc:chicken", { {"mobs_mc_chicken.png"}, }, visual_size = {x=2.2, y=2.2}, - + rotate = 270, makes_footstep_sound = true, walk_velocity = 1, + run_velocity = 3, drops = { {name = mobs_mc.items.chicken_raw, chance = 1, @@ -63,14 +66,25 @@ mobs:register_mob("mobs_mc:chicken", { run_start = 0, run_end = 40, }, - follow = mobs_mc.follow.chicken, + follow = "mcl_farming:wheat_seeds", + breed_distance = 1.5, + baby_size = 0.5, + follow_distance = 2, view_range = 16, fear_height = 4, + --why do chickend breed if they lay eggs?? on_rightclick = function(self, clicker) - if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end - if mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + return + end + + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return + end end, do_custom = function(self, dtime) @@ -95,37 +109,83 @@ mobs:register_mob("mobs_mc:chicken", { gain = 1.0, max_hear_distance = 16, }, true) - end, - + end, + + --head code + has_head = true, + head_bone = "head", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 1.675, + head_bone_pos_z = 0, + + head_height_offset = 0.55, + head_direction_offset = 0.0925, + + head_pitch_modifier = -math.pi/2, + --end head code }) --spawn mobs:spawn_specific( -"mobs_mc:chicken", -"overworld", +"mobs_mc:chicken", +"overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -9, -minetest.LIGHT_MAX+1, -30, 17000, -3, +9, +minetest.LIGHT_MAX+1, +30, 17000, +3, mobs_mc.spawn_height.water, mobs_mc.spawn_height.overworld_max) diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index 48fcc81975..0d6d31ffeb 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -3,12 +3,14 @@ local S = minetest.get_translator("mobs_mc") local cow_def = { + description = S("Cow"), type = "animal", spawn_class = "passive", hp_min = 10, hp_max = 10, xp_min = 1, xp_max = 3, + rotate = 270, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.39, 0.45}, visual = "mesh", mesh = "mobs_mc_cow.b3d", @@ -19,6 +21,7 @@ local cow_def = { visual_size = {x=2.8, y=2.8}, makes_footstep_sound = true, walk_velocity = 1, + run_velocity = 3, drops = { {name = mobs_mc.items.beef_raw, chance = 1, @@ -31,7 +34,7 @@ local cow_def = { max = 2, looting = "common",}, }, - runaway = true, + skittish = true, sounds = { random = "mobs_mc_cow", damage = "mobs_mc_cow_hurt", @@ -43,15 +46,20 @@ local cow_def = { stand_speed = 25, walk_speed = 40, run_speed = 60, stand_start = 0, stand_end = 0, walk_start = 0, - walk_end = 40, run_start = 0, + walk_end = 40, run_start = 0, run_end = 40, }, - follow = mobs_mc.follow.cow, + --follow = mobs_mc.follow.cow, on_rightclick = function(self, clicker) - if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end - if self.child then + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + return + end + + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) return end @@ -70,27 +78,49 @@ local cow_def = { end return end - mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end, + breed_distance = 1.5, + baby_size = 0.5, + follow_distance = 2, follow = mobs_mc.items.wheat, view_range = 10, fear_height = 4, + + --head code + has_head = true, + head_bone = "head", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 3.6, + head_bone_pos_z = -0.6, + + head_height_offset = 1.0525, + head_direction_offset = 0.5, + head_pitch_modifier = 0, + --end head code } mobs:register_mob("mobs_mc:cow", cow_def) -- Mooshroom local mooshroom_def = table.copy(cow_def) - +mooshroom_def.description = S("Mooshroom") mooshroom_def.mesh = "mobs_mc_cow.b3d" mooshroom_def.textures = { {"mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png"}, {"mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } } mooshroom_def.on_rightclick = function(self, clicker) - if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end - - if self.child then + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then return end + + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return + end + local item = clicker:get_wielded_item() -- Use shears to get mushrooms and turn mooshroom into cow if item:get_name() == mobs_mc.items.shears then @@ -138,8 +168,7 @@ mooshroom_def.on_rightclick = function(self, clicker) pos.y = pos.y + 0.5 minetest.add_item(pos, {name = mobs_mc.items.mushroom_stew}) end - end - mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) + end end mobs:register_mob("mobs_mc:mooshroom", mooshroom_def) @@ -147,50 +176,81 @@ mobs:register_mob("mobs_mc:mooshroom", mooshroom_def) -- Spawning mobs:spawn_specific( "mobs_mc:cow", -"overworld", +"overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -9, -minetest.LIGHT_MAX+1, -30, -17000, -10, -mobs_mc.spawn_height.water, +9, +minetest.LIGHT_MAX+1, +30, +17000, +10, +mobs_mc.spawn_height.water, mobs_mc.spawn_height.overworld_max) mobs:spawn_specific( -"mobs_mc:mooshroom", -"overworld", +"mobs_mc:mooshroom", +"overworld", "ground", { "MushroomIslandShore", "MushroomIsland" }, -9, -minetest.LIGHT_MAX+1, -30, -17000, -5, -mobs_mc.spawn_height.overworld_min, +9, +minetest.LIGHT_MAX+1, +30, +17000, +5, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- spawn egg diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 0c884d5699..4552d79d10 100644 --- a/mods/ENTITIES/mobs_mc/creeper.lua +++ b/mods/ENTITIES/mobs_mc/creeper.lua @@ -12,6 +12,8 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:creeper", { type = "monster", spawn_class = "hostile", + hostile = true, + rotate = 270, hp_min = 20, hp_max = 20, xp_min = 5, @@ -33,23 +35,39 @@ mobs:register_mob("mobs_mc:creeper", { explode = "tnt_explode", distance = 16, }, - makes_footstep_sound = true, + makes_footstep_sound = false, walk_velocity = 1.05, - run_velocity = 2.1, + run_velocity = 3.25, runaway_from = { "mobs_mc:ocelot", "mobs_mc:cat" }, attack_type = "explode", - + eye_height = 1.25, --hssssssssssss - explosion_strength = 3, - explosion_radius = 3.5, - explosion_damage_radius = 3.5, + explosion_strength = 10, + explosion_radius = 4, + explosion_damage_radius = 6, explosiontimer_reset_radius = 6, - reach = 3, - explosion_timer = 1.5, + reach = 1.5, + defuse_reach = 4, + explosion_timer = 0.3, allow_fuse_reset = true, stop_to_explode = true, + --head code + has_head = true, + head_bone = "head", + + swap_y_with_x = true, + reverse_head_yaw = true, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + -- Force-ignite creeper with flint and steel and explode after 1.5 seconds. -- TODO: Make creeper flash after doing this as well. -- TODO: Test and debug this code. @@ -130,6 +148,7 @@ mobs:register_mob("mobs_mc:creeper", { }) mobs:register_mob("mobs_mc:creeper_charged", { + description = S("Creeper"), type = "monster", spawn_class = "hostile", hp_min = 20, @@ -142,12 +161,13 @@ mobs:register_mob("mobs_mc:creeper_charged", { mesh = "mobs_mc_creeper.b3d", --BOOM - + textures = { {"mobs_mc_creeper.png", "mobs_mc_creeper_charge.png"}, }, visual_size = {x=3, y=3}, + rotate = 270, sounds = { attack = "tnt_ignite", death = "mobs_mc_creeper_death", @@ -156,18 +176,19 @@ mobs:register_mob("mobs_mc:creeper_charged", { explode = "tnt_explode", distance = 16, }, - makes_footstep_sound = true, + makes_footstep_sound = false, walk_velocity = 1.05, run_velocity = 2.1, runaway_from = { "mobs_mc:ocelot", "mobs_mc:cat" }, attack_type = "explode", - explosion_strength = 6, - explosion_radius = 8, - explosion_damage_radius = 8, - explosiontimer_reset_radius = 6, - reach = 3, - explosion_timer = 1.5, + explosion_strength = 24, + explosion_radius = 12, + explosion_damage_radius = 18, + explosiontimer_reset_radius = 10, + reach = 1.5, + defuse_reach = 4, + explosion_timer = 0.3, allow_fuse_reset = true, stop_to_explode = true, @@ -254,8 +275,8 @@ mobs:register_mob("mobs_mc:creeper_charged", { }) mobs:spawn_specific( -"mobs_mc:creeper", -"overworld", +"mobs_mc:creeper", +"overworld", "ground", { "Mesa", @@ -398,12 +419,12 @@ mobs:spawn_specific( "ExtremeHillsM_underground", "JungleEdgeM_underground", }, -0, -7, -20, -16500, -2, -mobs_mc.spawn_height.overworld_min, +0, +7, +20, +16500, +2, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index a6f4042754..2111105d39 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -5,16 +5,25 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:enderdragon", { + description = S("Ender Dragon"), type = "monster", spawn_class = "hostile", - pathfinding = 1, attacks_animals = true, walk_chance = 100, + rotate = 270, + tilt_fly = true, + hostile = true, + shoot_arrow = function(self, pos, dir) + -- 2-4 damage per arrow + local dmg = math.random(2,4) + mobs.shoot_projectile_handling("mobs_mc:dragon_fireball", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + end, hp_max = 200, hp_min = 200, xp_min = 500, xp_max = 500, - collisionbox = {-2, 3, -2, 2, 5, 2}, + collisionbox = {-2, 0, -2, 2, 2, 2}, + eye_height = 1, physical = false, visual = "mesh", mesh = "mobs_mc_dragon.b3d", @@ -23,6 +32,7 @@ mobs:register_mob("mobs_mc:enderdragon", { }, visual_size = {x=3, y=3}, view_range = 35, + reach = 20, walk_velocity = 6, run_velocity = 6, can_despawn = false, @@ -46,7 +56,7 @@ mobs:register_mob("mobs_mc:enderdragon", { lava_damage = 0, fire_damage = 0, on_rightclick = nil, - attack_type = "dogshoot", + attack_type = "projectile", arrow = "mobs_mc:dragon_fireball", shoot_interval = 0.5, shoot_offset = -1.0, @@ -132,10 +142,11 @@ mobs:register_arrow("mobs_mc:dragon_fireball", { -- node hit, explode hit_node = function(self, pos, node) - mobs:boom(self, pos, 2) + --mobs:boom(self, pos, 2) + mcl_explosions.explode(self.object:get_pos(), 2,{ drop_chance = 1.0 }) end }) mobs:register_egg("mobs_mc:enderdragon", S("Ender Dragon"), "mobs_mc_spawn_icon_dragon.png", 0, true) -mcl_wip.register_wip_item("mobs_mc:enderdragon") +--mcl_wip.register_wip_item("mobs_mc:enderdragon") diff --git a/mods/ENTITIES/mobs_mc/enderman.lua b/mods/ENTITIES/mobs_mc/enderman.lua index 9c47e98fcc..9ebc3d6fab 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -190,20 +190,22 @@ end local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false mobs:register_mob("mobs_mc:enderman", { + description = S("Enderman"), type = "monster", spawn_class = "passive", - passive = true, - pathfinding = 1, + neutral = true, hp_min = 40, hp_max = 40, xp_min = 5, xp_max = 5, + rotate = 270, collisionbox = {-0.3, -0.01, -0.3, 0.3, 2.89, 0.3}, visual = "mesh", mesh = "mobs_mc_enderman.b3d", textures = create_enderman_textures(), visual_size = {x=3, y=3}, makes_footstep_sound = true, + eye_height = 2.5, sounds = { -- TODO: Custom war cry sound war_cry = "mobs_sandmonster", @@ -212,8 +214,8 @@ mobs:register_mob("mobs_mc:enderman", { random = {name="mobs_mc_enderman_random", gain=0.5}, distance = 16, }, - walk_velocity = 0.2, - run_velocity = 3.4, + walk_velocity = 1, + run_velocity = 4, damage = 7, reach = 2, drops = { @@ -223,6 +225,22 @@ mobs:register_mob("mobs_mc:enderman", { max = 1, looting = "common"}, }, + + --head code + has_head = false, + head_bone = "head.low", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + animation = select_enderman_animation("normal"), _taken_node = "", do_custom = function(self, dtime) @@ -281,8 +299,8 @@ mobs:register_mob("mobs_mc:enderman", { --self:teleport(nil) --self.state = "" --else - if self.attack then - local target = self.attack + if self.attacking then + local target = self.attacking local pos = target:get_pos() if pos ~= nil then if vector.distance(self.object:get_pos(), target:get_pos()) > 10 then @@ -330,7 +348,7 @@ mobs:register_mob("mobs_mc:enderman", { end -- Check to see if people are near by enough to look at us. for _,obj in pairs(minetest.get_connected_players()) do - + --check if they are within radius local player_pos = obj:get_pos() if player_pos then -- prevent crashing in 1 in a million scenario @@ -355,16 +373,21 @@ mobs:register_mob("mobs_mc:enderman", { local ender_eye_pos = vector.new(enderpos.x, enderpos.y + 2.75, enderpos.z) local eye_distance_from_player = vector.distance(ender_eye_pos, look_pos) look_pos = vector.add(look_pos, vector.multiply(look_dir, eye_distance_from_player)) - + --if looking in general head position, turn hostile if minetest.line_of_sight(ender_eye_pos, look_pos_base) and vector.distance(look_pos, ender_eye_pos) <= 0.4 then self.provoked = "staring" - self.attack = minetest.get_player_by_name(obj:get_player_name()) + self.state = "stand" + self.hostile = false break - else -- I'm not sure what this part does, but I don't want to break anything - jordan4ibanez + --begin attacking the player + else if self.provoked == "staring" then self.provoked = "broke_contact" - end + self.hostile = true + self.state = "attack" + self.attacking = obj + end end end @@ -429,7 +452,7 @@ mobs:register_mob("mobs_mc:enderman", { self.base_texture = create_enderman_textures(block_type, self._taken_node) self.object:set_properties({ textures = self.base_texture }) self.animation = select_enderman_animation("block") - mobs:set_animation(self, self.animation.current) + mobs.set_mob_animation(self, self.animation.current) if def.sounds and def.sounds.dug then minetest.sound_play(def.sounds.dug, {pos = take_pos, max_hear_distance = 16}, true) end @@ -452,7 +475,7 @@ mobs:register_mob("mobs_mc:enderman", { local def = minetest.registered_nodes[self._taken_node] -- Update animation accordingly (removes visible block) self.animation = select_enderman_animation("normal") - mobs:set_animation(self, self.animation.current) + mobs.set_mob_animation(self, self.animation.current) if def.sounds and def.sounds.place then minetest.sound_play(def.sounds.place, {pos = place_pos, max_hear_distance = 16}, true) end @@ -556,29 +579,29 @@ mobs:register_mob("mobs_mc:enderman", { water_damage = 8, view_range = 64, fear_height = 4, - attack_type = "dogfight", + attack_type = "punch", }) -- End spawn mobs:spawn_specific( -"mobs_mc:enderman", -"end", +"mobs_mc:enderman", +"end", "ground", { "End" }, -0, -minetest.LIGHT_MAX+1, -30, -3000, -12, -mobs_mc.spawn_height.end_min, +0, +minetest.LIGHT_MAX+1, +30, +3000, +12, +mobs_mc.spawn_height.end_min, mobs_mc.spawn_height.end_max) -- Overworld spawn mobs:spawn_specific( -"mobs_mc:enderman", -"overworld", +"mobs_mc:enderman", +"overworld", "ground", { "Mesa", @@ -721,28 +744,28 @@ mobs:spawn_specific( "ExtremeHillsM_underground", "JungleEdgeM_underground", }, -0, -7, -30, -19000, -2, -mobs_mc.spawn_height.overworld_min, +0, +7, +30, +19000, +2, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- Nether spawn (rare) mobs:spawn_specific( -"mobs_mc:enderman", -"nether", +"mobs_mc:enderman", +"nether", "ground", { "Nether" }, -0, -7, -30, -27500, -4, -mobs_mc.spawn_height.nether_min, +0, +7, +30, +27500, +4, +mobs_mc.spawn_height.nether_min, mobs_mc.spawn_height.nether_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/endermite.lua b/mods/ENTITIES/mobs_mc/endermite.lua index da3922a106..712086828d 100644 --- a/mods/ENTITIES/mobs_mc/endermite.lua +++ b/mods/ENTITIES/mobs_mc/endermite.lua @@ -5,15 +5,19 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:endermite", { + description = S("Endermite"), type = "monster", spawn_class = "hostile", passive = false, + rotate = 270, + hostile = true, hp_min = 8, hp_max = 8, xp_min = 3, xp_max = 3, armor = {fleshy = 100, arthropod = 100}, group_attack = true, + attack_type = "punch", collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.29, 0.2}, visual = "mesh", mesh = "mobs_mc_endermite.b3d", diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index 83a10bfc40..609110bdb8 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -11,15 +11,20 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:ghast", { + description = S("Ghast"), type = "monster", spawn_class = "hostile", - pathfinding = 1, group_attack = true, + hostile = true, + fly_random_while_attack = true, hp_min = 10, hp_max = 10, + rotate = 270, xp_min = 5, xp_max = 5, - collisionbox = {-2, 5, -2, 2, 9, 2}, + reach = 20, + eye_height = 2.5, + collisionbox = {-2, 0, -2, 2, 4, 2}, visual = "mesh", mesh = "mobs_mc_ghast.b3d", textures = { @@ -35,8 +40,10 @@ mobs:register_mob("mobs_mc:ghast", { -- TODO: damage -- TODO: better death }, + walk_velocity = 1.6, run_velocity = 3.2, + drops = { {name = mobs_mc.items.gunpowder, chance = 1, min = 0, max = 2, looting = "common"}, {name = mobs_mc.items.ghast_tear, chance = 10/6, min = 0, max = 1, looting = "common", looting_ignore_chance = true}, @@ -47,22 +54,23 @@ mobs:register_mob("mobs_mc:ghast", { walk_start = 0, walk_end = 40, run_start = 0, run_end = 40, }, + fall_damage = 0, - view_range = 100, - attack_type = "dogshoot", - arrow = "mobs_mc:fireball", - shoot_interval = 3.5, - shoot_offset = -5, - dogshoot_switch = 1, - dogshoot_count_max =1, - passive = false, - jump = true, - jump_height = 4, + view_range = 28, + attack_type = "projectile", + arrow = "mobs_mc:ghast_fireball", floats=1, fly = true, makes_footstep_sound = false, - instant_death = true, fire_resistant = true, + projectile_cooldown_min = 5, + projectile_cooldown_max = 7, + shoot_arrow = function(self, pos, dir) + -- 2-4 damage per arrow + local dmg = math.random(2,4) + mobs.shoot_projectile_handling("mobs_mc:ghast_fireball", pos, dir, self.object:get_yaw(), self.object, 11, dmg,nil,nil,nil,-0.6) + end, + --[[ do_custom = function(self) if self.firing == true then self.base_texture = {"mobs_mc_ghast_firing.png"} @@ -72,53 +80,60 @@ mobs:register_mob("mobs_mc:ghast", { self.object:set_properties({textures=self.base_texture}) end end, + ]]-- }) mobs:spawn_specific( -"mobs_mc:ghast", -"nether", +"mobs_mc:ghast", +"nether", "ground", { "Nether" }, -0, -minetest.LIGHT_MAX+1, -30, -18000, -2, -mobs_mc.spawn_height.nether_min, +0, +minetest.LIGHT_MAX+1, +30, +18000, +2, +mobs_mc.spawn_height.nether_min, mobs_mc.spawn_height.nether_max) -- fireball (projectile) -mobs:register_arrow("mobs_mc:fireball", { +mobs:register_arrow("mobs_mc:ghast_fireball", { visual = "sprite", visual_size = {x = 1, y = 1}, textures = {"mcl_fire_fire_charge.png"}, velocity = 15, collisionbox = {-.5, -.5, -.5, .5, .5, .5}, + tail = 1, + tail_texture = "mobs_mc_spit.png^[colorize:black:255", --repurpose spit texture + tail_size = 5, + _is_fireball = true, hit_player = function(self, player) - if rawget(_G, "armor") and armor.last_damage_types then - armor.last_damage_types[player:get_player_name()] = "fireball" - end + --[[ player:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {fleshy = 6}, }, nil) - mobs:boom(self, self.object:get_pos(), 1, true) + ]]-- + --mobs:boom(self, self.object:get_pos(), 1, true) + mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) end, hit_mob = function(self, mob) mob:punch(self.object, 1.0, { full_punch_interval = 1.0, - damage_groups = {fleshy = 6}, + damage_groups = {fleshy = self._damage}, }, nil) - mobs:boom(self, self.object:get_pos(), 1, true) + --mobs:boom(self, self.object:get_pos(), 1, true) + mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) end, hit_node = function(self, pos, node) - mobs:boom(self, pos, 1, true) + --mobs:boom(self, pos, 1, true) + mcl_explosions.explode(self.object:get_pos(), 3,{ drop_chance = 1.0 }) end }) diff --git a/mods/ENTITIES/mobs_mc/guardian.lua b/mods/ENTITIES/mobs_mc/guardian.lua index 13c857ea39..241ac34444 100644 --- a/mods/ENTITIES/mobs_mc/guardian.lua +++ b/mods/ENTITIES/mobs_mc/guardian.lua @@ -5,6 +5,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:guardian", { + description = S("Guardian"), type = "monster", spawn_class = "hostile", hp_min = 30, @@ -13,7 +14,7 @@ mobs:register_mob("mobs_mc:guardian", { xp_max = 10, breath_max = -1, passive = false, - attack_type = "dogfight", + attack_type = "punch", pathfinding = 1, view_range = 16, walk_velocity = 2, diff --git a/mods/ENTITIES/mobs_mc/guardian_elder.lua b/mods/ENTITIES/mobs_mc/guardian_elder.lua index 089f6e38f7..4fb989e2fb 100644 --- a/mods/ENTITIES/mobs_mc/guardian_elder.lua +++ b/mods/ENTITIES/mobs_mc/guardian_elder.lua @@ -7,6 +7,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:guardian_elder", { + description = S("Elder Guardian"), type = "monster", spawn_class = "hostile", hp_min = 80, @@ -15,7 +16,7 @@ mobs:register_mob("mobs_mc:guardian_elder", { xp_max = 10, breath_max = -1, passive = false, - attack_type = "dogfight", + attack_type = "punch", pathfinding = 1, view_range = 16, walk_velocity = 2, diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index 938a6b6ace..461c60efd6 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -83,10 +83,15 @@ end -- Horse local horse = { + description = S("Horse"), type = "animal", spawn_class = "passive", visual = "mesh", mesh = "mobs_mc_horse.b3d", + rotate = 270, + walk_velocity = 1, + run_velocity = 8, + skittish = true, visual_size = {x=3.0, y=3.0}, collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825}, animation = { @@ -96,7 +101,7 @@ local horse = { walk_speed = 25, walk_start = 0, walk_end = 40, - run_speed = 60, + run_speed = 120, run_start = 0, run_end = 40, }, @@ -113,7 +118,8 @@ local horse = { fly = false, walk_chance = 60, view_range = 16, - follow = mobs_mc.follow.horse, + follow = "mcl_farming:wheat_item", + follow_distance = 3, passive = true, hp_min = 15, hp_max = 30, @@ -181,7 +187,7 @@ local horse = { -- if driver present and horse has a saddle allow control of horse if self.driver and self._saddle then - mobs.drive(self, "walk", "stand", false, dtime) + mobs.drive(self, "run", "stand", false, dtime) return false -- skip rest of mob functions end @@ -213,6 +219,21 @@ local horse = { local iname = item:get_name() local heal = 0 + --sneak click to breed the horse/feed it + if self.owner and self.owner == clicker:get_player_name() then + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + return + end + end + + --don't do any other logic with the baby + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return + end + -- Taming self.temper = self.temper or (math.random(1,100)) @@ -238,6 +259,7 @@ local horse = { self.buck_off_time = 40 -- TODO how long does it take in minecraft? if self.temper > 100 then self.tamed = true -- NOTE taming can only be finished by riding the horse + mobs.tamed_effect(self) if not self.owner or self.owner == "" then self.owner = clicker:get_player_name() end @@ -252,6 +274,14 @@ local horse = { -- If nothing happened temper_increase = 0 and addition does nothing self.temper = self.temper + temper_increase + --give the player some kind of idea + --of what's happening with the horse's temper + if self.temper <= 100 then + mobs.feed_effect(self) + else + mobs.tamed_effect(self) + end + return end @@ -281,10 +311,6 @@ local horse = { return end - if mobs:protect(self, clicker) then - return - end - -- Make sure tamed horse is mature and being clicked by owner only if self.tamed and not self.child and self.owner == clicker:get_player_name() then @@ -356,9 +382,6 @@ local horse = { self.object:set_properties({stepheight = 1.1}) mobs.attach(self, clicker) - -- Used to capture horse - elseif not self.driver and iname ~= "" then - mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end end end, @@ -418,6 +441,7 @@ mobs:register_mob("mobs_mc:horse", horse) -- Skeleton horse local skeleton_horse = table.copy(horse) +skeleton_horse.description = S("Skeleton Horse") skeleton_horse.breath_max = -1 skeleton_horse.armor = {undead = 100, fleshy = 100} skeleton_horse.textures = {{"blank.png", "mobs_mc_horse_skeleton.png", "blank.png"}} @@ -440,6 +464,7 @@ mobs:register_mob("mobs_mc:skeleton_horse", skeleton_horse) -- Zombie horse local zombie_horse = table.copy(horse) +zombie_horse.description = S("Zombie Horse") zombie_horse.breath_max = -1 zombie_horse.armor = {undead = 100, fleshy = 100} zombie_horse.textures = {{"blank.png", "mobs_mc_horse_zombie.png", "blank.png"}} @@ -464,6 +489,7 @@ mobs:register_mob("mobs_mc:zombie_horse", zombie_horse) -- Donkey local d = 0.86 -- donkey scale local donkey = table.copy(horse) +donkey.description = S("Donkey") donkey.textures = {{"blank.png", "mobs_mc_donkey.png", "blank.png"}} donkey.animation = { speed_normal = 25, @@ -494,6 +520,7 @@ mobs:register_mob("mobs_mc:donkey", donkey) -- Mule local m = 0.94 local mule = table.copy(donkey) +mule.description = S("Mule") mule.textures = {{"blank.png", "mobs_mc_mule.png", "blank.png"}} mule.visual_size = { x=horse.visual_size.x*m, y=horse.visual_size.y*m } mule.sounds = table.copy(donkey.sounds) @@ -515,35 +542,66 @@ mobs:spawn_specific( "overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -4, -mobs_mc.spawn_height.water+3, +0, +minetest.LIGHT_MAX+1, +30, +15000, +4, +mobs_mc.spawn_height.water+3, mobs_mc.spawn_height.overworld_max) mobs:spawn_specific( -"mobs_mc:donkey", -"overworld", +"mobs_mc:donkey", +"overworld", "ground", { "Mesa", @@ -553,12 +611,12 @@ mobs:spawn_specific( "MesaPlateauF_grasstop", "MesaBryce", }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -4, -mobs_mc.spawn_height.water+3, +0, +minetest.LIGHT_MAX+1, +30, +15000, +4, +mobs_mc.spawn_height.water+3, mobs_mc.spawn_height.overworld_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 2ccee2d0a2..48e573e133 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -12,11 +12,15 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:iron_golem", { + description = S("Iron Golem"), type = "npc", spawn_class = "passive", passive = true, + rotate = 270, hp_min = 100, - hp_max = 100, + hp_max = 100, + protect = true, + neutral = true, breath_max = -1, collisionbox = {-0.7, -0.01, -0.7, 0.7, 2.69, 0.7}, visual = "mesh", @@ -39,7 +43,7 @@ mobs:register_mob("mobs_mc:iron_golem", { reach = 3, group_attack = true, attacks_monsters = true, - attack_type = "dogfight", + attack_type = "punch", drops = { {name = mobs_mc.items.iron_ingot, chance = 1, diff --git a/mods/ENTITIES/mobs_mc/llama.lua b/mods/ENTITIES/mobs_mc/llama.lua index 8ff82b502a..58f565ec10 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -25,8 +25,18 @@ local carpets = { } mobs:register_mob("mobs_mc:llama", { + description = S("Llama"), type = "animal", spawn_class = "passive", + rotate = 270, + neutral = true, + group_attack = true, + attack_type = "projectile", + shoot_arrow = function(self, pos, dir) + -- 2-4 damage per arrow + local dmg = 1 + mobs.shoot_projectile_handling("mobs_mc:spit", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + end, hp_min = 15, hp_max = 30, xp_min = 1, @@ -49,7 +59,11 @@ mobs:register_mob("mobs_mc:llama", { walk_velocity = 1, run_velocity = 4.4, follow_velocity = 4.4, + breed_distance = 1.5, + baby_size = 0.5, + follow_distance = 2, floats = 1, + reach = 6, drops = { {name = mobs_mc.items.leather, chance = 1, @@ -82,7 +96,7 @@ mobs:register_mob("mobs_mc:llama", { look_start = 78, look_end = 108, }, - follow = mobs_mc.follow.llama, + follow = mobs_mc.items.hay_bale, view_range = 16, do_custom = function(self, dtime) @@ -125,30 +139,71 @@ mobs:register_mob("mobs_mc:llama", { return end - local item = clicker:get_wielded_item() - if item:get_name() == mobs_mc.items.hay_bale then - -- Breed with hay bale - if mobs:feed_tame(self, clicker, 1, true, false) then return end - else - -- Feed with anything else - if mobs:feed_tame(self, clicker, 1, false, true) then return end + --owner is broken for this + --we'll make the owner this guy + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + self.tamed = true + self.owner = clicker:get_player_name() + return + end + + --ignore other logic + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return end - if mobs:protect(self, clicker) then return end + -- Make sure tamed llama is mature and being clicked by owner only if self.tamed and not self.child and self.owner == clicker:get_player_name() then + local item = clicker:get_wielded_item() + --safety catch + if not item then + return + end + + + + --put chest on carpeted llama + if self.carpet and not self.chest and item:get_name() == "mcl_chests:chest" then + if not minetest.is_creative_enabled(clicker:get_player_name()) then + item:take_item() + clicker:set_wielded_item(item) + end + + self.base_texture = table.copy(self.base_texture) + self.base_texture[1] = "mobs_mc_llama_chest.png" + self.object:set_properties({ + textures = self.base_texture, + }) + self.chest = true + + return --don't attempt to ride + end + + -- Place carpet - --[[ TODO: Re-enable this code when carpet textures arrived. - if minetest.get_item_group(item:get_name(), "carpet") == 1 and not self.carpet then + --TODO: Re-enable this code when carpet textures arrived. + if minetest.get_item_group(item:get_name(), "carpet") == 1 then + for group, carpetdata in pairs(carpets) do if minetest.get_item_group(item:get_name(), group) == 1 then if not minetest.is_creative_enabled(clicker:get_player_name()) then item:take_item() clicker:set_wielded_item(item) + + --shoot off old carpet + if self.carpet then + minetest.add_item(self.object:get_pos(), self.carpet) + end end + local substr = carpetdata[2] local tex_carpet = "mobs_mc_llama_decor_"..substr..".png" + self.base_texture = table.copy(self.base_texture) self.base_texture[2] = tex_carpet self.object:set_properties({ @@ -169,23 +224,21 @@ mobs:register_mob("mobs_mc:llama", { end end end - ]] - -- detatch player already riding llama - if self.driver and clicker == self.driver then + if self.carpet then + -- detatch player already riding llama + if self.driver and clicker == self.driver then - mobs.detach(clicker, {x = 1, y = 0, z = 1}) + mobs.detach(clicker, {x = 1, y = 0, z = 1}) - -- attach player to llama - elseif not self.driver then + -- attach player to llama + elseif not self.driver then - self.object:set_properties({stepheight = 1.1}) - mobs.attach(self, clicker) + self.object:set_properties({stepheight = 1.1}) + mobs.attach(self, clicker) + end end - -- Used to capture llama - elseif not self.driver and clicker:get_wielded_item():get_name() ~= "" then - mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end end, @@ -229,13 +282,48 @@ mobs:spawn_specific( "MesaPlateauF_grasstop", "MesaBryce", }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -5, -mobs_mc.spawn_height.water+15, +0, +minetest.LIGHT_MAX+1, +30, +15000, +5, +mobs_mc.spawn_height.water+15, mobs_mc.spawn_height.overworld_max) -- spawn eggs mobs:register_egg("mobs_mc:llama", S("Llama"), "mobs_mc_spawn_icon_llama.png", 0) + + +-- llama spit +mobs:register_arrow("mobs_mc:spit", { + visual = "sprite", + visual_size = {x = 0.3, y = 0.3}, + textures = {"mobs_mc_spit.png"}, + velocity = 1, + speed = 1, + tail = 1, + tail_texture = "mobs_mc_spit.png", + tail_size = 2, + tail_distance_divider = 4, + + hit_player = function(self, player) + if rawget(_G, "armor") and armor.last_damage_types then + armor.last_damage_types[player:get_player_name()] = "spit" + end + player:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = self._damage}, + }, nil) + end, + + hit_mob = function(self, mob) + mob:punch(self.object, 1.0, { + full_punch_interval = 1.0, + damage_groups = {fleshy = _damage}, + }, nil) + end, + + hit_node = function(self, pos, node) + --does nothing + end +}) \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/models/attributes.txt b/mods/ENTITIES/mobs_mc/models/attributes.txt new file mode 100644 index 0000000000..ec59e0f702 --- /dev/null +++ b/mods/ENTITIES/mobs_mc/models/attributes.txt @@ -0,0 +1 @@ +Ghast fixed by epCode - Thanks! \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_ghast.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_ghast.b3d index cebc037c05..ab34f334f8 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_ghast.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_ghast.b3d differ diff --git a/mods/ENTITIES/mobs_mc/models/mobs_mc_slime.b3d b/mods/ENTITIES/mobs_mc/models/mobs_mc_slime.b3d index 18cc3d6294..b426ee23da 100644 Binary files a/mods/ENTITIES/mobs_mc/models/mobs_mc_slime.b3d and b/mods/ENTITIES/mobs_mc/models/mobs_mc_slime.b3d differ diff --git a/mods/ENTITIES/mobs_mc/ocelot.lua b/mods/ENTITIES/mobs_mc/ocelot.lua index f3c8c87ae1..e36abec771 100644 --- a/mods/ENTITIES/mobs_mc/ocelot.lua +++ b/mods/ENTITIES/mobs_mc/ocelot.lua @@ -27,9 +27,12 @@ end -- Ocelot local ocelot = { + description = S("Ocelot"), type = "animal", spawn_class = "passive", can_despawn = true, + rotate = 270, + skittish = true, hp_min = 10, hp_max = 10, xp_min = 1, @@ -42,7 +45,7 @@ local ocelot = { makes_footstep_sound = true, walk_chance = default_walk_chance, walk_velocity = 1, - run_velocity = 3, + run_velocity = 10, follow_velocity = 1, floats = 1, runaway = true, @@ -56,7 +59,7 @@ local ocelot = { }, animation = { speed_normal = 25, - run_speed = 50, + run_speed = 150, stand_start = 0, stand_end = 0, walk_start = 0, @@ -102,6 +105,7 @@ mobs:register_mob("mobs_mc:ocelot", ocelot) -- Cat local cat = table.copy(ocelot) +cat.description = S("Cat") cat.textures = {{"mobs_mc_cat_black.png"}, {"mobs_mc_cat_red.png"}, {"mobs_mc_cat_siamese.png"}} cat.can_despawn = false cat.owner = "" @@ -121,8 +125,6 @@ cat.sounds = { } cat.on_rightclick = function(self, clicker) if mobs:feed_tame(self, clicker, 1, true, false) then return end - if mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end - if mobs:protect(self, clicker) then return end if self.child then return end @@ -154,8 +156,8 @@ local base_spawn_chance = 5000 -- Spawn ocelot --they get the same as the llama because I'm trying to rework so much of this code right now -j4i mobs:spawn_specific( -"mobs_mc:ocelot", -"overworld", +"mobs_mc:ocelot", +"overworld", "ground", { "Jungle", @@ -163,12 +165,12 @@ mobs:spawn_specific( "JungleM", "JungleEdge", }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -5, -mobs_mc.spawn_height.water+15, +0, +minetest.LIGHT_MAX+1, +30, +15000, +5, +mobs_mc.spawn_height.water+15, mobs_mc.spawn_height.overworld_max) --[[ mobs:spawn({ @@ -183,7 +185,7 @@ mobs:spawn({ max_height = mobs_mc.spawn_height.overworld_max, on_spawn = function(self, pos) Note: Minecraft has a 1/3 spawn failure rate. - In this mod it is emulated by reducing the spawn rate accordingly (see above). + In this mod it is emulated by reducing the spawn rate accordingly (see above). -- 1/7 chance to spawn 2 ocelot kittens if pr:next(1,7) == 1 then diff --git a/mods/ENTITIES/mobs_mc/parrot.lua b/mods/ENTITIES/mobs_mc/parrot.lua index 5efcb191b4..de52c62523 100644 --- a/mods/ENTITIES/mobs_mc/parrot.lua +++ b/mods/ENTITIES/mobs_mc/parrot.lua @@ -12,6 +12,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:parrot", { + description = S("Parrot"), type = "npc", spawn_class = "passive", pathfinding = 1, @@ -19,11 +20,14 @@ mobs:register_mob("mobs_mc:parrot", { hp_max = 6, xp_min = 1, xp_max = 3, - collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.89, 0.25}, + tilt_fly = true, + collisionbox = {-0.25, 0, -0.25, 0.25, 0.9, 0.25}, + eye_height = 0.45, visual = "mesh", mesh = "mobs_mc_parrot.b3d", textures = {{"mobs_mc_parrot_blue.png"},{"mobs_mc_parrot_green.png"},{"mobs_mc_parrot_grey.png"},{"mobs_mc_parrot_red_blue.png"},{"mobs_mc_parrot_yellow_blue.png"}}, visual_size = {x=3, y=3}, + rotate = 270, walk_velocity = 3, run_velocity = 5, sounds = { @@ -84,8 +88,6 @@ mobs:register_mob("mobs_mc:parrot", { -- Feed to tame, but not breed if mobs:feed_tame(self, clicker, 1, false, true) then return end - if mobs:protect(self, clicker) then return end - if mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end end, }) @@ -93,7 +95,7 @@ mobs:register_mob("mobs_mc:parrot", { -- Parrots spawn rarely in jungles. TODO: Also check for jungle *biome* <- I'll get to this eventually -j4i mobs:spawn_specific( "mobs_mc:parrot", -"overworld", +"overworld", "ground", { "Jungle", @@ -101,12 +103,12 @@ mobs:spawn_specific( "JungleM", "JungleEdge", }, -0, -minetest.LIGHT_MAX+1, -7, -30000, -1, -mobs_mc.spawn_height.water+7, +0, +minetest.LIGHT_MAX+1, +7, +30000, +1, +mobs_mc.spawn_height.water+7, mobs_mc.spawn_height.overworld_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index b7cdf1afe9..d7433a092d 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -3,9 +3,11 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:pig", { + description = S("Pig"), type = "animal", spawn_class = "passive", - runaway = true, + skittish = true, + rotate = 270, hp_min = 10, hp_max = 10, xp_min = 1, @@ -18,11 +20,30 @@ mobs:register_mob("mobs_mc:pig", { "mobs_mc_pig.png", -- base "blank.png", -- saddle }}, + + --head code + has_head = true, + head_bone = "head", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + visual_size = {x=2.5, y=2.5}, makes_footstep_sound = true, walk_velocity = 1, run_velocity = 3, follow_velocity = 3.4, + breed_distance = 1.5, + baby_size = 0.5, + follow_distance = 2, drops = { {name = mobs_mc.items.porkchop_raw, chance = 1, @@ -49,7 +70,7 @@ mobs:register_mob("mobs_mc:pig", { run_start = 0, run_end = 40, }, - follow = mobs_mc.follow.pig, + follow = "mcl_farming:carrot_item", view_range = 8, do_custom = function(self, dtime) @@ -90,12 +111,17 @@ mobs:register_mob("mobs_mc:pig", { return end - local wielditem = clicker:get_wielded_item() - -- Feed pig - if wielditem:get_name() ~= mobs_mc.items.carrot_on_a_stick then - if mobs:feed_tame(self, clicker, 1, true, true) then return end + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + return + end + + --ignore other logic + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return end - if mobs:protect(self, clicker) then return end if self.child then return @@ -103,6 +129,8 @@ mobs:register_mob("mobs_mc:pig", { -- Put saddle on pig local item = clicker:get_wielded_item() + local wielditem = item + if item:get_name() == mobs_mc.items.saddle and self.saddle ~= "yes" then self.base_texture = { "blank.png", -- baby @@ -163,10 +191,6 @@ mobs:register_mob("mobs_mc:pig", { inv:set_stack("main",self.driver:get_wield_index(), wielditem) end return - - -- Capture pig - elseif not self.driver and clicker:get_wielded_item():get_name() ~= "" then - mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) end end, @@ -183,33 +207,64 @@ mobs:register_mob("mobs_mc:pig", { }) mobs:spawn_specific( -"mobs_mc:pig", -"overworld", +"mobs_mc:pig", +"overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -9, -minetest.LIGHT_MAX+1, -30, -15000, -8, -mobs_mc.spawn_height.overworld_min, +9, +minetest.LIGHT_MAX+1, +30, +15000, +8, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/polar_bear.lua b/mods/ENTITIES/mobs_mc/polar_bear.lua index 5d2853f6d2..0476229b50 100644 --- a/mods/ENTITIES/mobs_mc/polar_bear.lua +++ b/mods/ENTITIES/mobs_mc/polar_bear.lua @@ -8,6 +8,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:polar_bear", { + description = S("Polar Bear"), type = "animal", spawn_class = "passive", runaway = false, @@ -30,14 +31,14 @@ mobs:register_mob("mobs_mc:polar_bear", { walk_velocity = 1.2, run_velocity = 2.4, group_attack = true, - attack_type = "dogfight", + attack_type = "punch", drops = { -- 3/4 chance to drop raw fish (poor approximation) {name = mobs_mc.items.fish_raw, chance = 2, min = 0, max = 2, - looting = "common",}, + looting = "common",}, -- 1/4 to drop raw salmon {name = mobs_mc.items.salmon_raw, chance = 4, diff --git a/mods/ENTITIES/mobs_mc/rabbit.lua b/mods/ENTITIES/mobs_mc/rabbit.lua index 74bdffcd80..90d5c27bf0 100644 --- a/mods/ENTITIES/mobs_mc/rabbit.lua +++ b/mods/ENTITIES/mobs_mc/rabbit.lua @@ -3,11 +3,12 @@ local S = minetest.get_translator("mobs_mc") local rabbit = { + description = S("Rabbit"), type = "animal", spawn_class = "passive", passive = true, reach = 1, - + rotate = 270, hp_min = 3, hp_max = 3, xp_min = 1, @@ -61,8 +62,6 @@ local rabbit = { on_rightclick = function(self, clicker) -- Feed, tame protect or capture if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end - if mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end end, do_custom = function(self) -- Easter egg: Change texture if rabbit is named “Toast” @@ -83,6 +82,7 @@ mobs:register_mob("mobs_mc:rabbit", rabbit) -- The killer bunny (Only with spawn egg) local killer_bunny = table.copy(rabbit) +killer_bunny.description = S("Killer Bunny") killer_bunny.type = "monster" killer_bunny.spawn_class = "hostile" killer_bunny.attack_type = "dogfight" @@ -110,33 +110,64 @@ mobs:register_mob("mobs_mc:killer_bunny", killer_bunny) -- Different skins depending on spawn location <- we'll get to this when the spawning algorithm is fleshed out mobs:spawn_specific( -"mobs_mc:rabbit", -"overworld", +"mobs_mc:rabbit", +"overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -9, -minetest.LIGHT_MAX+1, -30, -15000, -8, -mobs_mc.spawn_height.overworld_min, +9, +minetest.LIGHT_MAX+1, +30, +15000, +8, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) --[[ diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index d82df8cf9d..1527fd6dac 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -56,14 +56,20 @@ local gotten_texture = { "blank.png", "mobs_mc_sheep.png" } --mcsheep mobs:register_mob("mobs_mc:sheep", { + description = S("Sheep"), type = "animal", spawn_class = "passive", hp_min = 8, hp_max = 8, xp_min = 1, xp_max = 3, + skittish = true, + breed_distance = 1.5, + baby_size = 0.5, + follow_distance = 2, + follow = mobs_mc.items.wheat, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45}, - + rotate = 270, visual = "mesh", visual_size = {x=3, y=3}, mesh = "mobs_mc_sheepfur.b3d", @@ -72,6 +78,23 @@ mobs:register_mob("mobs_mc:sheep", { color = "unicolor_white", makes_footstep_sound = true, walk_velocity = 1, + run_velocity = 3, + + --head code + has_head = true, + head_bone = "head", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 3.6, + head_bone_pos_z = -0.6, + + head_height_offset = 1.0525, + head_direction_offset = 0.5, + head_pitch_modifier = 0, + --end head code + drops = { {name = mobs_mc.items.mutton_raw, chance = 1, @@ -98,7 +121,6 @@ mobs:register_mob("mobs_mc:sheep", { walk_start = 0, walk_end = 40, run_start = 0, run_end = 40, }, - follow = mobs_mc.follow.sheep, view_range = 12, -- Eat grass @@ -194,8 +216,16 @@ mobs:register_mob("mobs_mc:sheep", { on_rightclick = function(self, clicker) local item = clicker:get_wielded_item() - if mobs:feed_tame(self, clicker, 1, true, true) then return end - if mobs:protect(self, clicker) then return end + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then + return + end + + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) + return + end if item:get_name() == mobs_mc.items.shears and not self.gotten and not self.child then self.gotten = true @@ -251,7 +281,6 @@ mobs:register_mob("mobs_mc:sheep", { end return end - if mobs:capture_mob(self, clicker, 0, 5, 70, false, nil) then return end end, on_breed = function(parent1, parent2) -- Breed sheep and choose a fur color for the child. @@ -308,30 +337,62 @@ mobs:spawn_specific( "overworld", "ground", { -"FlowerForest", -"Swampland", -"Taiga", -"ExtremeHills", -"BirchForest", -"MegaSpruceTaiga", -"MegaTaiga", -"ExtremeHills+", -"Forest", -"Plains", -"ColdTaiga", -"SunflowerPlains", -"RoofedForest", -"MesaPlateauFM_grasstop", -"ExtremeHillsM", -"BirchForestM", + "FlowerForest_beach", + "Forest_beach", + "StoneBeach", + "ColdTaiga_beach_water", + "Taiga_beach", + "Savanna_beach", + "Plains_beach", + "ExtremeHills_beach", + "ColdTaiga_beach", + "Swampland_shore", + "JungleM_shore", + "Jungle_shore", + "MesaPlateauFM_sandlevel", + "MesaPlateauF_sandlevel", + "MesaBryce_sandlevel", + "Mesa_sandlevel", + "Mesa", + "FlowerForest", + "Swampland", + "Taiga", + "ExtremeHills", + "Jungle", + "Savanna", + "BirchForest", + "MegaSpruceTaiga", + "MegaTaiga", + "ExtremeHills+", + "Forest", + "Plains", + "Desert", + "ColdTaiga", + "IcePlainsSpikes", + "SunflowerPlains", + "IcePlains", + "RoofedForest", + "ExtremeHills+_snowtop", + "MesaPlateauFM_grasstop", + "JungleEdgeM", + "ExtremeHillsM", + "JungleM", + "BirchForestM", + "MesaPlateauF", + "MesaPlateauFM", + "MesaPlateauF_grasstop", + "MesaBryce", + "JungleEdge", + "SavannaM", }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -3, -mobs_mc.spawn_height.overworld_min, +0, +minetest.LIGHT_MAX+1, +30, +15000, +3, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- spawn eggs mobs:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0) + diff --git a/mods/ENTITIES/mobs_mc/shulker.lua b/mods/ENTITIES/mobs_mc/shulker.lua index 8000d0937b..9932c5adda 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -10,11 +10,12 @@ local S = minetest.get_translator("mobs_mc") --################### -- animation 45-80 is transition between passive and attack stance - + mobs:register_mob("mobs_mc:shulker", { + description = S("Shulker"), type = "monster", spawn_class = "hostile", - attack_type = "shoot", + attack_type = "projectile", shoot_interval = 0.5, arrow = "mobs_mc:shulkerbullet", shoot_offset = 0.5, @@ -82,16 +83,16 @@ mobs:register_arrow("mobs_mc:shulkerbullet", { mobs:register_egg("mobs_mc:shulker", S("Shulker"), "mobs_mc_spawn_icon_shulker.png", 0) mobs:spawn_specific( -"mobs_mc:shulker", -"end", +"mobs_mc:shulker", +"end", "ground", { "End" }, -0, -minetest.LIGHT_MAX+1, -30, -5000, -2, -mobs_mc.spawn_height.end_min, +0, +minetest.LIGHT_MAX+1, +30, +5000, +2, +mobs_mc.spawn_height.end_min, mobs_mc.spawn_height.end_max) diff --git a/mods/ENTITIES/mobs_mc/silverfish.lua b/mods/ENTITIES/mobs_mc/silverfish.lua index 433211503b..148c4c722d 100644 --- a/mods/ENTITIES/mobs_mc/silverfish.lua +++ b/mods/ENTITIES/mobs_mc/silverfish.lua @@ -5,6 +5,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:silverfish", { + description = S("Silverfish"), type = "monster", spawn_class = "hostile", passive = false, @@ -43,7 +44,7 @@ mobs:register_mob("mobs_mc:silverfish", { run_start = 0, run_end = 20, }, view_range = 16, - attack_type = "dogfight", + attack_type = "punch", damage = 1, reach = 1, }) diff --git a/mods/ENTITIES/mobs_mc/skeleton+stray.lua b/mods/ENTITIES/mobs_mc/skeleton+stray.lua index 05b829bcd0..37b1fc6ddb 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -13,13 +13,18 @@ local mod_bows = minetest.get_modpath("mcl_bows") ~= nil local skeleton = { + description = S("Skeleton"), type = "monster", spawn_class = "hostile", + hostile = true, + rotate = 270, hp_min = 20, hp_max = 20, xp_min = 6, xp_max = 6, breath_max = -1, + eye_height = 1.5, + projectile_cooldown = 1.5, armor = {undead = 100, fleshy = 100}, collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.98, 0.3}, pathfinding = 1, @@ -30,6 +35,22 @@ local skeleton = { "mcl_bows_bow_0.png", -- bow "mobs_mc_skeleton.png", -- skeleton } }, + + --head code + has_head = false, + head_bone = "head", + + swap_y_with_x = true, + reverse_head_yaw = true, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + visual_size = {x=1, y=1}, makes_footstep_sound = true, textures = { @@ -42,7 +63,7 @@ local skeleton = { walk_velocity = 1.2, run_velocity = 2.4, damage = 2, - reach = 2, + reach = 3, drops = { {name = mobs_mc.items.arrow, chance = 1, @@ -74,6 +95,8 @@ local skeleton = { walk_speed = 15, walk_start = 40, walk_end = 60, + run_start = 40, + run_end = 60, run_speed = 30, shoot_start = 70, shoot_end = 90, @@ -85,13 +108,13 @@ local skeleton = { ignited_by_sunlight = true, view_range = 16, fear_height = 4, - attack_type = "dogshoot", + attack_type = "projectile", arrow = "mcl_bows:arrow_entity", shoot_arrow = function(self, pos, dir) if mod_bows then -- 2-4 damage per arrow - local dmg = math.max(4, math.random(2, 8)) - mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + local dmg = math.random(2,4) + mobs.shoot_projectile_handling("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end end, shoot_interval = 2, @@ -109,6 +132,7 @@ mobs:register_mob("mobs_mc:skeleton", skeleton) --################### local stray = table.copy(skeleton) +stray.description = S("Stray") stray.mesh = "mobs_mc_skeleton.b3d" stray.textures = { { diff --git a/mods/ENTITIES/mobs_mc/skeleton_wither.lua b/mods/ENTITIES/mobs_mc/skeleton_wither.lua index c089850f48..279a1d8cbb 100644 --- a/mods/ENTITIES/mobs_mc/skeleton_wither.lua +++ b/mods/ENTITIES/mobs_mc/skeleton_wither.lua @@ -10,6 +10,7 @@ local S = minetest.get_translator("mobs_mc") --################### mobs:register_mob("mobs_mc:witherskeleton", { + description = S("Wither Skeleton"), type = "monster", spawn_class = "hostile", hp_min = 20, @@ -86,7 +87,7 @@ mobs:register_mob("mobs_mc:witherskeleton", { fire_damage = 0, light_damage = 0, view_range = 16, - attack_type = "dogfight", + attack_type = "punch", dogshoot_switch = 1, dogshoot_count_max =0.5, fear_height = 4, diff --git a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua index 6c8000a50d..0cae6757dd 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -56,17 +56,18 @@ end -- Slime local slime_big = { + description = S("Slime"), type = "monster", spawn_class = "hostile", - pathfinding = 1, group_attack = { "mobs_mc:slime_big", "mobs_mc:slime_small", "mobs_mc:slime_tiny" }, hp_min = 16, hp_max = 16, xp_min = 4, xp_max = 4, + rotate = 270, collisionbox = {-1.02, -0.01, -1.02, 1.02, 2.03, 1.02}, visual_size = {x=12.5, y=12.5}, - textures = {{"mobs_mc_slime.png"}}, + textures = {{"mobs_mc_slime.png", "mobs_mc_slime.png"}}, visual = "mesh", mesh = "mobs_mc_slime.b3d", makes_footstep_sound = true, @@ -83,23 +84,21 @@ local slime_big = { drops = {}, -- TODO: Fix animations animation = { - speed_normal = 24, - speed_run = 48, - stand_start = 0, - stand_end = 23, - walk_start = 24, - walk_end = 47, - run_start = 48, - run_end = 62, - hurt_start = 64, - hurt_end = 86, - death_start = 88, - death_end = 118, + jump_speed = 17, + stand_speed = 17, + walk_speed = 17, + jump_start = 1, + jump_end = 20, + stand_start = 1, + stand_end = 20, + walk_start = 1, + walk_end = 20, }, fall_damage = 0, view_range = 16, - attack_type = "dogfight", + attack_type = "jump_punch", passive = false, + jump_only = true, jump = true, walk_velocity = 2.5, run_velocity = 2.5, @@ -158,8 +157,8 @@ local smin = mobs_mc.spawn_height.overworld_min local smax = mobs_mc.spawn_height.water - 23 mobs:spawn_specific( -"mobs_mc:slime_tiny", -"overworld", +"mobs_mc:slime_tiny", +"overworld", "ground", { "FlowerForest_underground", @@ -193,17 +192,17 @@ mobs:spawn_specific( "ExtremeHillsM_underground", "JungleEdgeM_underground", }, -0, -minetest.LIGHT_MAX+1, -30, -12000, -4, -smin, +0, +minetest.LIGHT_MAX+1, +30, +12000, +4, +smin, smax) mobs:spawn_specific( -"mobs_mc:slime_small", -"overworld", +"mobs_mc:slime_small", +"overworld", "ground", { "FlowerForest_underground", @@ -236,19 +235,19 @@ mobs:spawn_specific( "JungleM_underground", "ExtremeHillsM_underground", "JungleEdgeM_underground", -}, -0, -minetest.LIGHT_MAX+1, -30, -8500, -4, -smin, +}, +0, +minetest.LIGHT_MAX+1, +30, +8500, +4, +smin, smax) mobs:spawn_specific( -"mobs_mc:slime_big", -"overworld", -"ground", +"mobs_mc:slime_big", +"overworld", +"ground", { "FlowerForest_underground", "JungleEdge_underground", @@ -281,16 +280,17 @@ mobs:spawn_specific( "ExtremeHillsM_underground", "JungleEdgeM_underground", }, -0, -minetest.LIGHT_MAX+1, -30, -10000, -4, -smin, +0, +minetest.LIGHT_MAX+1, +30, +10000, +4, +smin, smax) -- Magma cube local magma_cube_big = { + description = S("Magma Cube"), type = "monster", spawn_class = "hostile", hp_min = 16, @@ -299,7 +299,7 @@ local magma_cube_big = { xp_max = 4, collisionbox = {-1.02, -0.01, -1.02, 1.02, 2.03, 1.02}, visual_size = {x=12.5, y=12.5}, - textures = {{ "mobs_mc_magmacube.png" }}, + textures = {{ "mobs_mc_magmacube.png", "mobs_mc_magmacube.png" }}, visual = "mesh", mesh = "mobs_mc_magmacube.b3d", makes_footstep_sound = true, @@ -311,6 +311,7 @@ local magma_cube_big = { }, walk_velocity = 4, run_velocity = 4, + rotate = 270, damage = 6, reach = 3, armor = 53, @@ -322,27 +323,25 @@ local magma_cube_big = { }, -- TODO: Fix animations animation = { - speed_normal = 24, - speed_run = 48, - stand_start = 0, - stand_end = 23, - walk_start = 24, - walk_end = 47, - run_start = 48, - run_end = 62, - hurt_start = 64, - hurt_end = 86, - death_start = 88, - death_end = 118, + jump_speed = 20, + stand_speed = 20, + walk_speed = 20, + jump_start = 1, + jump_end = 40, + stand_start = 1, + stand_end = 1, + walk_start = 1, + walk_end = 40, }, water_damage = 0, lava_damage = 0, - fire_damage = 0, + fire_damage = 0, light_damage = 0, fall_damage = 0, view_range = 16, - attack_type = "dogfight", + attack_type = "jump_punch", passive = false, + jump_only = true, jump = true, jump_height = 8, walk_chance = 0, @@ -401,49 +400,49 @@ local mmin = mobs_mc.spawn_height.nether_min local mmax = mobs_mc.spawn_height.nether_max mobs:spawn_specific( -"mobs_mc:magma_cube_tiny", -"nether", +"mobs_mc:magma_cube_tiny", +"nether", "ground", { "Nether" }, -0, -minetest.LIGHT_MAX+1, -30, -15000, -4, -mmin, +0, +minetest.LIGHT_MAX+1, +30, +15000, +4, +mmin, mmax) mobs:spawn_specific( -"mobs_mc:magma_cube_small", -"nether", +"mobs_mc:magma_cube_small", +"nether", "ground", { "Nether" }, -0, -minetest.LIGHT_MAX+1, -30, -15500, -4, -mmin, +0, +minetest.LIGHT_MAX+1, +30, +15500, +4, +mmin, mmax) mobs:spawn_specific( -"mobs_mc:magma_cube_big", -"nether", +"mobs_mc:magma_cube_big", +"nether", "ground", { "Nether" -}, -0, -minetest.LIGHT_MAX+1, -30, -16000, -4, -mmin, +}, +0, +minetest.LIGHT_MAX+1, +30, +16000, +4, +mmin, mmax) --mobs:spawn_specific("mobs_mc:magma_cube_tiny", mobs_mc.spawn.nether_fortress, {"air"}, 0, minetest.LIGHT_MAX+1, 30, 11000, 4, mmin, mmax) diff --git a/mods/ENTITIES/mobs_mc/snowman.lua b/mods/ENTITIES/mobs_mc/snowman.lua index 1ee88b3623..93f91c3303 100644 --- a/mods/ENTITIES/mobs_mc/snowman.lua +++ b/mods/ENTITIES/mobs_mc/snowman.lua @@ -21,6 +21,7 @@ local gotten_texture = { } mobs:register_mob("mobs_mc:snowman", { + description = S("Snow Golem"), type = "npc", spawn_class = "passive", passive = true, diff --git a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.4.ogg b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.4.ogg index 5c9ee492ba..acb236445e 100644 Binary files a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.4.ogg and b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.4.ogg differ diff --git a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.5.ogg b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.5.ogg index acb236445e..1ef7a52274 100644 Binary files a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.5.ogg and b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.5.ogg differ diff --git a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.6.ogg b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.6.ogg index 1ef7a52274..c2743fbcc6 100644 Binary files a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.6.ogg and b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.6.ogg differ diff --git a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.7.ogg b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.7.ogg deleted file mode 100644 index c2743fbcc6..0000000000 Binary files a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager.7.ogg and /dev/null differ diff --git a/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager_hurt.1.ogg b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager_hurt.1.ogg new file mode 100644 index 0000000000..5c9ee492ba Binary files /dev/null and b/mods/ENTITIES/mobs_mc/sounds/mobs_mc_villager_hurt.1.ogg differ diff --git a/mods/ENTITIES/mobs_mc/spider.lua b/mods/ENTITIES/mobs_mc/spider.lua index bb5e29eb1f..6ade915ab6 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -13,20 +13,26 @@ local S = minetest.get_translator("mobs_mc") -- Spider by AspireMint (fishyWET (CC-BY-SA 3.0 license for texture) local spider = { + description = S("Spider"), type = "monster", spawn_class = "hostile", passive = false, + hostile = true, + always_climb = true, docile_by_day = true, - attack_type = "dogfight", - pathfinding = 1, + attack_type = "punch", + punch_timer_cooloff = 0.5, + rotate = 270, damage = 2, reach = 2, hp_min = 16, hp_max = 16, + ignores_cobwebs = true, xp_min = 5, xp_max = 5, + eye_height = 0.475, armor = {fleshy = 100, arthropod = 100}, - collisionbox = {-0.7, -0.01, -0.7, 0.7, 0.89, 0.7}, + collisionbox = {-0.45, 0, -0.45, 0.45, 0.9, 0.45}, visual = "mesh", mesh = "mobs_mc_spider.b3d", textures = { @@ -43,7 +49,7 @@ local spider = { distance = 16, }, walk_velocity = 1.3, - run_velocity = 2.8, + run_velocity = 2.75, --spider can become extremely difficult if any higher jump = true, jump_height = 4, view_range = 16, @@ -72,6 +78,7 @@ mobs:register_mob("mobs_mc:spider", spider) -- Cave spider local cave_spider = table.copy(spider) +cave_spider.description = S("Cave Spider") cave_spider.textures = { {"mobs_mc_cave_spider.png^(mobs_mc_spider_eyes.png^[makealpha:0,0,0)"} } -- TODO: Poison damage -- TODO: Revert damage to 2 @@ -88,8 +95,8 @@ mobs:register_mob("mobs_mc:cave_spider", cave_spider) mobs:spawn_specific( -"mobs_mc:spider", -"overworld", +"mobs_mc:spider", +"overworld", "ground", { "Mesa", @@ -232,12 +239,12 @@ mobs:spawn_specific( "ExtremeHillsM_underground", "JungleEdgeM_underground", }, -0, -7, -30, -17000, -2, -mobs_mc.spawn_height.overworld_min, +0, +7, +30, +17000, +2, +mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max) -- spawn eggs diff --git a/mods/ENTITIES/mobs_mc/squid.lua b/mods/ENTITIES/mobs_mc/squid.lua index cf794ea5bf..55d4b05c3d 100644 --- a/mods/ENTITIES/mobs_mc/squid.lua +++ b/mods/ENTITIES/mobs_mc/squid.lua @@ -7,6 +7,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:squid", { + description = S("Squid"), type = "animal", spawn_class = "water", can_despawn = true, @@ -16,6 +17,8 @@ mobs:register_mob("mobs_mc:squid", { xp_min = 1, xp_max = 3, armor = 100, + rotate = 270, + tilt_swim = true, -- FIXME: If the squid is near the floor, it turns black collisionbox = {-0.4, 0.0, -0.4, 0.4, 0.9, 0.4}, visual = "mesh", @@ -47,8 +50,7 @@ mobs:register_mob("mobs_mc:squid", { }, visual_size = {x=3, y=3}, makes_footstep_sound = false, - fly = true, - fly_in = { mobs_mc.items.water_source, mobs_mc.items.river_water_source }, + swim = true, breathes_in_water = true, jump = false, view_range = 16, diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_chest.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_chest.png new file mode 100644 index 0000000000..e0715af9f0 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_chest.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_black.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_black.png new file mode 100644 index 0000000000..40c39648f4 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_black.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_blue.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_blue.png new file mode 100644 index 0000000000..b02c41b266 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_blue.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_brown.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_brown.png new file mode 100644 index 0000000000..2c7c71c2fa Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_brown.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_cyan.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_cyan.png new file mode 100644 index 0000000000..83f7a8faa1 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_cyan.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_gray.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_gray.png new file mode 100644 index 0000000000..a4bd9cb1f0 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_gray.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_green.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_green.png new file mode 100644 index 0000000000..c3297ce942 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_green.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_blue.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_blue.png new file mode 100644 index 0000000000..71eabea536 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_blue.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_gray.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_gray.png new file mode 100644 index 0000000000..929a609507 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_light_gray.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_lime.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_lime.png new file mode 100644 index 0000000000..1507d6d795 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_lime.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_magenta.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_magenta.png new file mode 100644 index 0000000000..809e645fb6 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_magenta.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_orange.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_orange.png new file mode 100644 index 0000000000..ff17ff67c3 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_orange.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_pink.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_pink.png new file mode 100644 index 0000000000..7009e6efc5 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_pink.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_purple.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_purple.png new file mode 100644 index 0000000000..1de65a407f Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_purple.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_red.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_red.png new file mode 100644 index 0000000000..645df49779 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_red.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_white.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_white.png new file mode 100644 index 0000000000..c6ae669dd8 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_white.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_yellow.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_yellow.png new file mode 100644 index 0000000000..6318e163d7 Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_llama_decor_yellow.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_slime.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_slime.png index 278fafb9d7..5a30e16fd9 100644 Binary files a/mods/ENTITIES/mobs_mc/textures/mobs_mc_slime.png and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_slime.png differ diff --git a/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png new file mode 100644 index 0000000000..6cdb3e0b3c Binary files /dev/null and b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png differ diff --git a/mods/ENTITIES/mobs_mc/vex.lua b/mods/ENTITIES/mobs_mc/vex.lua index cccdebe7a5..c23643cda0 100644 --- a/mods/ENTITIES/mobs_mc/vex.lua +++ b/mods/ENTITIES/mobs_mc/vex.lua @@ -10,11 +10,12 @@ local S = minetest.get_translator("mobs_mc") --################### mobs:register_mob("mobs_mc:vex", { + description = S("Vex"), type = "monster", spawn_class = "hostile", pathfinding = 1, passive = false, - attack_type = "dogfight", + attack_type = "punch", physical = false, hp_min = 14, hp_max = 14, diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index ab79edfec0..154e9411fb 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -927,6 +927,7 @@ end) --[=======[ MOB REGISTRATION AND SPAWNING ]=======] mobs:register_mob("mobs_mc:villager", { + description = S("Villager"), type = "npc", spawn_class = "passive", hp_min = 20, @@ -961,14 +962,18 @@ mobs:register_mob("mobs_mc:villager", { }, }, visual_size = {x=2.75, y=2.75}, + rotate = 270, + skittish = true, makes_footstep_sound = true, walk_velocity = 1.2, - run_velocity = 2.4, + run_velocity = 3, drops = {}, can_despawn = false, -- TODO: sounds sounds = { random = "mobs_mc_villager", + damage = "mobs_mc_villager_hurt", + death = "mobs_mc_villager_hurt", distance = 10, }, animation = { diff --git a/mods/ENTITIES/mobs_mc/villager_evoker.lua b/mods/ENTITIES/mobs_mc/villager_evoker.lua index abe0e9ca2b..f87483e2bc 100644 --- a/mods/ENTITIES/mobs_mc/villager_evoker.lua +++ b/mods/ENTITIES/mobs_mc/villager_evoker.lua @@ -12,6 +12,7 @@ local S = minetest.get_translator("mobs_mc") local pr = PseudoRandom(os.time()*666) mobs:register_mob("mobs_mc:evoker", { + description = S("Evoker"), type = "monster", spawn_class = "hostile", physical = true, @@ -34,7 +35,7 @@ mobs:register_mob("mobs_mc:evoker", { walk_velocity = 0.2, run_velocity = 1.4, group_attack = true, - attack_type = "dogfight", + attack_type = "punch", -- Summon vexes custom_attack = function(self, to_attack) local r = pr:next(2,4) diff --git a/mods/ENTITIES/mobs_mc/villager_illusioner.lua b/mods/ENTITIES/mobs_mc/villager_illusioner.lua index 0bbe2a5f6d..46b8760a1f 100644 --- a/mods/ENTITIES/mobs_mc/villager_illusioner.lua +++ b/mods/ENTITIES/mobs_mc/villager_illusioner.lua @@ -7,9 +7,10 @@ local S = minetest.get_translator("mobs_mc") local mod_bows = minetest.get_modpath("mcl_bows") ~= nil mobs:register_mob("mobs_mc:illusioner", { + description = S("Illusioner"), type = "monster", spawn_class = "hostile", - attack_type = "shoot", + attack_type = "projectile", shoot_interval = 2.5, shoot_offset = 1.5, arrow = "mcl_bows:arrow_entity", @@ -17,7 +18,7 @@ mobs:register_mob("mobs_mc:illusioner", { if mod_bows then -- 1-4 damage per arrow local dmg = math.random(1, 4) - mcl_bows.shoot_arrow("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) + mobs.shoot_projectile_handling("mcl_bows:arrow", pos, dir, self.object:get_yaw(), self.object, nil, dmg) end end, hp_min = 32, diff --git a/mods/ENTITIES/mobs_mc/villager_vindicator.lua b/mods/ENTITIES/mobs_mc/villager_vindicator.lua index 56b295066b..7df54ef58d 100644 --- a/mods/ENTITIES/mobs_mc/villager_vindicator.lua +++ b/mods/ENTITIES/mobs_mc/villager_vindicator.lua @@ -11,6 +11,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:vindicator", { + description = S("Vindicator"), type = "monster", spawn_class = "hostile", physical = false, @@ -36,7 +37,7 @@ mobs:register_mob("mobs_mc:vindicator", { reach = 2, walk_velocity = 1.2, run_velocity = 2.4, - attack_type = "dogfight", + attack_type = "punch", drops = { {name = mobs_mc.items.emerald, chance = 1, diff --git a/mods/ENTITIES/mobs_mc/villager_zombie.lua b/mods/ENTITIES/mobs_mc/villager_zombie.lua index b908236292..450710c49f 100644 --- a/mods/ENTITIES/mobs_mc/villager_zombie.lua +++ b/mods/ENTITIES/mobs_mc/villager_zombie.lua @@ -26,8 +26,12 @@ local professions = { } mobs:register_mob("mobs_mc:villager_zombie", { + description = S("Zombie Villager"), type = "monster", spawn_class = "hostile", + hostile = true, + rotate = 270, + eye_height = 1.65, hp_min = 20, hp_max = 20, xp_min = 5, @@ -50,8 +54,8 @@ mobs:register_mob("mobs_mc:villager_zombie", { damage = 3, reach = 2, walk_velocity = 1.2, - run_velocity = 2.4, - attack_type = "dogfight", + run_velocity = 3.5, + attack_type = "punch", group_attack = true, drops = { {name = mobs_mc.items.rotten_flesh, diff --git a/mods/ENTITIES/mobs_mc/witch.lua b/mods/ENTITIES/mobs_mc/witch.lua index f9f9b8d1f0..0c72d00188 100644 --- a/mods/ENTITIES/mobs_mc/witch.lua +++ b/mods/ENTITIES/mobs_mc/witch.lua @@ -13,6 +13,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:witch", { + description = S("Witch"), type = "monster", spawn_class = "hostile", hp_min = 26, @@ -33,7 +34,7 @@ mobs:register_mob("mobs_mc:witch", { run_velocity = 2.4, pathfinding = 1, group_attack = true, - attack_type = "dogshoot", + attack_type = "projectile", arrow = "mobs_mc:potion_arrow", shoot_interval = 2.5, shoot_offset = 1, diff --git a/mods/ENTITIES/mobs_mc/wither.lua b/mods/ENTITIES/mobs_mc/wither.lua index 2d53cc547f..7c9072f431 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -10,6 +10,7 @@ local S = minetest.get_translator("mobs_mc") --################### mobs:register_mob("mobs_mc:wither", { + description = S("Wither"), type = "monster", spawn_class = "hostile", hp_max = 300, @@ -52,7 +53,7 @@ mobs:register_mob("mobs_mc:wither", { }, lava_damage = 0, fire_damage = 0, - attack_type = "dogshoot", + attack_type = "projectile", explosion_strength = 8, dogshoot_stop = true, arrow = "mobs_mc:wither_skull", diff --git a/mods/ENTITIES/mobs_mc/wolf.lua b/mods/ENTITIES/mobs_mc/wolf.lua index b1c077d465..89a4b46290 100644 --- a/mods/ENTITIES/mobs_mc/wolf.lua +++ b/mods/ENTITIES/mobs_mc/wolf.lua @@ -19,16 +19,35 @@ end -- Wolf local wolf = { + description = S("Wolf"), type = "animal", spawn_class = "passive", can_despawn = true, + neutral = true, hp_min = 8, hp_max = 8, xp_min = 1, xp_max = 3, + rotate = 270, passive = false, group_attack = true, - collisionbox = {-0.3, -0.01, -0.3, 0.3, 0.84, 0.3}, + + --head code + has_head = false, + head_bone = "head", + + swap_y_with_x = false, + reverse_head_yaw = false, + + head_bone_pos_y = 3.6, + head_bone_pos_z = -0.6, + + head_height_offset = 1.0525, + head_direction_offset = 0.5, + head_pitch_modifier = 0, + --end head code + + collisionbox = {-0.3, -0.00, -0.3, 0.3, 0.85, 0.3}, visual = "mesh", mesh = "mobs_mc_wolf.b3d", textures = { @@ -52,7 +71,7 @@ local wolf = { run_velocity = 3, damage = 4, reach = 2, - attack_type = "dogfight", + attack_type = "punch", fear_height = 4, follow = mobs_mc.follow.wolf, on_rightclick = function(self, clicker) @@ -74,6 +93,7 @@ local wolf = { dog:set_yaw(yaw) ent = dog:get_luaentity() ent.owner = clicker:get_player_name() + ent.tamed = true -- cornfirm taming minetest.sound_play("mobs_mc_wolf_bark", {object=dog, max_hear_distance=16}, true) -- Replace wolf @@ -138,20 +158,32 @@ dog.owner = "" -- TODO: Start sitting by default dog.order = "roam" dog.owner_loyal = true -dog.follow_velocity = 3.2 +dog.follow_velocity = 3.2 -- Automatically teleport dog to owner dog.do_custom = mobs_mc.make_owner_teleport_function(12) -dog.follow = mobs_mc.follow.dog dog.attack_animals = nil dog.specific_attack = nil +dog.breed_distance = 1.5 +dog.baby_size = 0.5 +dog.follow_distance = 2 +dog.follow = "mcl_mobitems:beef" + dog.on_rightclick = function(self, clicker) local item = clicker:get_wielded_item() - if mobs:protect(self, clicker) then + --owner is broken for this + --attempt to enter breed state + if mobs.enter_breed_state(self,clicker) then return - elseif item:get_name() ~= "" and mobs:capture_mob(self, clicker, 0, 2, 80, false, nil) then + end + + --make baby grow faster + if self.baby then + mobs.make_baby_grow_faster(self,clicker) return - elseif is_food(item:get_name()) then + end + + if is_food(item:get_name()) then -- Feed to increase health local hp = self.health local hp_add = 0 @@ -254,12 +286,12 @@ mobs:spawn_specific( "ExtremeHillsM", "BirchForestM", }, -0, -minetest.LIGHT_MAX+1, -30, -9000, -7, -mobs_mc.spawn_height.water+3, +0, +minetest.LIGHT_MAX+1, +30, +9000, +7, +mobs_mc.spawn_height.water+3, mobs_mc.spawn_height.overworld_max) mobs:register_egg("mobs_mc:wolf", S("Wolf"), "mobs_mc_spawn_icon_wolf.png", 0) diff --git a/mods/ENTITIES/mobs_mc/zombie.lua b/mods/ENTITIES/mobs_mc/zombie.lua index 1be47848b8..7d0fb14913 100644 --- a/mods/ENTITIES/mobs_mc/zombie.lua +++ b/mods/ENTITIES/mobs_mc/zombie.lua @@ -46,8 +46,11 @@ table.insert(drops_zombie, { }) local zombie = { + description = S("Zombie"), type = "monster", spawn_class = "hostile", + hostile = true, + rotate = 270, hp_min = 20, hp_max = 20, xp_min = 5, @@ -73,8 +76,25 @@ local zombie = { damage = "mobs_mc_zombie_hurt", distance = 16, }, - walk_velocity = .8, - run_velocity = 1.6, + + --head code + has_head = false, + head_bone = "Head", + + swap_y_with_x = true, + reverse_head_yaw = true, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + + eye_height = 1.65, + walk_velocity = 1, + run_velocity = 3.5, damage = 3, reach = 2, fear_height = 4, @@ -92,7 +112,8 @@ local zombie = { ignited_by_sunlight = true, sunlight_damage = 2, view_range = 16, - attack_type = "dogfight", + attack_type = "punch", + punch_timer_cooloff = 0.5, harmed_by_heal = true, } @@ -102,6 +123,7 @@ mobs:register_mob("mobs_mc:zombie", zombie) -- A smaller and more dangerous variant of the zombie local baby_zombie = table.copy(zombie) +baby_zombie.description = S("Baby Zombie") baby_zombie.collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.94, 0.25} baby_zombie.xp_min = 12 baby_zombie.xp_max = 12 @@ -115,6 +137,7 @@ mobs:register_mob("mobs_mc:baby_zombie", baby_zombie) -- Husk. -- Desert variant of the zombie local husk = table.copy(zombie) +husk.description = S("Husk") husk.textures = { { "mobs_mc_empty.png", -- armor @@ -132,6 +155,7 @@ mobs:register_mob("mobs_mc:husk", husk) -- Baby husk. -- A smaller and more dangerous variant of the husk local baby_husk = table.copy(husk) +baby_husk.description = S("Baby Husk") baby_husk.collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.94, 0.25} baby_husk.xp_min = 12 baby_husk.xp_max = 12 diff --git a/mods/ENTITIES/mobs_mc/zombiepig.lua b/mods/ENTITIES/mobs_mc/zombiepig.lua index ebd8ce4856..72a19f4139 100644 --- a/mods/ENTITIES/mobs_mc/zombiepig.lua +++ b/mods/ENTITIES/mobs_mc/zombiepig.lua @@ -11,16 +11,20 @@ local S = minetest.get_translator("mobs_mc") local pigman = { + description = S("Zombie Pigman"), -- type="animal", passive=false: This combination is needed for a neutral mob which becomes hostile, if attacked type = "animal", passive = false, + neutral = true, + rotate = 270, spawn_class = "passive", + hostile_cooldown = 15, --seconds hp_min = 20, hp_max = 20, xp_min = 6, xp_max = 6, armor = {undead = 90, fleshy = 90}, - attack_type = "dogfight", + attack_type = "punch", group_attack = { "mobs_mc:pigman", "mobs_mc:baby_pigman" }, damage = 9, reach = 2, @@ -40,6 +44,22 @@ local pigman = { damage = "mobs_mc_zombiepig_hurt", distance = 16, }, + + --head code + has_head = false, + head_bone = "head", + + swap_y_with_x = true, + reverse_head_yaw = true, + + head_bone_pos_y = 2.4, + head_bone_pos_z = 0, + + head_height_offset = 1.1, + head_direction_offset = 0, + head_pitch_modifier = 0, + --end head code + jump = true, makes_footstep_sound = true, walk_velocity = .8, @@ -94,6 +114,7 @@ mobs:register_mob("mobs_mc:pigman", pigman) -- A smaller and more dangerous variant of the pigman local baby_pigman = table.copy(pigman) +baby_pigman.description = S("Baby Zombie Pigman") baby_pigman.collisionbox = {-0.25, -0.01, -0.25, 0.25, 0.94, 0.25} baby_pigman.xp_min = 13 baby_pigman.xp_max = 13 @@ -112,33 +133,33 @@ mobs:register_mob("mobs_mc:baby_pigman", baby_pigman) -- Regular spawning in the Nether mobs:spawn_specific( -"mobs_mc:pigman", -"nether", +"mobs_mc:pigman", +"nether", "ground", { "Nether" }, -0, +0, minetest.LIGHT_MAX+1, -30, -6000, -3, -mobs_mc.spawn_height.nether_min, +30, +6000, +3, +mobs_mc.spawn_height.nether_min, mobs_mc.spawn_height.nether_max) -- Baby zombie is 20 times less likely than regular zombies mobs:spawn_specific( -"mobs_mc:baby_pigman", -"nether", +"mobs_mc:baby_pigman", +"nether", "ground", { "Nether" -}, -0, -minetest.LIGHT_MAX+1, -30, -100000, -4, -mobs_mc.spawn_height.nether_min, +}, +0, +minetest.LIGHT_MAX+1, +30, +100000, +4, +mobs_mc.spawn_height.nether_min, mobs_mc.spawn_height.nether_max) -- Spawning in Nether portals in the Overworld diff --git a/mods/ENVIRONMENT/lightning/init.lua b/mods/ENVIRONMENT/lightning/init.lua index 345f733d5e..4a58866f98 100644 --- a/mods/ENVIRONMENT/lightning/init.lua +++ b/mods/ENVIRONMENT/lightning/init.lua @@ -11,7 +11,6 @@ of the license, or (at your option) any later version. local S = minetest.get_translator("lightning") -local has_mcl_death_msg = minetest.get_modpath("mcl_death_messages") local get_connected_players = minetest.get_connected_players local line_of_sight = minetest.line_of_sight local get_node = minetest.get_node @@ -139,48 +138,39 @@ lightning.strike = function(pos) for o=1, #objs do local obj = objs[o] local lua = obj:get_luaentity() - if obj:is_player() then - -- Player damage - if has_mcl_death_msg then - mcl_death_messages.player_damage(obj, S("@1 was struck by lightning.", obj:get_player_name())) - end - obj:set_hp(obj:get_hp()-5, { type = "punch", from = "mod" }) - -- Mobs - elseif lua and lua._cmi_is_mob then - -- pig → zombie pigman (no damage) - if lua.name == "mobs_mc:pig" then - local rot = obj:get_yaw() - obj:remove() - obj = add_entity(pos2, "mobs_mc:pigman") - obj:set_yaw(rot) + -- pig → zombie pigman (no damage) + if lua and lua.name == "mobs_mc:pig" then + local rot = obj:get_yaw() + obj:remove() + obj = add_entity(pos2, "mobs_mc:pigman") + obj:set_yaw(rot) -- mooshroom: toggle color red/brown (no damage) - elseif lua.name == "mobs_mc:mooshroom" then - if lua.base_texture[1] == "mobs_mc_mooshroom.png" then - lua.base_texture = { "mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } - else - lua.base_texture = { "mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png" } - end - obj:set_properties({textures = lua.base_texture}) - -- villager → witch (no damage) - elseif lua.name == "mobs_mc:villager" then - -- Witches are incomplete, this code is unused - -- TODO: Enable this code when witches are working. - --[[ - local rot = obj:get_yaw() - obj:remove() - obj = minetest.add_entity(pos2, "mobs_mc:witch") - obj:set_yaw(rot) - ]] - -- charged creeper - elseif lua.name == "mobs_mc:creeper" then - local rot = obj:get_yaw() - obj:remove() - obj = add_entity(pos2, "mobs_mc:creeper_charged") - obj:set_yaw(rot) - -- Other mobs: Just damage + elseif lua and lua.name == "mobs_mc:mooshroom" then + if lua.base_texture[1] == "mobs_mc_mooshroom.png" then + lua.base_texture = { "mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } else - obj:set_hp(obj:get_hp()-5, { type = "punch", from = "mod" }) + lua.base_texture = { "mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png" } end + obj:set_properties({textures = lua.base_texture}) + -- villager → witch (no damage) + elseif lua and lua.name == "mobs_mc:villager" then + -- Witches are incomplete, this code is unused + -- TODO: Enable this code when witches are working. + --[[ + local rot = obj:get_yaw() + obj:remove() + obj = minetest.add_entity(pos2, "mobs_mc:witch") + obj:set_yaw(rot) + ]] + -- charged creeper + elseif lua and lua.name == "mobs_mc:creeper" then + local rot = obj:get_yaw() + obj:remove() + obj = add_entity(pos2, "mobs_mc:creeper_charged") + obj:set_yaw(rot) + -- Other objects: Just damage + else + mcl_util.deal_damage(obj, 5, {type = "lightning_bolt"}) end end diff --git a/mods/ENVIRONMENT/lightning/mod.conf b/mods/ENVIRONMENT/lightning/mod.conf index b0d7563183..346a4a0b9d 100644 --- a/mods/ENVIRONMENT/lightning/mod.conf +++ b/mods/ENVIRONMENT/lightning/mod.conf @@ -2,5 +2,4 @@ name = lightning author = sofar description = A mod that adds thunder and lightning effects. depends = mcl_fire -optional_depends = mcl_death_messages diff --git a/mods/ENVIRONMENT/mcl_void_damage/init.lua b/mods/ENVIRONMENT/mcl_void_damage/init.lua index ee40ed7022..24f7d0e4b6 100644 --- a/mods/ENVIRONMENT/mcl_void_damage/init.lua +++ b/mods/ENVIRONMENT/mcl_void_damage/init.lua @@ -5,7 +5,6 @@ local pos_to_dim = mcl_worlds.pos_to_dimension local dim_change = mcl_worlds.dimension_change local is_in_void = mcl_worlds.is_in_void local get_spawn_pos = mcl_spawn.get_player_spawn_pos -local death_msg = mcl_death_messages.player_damage local send_chat = minetest.chat_send_player local get_connected = minetest.get_connected_players @@ -40,7 +39,6 @@ minetest.register_on_mods_loaded(function() end self._void_timer = 0 - local pos = obj:get_pos() local void, void_deadly = is_in_void(pos) if void_deadly then local ent = obj:get_luaentity() @@ -80,8 +78,7 @@ minetest.register_globalstep(function(dtime) elseif enable_damage and not is_immortal then -- Damage enabled, not immortal: Deal void damage (4 HP / 0.5 seconds) if player:get_hp() > 0 then - death_msg(player, S("@1 fell into the endless void.", player:get_player_name())) - player:set_hp(player:get_hp() - VOID_DAMAGE) + mcl_util.deal_damage(player, VOID_DAMAGE, {type = "out_of_world"}) end end end diff --git a/mods/ENVIRONMENT/mcl_void_damage/mod.conf b/mods/ENVIRONMENT/mcl_void_damage/mod.conf index 3f34fa5a16..1358e52172 100644 --- a/mods/ENVIRONMENT/mcl_void_damage/mod.conf +++ b/mods/ENVIRONMENT/mcl_void_damage/mod.conf @@ -1,4 +1,4 @@ name = mcl_void_damage author = Wuzzy description = Deal damage to entities stuck in the deep void -depends = mcl_worlds, mcl_death_messages +depends = mcl_worlds diff --git a/mods/HELP/doc/doc_items/locale/doc_items.de.tr b/mods/HELP/doc/doc_items/locale/doc_items.de.tr index 90747c38a6..f14c99314b 100644 --- a/mods/HELP/doc/doc_items/locale/doc_items.de.tr +++ b/mods/HELP/doc/doc_items/locale/doc_items.de.tr @@ -10,9 +10,9 @@ # Itemname (ca. 25%) @1 (ca. @2%)=@1 (ca. @2%) # List separator (e.g. “one, two, three”) -, =, +, =, # Final list separator (e.g. “One, two and three”) - and = und + and = und 1 second=1 Sekunde A transparent block, basically empty space. It is usually left behind after digging something.=Ein transparenter Block, praktisch leerer Raum. Er wird üblicherweise hinterlassen, nachdem man etwas ausgegraben hat. Air=Luft @@ -32,7 +32,7 @@ Item reference of items which are neither blocks, tools or weapons (esp. craftin Liquids can flow into this block and destroy it.=Flüssigkeiten können in diesen Block hereinfließen und ihn zerstören. Maximum stack size: @1=Maximale Stapelgröße: @1 Mining level: @1=Grabestufe: @1 -Mining ratings:=Grabewertungen: +Mining ratings:=Grabewertungen: • @1, rating @2: @3 s - @4 s=• @1, Wertung @2: @3 s - @4 s • @1, rating @2: @3 s=• @1, Wertung @2: @3 s Mining times:=Grabezeiten: @@ -76,9 +76,8 @@ This block connects to these blocks: @1.=Dieser Block verbindet sich mit den fol This block connects to this block: @1.=Dieser Block verbindet sich mit diesem Block: @1. This block decreases your breath and causes a drowning damage of @1 hit point every 2 seconds.=Dieser Block reduziert Ihren Atem und verursacht beim Ertrinken einen Schaden von @1 Trefferpunkt alle 2 Sekunden. This block decreases your breath and causes a drowning damage of @1 hit points every 2 seconds.=Dieser Block reduziert Ihren Atem und verursacht beim Ertrinken einen Schaden von @1 Trefferpunkten alle 2 Sekunden. -This block glows faintly. It is barely noticable.=Dieser Block leuchtet schwach. Es ist kaum merklich. This block is a light source with a light level of @1.=Dieser Block ist eine Lichtquelle mit einer Helligkeitsstufe von @1. -This block glows faintly with a light level of @1.=Dieser Block leuchtet schwach mit einer Helligkeitsstufe von @1. +This block glows faintly with a light level of @1.=Dieser Block leuchtet schwach mit einer Helligkeitsstufe von @1. This block is a building block for creating various buildings.=Dieser Block ist für den Bau diverser Gebäude vorgesehen. This block is a liquid with these properties:=Dieser Block ist eine Flüssigkeit mit folgenden Eigenschaften: This block is affected by gravity and can fall.=Dieser Block wird von der Schwerkraft beeinflusst und kann fallen. diff --git a/mods/HELP/doc/doc_items/locale/template.txt b/mods/HELP/doc/doc_items/locale/template.txt index 484e40ec18..77f1078636 100644 --- a/mods/HELP/doc/doc_items/locale/template.txt +++ b/mods/HELP/doc/doc_items/locale/template.txt @@ -2,7 +2,7 @@ Using it as fuel turns it into: @1.= @1 seconds= # Item count times item name -%@1×@2= +@1×@2= # Itemname (25%) @1 (@2%)= # Itemname (<0.5%) diff --git a/mods/HUD/awards/locale/awards.de.tr b/mods/HUD/awards/locale/awards.de.tr index 2fb04c4ca4..489a196833 100644 --- a/mods/HUD/awards/locale/awards.de.tr +++ b/mods/HUD/awards/locale/awards.de.tr @@ -1,7 +1,7 @@ # textdomain:awards @1: @2=@1: @2 @1 (got)=@1 (erhalten) -@1’s awards:=Auszeichnungen von @1: +@1’s awards:=Auszeichnungen von @: (Secret Award)=(Geheime Auszeichnung) Achievement gotten!=Auszeichnung erhalten! Achievement gotten:=Auszeichnung erhalten: @@ -27,7 +27,6 @@ Awards=Auszeichnungen @1/@2 deaths=@1/@2 Tode @1/@2 dug=@1/@2 abgebaut @1/@2 game joins=@1/@2 Spielen beigetreten -@1/@2 lines of chat=@1/@2 Chatzeilen @1/@2 placed=@1/@2 platziert Die @1 times.=Sterben Sie @1 mal. Die.=Sterben Sie. @@ -58,3 +57,7 @@ Invalid action.=Ungültige Aktion. Player is not online.=Spieler ist nicht online. Done.=Fertig. Achievement “@1” does not exist.=Auszeichnung »@1« existiert nicht. +@1 has made the achievement @2=@1 hat die Auszeichnung @2 erhalten +Write something in chat.=Schreiben Sie etwas in den Chat. +Write @1 chat messages.=Schreiben Sie @1 Chatnachrichten. +@1/@2 chat messages=@1/@2 Chatnachrichten diff --git a/mods/HUD/awards/locale/template.txt b/mods/HUD/awards/locale/template.txt index a1505b3491..ac6a1d7526 100644 --- a/mods/HUD/awards/locale/template.txt +++ b/mods/HUD/awards/locale/template.txt @@ -6,12 +6,11 @@ @1/@2 game joins= @1/@2 placed= @1 (got)= -@1: @1= +@1: @2= @1’s awards:= (Secret Award)= = = -A Cat in a Pop-Tart?!= Achievement gotten!= Achievement gotten:= Achievement gotten: @1= @@ -28,9 +27,9 @@ Join the game.= List awards in chat (deprecated)= Place a block: @1= Place blocks: @1×@2= -Secret Achievement gotten!= -Secret Achievement gotten:= -Secret Achievement gotten: @1= +Secret achievement gotten!= +Secret achievement gotten:= +Secret achievement gotten: @1= Show details of an achievement= Show, clear, disable or enable your achievements= Get this achievement to find out what it is.= @@ -60,3 +59,5 @@ Player is not online.= Done.= Achievement “@1” does not exist.= @1 has made the achievement @2= +Mine a block: @1= +Mine blocks: @1×@2= diff --git a/mods/HUD/mcl_base_textures/textures/object_crosshair.png b/mods/HUD/mcl_base_textures/textures/object_crosshair.png index e5a400e951..8e94dcc6be 100644 Binary files a/mods/HUD/mcl_base_textures/textures/object_crosshair.png and b/mods/HUD/mcl_base_textures/textures/object_crosshair.png differ diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 6fd7e0c93a..9087c41e94 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -1,307 +1,247 @@ local S = minetest.get_translator("mcl_death_messages") -local N = function(s) return s end -local C = minetest.colorize -local color_skyblue = mcl_colors.AQUA - -local function get_tool_name(item) - local name = item:get_meta():get_string("name") - if name ~= "" then - return name - end - local def = item:get_definition() - return def._tt_original_description or def.description - end - -mcl_death_messages = {} - --- Death messages -local msgs = { - ["arrow"] = { - N("@1 was fatally hit by an arrow."), - N("@1 has been killed by an arrow."), +mcl_death_messages = { + assist = {}, + messages = { + in_fire = { + _translator = S, + plain = "@1 went up in flames", + assist = "@1 walked into fire whilst fighting @2", + }, + lightning_bolt = { + _translator = S, + plain = "@1 was struck by lightning", + assist = "@1 was struck by lightning whilst fighting @2", + }, + on_fire = { + _translator = S, + plain = "@1 burned to death", + assist = "@1 was burnt to a crisp whilst fighting @2", + }, + lava = { + _translator = S, + plain = "@1 tried to swim in lava", + assist = "@1 tried to swim in lava to escape @2" + }, + hot_floor = { + _translator = S, + plain = "@1 discovered the floor was lava", + assist = "@1 walked into danger zone due to @2", + }, + in_wall = { + _translator = S, + plain = "@1 suffocated in a wall", + assist = "@1 suffocated in a wall whilst fighting @2", + }, + drown = { + _translator = S, + plain = "@1 drowned", + assist = "@1 drowned whilst trying to escape @2", + }, + starve = { + _translator = S, + plain = "@1 starved to death", + assist = "@1 starved to death whilst fighting @2", + }, + cactus = { + _translator = S, + plain = "@1 was pricked to death", + assist = "@1 walked into a cactus whilst trying to escape @2", + }, + fall = { + _translator = S, + plain = "@1 hit the ground too hard", + assist = "@1 hit the ground too hard whilst trying to escape @2", + -- "@1 fell from a high place" -- for fall distance > 5 blocks + -- "@1 fell while climbing" + -- "@1 fell off some twisting vines" + -- "@1 fell off some weeping vines" + -- "@1 fell off some vines" + -- "@1 fell off scaffolding" + -- "@1 fell off a ladder" + }, + fly_into_wall = { + _translator = S, + plain = "@1 experienced kinetic energy", + assist = "@1 experienced kinetic energy whilst trying to escape @2", + }, + out_of_world = { + _translator = S, + plain = "@1 fell out of the world", + assist = "@1 didn't want to live in the same world as @2", + }, + generic = { + _translator = S, + plain = "@1 died", + assist = "@1 died because of @2", + }, + magic = { + _translator = S, + plain = "@1 was killed by magic", + assist = "@1 was killed by magic whilst trying to escape @2", + killer = "@1 was killed by @2 using magic", + item = "@1 was killed by @2 using @3", + }, + dragon_breath = { + _translator = S, + plain = "@1 was roasted in dragon breath", + killer = "@1 was roasted in dragon breath by @2", + }, + wither = { + _translator = S, + plain = "@1 withered away", + escape = "@1 withered away whilst fighting @2", + }, + wither_skull = { + _translator = S, + plain = "@1 was killed by magic", + killer = "@1 was shot by a skull from @2", + }, + anvil = { + _translator = S, + plain = "@1 was squashed by a falling anvil", + escape = "@1 was squashed by a falling anvil whilst fighting @2", + }, + falling_node = { + _translator = S, + plain = "@1 was squashed by a falling block", + assist = "@1 was squashed by a falling block whilst fighting @2", + }, + mob = { + _translator = S, + killer = "@1 was slain by @2", + item = "@1 was slain by @2 using @3", + }, + player = { + _translator = S, + killer = "@1 was slain by @2", + item = "@1 was slain by @2 using @3" + }, + arrow = { + _translator = S, + killer = "@1 was shot by @2", + item = "@1 was shot by @2 using @3", + }, + fireball = { + _translator = S, + killer = "@1 was fireballed by @2", + item = "@1 was fireballed by @2 using @3", + }, + thorns = { + _translator = S, + killer = "@1 was killed trying to hurt @2", + item = "@1 was killed by @3 trying to hurt @2", -- yes, the order is intentional: @1 @3 @2 + }, + explosion = { + _translator = S, + plain = "@1 blew up", + killer = "@1 was blown up by @2", + item = "@1 was blown up by @2 using @3", + -- "@1 was killed by [Intentional Game Design]" -- for exploding bed in nether or end + }, + cramming = { + _translator = S, + plain = "@1 was squished too much", + assist = "@1 was squashed by @2", -- surprisingly "escape" is actually the correct subtype + }, + fireworks = { + _translator = S, + plain = "@1 went off with a bang", + item = "@1 went off with a bang due to a firework fired from @3 by @2", -- order is intentional + }, + -- Missing snowballs: The Minecraft wiki mentions them but the MC source code does not. }, - ["arrow_name"] = { - N("@1 was shot by @2 using [@3]"), - }, - ["arrow_skeleton"] = { - N("@1 was shot by Skeleton."), - }, - ["arrow_stray"] = { - N("@1 was shot by Stray."), - }, - ["arrow_illusioner"] = { - N("@1 was shot by Illusioner."), - }, - ["arrow_mob"] = { - N("@1 was shot."), - }, - ["drown"] = { - N("@1 forgot to breathe."), - N("@1 drowned."), - N("@1 ran out of oxygen."), - }, - ["murder"] = { - N("@1 was slain by @2 using [@3]"), - }, - ["murder_hand"] = { - N("@1 was slain by @2"), - }, - ["murder_any"] = { - N("@1 was killed."), - }, - ["mob_kill"] = { - N("@1 was slain by a mob."), - }, - ["blaze_fireball"] = { - N("@1 was burned to death by a Blaze's fireball."), - N("@1 was fireballed by a Blaze"), - }, - ["fire_charge"] = { - N("@1 was burned by a fire charge."), - }, - ["ghast_fireball"] = { - N("A Ghast scared @1 to death."), - N("@1 has been fireballed by a Ghast."), - }, - ["fall"] = { - N("@1 fell from a high cliff."), - N("@1 took fatal fall damage."), - N("@1 fell victim to gravity."), - N("@1 hit the ground too hard.") - }, - - ["other"] = { - N("@1 died."), - } } -local mobkills = { - ["mobs_mc:zombie"] = N("@1 was slain by Zombie."), - ["mobs_mc:baby_zombie"] = N("@1 was slain by Baby Zombie."), - ["mobs_mc:blaze"] = N("@1 was burnt to a crisp while fighting Blaze."), - ["mobs_mc:slime"] = N("@1 was slain by Slime."), - ["mobs_mc:witch"] = N("@1 was slain by Witch using magic."), - ["mobs_mc:magma_cube_tiny"] = N("@1 was slain by Magma Cube."), - ["mobs_mc:magma_cube_small"] = N("@1 was slain by Magma Cube."), - ["mobs_mc:magma_cube_big"] = N("@1 was slain by Magma Cube."), - ["mobs_mc:wolf"] = N("@1 was slain by Wolf."), - ["mobs_mc:cat"] = N("@1 was slain by Cat."), - ["mobs_mc:ocelot"] = N("@1 was slain by Ocelot."), - ["mobs_mc:enderdragon"] = N("@1 was slain by Enderdragon."), - ["mobs_mc:wither"] = N("@1 was slain by Wither."), - ["mobs_mc:enderman"] = N("@1 was slain by Enderman."), - ["mobs_mc:endermite"] = N("@1 was slain by Endermite."), - ["mobs_mc:ghast"] = N("@1 was fireballed by a Ghast."), - ["mobs_mc:guardian_elder"] = N("@1 was slain by Elder Guardian."), - ["mobs_mc:guardian"] = N("@1 was slain by Guardian."), - ["mobs_mc:iron_golem"] = N("@1 was slain by Iron Golem."), - ["mobs_mc:polar_bear"] = N("@1 was slain by Polar Bear."), - ["mobs_mc:killer_bunny"] = N("@1 was slain by Killer Bunny."), - ["mobs_mc:shulker"] = N("@1 was slain by Shulker."), - ["mobs_mc:silverfish"] = N("@1 was slain by Silverfish."), - ["mobs_mc:skeleton"] = N("@1 was shot by Skeleton."), - ["mobs_mc:stray"] = N("@1 was shot by Stray."), - ["mobs_mc:slime_tiny"] = N("@1 was slain by Slime."), - ["mobs_mc:slime_small"] = N("@1 was slain by Slime."), - ["mobs_mc:slime_big"] = N("@1 was slain by Slime."), - ["mobs_mc:spider"] = N("@1 was slain by Spider."), - ["mobs_mc:cave_spider"] = N("@1 was slain by Cave Spider."), - ["mobs_mc:vex"] = N("@1 was slain by Vex."), - ["mobs_mc:evoker"] = N("@1 was slain by Evoker."), - ["mobs_mc:illusioner"] = N("@1 was slain by Illusioner."), - ["mobs_mc:vindicator"] = N("@1 was slain by Vindicator."), - ["mobs_mc:villager_zombie"] = N("@1 was slain by Zombie Villager."), - ["mobs_mc:husk"] = N("@1 was slain by Husk."), - ["mobs_mc:baby_husk"] = N("@1 was slain by Baby Husk."), - ["mobs_mc:pigman"] = N("@1 was slain by Zombie Pigman."), - ["mobs_mc:baby_pigman"] = N("@1 was slain by Baby Zombie Pigman."), -} - --- Select death message -local dmsg = function(mtype, ...) - local r = math.random(1, #msgs[mtype]) - return S(msgs[mtype][r], ...) -end - --- Select death message for death by mob -local mmsg = function(mtype, ...) - if mobkills[mtype] then - return S(mobkills[mtype], ...) - else - return dmsg("mob_kill", ...) +local function get_item_killer_message(obj, messages, reason) + if messages.item then + local wielded = mcl_util.get_wielded_item(reason.source) + local itemname = wielded:get_meta():get_string("name") + if itemname ~= "" then + itemname = "[" .. itemname .. "]" + if mcl_enchanting.is_enchanted(wielded:get_name()) then + itemname = minetest.colorize(mcl_colors.AQUA, itemname) + end + return messages._translator(messages.item, mcl_util.get_object_name(obj), mcl_util.get_object_name(reason.source), itemname) + end end end -local last_damages = { } +local function get_plain_killer_message(obj, messages, reason) + return messages.killer and messages._translator(messages.killer, mcl_util.get_object_name(obj), mcl_util.get_object_name(reason.source)) +end -minetest.register_on_dieplayer(function(player, reason) - -- Death message - local message = minetest.settings:get_bool("mcl_showDeathMessages") --Maybe cache the setting? - if message == nil then - message = true +local function get_killer_message(obj, messages, reason) + return reason.source and (get_item_killer_message(obj, messages, reason) or get_plain_killer_message(obj, messages, reason)) +end + +local function get_assist_message(obj, messages, reason) + if messages.assist and mcl_death_messages.assist[obj] then + return messages._translator(messages.assist, mcl_util.get_object_name(obj), mcl_death_messages.assist[obj].name) end - if message then - local name = player:get_player_name() - if not name then - return - end - local msg - if last_damages[name] then - -- custom message - msg = last_damages[name].message - elseif reason.type == "node_damage" then - local pos = player:get_pos() - -- Check multiple nodes because players occupy multiple nodes - -- (we add one additional node because the check may fail if the player was - -- just barely touching the node with the head) - local posses = { pos, {x=pos.x,y=pos.y+1,z=pos.z}, {x=pos.x,y=pos.y+2,z=pos.z}} - local highest_damage = 0 - local highest_damage_def = nil - -- Show message for node that dealt the most damage - for p=1, #posses do - local def = minetest.registered_nodes[minetest.get_node(posses[p]).name] - local dmg = def.damage_per_second - if dmg and dmg > highest_damage then - highest_damage = dmg - highest_damage_def = def - end - end - if highest_damage_def and highest_damage_def._mcl_node_death_message then - local field = highest_damage_def._mcl_node_death_message - local field_msg - if type(field) == "table" then - field_msg = field[math.random(1, #field)] - else - field_msg = field - end - local textdomain - if highest_damage_def.mod_origin then - textdomain = highest_damage_def.mod_origin - else - textdomain = "mcl_death_messages" - end - -- We assume the textdomain of the death message in the node definition - -- equals the modname. - msg = minetest.translate(textdomain, field_msg, name) - end - elseif reason.type == "drown" then - msg = dmsg("drown", name) - elseif reason.type == "punch" then - -- Punches - local hitter = reason.object +end - -- Player was slain by potions - if not hitter then return end +local function get_plain_message(obj, messages, reason) + if messages.plain then + return messages._translator(messages.plain, mcl_util.get_object_name(obj)) + end +end - local hittername, hittertype, hittersubtype, shooter - local hitter_toolname = get_tool_name(hitter:get_wielded_item()) +local function get_fallback_message(obj, messages, reason) + return "mcl_death_messages.messages." .. reason.type .. " " .. mcl_util.get_object_name(obj) +end - -- Custom message - if last_damages[name] then - msg = last_damages[name].message - -- Unknown hitter - elseif hitter == nil then - msg = dmsg("murder_any", name) - -- Player - elseif hitter:is_player() then - hittername = hitter:get_player_name() - if hittername ~= nil then - if hitter_toolname == "" then - msg = dmsg("murder_hand", name, hittername) - else - msg = dmsg("murder", name, hittername, C(color_skyblue, hitter_toolname)) - end - else - msg = dmsg("murder_any", name) - end - -- Mob (according to Common Mob Interface) - elseif hitter:get_luaentity()._cmi_is_mob then - if hitter:get_luaentity().nametag and hitter:get_luaentity().nametag ~= "" then - hittername = hitter:get_luaentity().nametag - end - hittersubtype = hitter:get_luaentity().name - if hittername then - msg = dmsg("murder_hand", name, hittername) - elseif hittersubtype ~= nil and hittersubtype ~= "" then - msg = mmsg(hittersubtype, name) - else - msg = dmsg("murder_any", name) - end - -- Arrow - elseif hitter:get_luaentity().name == "mcl_bows:arrow_entity" or hitter:get_luaentity().name == "mobs_mc:arrow_entity" and not killed_by_potion then - local shooter - if hitter:get_luaentity()._shooter then - shooter = hitter:get_luaentity()._shooter - end - local is_mob = false - local s_ent = shooter and shooter:get_luaentity() - if shooter == nil then - msg = dmsg("arrow", name) - elseif shooter:is_player() then - msg = dmsg("arrow_name", name, shooter:get_player_name(), C(color_skyblue, get_tool_name(shooter:get_wielded_item()))) - elseif s_ent and s_ent._cmi_is_mob then - if s_ent.nametag ~= "" then - msg = dmsg("arrow_name", name, shooter:get_player_name(), get_tool_name(shooter:get_wielded_item())) - elseif s_ent.name == "mobs_mc:skeleton" then - msg = dmsg("arrow_skeleton", name) - elseif s_ent.name == "mobs_mc:stray" then - msg = dmsg("arrow_stray", name) - elseif s_ent.name == "mobs_mc:illusioner" then - msg = dmsg("arrow_illusioner", name) - else - msg = dmsg("arrow_mob", name) - end - else - msg = dmsg("arrow", name) - end - -- Blaze fireball - elseif hitter:get_luaentity().name == "mobs_mc:blaze_fireball" then - if hitter:get_luaentity()._shot_from_dispenser then - msg = dmsg("fire_charge", name) - else - msg = dmsg("blaze_fireball", name) - end - -- Ghast fireball - elseif hitter:get_luaentity().name == "mobs_monster:fireball" then - msg = dmsg("ghast_fireball", name) - end - -- Falling - elseif reason.type == "fall" then - msg = dmsg("fall", name) - -- Other - elseif reason.type == "set_hp" then - if last_damages[name] then - msg = last_damages[name].message - end +local function fallback_translator(s) + return s +end + +mcl_damage.register_on_death(function(obj, reason) + if not minetest.settings:get_bool("mcl_showDeathMessages", true) then + return + end + + local send_to + + if obj:is_player() then + send_to = true + end -- ToDo: add mob death messages for owned mobs, only send to owner (sent_to = "player name") + + + if send_to then + local messages = mcl_death_messages.messages[reason.type] or {} + messages._translator = messages._translator or fallback_translator + + local message = + get_killer_message(obj, messages, reason) or + get_assist_message(obj, messages, reason) or + get_plain_message(obj, messages, reason) or + get_fallback_message(obj, messages, reason) + + if send_to == true then + minetest.chat_send_all(message) + else + minetest.chat_send_player(send_to, message) end - if not msg then - msg = dmsg("other", name) - end - minetest.chat_send_all(msg) - last_damages[name] = nil end end) --- dmg_sequence_number is used to discard old damage events -local dmg_sequence_number = 0 -local start_damage_reset_countdown = function (player, sequence_number) - minetest.after(1, function(playername, sequence_number) - if last_damages[playername] and last_damages[playername].sequence_number == sequence_number then - last_damages[playername] = nil +mcl_damage.register_on_damage(function(obj, damage, reason) + if obj:get_hp() - damage > 0 then + if reason.source then + mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), timeout = 5} + else + mcl_death_messages.assist[obj] = nil end - end, player:get_player_name(), sequence_number) -end - --- Send a custom death mesage when damaging a player via set_hp or punch. --- To be called directly BEFORE damaging a player via set_hp or punch. --- The next time the player dies due to a set_hp, the message will be shown. --- The player must die via set_hp within 0.1 seconds, otherwise the message will be discarded. -function mcl_death_messages.player_damage(player, message) - last_damages[player:get_player_name()] = { message = message, sequence_number = dmg_sequence_number } - start_damage_reset_countdown(player, dmg_sequence_number) - dmg_sequence_number = dmg_sequence_number + 1 - if dmg_sequence_number >= 65535 then - dmg_sequence_number = 0 end -end +end) + +minetest.register_globalstep(function(dtime) + local new_assist = {} + + for obj, tbl in pairs(mcl_death_messages.assist) do + tbl.timeout = tbl.timeout - dtime + if (obj:is_player() or obj:get_luaentity()) and tbl.timeout > 0 then + new_assist[obj] = tbl + end + end +end) diff --git a/mods/HUD/mcl_death_messages/locale/mcl_death_messages.de.tr b/mods/HUD/mcl_death_messages/locale/mcl_death_messages.de.tr index ffb567b8be..39235dff70 100644 --- a/mods/HUD/mcl_death_messages/locale/mcl_death_messages.de.tr +++ b/mods/HUD/mcl_death_messages/locale/mcl_death_messages.de.tr @@ -1,59 +1,58 @@ # textdomain: mcl_death_messages -@1 was fatally hit by an arrow.=@1 wurde tödlich von einem Pfeil getroffen. -@1 has been killed by an arrow.=@1 wurde von einem Pfeil getötet. -@1 was shot by an arrow from @2.=@1 wurde mit einem Pfeil von @2 abgeschossen. -@1 was shot by an arrow from a skeleton.=@1 wurde von einem Skelett mit Pfeil und Bogen abgeschossen. -@1 was shot by an arrow from a stray.=@1 wurde von einem Eiswanderer mit Pfeil und Bogen abgeschossen. -@1 was shot by an arrow from an illusioner.=@1 wurde von einem Illusionisten mit Pfeil und Bogen abgeschossen. -@1 was shot by an arrow.=@1 wurde mit einem Pfeil abgeschossen. -@1 forgot to breathe.=@1 vergaß, zu atmen. -@1 drowned.=@1 ertrank. -@1 ran out of oxygen.=@1 ging die Luft aus. -@1 was killed by @2.=@1 wurde von @2 getötet. -@1 was killed.=@1 wurde getötet. -@1 was killed by a mob.=@1 wurde von einem Mob getötet. -@1 was burned to death by a blaze's fireball.=@1 wurde von einem Feuerball einer Lohe zu Tode verbrannt. -@1 was killed by a fireball from a blaze.=@1 wurde von einem Feuerball einer Lohe getötet. -@1 was burned by a fire charge.=@1 wurde von einer Feuerkugel verbrannt. -A ghast scared @1 to death.=Ein Ghast hat @1 zu Tode erschrocken. -@1 has been fireballed by a ghast.=@1 wurde von einem Ghast mit einer Feuerkugel abgeschossen. -@1 fell from a high cliff.=@1 stürzte von einer hohen Klippe. -@1 took fatal fall damage.=@1 nahm tödlichen Fallschaden. -@1 fell victim to gravity.=@1 fiel der Schwerkraft zum Opfer. -@1 died.=@1 starb. -@1 was killed by a zombie.=@1 wurde von einem Zombie getötet. -@1 was killed by a baby zombie.=@1 wurde von einem Zombiebaby getötet. -@1 was killed by a blaze.=@1 wurde von einer Lohe getötet. -@1 was killed by a slime.=@1 wurde von einem Schleim getötet. -@1 was killed by a witch.=@1 wurde von einer Hexe getötet. -@1 was killed by a magma cube.=@1 wurde von einem Magmakubus getötet. -@1 was killed by a wolf.=@1 wurde von einem Wolf getötet. -@1 was killed by a cat.=@1 wurde von einer Katze getötet. -@1 was killed by an ocelot.=@1 wurde von einem Ozelot getötet. -@1 was killed by an ender dragon.=@1 wurde von einem Enderdrachen getötet. -@1 was killed by a wither.=@1 wurde von einem Wither getötet. -@1 was killed by an enderman.=@1 wurde von einem Enderman getötet. -@1 was killed by an endermite.=@1 wurde von einer Endermilbe getötet. -@1 was killed by a ghast.=@1 wurde von einem Ghast getötet. -@1 was killed by an elder guardian.=@1 wurde von einem Großen Wächter getötet. -@1 was killed by a guardian.=@1 wurde von einem Wächter getötet. -@1 was killed by an iron golem.=@1 wurde von einem Eisengolem getötet. -@1 was killed by a polar_bear.=@1 wurde von einem Eisbären getötet. -@1 was killed by a killer bunny.=@1 wurde von einem Killerkaninchen getötet. -@1 was killed by a shulker.=@1 wurde von einem Schulker getötet. -@1 was killed by a silverfish.=@1 wurde von einem Silberfischchen getötet. -@1 was killed by a skeleton.=@1 wurde von einem Skelett getötet. -@1 was killed by a stray.=@1 wurde von einem Eiswanderer getötet. -@1 was killed by a slime.=@1 wurde von einem Schleim getötet. -@1 was killed by a spider.=@1 wurde von einer Spinne getötet. -@1 was killed by a cave spider.=@1 wurde von einer Höhlenspinne getötet. -@1 was killed by a vex.=@1 wurde von einem Plagegeist getötet. -@1 was killed by an evoker.=@1 wurde von einem Magier getötet. -@1 was killed by an illusioner.=@1 wurde von einem Illusionisten getötet. -@1 was killed by a vindicator.=@1 wurde von einem Diener getötet. -@1 was killed by a zombie villager.=@1 wurde von einem Dorfbewohnerzombie getötet. -@1 was killed by a husk.=@1 wurde von einem Wüstenzombie getötet. -@1 was killed by a baby husk.=@1 wurde von einem Wüstenzombiebaby getötet. -@1 was killed by a zombie pigman.=@1 wurde von einem Schweinezombie getötet. -@1 was killed by a baby zombie pigman.=@1 wurde von einem Schweinezombiebaby getötet. -@1 was slain by @2.= +@1 went up in flames=@1 ging in Flammen auf +@1 walked into fire whilst fighting @2=@1 ist während eines Kampfes mit @2 in ein Feuer gelaufen +@1 was struck by lightning=@1 wurde von einem Blitz erschlagen +@1 was struck by lightning whilst fighting @2=@1 wurde während eines Kampfes mit @2 von einem Blitz erschlagen +@1 burned to death=@1 ist verbrannt +@1 was burnt to a crisp whilst fighting @2=@1 ist während eines Kampfes mit @2 verbrannt +@1 tried to swim in lava=@1 hat versucht, in Lava zu schwimmen +@1 tried to swim in lava to escape @2=@1 hat versucht, in Lava zu schwimmen, um @2 zu entkommen +@1 discovered the floor was lava=@1 hat festgestellt, dass der Boden Lava ist +@1 walked into danger zone due to @2=@1 ist wegen @2 in eine Gefahrenzone gelaufen +@1 suffocated in a wall=@1 ist in einer Mauer erstickt +@1 suffocated in a wall whilst fighting @2=@1 ist während eines Kampfes mit @2 in einer Mauer erstickt +@1 drowned=@1 ist ertrunken +@1 drowned whilst trying to escape @2=@1 ist während dem Versuch, @2 zu entkommen, ertrunken +@1 starved to death=@1 ist verhungert +@1 starved to death whilst fighting @2=@1 ist während eines Kampfes mit @2 verhungert +@1 was pricked to death=@1 wurde zu Tode gestochen +@1 walked into a cactus whilst trying to escape @2=@1 ist während dem Versuch, @2 zu entkommen, in einen Kaktus gelaufen +@1 hit the ground too hard=@1 ist zu hart auf dem Boden aufgetroffen +@1 hit the ground too hard whilst trying to escape @2=@1 ist während dem Versuch, @2 zu entkommen, zu hart auf dem Boden aufgetroffen +@1 experienced kinetic energy=@1 hat kinetische Energie erfahren +@1 experienced kinetic energy whilst trying to escape @2=@1 hat während dem Versuch, @2 zu entkommen, kinetische Energie erfahren +@1 fell out of the world=@1 ist aus der Welt gefallen +@1 didn't want to live in the same world as @2=@1 wollte nicht in der gleichen Welt wie @2 leben +@1 died=@1 ist gestorben +@1 died because of @2=@1 ist wegen @2 gestorben +@1 was killed by magic=@1 wurde von Magie getötet +@1 was killed by magic whilst trying to escape @2=@1 wurde während dem Versuch, @2 zu entkommen, von Magie getötet +@1 was killed by @2 using magic=@1 wurde von @2 mit Magie getötet +@1 was killed by @2 using @3=@1 wurde von @2 mit @3 getötet +@1 was roasted in dragon breath=@1 wurde in Drachenatem geröstet +@1 was roasted in dragon breath by @2=@1 wurde in Drachenatem von @2 geröstet +@1 withered away=@1 ist davon gewithert +@1 withered away whilst fighting @2=@1 ist während einem Kampf mit @2 davon gewithert +@1 was killed by magic=@1 wurde von Magie getötet +@1 was shot by a skull from @2=@1 wurde von einem Schädel von @2 erschossen +@1 was squashed by a falling anvil=@1 wurde von einem fallenden Amboss erquetscht +@1 was squashed by a falling anvil whilst fighting @2=@1 wurde während einem Kampf mit @2 von einem fallenden Amboss erquetscht +@1 was squashed by a falling block=@1 wurde von einem fallenden Block erquetscht +@1 was squashed by a falling block whilst fighting @2=@1 wurde während einem Kampf mit @2 von einem fallenden Block erquetscht +@1 was slain by @2=@1 wurde von @2 erschlagen +@1 was slain by @2 using @3=@1 wurde von @2 mit @3 erschlagen +@1 was slain by @2=@1 wurde von @2 erschlagen +@1 was slain by @2 using @3=@1 wurde von @2 mit @3 erschlagen +@1 was shot by @2=@1 wurde von @2 erschossen +@1 was shot by @2 using @3=@1 wurde von @2 mit @3 erschossen +@1 was fireballed by @2=@1 wurde von @2 gefeuerballt +@1 was fireballed by @2 using @3=@1 wurde von @2 mit @3 gefeuerballt +@1 was killed trying to hurt @2=@1 ist bei dem Versuch, @2 zu verletzten gestorben +@1 was killed by @3 trying to hurt @2=@1 ist bei dem Versuch, @2 zu verletzten, von @3 getötet worden +@1 blew up=@1 ist gesprengt worden +@1 was blown up by @2=@1 wurde von @2 gesprengt +@1 was blown up by @2 using @3=@1 wurde von @2 mit @3 gesprengt +@1 was squished too much=@1 war zu gequetscht +@1 was squashed by @2=@1 wurde von @2 erquetscht +@1 went off with a bang=@1 ging mit einem Knall ab +@1 went off with a bang due to a firework fired from @3 by @2=@1 ging mit einem Knall wegen eines Feuerwerks, das mit @3 von @2 gefeuert wurde, ab diff --git a/mods/HUD/mcl_death_messages/locale/template.txt b/mods/HUD/mcl_death_messages/locale/template.txt index d1e3b832ba..67ba9fd1cc 100644 --- a/mods/HUD/mcl_death_messages/locale/template.txt +++ b/mods/HUD/mcl_death_messages/locale/template.txt @@ -1,59 +1,58 @@ # textdomain: mcl_death_messages -@1 was fatally hit by an arrow.= -@1 has been killed with an arrow.= -@1 was shot by an arrow from @2.= -@1 was shot by an arrow from a skeleton.= -@1 was shot by an arrow from a stray.= -@1 was shot by an arrow from an illusioner.= -@1 was shot by an arrow.= -@1 forgot to breathe.= -@1 drowned.= -@1 ran out of oxygen.= -@1 was killed by @2.= -@1 was killed.= -@1 was killed by a mob.= -@1 was burned to death by a blaze's fireball.= -@1 was killed by a fireball from a blaze.= -@1 was burned by a fire charge.= -A ghast scared @1 to death.= -@1 has been fireballed by a ghast.= -@1 fell from a high cliff.= -@1 took fatal fall damage.= -@1 fell victim to gravity.= -@1 died.= -@1 was killed by a zombie.= -@1 was killed by a baby zombie.= -@1 was killed by a blaze.= -@1 was killed by a slime.= -@1 was killed by a witch.= -@1 was killed by a magma cube.= -@1 was killed by a wolf.= -@1 was killed by a cat.= -@1 was killed by an ocelot.= -@1 was killed by an ender dragon.= -@1 was killed by a wither.= -@1 was killed by an enderman.= -@1 was killed by an endermite.= -@1 was killed by a ghast.= -@1 was killed by an elder guardian.= -@1 was killed by a guardian.= -@1 was killed by an iron golem.= -@1 was killed by a polar_bear.= -@1 was killed by a killer bunny.= -@1 was killed by a shulker.= -@1 was killed by a silverfish.= -@1 was killed by a skeleton.= -@1 was killed by a stray.= -@1 was killed by a slime.= -@1 was killed by a spider.= -@1 was killed by a cave spider.= -@1 was killed by a vex.= -@1 was killed by an evoker.= -@1 was killed by an illusioner.= -@1 was killed by a vindicator.= -@1 was killed by a zombie villager.= -@1 was killed by a husk.= -@1 was killed by a baby husk.= -@1 was killed by a zombie pigman.= -@1 was killed by a baby zombie pigman.= -@1 was slain by @2.= +@1 went up in flames= +@1 walked into fire whilst fighting @2= +@1 was struck by lightning= +@1 was struck by lightning whilst fighting @2= +@1 burned to death= +@1 was burnt to a crisp whilst fighting @2= +@1 tried to swim in lava= +@1 tried to swim in lava to escape @2= +@1 discovered the floor was lava= +@1 walked into danger zone due to @2= +@1 suffocated in a wall= +@1 suffocated in a wall whilst fighting @2= +@1 drowned= +@1 drowned whilst trying to escape @2= +@1 starved to death= +@1 starved to death whilst fighting @2= +@1 was pricked to death= +@1 walked into a cactus whilst trying to escape @2= +@1 hit the ground too hard= +@1 hit the ground too hard whilst trying to escape @2= +@1 experienced kinetic energy= +@1 experienced kinetic energy whilst trying to escape @2= +@1 fell out of the world= +@1 didn't want to live in the same world as @2= +@1 died= +@1 died because of @2= +@1 was killed by magic= +@1 was killed by magic whilst trying to escape @2= +@1 was killed by @2 using magic= +@1 was killed by @2 using @3= +@1 was roasted in dragon breath= +@1 was roasted in dragon breath by @2= +@1 withered away= +@1 withered away whilst fighting @2= +@1 was killed by magic= +@1 was shot by a skull from @2= +@1 was squashed by a falling anvil= +@1 was squashed by a falling anvil whilst fighting @2= +@1 was squashed by a falling block= +@1 was squashed by a falling block whilst fighting @2= +@1 was slain by @2= +@1 was slain by @2 using @3= +@1 was slain by @2= +@1 was slain by @2 using @3= +@1 was shot by @2= +@1 was shot by @2 using @3= +@1 was fireballed by @2= +@1 was fireballed by @2 using @3= +@1 was killed trying to hurt @2= +@1 was killed by @3 trying to hurt @2= +@1 blew up= +@1 was blown up by @2= +@1 was blown up by @2 using @3= +@1 was squished too much= +@1 was squashed by @2= +@1 went off with a bang= +@1 went off with a bang due to a firework fired from @3 by @2= diff --git a/mods/HUD/mcl_experience/init.lua b/mods/HUD/mcl_experience/init.lua index df733e138e..47db77bcab 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -263,34 +263,7 @@ function mcl_experience.add_experience(player, experience) local can = final_candidates[math.random(#final_candidates)] local stack, list, index, wear = can.stack, can.list, can.index, can.wear local unbreaking_level = mcl_enchanting.get_enchantment(stack, "unbreaking") - local uses - local armor_uses = minetest.get_item_group(stack:get_name(), "mcl_armor_uses") - if armor_uses > 0 then - uses = armor_uses - if unbreaking_level > 0 then - uses = uses / (0.6 + 0.4 / (unbreaking_level + 1)) - end - else - local def = stack:get_definition() - if def then - local fixed_uses = def._mcl_uses - if fixed_uses then - uses = fixed_uses - if unbreaking_level > 0 then - uses = uses * (unbreaking_level + 1) - end - end - end - if not uses then - local toolcaps = stack:get_tool_capabilities() - local groupcaps = toolcaps.groupcaps - for _, v in pairs(groupcaps) do - uses = v.uses - break - end - end - end - uses = uses or 0 + local uses = mcl_util.calculate_durability(itemstack) local multiplier = 2 * 65535 / uses local repair = experience * multiplier local new_wear = wear - repair diff --git a/mods/HUD/mcl_hbarmor/init.lua b/mods/HUD/mcl_hbarmor/init.lua index 89b2db7a89..9e5aa634b8 100644 --- a/mods/HUD/mcl_hbarmor/init.lua +++ b/mods/HUD/mcl_hbarmor/init.lua @@ -1,9 +1,5 @@ local S = minetest.get_translator("mcl_hbarmor") -if (not armor) or (not armor.def) then - minetest.log("error", "[mcl_hbarmor] Outdated mcl_armor version. Please update your version of mcl_armor!") -end - local mcl_hbarmor = {} -- HUD statbar values @@ -60,11 +56,8 @@ end hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { icon = "hbarmor_icon.png", bgicon = "hbarmor_bgicon.png", bar = "hbarmor_bar.png" }, 0, 0, 20, mcl_hbarmor.autohide) function mcl_hbarmor.get_armor(player) - if not player or not armor.def then - return false - end local name = player:get_player_name() - local pts = armor:get_armor_points(player) + local pts = player:get_meta():get_int("mcl_armor:armor_points") if not pts then return false else diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index b3ee40bf7f..61ba39b106 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -7,7 +7,6 @@ local players = {} -- Containing all the items for each Creative Mode tab local inventory_lists = {} -local show_armor = minetest.get_modpath("mcl_armor") ~= nil local mod_player = minetest.get_modpath("mcl_player") ~= nil -- Create tables @@ -334,23 +333,7 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, inv_siz if minetest.settings:get_bool("3d_player_preview", true) then player_preview = mcl_player.get_player_formspec_model(player, 3.9, 1.4, 1.2333, 2.4666, "") else - local img, img_player - if mod_player then - img_player = mcl_player.player_get_preview(player) - else - img_player = "player.png" - end - img = img_player - player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]" - if show_armor and armor.textures[playername] and armor.textures[playername].preview then - img = armor.textures[playername].preview - local s1 = img:find("character_preview") - if s1 ~= nil then - s1 = img:sub(s1+21) - img = img_player..s1 - end - player_preview = "image[3.9,1.4;1.2333,2.4666;"..img.."]" - end + player_preview = "image[3.9,1.4;1.2333,2.4666;"..mcl_player.player_get_preview(player).."]" end -- Background images for armor slots (hide if occupied) @@ -373,10 +356,10 @@ mcl_inventory.set_creative_formspec = function(player, start_i, pagenum, inv_siz main_list = "list[current_player;main;0,3.75;9,3;9]".. mcl_formspec.get_itemslot_bg(0,3.75,9,3).. -- armor - "list[detached:"..playername.."_armor;armor;2.5,1.3;1,1;1]".. - "list[detached:"..playername.."_armor;armor;2.5,2.75;1,1;2]".. - "list[detached:"..playername.."_armor;armor;5.5,1.3;1,1;3]".. - "list[detached:"..playername.."_armor;armor;5.5,2.75;1,1;4]".. + "list[current_player;armor;2.5,1.3;1,1;1]".. + "list[current_player;armor;2.5,2.75;1,1;2]".. + "list[current_player;armor;5.5,1.3;1,1;3]".. + "list[current_player;armor;5.5,2.75;1,1;4]".. mcl_formspec.get_itemslot_bg(2.5,1.3,1,1).. mcl_formspec.get_itemslot_bg(2.5,2.75,1,1).. mcl_formspec.get_itemslot_bg(5.5,1.3,1,1).. diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 0544240515..1744ec089d 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -3,7 +3,6 @@ local F = minetest.formspec_escape mcl_inventory = {} -local show_armor = minetest.get_modpath("mcl_armor") ~= nil local mod_player = minetest.get_modpath("mcl_player") ~= nil local mod_craftguide = minetest.get_modpath("mcl_craftguide") ~= nil @@ -68,23 +67,7 @@ local function set_inventory(player, armor_change_only) if minetest.settings:get_bool("3d_player_preview", true) then player_preview = mcl_player.get_player_formspec_model(player, 1.0, 0.0, 2.25, 4.5, "") else - local img, img_player - if mod_player then - img_player = mcl_player.player_get_preview(player) - else - img_player = "player.png" - end - img = img_player - player_preview = "image[0.6,0.2;2,4;"..img.."]" - if show_armor and armor.textures[player_name] and armor.textures[player_name].preview then - img = armor.textures[player_name].preview - local s1 = img:find("character_preview") - if s1 ~= nil then - s1 = img:sub(s1+21) - img = img_player..s1 - end - player_preview = "image[1.1,0.2;2,4;"..img.."]" - end + player_preview = "image[1.1,0.2;2,4;"..mcl_player.player_get_preview(player).."]" end local armor_slots = {"helmet", "chestplate", "leggings", "boots"} @@ -99,10 +82,10 @@ local function set_inventory(player, armor_change_only) "background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]".. player_preview.. --armor - "list[detached:"..player_name.."_armor;armor;0,0;1,1;1]".. - "list[detached:"..player_name.."_armor;armor;0,1;1,1;2]".. - "list[detached:"..player_name.."_armor;armor;0,2;1,1;3]".. - "list[detached:"..player_name.."_armor;armor;0,3;1,1;4]".. + "list[current_player;armor;0,0;1,1;1]".. + "list[current_player;armor;0,1;1,1;2]".. + "list[current_player;armor;0,2;1,1;3]".. + "list[current_player;armor;0,3;1,1;4]".. mcl_formspec.get_itemslot_bg(0,0,1,1).. mcl_formspec.get_itemslot_bg(0,1,1,1).. mcl_formspec.get_itemslot_bg(0,2,1,1).. @@ -133,10 +116,10 @@ local function set_inventory(player, armor_change_only) "tooltip[__mcl_achievements;"..F(S("Achievements")).."]".. -- for shortcuts "listring[current_player;main]".. - "listring[current_player;craft]".. - "listring[current_player;main]".. - "listring[detached:"..player_name.."_armor;armor]" - + "listring[current_player;armor]".. + "listring[current_player;main]" .. + "listring[current_player;craft]" .. + "listring[current_player;main]" player:set_inventory_formspec(form) end @@ -176,18 +159,10 @@ minetest.register_on_joinplayer(function(player) player:hud_set_hotbar_image("mcl_inventory_hotbar.png") player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") - if show_armor then - local set_player_armor_original = armor.set_player_armor - local update_inventory_original = armor.update_inventory - armor.set_player_armor = function(self, player) - set_player_armor_original(self, player) - end - armor.update_inventory = function(self, player) - update_inventory_original(self, player) - set_inventory(player, true) - end - armor:set_player_armor(player) - armor:update_inventory(player) + local old_update_player = mcl_armor.update_player + mcl_armor.update_player = function(player, info) + old_update_player(player, info) + set_inventory(player, true) end -- In Creative Mode, the initial inventory setup is handled in creative.lua diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index b6d0d2ef69..02ed70aed8 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -136,94 +136,32 @@ local dispenserdef = { -- Hardcoded dispensions -- -- Armor, mob heads and pumpkins - if igroups.armor_head or igroups.armor_torso or igroups.armor_legs or igroups.armor_feet then - local armor_type, armor_slot - local armor_dispensed = false - if igroups.armor_head then - armor_type = "armor_head" - armor_slot = 2 - elseif igroups.armor_torso then - armor_type = "armor_torso" - armor_slot = 3 - elseif igroups.armor_legs then - armor_type = "armor_legs" - armor_slot = 4 - elseif igroups.armor_feet then - armor_type = "armor_feet" - armor_slot = 5 - end + if igroups.armor then + local droppos_below = {x = droppos.x, y = droppos.y - 1, z = droppos.z} - local droppos_below = {x=droppos.x, y=droppos.y-1, z=droppos.z} - local dropnode_below = minetest.get_node(droppos_below) - -- Put armor on player or armor stand - local standpos - if dropnode.name == "mcl_armor_stand:armor_stand" then - standpos = droppos - elseif dropnode_below.name == "mcl_armor_stand:armor_stand" then - standpos = droppos_below - end - if standpos then - local dropmeta = minetest.get_meta(standpos) - local dropinv = dropmeta:get_inventory() - if dropinv:room_for_item(armor_type, dropitem) then - dropinv:add_item(armor_type, dropitem) - minetest.registered_nodes["mcl_armor_stand:armor_stand"].on_metadata_inventory_put(standpos) - stack:take_item() - inv:set_stack("main", stack_id, stack) - armor:play_equip_sound(dropitem, nil, standpos) - armor_dispensed = true - end - else - -- Put armor on nearby player - -- First search for player in front of dispenser (check 2 nodes) - local objs1 = minetest.get_objects_inside_radius(droppos, 1) - local objs2 = minetest.get_objects_inside_radius(droppos_below, 1) - local objs_table = {objs1, objs2} - local player - for oi=1, #objs_table do - local objs_inner = objs_table[oi] - for o=1, #objs_inner do - --[[ First player in list is the lucky one. The other player get nothing :-( - If multiple players are close to the dispenser, it can be a bit - -- unpredictable on who gets the armor. ]] - if objs_inner[o]:is_player() then - player = objs_inner[o] - break - end - end - if player then + for _, objs in ipairs({minetest.get_objects_inside_radius(droppos, 1), minetest.get_objects_inside_radius(droppos_below, 1)}) do + for _, obj in ipairs(objs) do + stack = mcl_armor.equip(stack, obj) + if stack:is_empty() then break end end - -- If player found, add armor - if player then - local ainv = minetest.get_inventory({type="detached", name=player:get_player_name().."_armor"}) - local pinv = player:get_inventory() - if ainv:get_stack("armor", armor_slot):is_empty() and pinv:get_stack("armor", armor_slot):is_empty() then - ainv:set_stack("armor", armor_slot, dropitem) - pinv:set_stack("armor", armor_slot, dropitem) - armor:set_player_armor(player) - armor:update_inventory(player) - armor:play_equip_sound(dropitem, player) - - stack:take_item() - inv:set_stack("main", stack_id, stack) - armor_dispensed = true - end + if stack:is_empty() then + break end + end -- Place head or pumpkin as node, if equipping it as armor has failed - if not armor_dispensed then - if igroups.head or iname == "mcl_farming:pumpkin_face" then - if dropnodedef.buildable_to then - minetest.set_node(droppos, {name = iname, param2 = node.param2}) - stack:take_item() - inv:set_stack("main", stack_id, stack) - end + if not stack:is_empty() then + if igroups.head or iname == "mcl_farming:pumpkin_face" then + if dropnodedef.buildable_to then + minetest.set_node(droppos, {name = iname, param2 = node.param2}) + stack:take_item() end end end + inv:set_stack("main", stack_id, stack) -- Spawn Egg elseif igroups.spawn_egg then -- Spawn mob diff --git a/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua b/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua index a0ecf354da..92c809785c 100644 --- a/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua +++ b/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua @@ -37,7 +37,6 @@ minetest.register_node("mesecons_walllever:wall_lever_off", { wield_image = "jeija_wall_lever.png", paramtype = "light", paramtype2 = "facedir", - drawtype = "mesh", mesh = "jeija_wall_lever_off.obj", sunlight_propagates = true, walkable = false, diff --git a/mods/ITEMS/mcl_armor/api.lua b/mods/ITEMS/mcl_armor/api.lua new file mode 100644 index 0000000000..d58b5e666d --- /dev/null +++ b/mods/ITEMS/mcl_armor/api.lua @@ -0,0 +1,268 @@ +function mcl_armor.play_equip_sound(stack, obj, pos, unequip) + local def = stack:get_definition() + local estr = "equip" + if unequip then + estr = "unequip" + end + local snd = def.sounds and def.sounds["_mcl_armor_" .. estr] + if not snd then + -- Fallback sound + snd = { name = "mcl_armor_" .. estr .. "_generic" } + end + if snd then + local dist = 8 + if pos then + dist = 16 + end + minetest.sound_play(snd, {object = obj, pos = pos, gain = 0.5, max_hear_distance = dist}, true) + end +end + +function mcl_armor.on_equip(itemstack, obj) + local def = itemstack:get_definition() + mcl_armor.play_equip_sound(itemstack, obj) + if def._on_equip then + def._on_equip(obj, itemstack) + end + mcl_armor.update(obj) +end + +function mcl_armor.on_unequip(itemstack, obj) + local def = itemstack:get_definition() + mcl_armor.play_equip_sound(itemstack, obj, nil, true) + if def._on_unequip then + def._on_unequip(obj, itemstack) + end + mcl_armor.update(obj) +end + +function mcl_armor.equip(itemstack, obj, swap) + local def = itemstack:get_definition() + + if not def then + return itemstack + end + + local inv = mcl_util.get_inventory(obj, true) + + if not inv or inv:get_size("armor") == 0 then + return itemstack + end + + local element = mcl_armor.elements[def._mcl_armor_element or ""] + + if element then + local old_stack = inv:get_stack("armor", element.index) + + if swap or old_stack:is_empty() then + local new_stack + + if swap then + new_stack = itemstack + itemstack = old_stack + else + new_stack = itemstack:take_item() + end + + inv:set_stack("armor", element.index, new_stack) + mcl_armor.on_equip(new_stack, obj) + end + end + + return itemstack +end + +function mcl_armor.equip_on_use(itemstack, player, pointed_thing) + if not player or not player:is_player() then + return itemstack + end + + local new_stack = mcl_util.call_on_rightclick(itemstack, player, pointed_thing) + if new_stack then + return new_stack + end + + return mcl_armor.equip(itemstack, player) +end + +function mcl_armor.register_set(def) + local modname = minetest.get_current_modname() + local S = minetest.get_translator(modname) + local descriptions = def.descriptions or {} + local groups = def.groups or {} + local on_equip_callbacks = def.on_equip_callbacks or {} + local on_unequip_callbacks = def.on_unequip_callbacks or {} + local on_break_callbacks = def.on_break_callbacks or {} + local textures = def.textures or {} + local previews = def.previews or {} + local durabilities = def.durabilities or {} + local element_groups = def.element_groups or {} + + for name, element in pairs(mcl_armor.elements) do + local itemname = element.name .. "_" .. def.name + local itemstring = modname .. ":" .. itemname + + local groups = table.copy(groups) + groups["armor_" .. name] = 1 + groups["combat_armor_" .. name] = 1 + groups.armor = 1 + groups.combat_armor = 1 + groups.mcl_armor_points = def.points[name] + groups.mcl_armor_toughness = def.toughness + groups.mcl_armor_uses = (durabilities[name] or math.floor(def.durability * element.durability)) + 1 + groups.enchantability = def.enchantability + + for k, v in pairs(element_groups) do + groups[k] = v + end + + minetest.register_tool(itemstring, { + description = S(def.description .. " " .. (descriptions[name] or element.description)), + _doc_items_longdesc = mcl_armor.longdesc, + _doc_items_usagehelp = mcl_armor.usage, + inventory_image = modname .. "_inv_" .. itemname .. ".png", + _repair_material = def.repair_material or def.craft_material, + groups = groups, + sounds = { + _mcl_armor_equip = def.sound_equip or modname .. "_equip_" .. def.name, + _mcl_armor_unequip = def.sound_unequip or modname .. "_unequip_" .. def.name, + }, + on_place = mcl_armor.equip_on_use, + on_secondary_use = mcl_armor.equip_on_use, + _on_equip = on_equip_callbacks[name] or def.on_equip, + _on_unequip = on_unequip_callbacks[name] or def.on_unequip, + _on_break = on_break_callbacks[name] or def.on_break, + _mcl_armor_element = name, + _mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png", + _mcl_armor_preview = previews[name] or modname .. "_" .. itemname .. "_preview.png", + }) + + if def.craft_material then + minetest.register_craft({ + output = itemstring, + recipe = element.craft(def.craft_material), + }) + end + + if def.cook_material then + minetest.register_craft({ + type = "cooking", + output = def.cook_material, + recipe = itemstring, + cooktime = 10, + }) + end + end +end + +mcl_armor.protection_enchantments = { + flags = {}, + types = {}, + wildcard = {}, +} + +function mcl_armor.register_protection_enchantment(def) + local prot_def = {id = def.id, factor = def.factor} + if def.damage_flag then + local tbl = mcl_armor.protection_enchantments.flags[def.damage_flag] or {} + table.insert(tbl, prot_def) + mcl_armor.protection_enchantments.flags = tbl + elseif def.damage_type then + local tbl = mcl_armor.protection_enchantments.types[def.damage_type] or {} + table.insert(tbl, prot_def) + mcl_armor.protection_enchantments.types = tbl + else + table.insert(mcl_armor.protection_enchantments.wildcard, prot_def) + end + mcl_enchanting.enchantments[def.id] = { + name = def.name, + max_level = def.max_level or 4, + primary = def.primary or {combat_armor = true}, + secondary = {}, + disallow = {}, + incompatible = def.incompatible or {}, + weight = def.weight or 5, + description = def.description, + curse = false, + on_enchant = function() end, + requires_tool = false, + treasure = def.treasure or false, + power_range_table = def.power_range_table, + inv_combat_tab = true, + inv_tool_tab = false, + } +end + +function mcl_armor.update(obj) + local info = {points = 0, view_range_factors = {}} + + local inv = mcl_util.get_inventory(obj) + + if inv then + for i = 2, 5 do + local itemstack = inv:get_stack("armor", i) + + local itemname = itemstack:get_name() + if minetest.registered_aliases[itemname] then + itemname = minetest.registered_aliases[itemname] + end + + if not itemstack:is_empty() then + local def = itemstack:get_definition() + + local texture = def._mcl_armor_texture + + if texture then + if type(texture) == "function" then + texture = texture(obj, itemstack) + end + if texture then + info.texture = "(" .. texture .. ")" .. (info.texture and "^" .. info.texture or "") + end + end + + local preview = def._mcl_armor_preview + + if obj:is_player() and preview then + if type(preview) == "function" then + preview = preview(obj, itemstack) + end + if preview then + info.preview = "(player.png^[opacity:0^" .. def._mcl_armor_preview .. ")" .. (info.preview and "^" .. info.preview or "" ) + end + end + + info.points = info.points + minetest.get_item_group(itemname, "mcl_armor_points") + + local mob_range_mob = def._mcl_armor_mob_range_mob + + if mob_range_mob then + local factor = info.view_range_factors[mob_range_mob] + + if factor then + if factor > 0 then + info.view_range_factors[mob_range_mob] = factor * def._mcl_armor_mob_range_factor + end + else + info.view_range_factors[mob_range_mob] = def._mcl_armor_mob_range_factor + end + end + end + end + end + + info.texture = info.texture or "blank.png" + + if obj:is_player() then + info.preview = info.preview or "blank.png" + + mcl_armor.update_player(obj, info) + else + local luaentity = obj:get_luaentity() + + if luaentity.update_armor then + luaentity:update_armor(info) + end + end +end + diff --git a/mods/ITEMS/mcl_armor/armor.lua b/mods/ITEMS/mcl_armor/armor.lua deleted file mode 100644 index a35841fe27..0000000000 --- a/mods/ITEMS/mcl_armor/armor.lua +++ /dev/null @@ -1,675 +0,0 @@ -local ARMOR_INIT_DELAY = 1 -local ARMOR_INIT_TIMES = 1 -local ARMOR_BONES_DELAY = 1 - -local skin_mod = nil - -local modpath = minetest.get_modpath(minetest.get_current_modname()) - -armor = { - timer = 0, - elements = {"head", "torso", "legs", "feet"}, - physics = {"jump","speed","gravity"}, - formspec = "size[8,8.5]image[2,0.75;2,4;armor_preview]" - .."list[current_player;main;0,4.5;8,4;]" - .."list[current_player;craft;4,1;3,3;]" - .."list[current_player;craftpreview;7,2;1,1;]" - .."listring[current_player;main]" - .."listring[current_player;craft]", - textures = {}, - default_skin = "character", - last_damage_types = {}, -} - -if minetest.get_modpath("mcl_skins") then - skin_mod = "mcl_skins" -elseif minetest.get_modpath("skins") then - skin_mod = "skins" -elseif minetest.get_modpath("simple_skins") then - skin_mod = "simple_skins" -elseif minetest.get_modpath("u_skins") then - skin_mod = "u_skins" -elseif minetest.get_modpath("wardrobe") then - skin_mod = "wardrobe" -end - -function armor.on_armor_use(itemstack, user, pointed_thing) - if not user or user:is_player() == false then - return itemstack - end - - -- Call on_rightclick if the pointed node defines it - if pointed_thing.type == "node" then - local node = minetest.get_node(pointed_thing.under) - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack - end - end - end - - local name, player_inv, armor_inv = armor:get_valid_player(user, "[on_armor_use]") - if not name then - return itemstack - end - - local def = itemstack:get_definition() - local slot - if def.groups and def.groups.armor_head then - slot = 2 - elseif def.groups and def.groups.armor_torso then - slot = 3 - elseif def.groups and def.groups.armor_legs then - slot = 4 - elseif def.groups and def.groups.armor_feet then - slot = 5 - end - - if slot then - local itemstack_single = ItemStack(itemstack) - itemstack_single:set_count(1) - local itemstack_slot = armor_inv:get_stack("armor", slot) - if itemstack_slot:is_empty() then - armor_inv:set_stack("armor", slot, itemstack_single) - player_inv:set_stack("armor", slot, itemstack_single) - armor:set_player_armor(user) - armor:update_inventory(user) - armor:play_equip_sound(itemstack_single, user) - itemstack:take_item() - elseif itemstack:get_count() <= 1 and not mcl_enchanting.has_enchantment(itemstack_slot, "curse_of_binding") then - armor_inv:set_stack("armor", slot, itemstack_single) - player_inv:set_stack("armor", slot, itemstack_single) - armor:set_player_armor(user) - armor:update_inventory(user) - armor:play_equip_sound(itemstack_single, user) - itemstack = ItemStack(itemstack_slot) - end - end - - return itemstack -end - -armor.def = { - count = 0, -} - -armor.update_player_visuals = function(self, player) - if not player then - return - end - - local wielditem = player:get_wielded_item() - local def = wielditem:get_definition() - if def and def._mcl_toollike_wield then - player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0)) - elseif string.find(wielditem:get_name(), "mcl_bows:bow") then - player:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20)) - else - player:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90)) - end - - local name = player:get_player_name() - if self.textures[name] then - mcl_player.player_set_textures(player, { - self.textures[name].skin, - self.textures[name].armor, - self.textures[name].wielditem, - }) - end -end - -armor.set_player_armor = function(self, player) - local name, player_inv = armor:get_valid_player(player, "[set_player_armor]") - if not name then - return - end - local armor_texture = "blank.png" - local armor_level = 0 - local mcl_armor_points = 0 - local items = 0 - local elements = {} - local textures = {} - local physics_o = {speed=1,gravity=1,jump=1} - local material = {type=nil, count=1} - local preview - for _,v in ipairs(self.elements) do - elements[v] = false - end - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - local item = stack:get_name() - if minetest.registered_aliases[item] then - item = minetest.registered_aliases[item] - end - if stack:get_count() == 1 then - local def = stack:get_definition() - for k, v in pairs(elements) do - if v == false then - local level = def.groups["armor_"..k] - if level then - local texture = def.texture or item:gsub("%:", "_") - local enchanted_addition = (mcl_enchanting.is_enchanted(item) and mcl_enchanting.overlay or "") - table.insert(textures, "("..texture..".png"..enchanted_addition..")") - preview = "(player.png^[opacity:0^"..texture.."_preview.png"..enchanted_addition..")"..(preview and "^"..preview or "") - armor_level = armor_level + level - items = items + 1 - mcl_armor_points = mcl_armor_points + (def.groups["mcl_armor_points"] or 0) - for kk,vv in ipairs(self.physics) do - local o_value = def.groups["physics_"..vv] - if o_value then - physics_o[vv] = physics_o[vv] + o_value - end - end - local mat = string.match(item, "%:.+_(.+)$") - if material.type then - if material.type == mat then - material.count = material.count + 1 - end - else - material.type = mat - end - elements[k] = true - end - end - end - end - end - preview = (armor:get_preview(name) or "character_preview.png")..(preview and "^"..preview or "") - if minetest.get_modpath("shields") then - armor_level = armor_level * 0.9 - end - if material.type and material.count == #self.elements then - armor_level = armor_level * 1.1 - end - if #textures > 0 then - armor_texture = table.concat(textures, "^") - end - local armor_groups = player:get_armor_groups() - armor_groups.fleshy = 100 - armor_groups.level = nil - if armor_level > 0 then - armor_groups.level = math.floor(armor_level / 20) - armor_groups.fleshy = 100 - armor_level - end - player:set_armor_groups(armor_groups) - -- Physics override intentionally removed because of possible conflicts - self.textures[name].armor = armor_texture - self.textures[name].preview = preview - self.def[name].count = items - self.def[name].level = armor_level - self.def[name].heal = mcl_armor_points - self.def[name].jump = physics_o.jump - self.def[name].speed = physics_o.speed - self.def[name].gravity = physics_o.gravity - self:update_player_visuals(player) -end - -armor.update_armor = function(self, player) - -- Legacy support: Called when armor levels are changed - -- Other mods can hook on to this function, see hud mod for example -end - -armor.get_armor_points = function(self, player) - local name, player_inv, armor_inv = armor:get_valid_player(player, "[get_armor_points]") - if not name then - return nil - end - local pts = 0 - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - if stack:get_count() > 0 then - local p = minetest.get_item_group(stack:get_name(), "mcl_armor_points") - if p then - pts = pts + p - end - end - end - return pts -end - --- Returns a change factor for a mob's view_range for the given player --- or nil, if there's no change. Certain armors (like mob heads) can --- affect the view range of mobs. -armor.get_mob_view_range_factor = function(self, player, mob) - local name, player_inv, armor_inv = armor:get_valid_player(player, "[get_mob_view_range_factor]") - if not name then - return - end - local factor - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - if stack:get_count() > 0 then - local def = stack:get_definition() - if def._mcl_armor_mob_range_mob == mob then - if not factor then - factor = def._mcl_armor_mob_range_factor - elseif factor == 0 then - return 0 - else - factor = factor * def._mcl_armor_mob_range_factor - end - end - end - end - return factor -end - -armor.get_player_skin = function(self, name) - local skin = nil - if skin_mod == "mcl_skins" then - skin = mcl_skins.skins[name] - elseif skin_mod == "skins" or skin_mod == "simple_skins" then - skin = skins.skins[name] - elseif skin_mod == "u_skins" then - skin = u_skins.u_skins[name] - elseif skin_mod == "wardrobe" then - skin = string.gsub(wardrobe.playerSkins[name], "%.png$","") - end - return skin or armor.default_skin -end - -armor.get_preview = function(self, name) - if skin_mod == "skins" then - return armor:get_player_skin(name).."_preview.png" - end -end - -armor.get_armor_formspec = function(self, name) - if not armor.textures[name] then - minetest.log("error", "mcl_armor: Player texture["..name.."] is nil [get_armor_formspec]") - return "" - end - if not armor.def[name] then - minetest.log("error", "mcl_armor: Armor def["..name.."] is nil [get_armor_formspec]") - return "" - end - local formspec = armor.formspec.."list[detached:"..name.."_armor;armor;0,1;2,3;]" - formspec = formspec:gsub("armor_preview", armor.textures[name].preview) - formspec = formspec:gsub("armor_level", armor.def[name].level) - formspec = formspec:gsub("mcl_armor_points", armor.def[name].heal) - return formspec -end - -armor.update_inventory = function(self, player) -end - -armor.get_valid_player = function(self, player, msg) - msg = msg or "" - if not player then - minetest.log("error", "mcl_armor: Player reference is nil "..msg) - return - end - local name = player:get_player_name() - if not name then - minetest.log("error", "mcl_armor: Player name is nil "..msg) - return - end - local pos = player:get_pos() - local player_inv = player:get_inventory() - local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"}) - if not pos then - minetest.log("error", "mcl_armor: Player position is nil "..msg) - return - elseif not player_inv then - minetest.log("error", "mcl_armor: Player inventory is nil "..msg) - return - elseif not armor_inv then - minetest.log("error", "mcl_armor: Detached armor inventory is nil "..msg) - return - end - return name, player_inv, armor_inv, pos -end - -armor.play_equip_sound = function(self, stack, player, pos, unequip) - local def = stack:get_definition() - local estr = "equip" - if unequip then - estr = "unequip" - end - local snd = def.sounds and def.sounds["_mcl_armor_"..estr] - if not snd then - -- Fallback sound - snd = { name = "mcl_armor_"..estr.."_generic" } - end - if snd then - local dist = 8 - if pos then - dist = 16 - end - minetest.sound_play(snd, {object=player, pos=pos, gain=0.5, max_hear_distance=dist}, true) - end -end - --- Register Player Model - -mcl_player.player_register_model("mcl_armor_character.b3d", { - animation_speed = 30, - textures = { - armor.default_skin..".png", - "blank.png", - "blank.png", - }, - animations = { - stand = {x=0, y=79}, - lay = {x=162, y=166}, - walk = {x=168, y=187}, - mine = {x=189, y=198}, - walk_mine = {x=200, y=219}, - sit = {x=81, y=160}, - sneak_stand = {x=222, y=302}, - sneak_mine = {x=346, y=365}, - sneak_walk = {x=304, y=323}, - sneak_walk_mine = {x=325, y=344}, - swim_walk = {x=368, y=387}, - swim_walk_mine = {x=389, y=408}, - swim_stand = {x=434, y=434}, - swim_mine = {x=411, y=430}, - run_walk = {x=440, y=459}, - run_walk_mine = {x=461, y=480}, - sit_mount = {x=484, y=484}, - die = {x=498, y=498}, - fly = {x=502, y=581}, - }, -}) - -mcl_player.player_register_model("mcl_armor_character_female.b3d", { - animation_speed = 30, - textures = { - armor.default_skin..".png", - "blank.png", - "blank.png", - }, - animations = { - stand = {x=0, y=79}, - lay = {x=162, y=166}, - walk = {x=168, y=187}, - mine = {x=189, y=198}, - walk_mine = {x=200, y=219}, - sit = {x=81, y=160}, - sneak_stand = {x=222, y=302}, - sneak_mine = {x=346, y=365}, - sneak_walk = {x=304, y=323}, - sneak_walk_mine = {x=325, y=344}, - swim_walk = {x=368, y=387}, - swim_walk_mine = {x=389, y=408}, - swim_stand = {x=434, y=434}, - swim_mine = {x=411, y=430}, - run_walk = {x=440, y=459}, - run_walk_mine = {x=461, y=480}, - sit_mount = {x=484, y=484}, - die = {x=498, y=498}, - fly = {x=502, y=581}, - }, -}) - --- Register Callbacks - -minetest.register_on_player_receive_fields(function(player, formname, fields) - local name = armor:get_valid_player(player, "[on_player_receive_fields]") - if not name then - return - end - if fields.armor then - return - end - for field, _ in pairs(fields) do - if string.find(field, "skins_set") then - minetest.after(0, function(name) - local player = minetest.get_player_by_name(name) - if not player then - return - end - local skin = armor:get_player_skin(name) - armor.textures[name].skin = skin..".png" - armor:set_player_armor(player) - end, player:get_player_name()) - end - end -end) - -minetest.register_on_joinplayer(function(player) - mcl_player.player_set_model(player, "mcl_armor_character.b3d") - local name = player:get_player_name() - local player_inv = player:get_inventory() - local armor_inv = minetest.create_detached_inventory(name.."_armor", { - on_put = function(inv, listname, index, stack, player) - player:get_inventory():set_stack(listname, index, stack) - armor:set_player_armor(player) - armor:update_inventory(player) - armor:play_equip_sound(stack, player) - end, - on_take = function(inv, listname, index, stack, player) - player:get_inventory():set_stack(listname, index, nil) - armor:set_player_armor(player) - armor:update_inventory(player) - armor:play_equip_sound(stack, player, nil, true) - end, - on_move = function(inv, from_list, from_index, to_list, to_index, count, player) - local plaver_inv = player:get_inventory() - local stack = inv:get_stack(to_list, to_index) - player_inv:set_stack(to_list, to_index, stack) - player_inv:set_stack(from_list, from_index, nil) - armor:set_player_armor(player) - armor:update_inventory(player) - armor:play_equip_sound(stack, player) - end, - allow_put = function(inv, listname, index, stack, player) - local iname = stack:get_name() - local g - local groupcheck - if index == 2 then - g = minetest.get_item_group(iname, "armor_head") - elseif index == 3 then - g = minetest.get_item_group(iname, "armor_torso") - elseif index == 4 then - g = minetest.get_item_group(iname, "armor_legs") - elseif index == 5 then - g = minetest.get_item_group(iname, "armor_feet") - end - -- Minor FIXME: If player attempts to place stack into occupied slot, this is rejected. - -- It would be better if 1 item is placed in exchanged for the item in the slot. - if g ~= 0 and g ~= nil and (inv:get_stack(listname, index):is_empty() or (inv:get_stack(listname, index):get_name() ~= stack:get_name()) and stack:get_count() <= 1) then - return 1 - else - return 0 - end - end, - allow_take = function(inv, listname, index, stack, player) - if mcl_enchanting.has_enchantment(stack, "curse_of_binding") and not minetest.settings:get_bool("creative") then - return 0 - end - return stack:get_count() - end, - allow_move = function(inv, from_list, from_index, to_list, to_index, count, player) - return 0 - end, - }, name) - armor_inv:set_size("armor", 6) - player_inv:set_size("armor", 6) - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - armor_inv:set_stack("armor", i, stack) - end - armor.def[name] = { - count = 0, - level = 0, - heal = 0, - jump = 1, - speed = 1, - gravity = 1, - } - armor.textures[name] = { - skin = armor.default_skin..".png", - armor = "blank.png", - wielditem = "blank.png", - preview = armor.default_skin.."_preview.png", - } - if skin_mod == "mcl_skins" then - local skin = mcl_skins.skins[name] - if skin then - armor.textures[name].skin = skin..".png" - end - elseif skin_mod == "skins" then - local skin = skins.skins[name] - if skin and skins.get_type(skin) == skins.type.MODEL then - armor.textures[name].skin = skin..".png" - end - elseif skin_mod == "simple_skins" then - local skin = skins.skins[name] - if skin then - armor.textures[name].skin = skin..".png" - end - elseif skin_mod == "u_skins" then - local skin = u_skins.u_skins[name] - if skin and u_skins.get_type(skin) == u_skins.type.MODEL then - armor.textures[name].skin = skin..".png" - end - elseif skin_mod == "wardrobe" then - local skin = wardrobe.playerSkins[name] - if skin then - armor.textures[name].skin = skin - end - end - if minetest.get_modpath("player_textures") then - local filename = minetest.get_modpath("player_textures").."/textures/player_"..name - local f = io.open(filename..".png") - if f then - f:close() - armor.textures[name].skin = "player_"..name..".png" - end - end - for i=1, ARMOR_INIT_TIMES do - minetest.after(ARMOR_INIT_DELAY * i, function(name) - local player = minetest.get_player_by_name(name) - if not player then - return - end - armor:set_player_armor(player) - end, player:get_player_name()) - end -end) - -minetest.register_on_player_hpchange(function(player, hp_change, reason) - local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]") - if name and hp_change < 0 then - local damage_type = armor.last_damage_types[name] - armor.last_damage_types[name] = nil - - -- Armor doesn't protect from set_hp (commands like /kill), - if reason.type == "set_hp" then - return hp_change - end - - local regular_reduction = reason.type ~= "drown" and reason.type ~= "fall" and reason.other ~= "harming" and reason.other ~= "poison" - - local heal_max = 0 - local items = 0 - local armor_damage = math.max(1, math.floor(math.abs(hp_change)/4)) - - local total_points = 0 - local total_toughness = 0 - local epf = 0 - local thorns_damage = 0 - local thorns_damage_regular = 0 - for i=1, 6 do - local stack = player_inv:get_stack("armor", i) - if stack:get_count() > 0 then - local enchantments = mcl_enchanting.get_enchantments(stack) - local pts = stack:get_definition().groups["mcl_armor_points"] or 0 - local tough = stack:get_definition().groups["mcl_armor_toughness"] or 0 - total_points = total_points + pts - total_toughness = total_toughness + tough - - local protection_level = enchantments.protection or 0 - if protection_level > 0 then - epf = epf + protection_level * 1 - end - local blast_protection_level = enchantments.blast_protection or 0 - if blast_protection_level > 0 and damage_type == "explosion" then - epf = epf + blast_protection_level * 2 - end - local fire_protection_level = enchantments.fire_protection or 0 - if fire_protection_level > 0 and (damage_type == "burning" or damage_type == "fireball" or reason.type == "node_damage" and - (reason.node == "mcl_fire:fire" or reason.node == "mcl_core:lava_source" or reason.node == "mcl_core:lava_flowing")) then - epf = epf + fire_protection_level * 2 - end - local projectile_protection_level = enchantments.projectile_protection or 0 - if projectile_protection_level and (damage_type == "projectile" or damage_type == "fireball") then - epf = epf + projectile_protection_level * 2 - end - local feather_falling_level = enchantments.feather_falling or 0 - if feather_falling_level and reason.type == "fall" then - epf = epf + feather_falling_level * 3 - end - - local did_thorns_damage = false - local thorns_level = enchantments.thorns or 0 - if thorns_level then - if thorns_level > 10 then - thorns_damage = thorns_damage + thorns_level - 10 - did_thorns_damage = true - elseif thorns_damage_regular < 4 and thorns_level * 0.15 > math.random() then - local thorns_damage_regular_new = math.min(4, thorns_damage_regular + math.random(4)) - thorns_damage = thorns_damage + thorns_damage_regular_new - thorns_damage_regular - thorns_damage_regular = thorns_damage_regular_new - did_thorns_damage = true - end - end - - -- Damage armor - local use = stack:get_definition().groups["mcl_armor_uses"] or 0 - if use > 0 and regular_reduction then - local unbreaking_level = enchantments.unbreaking or 0 - if unbreaking_level > 0 then - use = use / (0.6 + 0.4 / (unbreaking_level + 1)) - end - local wear = armor_damage * math.floor(65536/use) - if did_thorns_damage then - wear = wear * 3 - end - stack:add_wear(wear) - end - - local item = stack:get_name() - armor_inv:set_stack("armor", i, stack) - player_inv:set_stack("armor", i, stack) - items = items + 1 - if stack:get_count() == 0 then - armor:set_player_armor(player) - armor:update_inventory(player) - end - end - end - local damage = math.abs(hp_change) - - if regular_reduction then - -- Damage calculation formula (from ) - damage = damage * (1 - math.min(20, math.max((total_points/5), total_points - damage / (2+(total_toughness/4)))) / 25) - end - damage = damage * (1 - (math.min(20, epf) / 25)) - damage = math.floor(damage+0.5) - - if reason.type == "punch" and thorns_damage > 0 then - local obj = reason.object - if obj then - local luaentity = obj:get_luaentity() - if luaentity then - local shooter = obj._shooter - if shooter then - obj = shooter - end - end - obj:punch(player, 1.0, { - full_punch_interval=1.0, - damage_groups = {fleshy = thorns_damage}, - }) - end - end - - hp_change = -math.abs(damage) - - armor.def[name].count = items - armor:update_armor(player) - end - return hp_change -end, true) diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua new file mode 100644 index 0000000000..f170334954 --- /dev/null +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -0,0 +1,102 @@ +local function use_durability(obj, inv, index, stack, uses) + local def = stack:get_definition() + mcl_util.use_item_durability(stack, uses) + if stack:is_empty() and def and def._on_break then + stack = def._on_break(obj) or stack + end + inv:set_stack("armor", index, stack) +end + +mcl_damage.register_modifier(function(obj, damage, reason) + local flags = reason.flags + + if flags.bypasses_armor and flags.bypasses_magic then + return damage + end + + local uses = math.max(1, math.floor(damage / 4)) + + local points = 0 + local toughness = 0 + local enchantment_protection_factor = 0 + + local thorns_damage_regular = 0 + local thorns_damage_irregular = 0 + local thorns_pieces = {} + + local inv = mcl_util.get_inventory(obj) + + if inv then + for name, element in pairs(mcl_armor.elements) do + local itemstack = inv:get_stack("armor", element.index) + if not itemstack:is_empty() then + local itemname = itemstack:get_name() + local enchantments = mcl_enchanting.get_enchantments(itemstack) + + if not flags.bypasses_armor then + points = points + minetest.get_item_group(itemname, "mcl_armor_points") + toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness") + + use_durability(obj, inv, element.index, itemstack, uses) + end + + if not flags.bypasses_magic then + local function add_enchantments(tbl) + if tbl then + for _, enchantment in pairs(tbl) do + local level = enchantments[enchantment.id] + + if level and level > 0 then + enchantment_protection_factor = enchantment_protection_factor + level * enchantment.factor + end + end + end + end + + add_enchantments(mcl_armor.protection_enchantments.wildcard) + add_enchantments(mcl_armor.protection_enchantments.types[reason.type]) + + for flag, value in pairs(flags) do + if value then + add_enchantments(mcl_armor.protection_enchantments.flags[flag]) + end + end + end + + if reason.source and enchantments.thorns and enchantments.thorns > 0 then + local do_irregular_damage = enchantments.thorns > 10 + + if do_irregular_damage or thorns_damage_regular < 4 and math.random() < enchantments.thorns * 0.15 then + if do_irregular_damage then + thorns_damage_irregular = thorns_damage_irregular + throrns_level - 10 + else + thorns_damage_regular = math.min(4, thorns_damage_regular + math.random(4)) + end + end + + table.insert(thorns_pieces, {index = element.index, itemstack = itemstack}) + end + end + end + end + + -- https://minecraft.gamepedia.com/Armor#Damage_protection + damage = damage * (1 - math.min(20, math.max((points / 5), points - damage / (2 + (toughness / 4)))) / 25) + + -- https://minecraft.gamepedia.com/Armor#Enchantments + damage = damage * (1 - math.min(20, enchantment_protection_factor) / 25) + + local thorns_damage = thorns_damage_regular + thorns_damage_irregular + + if thorns_damage > 0 and reason.type ~= "thorns" and reason.source ~= obj then + mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj}) + + local thorns_item = thorns_pieces[math.random(#thorns_pieces)] + + use_durability(obj, inv, thorns_item.index, thorns_item.itemstack, 2) + end + + mcl_armor.update(obj) + + return math.floor(damage + 0.5) +end, 0) diff --git a/mods/ITEMS/mcl_armor/init.lua b/mods/ITEMS/mcl_armor/init.lua index df06ecd04d..0f7725010a 100644 --- a/mods/ITEMS/mcl_armor/init.lua +++ b/mods/ITEMS/mcl_armor/init.lua @@ -1,406 +1,68 @@ local S = minetest.get_translator("mcl_armor") -dofile(minetest.get_modpath(minetest.get_current_modname()).."/armor.lua") -dofile(minetest.get_modpath(minetest.get_current_modname()).."/alias.lua") - --- Regisiter Head Armor - -local longdesc = S("This is a piece of equippable armor which reduces the amount of damage you receive.") -local usage = S("To equip it, put it on the corresponding armor slot in your inventory menu.") - -minetest.register_tool("mcl_armor:elytra", { - description = S("Elytra"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_elytra.png", - groups = {armor_torso=1, mcl_armor_points=0, mcl_armor_uses=10, enchantability=0}, - _repair_material = "mcl_mobitems:leather", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_leather", - _mcl_armor_unequip = "mcl_armor_unequip_leather", +mcl_armor = { + longdesc = S("This is a piece of equippable armor which reduces the amount of damage you receive."), + usage = S("To equip it, put it on the corresponding armor slot in your inventory menu."), + elements = { + head = { + name = "helmet", + description = "Helmet", + durability = 0.6857, + index = 2, + craft = function(m) + return { + { m, m, m}, + { m, "", m}, + {"", "", ""}, + } + end, + }, + torso = { + name = "chestplate", + description = "Chestplate", + durability = 1.0, + index = 3, + craft = function(m) + return { + { m, "", m}, + { m, m, m}, + { m, m, m}, + } + end, + }, + legs = { + name = "leggings", + description = "Leggings", + durability = 0.9375, + index = 4, + craft = function(m) + return { + { m, m, m}, + { m, "", m}, + { m, "", m}, + } + end, + }, + feet = { + name = "boots", + description = "Boots", + durability = 0.8125, + index = 5, + craft = function(m) + return { + { m, "", m}, + { m, "", m}, + } + end, + } }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:helmet_leather", { - description = S("Leather Cap"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_helmet_leather.png", - groups = {armor_head=1, mcl_armor_points=1, mcl_armor_uses=56, enchantability=15}, - _repair_material = "mcl_mobitems:leather", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_leather", - _mcl_armor_unequip = "mcl_armor_unequip_leather", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:helmet_iron", { - description = S("Iron Helmet"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_helmet_iron.png", - groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166, enchantability=9 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:helmet_gold", { - description = S("Golden Helmet"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_helmet_gold.png", - groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=78, enchantability=25 }, - _repair_material = "mcl_core:gold_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:helmet_diamond",{ - description = S("Diamond Helmet"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_helmet_diamond.png", - groups = {armor_head=1, mcl_armor_points=3, mcl_armor_uses=364, mcl_armor_toughness=2, enchantability=10 }, - _repair_material = "mcl_core:diamond", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_diamond", - _mcl_armor_unequip = "mcl_armor_unequip_diamond", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:helmet_chain", { - description = S("Chain Helmet"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_helmet_chain.png", - groups = {armor_head=1, mcl_armor_points=2, mcl_armor_uses=166, enchantability=12 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_chainmail", - _mcl_armor_unequip = "mcl_armor_unequip_chainmail", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - --- Regisiter Torso Armor - -minetest.register_tool("mcl_armor:chestplate_leather", { - description = S("Leather Tunic"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_chestplate_leather.png", - groups = {armor_torso=1, mcl_armor_points=3, mcl_armor_uses=81, enchantability=15 }, - _repair_material = "mcl_mobitems:leather", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_leather", - _mcl_armor_unequip = "mcl_armor_unequip_leather", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:chestplate_iron", { - description = S("Iron Chestplate"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_chestplate_iron.png", - groups = {armor_torso=1, mcl_armor_points=6, mcl_armor_uses=241, enchantability=9 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:chestplate_gold", { - description = S("Golden Chestplate"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_chestplate_gold.png", - groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=113, enchantability=25 }, - _repair_material = "mcl_core:gold_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:chestplate_diamond",{ - description = S("Diamond Chestplate"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_chestplate_diamond.png", - groups = {armor_torso=1, mcl_armor_points=8, mcl_armor_uses=529, mcl_armor_toughness=2, enchantability=10 }, - _repair_material = "mcl_core:diamond", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_diamond", - _mcl_armor_unequip = "mcl_armor_unequip_diamond", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:chestplate_chain", { - description = S("Chain Chestplate"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_chestplate_chain.png", - groups = {armor_torso=1, mcl_armor_points=5, mcl_armor_uses=241, enchantability=12 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_chainmail", - _mcl_armor_unequip = "mcl_armor_unequip_chainmail", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - --- Regisiter Leg Armor - -minetest.register_tool("mcl_armor:leggings_leather", { - description = S("Leather Pants"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_leggings_leather.png", - groups = {armor_legs=1, mcl_armor_points=2, mcl_armor_uses=76, enchantability=15 }, - _repair_material = "mcl_mobitems:leather", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_leather", - _mcl_armor_unequip = "mcl_armor_unequip_leather", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:leggings_iron", { - description = S("Iron Leggings"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_leggings_iron.png", - groups = {armor_legs=1, mcl_armor_points=5, mcl_armor_uses=226, enchantability=9 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:leggings_gold", { - description = S("Golden Leggings"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_leggings_gold.png", - groups = {armor_legs=1, mcl_armor_points=3, mcl_armor_uses=106, enchantability=25 }, - _repair_material = "mcl_core:gold_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:leggings_diamond",{ - description = S("Diamond Leggings"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_leggings_diamond.png", - groups = {armor_legs=1, mcl_armor_points=6, mcl_armor_uses=496, mcl_armor_toughness=2, enchantability=10 }, - _repair_material = "mcl_core:diamond", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_diamond", - _mcl_armor_unequip = "mcl_armor_unequip_diamond", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:leggings_chain", { - description = S("Chain Leggings"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_leggings_chain.png", - groups = {armor_legs=1, mcl_armor_points=4, mcl_armor_uses=226, enchantability=12 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_chainmail", - _mcl_armor_unequip = "mcl_armor_unequip_chainmail", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) --- Regisiter Boots - -minetest.register_tool("mcl_armor:boots_leather", { - description = S("Leather Boots"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_boots_leather.png", - groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=66, enchantability=15 }, - _repair_material = "mcl_mobitems:leather", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_leather", - _mcl_armor_unequip = "mcl_armor_unequip_leather", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:boots_iron", { - description = S("Iron Boots"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_boots_iron.png", - groups = {armor_feet=1, mcl_armor_points=2, mcl_armor_uses=196, enchantability=9 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:boots_gold", { - description = S("Golden Boots"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_boots_gold.png", - groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=92, enchantability=25 }, - _repair_material = "mcl_core:gold_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_iron", - _mcl_armor_unequip = "mcl_armor_unequip_iron", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:boots_diamond",{ - description = S("Diamond Boots"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_boots_diamond.png", - groups = {armor_feet=1, mcl_armor_points=3, mcl_armor_uses=430, mcl_armor_toughness=2, enchantability=10 }, - _repair_material = "mcl_core:diamond", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_diamond", - _mcl_armor_unequip = "mcl_armor_unequip_diamond", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - -minetest.register_tool("mcl_armor:boots_chain", { - description = S("Chain Boots"), - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usage, - inventory_image = "mcl_armor_inv_boots_chain.png", - groups = {armor_feet=1, mcl_armor_points=1, mcl_armor_uses=196, enchantability=12 }, - _repair_material = "mcl_core:iron_ingot", - sounds = { - _mcl_armor_equip = "mcl_armor_equip_chainmail", - _mcl_armor_unequip = "mcl_armor_unequip_chainmail", - }, - on_place = armor.on_armor_use, - on_secondary_use = armor.on_armor_use, -}) - --- Register Craft Recipies - -local craft_ingreds = { - leather = { "mcl_mobitems:leather" }, - iron = { "mcl_core:iron_ingot", "mcl_core:iron_nugget" }, - gold = { "mcl_core:gold_ingot", "mcl_core:gold_nugget" }, - diamond = { "mcl_core:diamond" }, - chain = { nil, "mcl_core:iron_nugget"} , + player_view_range_factors = {}, } -for k, v in pairs(craft_ingreds) do - -- material - local m = v[1] - -- cooking result - local c = v[2] - if m ~= nil then - minetest.register_craft({ - output = "mcl_armor:helmet_"..k, - recipe = { - {m, m, m}, - {m, "", m}, - {"", "", ""}, - }, - }) - minetest.register_craft({ - output = "mcl_armor:chestplate_"..k, - recipe = { - {m, "", m}, - {m, m, m}, - {m, m, m}, - }, - }) - minetest.register_craft({ - output = "mcl_armor:leggings_"..k, - recipe = { - {m, m, m}, - {m, "", m}, - {m, "", m}, - }, - }) - minetest.register_craft({ - output = "mcl_armor:boots_"..k, - recipe = { - {m, "", m}, - {m, "", m}, - }, - }) - end - if c ~= nil then - minetest.register_craft({ - type = "cooking", - output = c, - recipe = "mcl_armor:helmet_"..k, - cooktime = 10, - }) - minetest.register_craft({ - type = "cooking", - output = c, - recipe = "mcl_armor:chestplate_"..k, - cooktime = 10, - }) - minetest.register_craft({ - type = "cooking", - output = c, - recipe = "mcl_armor:leggings_"..k, - cooktime = 10, - }) - minetest.register_craft({ - type = "cooking", - output = c, - recipe = "mcl_armor:boots_"..k, - cooktime = 10, - }) - end -end +local modpath = minetest.get_modpath("mcl_armor") + +dofile(modpath .. "/api.lua") +dofile(modpath .. "/player.lua") +dofile(modpath .. "/damage.lua") +dofile(modpath .. "/register.lua") +dofile(modpath .. "/alias.lua") diff --git a/mods/ITEMS/mcl_armor/player.lua b/mods/ITEMS/mcl_armor/player.lua new file mode 100644 index 0000000000..9dba0773c2 --- /dev/null +++ b/mods/ITEMS/mcl_armor/player.lua @@ -0,0 +1,169 @@ +mcl_player.player_register_model("mcl_armor_character.b3d", { + animation_speed = 30, + textures = { + "character.png", + "blank.png", + "blank.png", + }, + animations = { + stand = {x=0, y=79}, + lay = {x=162, y=166}, + walk = {x=168, y=187}, + mine = {x=189, y=198}, + walk_mine = {x=200, y=219}, + sit = {x=81, y=160}, + sneak_stand = {x=222, y=302}, + sneak_mine = {x=346, y=365}, + sneak_walk = {x=304, y=323}, + sneak_walk_mine = {x=325, y=344}, + swim_walk = {x=368, y=387}, + swim_walk_mine = {x=389, y=408}, + swim_stand = {x=434, y=434}, + swim_mine = {x=411, y=430}, + run_walk = {x=440, y=459}, + run_walk_mine = {x=461, y=480}, + sit_mount = {x=484, y=484}, + die = {x=498, y=498}, + fly = {x=502, y=581}, + }, +}) + +mcl_player.player_register_model("mcl_armor_character_female.b3d", { + animation_speed = 30, + textures = { + "character.png", + "blank.png", + "blank.png", + }, + animations = { + stand = {x=0, y=79}, + lay = {x=162, y=166}, + walk = {x=168, y=187}, + mine = {x=189, y=198}, + walk_mine = {x=200, y=219}, + sit = {x=81, y=160}, + sneak_stand = {x=222, y=302}, + sneak_mine = {x=346, y=365}, + sneak_walk = {x=304, y=323}, + sneak_walk_mine = {x=325, y=344}, + swim_walk = {x=368, y=387}, + swim_walk_mine = {x=389, y=408}, + swim_stand = {x=434, y=434}, + swim_mine = {x=411, y=430}, + run_walk = {x=440, y=459}, + run_walk_mine = {x=461, y=480}, + sit_mount = {x=484, y=484}, + die = {x=498, y=498}, + fly = {x=502, y=581}, + }, +}) + +function mcl_armor.update_player(player, info) + mcl_player.player_set_armor(player, info.texture, info.preview) + + local meta = player:get_meta() + meta:set_int("mcl_armor:armor_points", info.points) + + mcl_armor.player_view_range_factors[player] = info.view_range_factors +end + +local function is_armor_action(inventory_info) + return inventory_info.from_list == "armor" or inventory_info.to_list == "armor" or inventory_info.listname == "armor" +end + +local function limit_put(player, inventory, index, stack, count) + local def = stack:get_definition() + + if not def then + return 0 + end + + local element = def._mcl_armor_element + + if not element then + return 0 + end + + local element_index = mcl_armor.elements[element].index + + if index ~= 1 and index ~= element_index then + return 0 + end + + local old_stack = inventory:get_stack("armor", element_index) + + if old_stack:is_empty() or index ~= 1 and old_stack:get_name() ~= stack:get_name() and count <= 1 then + return count + else + return 0 + end +end + +local function limit_take(player, inventory, index, stack, count) + if mcl_enchanting.has_enchantment(stack, "curse_of_binding") and not minetest.is_creative_enabled(player:get_player_name()) then + return 0 + end + + return count +end + +minetest.register_allow_player_inventory_action(function(player, action, inventory, inventory_info) + if not is_armor_action(inventory_info) then + return + end + + if action == "put" then + return limit_put(player, inventory, inventory_info.index, inventory_info.stack, inventory_info.stack:get_count()) + elseif action == "take" then + return limit_take(player, inventory, inventory_info.index, inventory_info.stack, inventory_info.stack:get_count()) + else + if inventory_info.from_list ~= "armor" then + return limit_put(player, inventory, inventory_info.to_index, inventory:get_stack(inventory_info.from_list, inventory_info.from_index), inventory_info.count) + elseif inventory_info.to_list ~= "armor" then + return limit_take(player, inventory, inventory_info.from_index, inventory:get_stack(inventory_info.from_list, inventory_info.from_index), inventory_info.count) + else + return 0 + end + end +end) + +local function on_put(player, inventory, index, stack) + if index == 1 then + mcl_armor.equip(stack, player) + inventory:set_stack("armor", 1, nil) + else + mcl_armor.on_equip(stack, player) + end +end + +minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info) + if is_armor_action(inventory_info) then + if action == "put" then + on_put(player, inventory, inventory_info.index, inventory_info.stack) + elseif action == "take" then + mcl_armor.on_unequip(inventory_info.stack, player) + else + local stack = inventory:get_stack(inventory_info.to_list, inventory_info.to_index) + if inventory_info.to_list == "armor" then + on_put(player, inventory, inventory_info.to_index, stack) + elseif inventory_info.from_list == "armor" then + mcl_armor.on_unequip(stack, player) + end + end + end +end) + +minetest.register_on_joinplayer(function(player) + mcl_player.player_set_model(player, "mcl_armor_character.b3d") + player:get_inventory():set_size("armor", 5) + + minetest.after(1, function() + if player:is_player() then + mcl_armor.update(player) + end + end) +end) + +minetest.register_on_leaveplayer(function(player) + mcl_armor.player_view_range_factors[player] = nil +end) diff --git a/mods/ITEMS/mcl_armor/register.lua b/mods/ITEMS/mcl_armor/register.lua new file mode 100644 index 0000000000..de17fd20d9 --- /dev/null +++ b/mods/ITEMS/mcl_armor/register.lua @@ -0,0 +1,205 @@ +local S = minetest.get_translator("mcl_armor") + +mcl_armor.register_set({ + name = "leather", + description = "Leather", + descriptions = { + head = "Cap", + torso = "Tunic", + legs = "Pants", + }, + durability = 80, + enchantability = 15, + points = { + head = 1, + torso = 3, + legs = 2, + feet = 1, + }, + craft_material = "mcl_mobitems:leather", +}) + +mcl_armor.register_set({ + name = "gold", + description = "Golden", + durability = 112, + enchantability = 25, + points = { + head = 2, + torso = 5, + legs = 3, + feet = 1, + }, + craft_material = "mcl_core:gold_ingot", + cook_material = "mcl_core:gold_nugget", + sound_equip = "mcl_armor_equip_iron", + sound_unequip = "mcl_armor_unequip_iron", +}) + +mcl_armor.register_set({ + name = "chain", + description = "Chain", + durability = 240, + enchantability = 12, + points = { + head = 2, + torso = 5, + legs = 4, + feet = 1, + }, + repair_material = "mcl_core:iron_ingot", + cook_material = "mcl_core:iron_nugget", +}) + +mcl_armor.register_set({ + name = "iron", + description = "Iron", + durability = 240, + enchantability = 9, + points = { + head = 2, + torso = 6, + legs = 5, + feet = 2, + }, + craft_material = "mcl_core:iron_ingot", + cook_material = "mcl_core:iron_nugget", +}) + +mcl_armor.register_set({ + name = "diamond", + description = "Diamond", + durability = 528, + enchantability = 10, + points = { + head = 3, + torso = 8, + legs = 6, + feet = 3, + }, + toughness = 2, + craft_material = "mcl_core:diamond", +}) + +mcl_armor.register_protection_enchantment({ + id = "projectile_protection", + name = S("Projectile Protection"), + description = S("Reduces projectile damage."), + power_range_table = {{1, 16}, {11, 26}, {21, 36}, {31, 46}, {41, 56}}, + incompatible = {blast_protection = true, fire_protection = true, protection = true}, + factor = 2, + damage_flag = "is_projectile", +}) + +mcl_armor.register_protection_enchantment({ + id = "blast_protection", + name = S("Blast Protection"), + description = S("Reduces explosion damage and knockback."), + power_range_table = {{5, 13}, {13, 21}, {21, 29}, {29, 37}}, + weight = 2, + incompatible = {fire_protection = true, protection = true, projectile_protection = true}, + factor = 2, + damage_flag = "is_explosion", +}) + +mcl_armor.register_protection_enchantment({ + id = "fire_protection", + name = S("Fire Protection"), + description = S("Reduces fire damage."), + power_range_table = {{5, 13}, {13, 21}, {21, 29}, {29, 37}}, + incompatible = {blast_protection = true, protection = true, projectile_protection = true}, + factor = 2, + damage_flag = "is_fire", +}) + +mcl_armor.register_protection_enchantment({ + id = "protection", + name = S("Protection"), + description = S("Reduces most types of damage by 4% for each level."), + power_range_table = {{1, 12}, {12, 23}, {23, 34}, {34, 45}}, + incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true}, + factor = 1, +}) + +mcl_armor.register_protection_enchantment({ + id = "feather_falling", + name = S("Feather Falling"), + description = S("Reduces fall damage."), + power_range_table = {{5, 11}, {11, 17}, {17, 23}, {23, 29}}, + factor = 3, + primary = {combat_armor_feet = true}, + damage_type = "fall", +}) + +-- requires engine change +--[[mcl_enchanting.enchantments.aqua_affinity = { + name = S("Aqua Affinity"), + max_level = 1, + primary = {armor_head = true}, + secondary = {}, + disallow = {non_combat_armor = true}, + incompatible = {}, + weight = 2, + description = S("Increases underwater mining speed."), + curse = false, + on_enchant = function() end, + requires_tool = false, + treasure = false, + power_range_table = {{1, 41}}, + inv_combat_tab = true, + inv_tool_tab = false, +}]]-- + +mcl_enchanting.enchantments.curse_of_binding = { + name = S("Curse of Binding"), + max_level = 1, + primary = {}, + secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, + disallow = {}, + incompatible = {}, + weight = 1, + description = S("Item cannot be removed from armor slots except due to death, breaking or in Creative Mode."), + curse = true, + on_enchant = function() end, + requires_tool = false, + treasure = true, + power_range_table = {{25, 50}}, + inv_combat_tab = true, + inv_tool_tab = false, +} + +mcl_enchanting.enchantments.thorns = { + name = S("Thorns"), + max_level = 3, + primary = {combat_armor_chestplate = true}, + secondary = {combat_armor = true}, + disallow = {}, + incompatible = {}, + weight = 1, + description = S("Reflects some of the damage taken when hit, at the cost of reducing durability with each proc."), + curse = false, + on_enchant = function() end, + requires_tool = false, + treasure = false, + power_range_table = {{10, 61}, {30, 71}, {50, 81}}, + inv_combat_tab = true, + inv_tool_tab = false, +} + +-- Elytra + +minetest.register_tool("mcl_armor:elytra", { + description = S("Elytra"), + _doc_items_longdesc = mcl_armor.longdesc, + _doc_items_usagehelp = mcl_armor.usage, + inventory_image = "mcl_armor_inv_elytra.png", + groups = {armor = 1, non_combat_armor = 1, armor_torso = 1, non_combat_torso = 1, mcl_armor_uses = 10}, + sounds = { + _mcl_armor_equip = "mcl_armor_equip_leather", + _mcl_armor_unequip = "mcl_armor_unequip_leather", + }, + on_place = mcl_armor.equip_on_use, + on_secondary_use = mcl_armor.equip_on_use, + _mcl_armor_element = "torso", + _mcl_armor_texture = "mcl_armor_elytra.png" +}) diff --git a/mods/ITEMS/mcl_armor_stand/init.lua b/mods/ITEMS/mcl_armor_stand/init.lua index c451b6de10..870d567fc1 100644 --- a/mods/ITEMS/mcl_armor_stand/init.lua +++ b/mods/ITEMS/mcl_armor_stand/init.lua @@ -1,84 +1,41 @@ local S = minetest.get_translator("mcl_armor_stand") -local elements = {"head", "torso", "legs", "feet"} - -local function get_stand_object(pos) - local object = nil - local objects = minetest.get_objects_inside_radius(pos, 0.5) or {} - for _, obj in pairs(objects) do - local ent = obj:get_luaentity() - if ent then - if ent.name == "mcl_armor_stand:armor_entity" then - -- Remove duplicates - if object then - obj:remove() - else - object = obj - end - end - end - end - return object +-- Spawn a stand entity +local function spawn_stand_entity(pos, node) + local luaentity = minetest.add_entity(pos, "mcl_armor_stand:armor_entity"):get_luaentity() + luaentity:update_rotation(node or minetest.get_node(pos)) + return luaentity end -local function update_entity(pos) - local node = minetest.get_node(pos) - local object = get_stand_object(pos) - if object then - if not string.find(node.name, "mcl_armor_stand:") then - object:remove() - return +-- Find a stand entity or spawn one +local function get_stand_entity(pos, node) + for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 0)) do + local luaentity = obj:get_luaentity() + if luaentity and luaentity.name == "mcl_armor_stand:armor_entity" then + return luaentity end - else - object = minetest.add_entity(pos, "mcl_armor_stand:armor_entity") end - if object then - local texture = "blank.png" - local textures = {} - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - local yaw = 0 - if inv then - for _, element in pairs(elements) do - local stack = inv:get_stack("armor_"..element, 1) - if stack:get_count() == 1 then - local item = stack:get_name() or "" - if minetest.registered_aliases[item] then - item = minetest.registered_aliases[item] - end - local def = stack:get_definition() or {} - local groups = def.groups or {} - if groups["armor_"..element] then - local texture = def.texture or item:gsub("%:", "_") - table.insert(textures, texture..".png") - end - end - end + return spawn_stand_entity(pos, node) +end + +-- Migrate the old inventory format +local function migrate_inventory(inv) + inv:set_size("armor", 5) + local lists = inv:get_lists() + for name, element in pairs(mcl_armor.elements) do + local listname = "armor_" .. name + local list = lists[listname] + if list then + inv:set_stack("armor", element.index, list[1]) + inv:set_size(listname, 0) end - if #textures > 0 then - texture = table.concat(textures, "^") - end - if node.param2 then - local rot = node.param2 % 4 - if rot == 1 then - yaw = 3 * math.pi / 2 - elseif rot == 2 then - yaw = math.pi - elseif rot == 3 then - yaw = math.pi / 2 - end - end - object:set_yaw(yaw) - object:set_properties({textures={texture}}) end end --- Drop all armor of the armor stand on the ground -local drop_armor = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - for _, element in pairs(elements) do - local stack = inv:get_stack("armor_"..element, 1) +-- Drop all armor on the ground when it got destroyed +local function drop_inventory(pos) + local inv = minetest.get_meta(pos):get_inventory() + for _, stack in pairs(inv:get_list("armor")) do if not stack:is_empty() then local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} minetest.add_item(p, stack) @@ -111,136 +68,26 @@ minetest.register_node("mcl_armor_stand:armor_stand", { _mcl_hardness = 2, sounds = mcl_sounds.node_sound_wood_defaults(), on_construct = function(pos) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - for _, element in pairs(elements) do - inv:set_size("armor_"..element, 1) - end + spawn_stand_entity(pos) + end, + on_destruct = function(pos) + drop_inventory(pos) end, - -- Drop all armor on the ground when it got destroyed - on_destruct = drop_armor, - -- Put piece of armor on armor stand, or take one away on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local protname = clicker:get_player_name() + if minetest.is_protected(pos, protname) then minetest.record_protection_violation(pos, protname) return itemstack end - local inv = minetest.get_inventory({type = "node", pos = pos}) - if not inv then - return itemstack - end - - -- Check if player wields armor - local name = itemstack:get_name() - local list - for e=1, #elements do - local g = minetest.get_item_group(name, "armor_" .. elements[e]) - if g ~= nil and g ~= 0 then - list = "armor_" .. elements[e] - break - end - end - -- If player wields armor, put it on armor stand - local wielditem = clicker:get_wielded_item() - if list then - -- ... but only if the slot is free - local single_item = ItemStack(itemstack) - single_item:set_count(1) - if inv:is_empty(list) then - inv:add_item(list, single_item) - armor:play_equip_sound(single_item, nil, pos) - update_entity(pos) - itemstack:take_item() - return itemstack - end - end - - -- Take armor from stand if player has a free hand or wields the same armor type (if stackable) - for e=1, #elements do - local stand_armor = inv:get_stack("armor_" .. elements[e], 1) - if not stand_armor:is_empty() then - local pinv = clicker:get_inventory() - local taken = false - -- Empty hand - if wielditem:get_name() == "" then - pinv:set_stack("main", clicker:get_wield_index(), stand_armor) - taken = true - -- Stackable armor type (if not already full). This is the case for e.g. mob heads. - -- This is done purely for convenience. - elseif (wielditem:get_name() == stand_armor:get_name() and wielditem:get_count() < wielditem:get_stack_max()) then - wielditem:set_count(wielditem:get_count()+1) - pinv:set_stack("main", clicker:get_wield_index(), wielditem) - taken = true - end - if taken then - armor:play_equip_sound(stand_armor, nil, pos, true) - stand_armor:take_item() - inv:set_stack("armor_" .. elements[e], 1, stand_armor) - end - update_entity(pos) - return clicker:get_wielded_item() - end - end - update_entity(pos) - return itemstack - end, - after_place_node = function(pos) - minetest.add_entity(pos, "mcl_armor_stand:armor_entity") - end, - allow_metadata_inventory_take = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - else - return stack:get_count() - end - end, - allow_metadata_inventory_put = function(pos, listname, index, stack, player) - local name = player:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return 0 - end - local def = stack:get_definition() or {} - local groups = def.groups or {} - if groups[listname] then - return 1 - end - return 0 - end, - allow_metadata_inventory_move = function() - return 0 - end, - on_metadata_inventory_put = function(pos) - update_entity(pos) - end, - on_metadata_inventory_take = function(pos) - update_entity(pos) - end, - after_destruct = function(pos) - update_entity(pos) - end, - on_blast = function(pos, _, do_drop) - local object = get_stand_object(pos) - if object then - object:remove() - end - minetest.after(1, function(pos) - update_entity(pos) - end, pos) - minetest.remove_node(pos) - if do_drop then - minetest.add_item(pos, "mcl_armor_stand:armor_stand") - end + return mcl_armor.equip(itemstack, get_stand_entity(pos, node).object, true) end, on_rotate = function(pos, node, user, mode) if mode == screwdriver.ROTATE_FACE then node.param2 = (node.param2 + 1) % 4 minetest.swap_node(pos, node) - update_entity(pos) + get_stand_entity(pos, node):update_rotation(node) return true end return false @@ -248,50 +95,44 @@ minetest.register_node("mcl_armor_stand:armor_stand", { }) minetest.register_entity("mcl_armor_stand:armor_entity", { - physical = true, - visual = "mesh", - mesh = "3d_armor_entity.obj", - visual_size = {x=1, y=1}, - collisionbox = {-0.1,-0.4,-0.1, 0.1,1.3,0.1}, - pointable = false, - textures = {"blank.png"}, - pos = nil, - timer = 0, + initial_properties = { + physical = true, + visual = "mesh", + mesh = "3d_armor_entity.obj", + visual_size = {x=1, y=1}, + collisionbox = {-0.1,-0.4,-0.1, 0.1,1.3,0.1}, + pointable = false, + textures = {"blank.png"}, + timer = 0, + static_save = false, + }, on_activate = function(self) - local pos = self.object:get_pos() - self.object:set_armor_groups({immortal=1}) - if pos then - self.pos = vector.round(pos) - update_entity(pos) - end + self.object:set_armor_groups({immortal = 1}) + self.node_pos = vector.round(self.object:get_pos()) + self.inventory = minetest.get_meta(self.node_pos):get_inventory() + migrate_inventory(self.inventory) + mcl_armor.update(self.object) end, on_step = function(self, dtime) - if not self.pos then - return - end - self.timer = self.timer + dtime - if self.timer > 1 then - self.timer = 0 - local pos = self.object:get_pos() - if pos then - if vector.equals(vector.round(pos), self.pos) then - return - end - end - update_entity(self.pos) + if minetest.get_node(self.node_pos).name ~= "mcl_armor_stand:armor_stand" then self.object:remove() end end, + update_armor = function(self, info) + self.object:set_properties({textures = {info.texture}}) + end, + update_rotation = function(self, node) + self.object:set_yaw(minetest.dir_to_yaw(minetest.facedir_to_dir(node.param2))) + end, }) --- FIXME: Armor helper entity can get destroyed by /clearobjects minetest.register_lbm({ label = "Respawn armor stand entities", name = "mcl_armor_stand:respawn_entities", nodenames = {"mcl_armor_stand:armor_stand"}, run_at_every_load = true, action = function(pos, node) - update_entity(pos, node) + spawn_stand_entity(pos, node) end, }) @@ -304,7 +145,6 @@ minetest.register_craft({ } }) - -- Legacy handling minetest.register_alias("3d_armor_stand:armor_stand", "mcl_armor_stand:armor_stand") minetest.register_entity(":3d_armor_stand:armor_entity", { diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index b1ce06b96e..ecd7496036 100644 --- a/mods/ITEMS/mcl_beds/functions.lua +++ b/mods/ITEMS/mcl_beds/functions.lua @@ -88,7 +88,7 @@ local function lay_down(player, pos, bed_pos, state, skip) end for _, other_pos in pairs(mcl_beds.bed_pos) do - if vector.distance(bed_pos, other_pos) < 0.1 then + if vector.distance(bed_pos2, other_pos) < 0.1 then return false, S("This bed is already occupied!") end end @@ -170,7 +170,7 @@ local function lay_down(player, pos, bed_pos, state, skip) mcl_beds.player[name] = 1 mcl_beds.pos[name] = pos - mcl_beds.bed_pos[name] = bed_pos + mcl_beds.bed_pos[name] = bed_pos2 player_in_bed = player_in_bed + 1 -- physics, eye_offset, etc player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0}) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index cb92593f80..a6f0c13dbe 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -69,6 +69,7 @@ local ARROW_ENTITY={ _stuckrechecktimer=nil,-- An additional timer for periodically re-checking the stuck status of an arrow _stuckin=nil, --Position of node in which arow is stuck. _shooter=nil, -- ObjectRef of player or mob who shot it + _is_arrow = true, _viscosity=0, -- Viscosity of node the arrow is currently in _deflection_cooloff=0, -- Cooloff timer after an arrow deflection, to prevent many deflections in quick succession @@ -254,9 +255,6 @@ ARROW_ENTITY.on_step = function(self, dtime) -- Punch target object but avoid hurting enderman. if not lua or lua.name ~= "mobs_mc:enderman" then - if obj:is_player() and rawget(_G, "armor") and armor.last_damage_types then - armor.last_damage_types[obj:get_player_name()] = "projectile" - end if self._in_player == false then damage_particles(self.object:get_pos(), self._is_critical) end diff --git a/mods/ITEMS/mcl_bows/bow.lua b/mods/ITEMS/mcl_bows/bow.lua index 45912384ea..2257fcc5ea 100644 --- a/mods/ITEMS/mcl_bows/bow.lua +++ b/mods/ITEMS/mcl_bows/bow.lua @@ -59,6 +59,7 @@ mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damag obj:set_yaw(yaw-math.pi/2) local le = obj:get_luaentity() le._shooter = shooter + le._source_object = shooter le._damage = damage le._is_critical = is_critical le._startpos = pos diff --git a/mods/ITEMS/mcl_chests/locale/template.txt b/mods/ITEMS/mcl_chests/locale/template.txt index d680c24c9d..1d947184b1 100644 --- a/mods/ITEMS/mcl_chests/locale/template.txt +++ b/mods/ITEMS/mcl_chests/locale/template.txt @@ -24,7 +24,7 @@ Red Shulker Box= Grey Shulker Box= Black Shulker Box= A shulker box is a portable container which provides 27 inventory slots for any item except shulker boxes. Shulker boxes keep their inventory when broken, so shulker boxes as well as their contents can be taken as a single item. Shulker boxes come in many different colors.= -To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out. Place the shulker box again to be able to retrieve its contents.= +To access the inventory of a shulker box, place and right-click it. To take a shulker box and its contents with you, just break and collect it, the items will not fall out.= Shulker Box= Large Chest= Inventory= diff --git a/mods/ITEMS/mcl_core/locale/mcl_core.de.tr b/mods/ITEMS/mcl_core/locale/mcl_core.de.tr index 8fbd797222..3d90dd5ae8 100644 --- a/mods/ITEMS/mcl_core/locale/mcl_core.de.tr +++ b/mods/ITEMS/mcl_core/locale/mcl_core.de.tr @@ -274,3 +274,4 @@ Slows down movement=Verlangsamt die Fortbewegung 2×2 saplings @= large tree=2×2 Setzlinge @= großer Baum Grows on sand or dirt next to water=Wächst auf Sand oder Erde neben Wasser Stackable=Stapelbar +Needs soil and water to grow=Braucht Nährboden und Wasser zum wachsen diff --git a/mods/ITEMS/mcl_core/nodes_liquid.lua b/mods/ITEMS/mcl_core/nodes_liquid.lua index 4696a629ac..c49b685eba 100644 --- a/mods/ITEMS/mcl_core/nodes_liquid.lua +++ b/mods/ITEMS/mcl_core/nodes_liquid.lua @@ -203,7 +203,7 @@ S("• When lava is directly above water, the water turns into stone."), _mcl_node_death_message = lava_death_messages, post_effect_color = {a=245, r=208, g=73, b=10}, stack_max = 64, - groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15}, + groups = { lava=3, lava_source=1, liquid=2, destroys_items=1, not_in_creative_inventory=1, dig_by_piston=1, set_on_fire=15, fire_damage=1}, _mcl_blast_resistance = 100, -- Hardness intentionally set to infinite instead of 100 (Minecraft value) to avoid problems in creative mode _mcl_hardness = -1, diff --git a/mods/ITEMS/mcl_enchanting/enchantments.lua b/mods/ITEMS/mcl_enchanting/enchantments.lua index fa3bc3ed5f..84327e3f6d 100644 --- a/mods/ITEMS/mcl_enchanting/enchantments.lua +++ b/mods/ITEMS/mcl_enchanting/enchantments.lua @@ -10,25 +10,6 @@ local function increase_damage(damage_group, factor) end end --- requires engine change ---[[mcl_enchanting.enchantments.aqua_affinity = { - name = S("Aqua Affinity"), - max_level = 1, - primary = {armor_head = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {}, - weight = 2, - description = S("Increases underwater mining speed."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{1, 41}}, - inv_combat_tab = true, - inv_tool_tab = false, -}]]-- - -- implemented via on_enchant and additions in mobs_mc; Slowness IV part unimplemented mcl_enchanting.enchantments.bane_of_arthropods = { name = S("Bane of Arthropods"), @@ -48,25 +29,6 @@ mcl_enchanting.enchantments.bane_of_arthropods = { inv_tool_tab = false, } --- implemented in mcl_armor -mcl_enchanting.enchantments.blast_protection = { - name = S("Blast Protection"), - max_level = 4, - primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {fire_protection = true, protection = true, projectile_protection = true}, - weight = 2, - description = S("Reduces explosion damage and knockback."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{5, 13}, {13, 21}, {21, 29}, {29, 37}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - -- requires missing MineClone2 feature --[[mcl_enchanting.enchantments.channeling = { name = S("Channeling"), @@ -86,25 +48,6 @@ mcl_enchanting.enchantments.blast_protection = { inv_tool_tab = false, }]]-- --- implemented in mcl_armor -mcl_enchanting.enchantments.curse_of_binding = { - name = S("Curse of Binding"), - max_level = 1, - primary = {}, - secondary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, - disallow = {}, - incompatible = {}, - weight = 1, - description = S("Item cannot be removed from armor slots except due to death, breaking or in Creative Mode."), - curse = true, - on_enchant = function() end, - requires_tool = false, - treasure = true, - power_range_table = {{25, 50}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - -- implemented in mcl_death_drop mcl_enchanting.enchantments.curse_of_vanishing = { name = S("Curse of Vanishing"), @@ -164,24 +107,6 @@ mcl_enchanting.enchantments.efficiency = { inv_tool_tab = true, } --- implemented in mcl_armor -mcl_enchanting.enchantments.feather_falling = { - name = S("Feather Falling"), - max_level = 4, - primary = {armor_feet = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {}, - weight = 5, - description = S("Reduces fall damage."),curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{5, 11}, {11, 17}, {17, 23}, {23, 29}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - -- implemented in mcl_mobs and via register_on_punchplayer callback mcl_enchanting.enchantments.fire_aspect = { name = S("Fire Aspect"), @@ -207,31 +132,12 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, if wielditem then local fire_aspect_level = mcl_enchanting.get_enchantment(wielditem, "fire_aspect") if fire_aspect_level > 0 then - mcl_burning.set_on_fire(player, fire_aspect_level * 4, hitter:get_player_name()) + mcl_burning.set_on_fire(player, fire_aspect_level * 4) end end end end) --- implemented in mcl_armor -mcl_enchanting.enchantments.fire_protection = { - name = S("Fire Protection"), - max_level = 4, - primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {blast_protection = true, protection = true, projectile_protection = true}, - weight = 5, - description = S("Reduces fire damage."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{10, 18}, {18, 26}, {26, 34}, {34, 42}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - mcl_enchanting.enchantments.flame = { name = S("Flame"), max_level = 1, @@ -530,44 +436,6 @@ mcl_enchanting.enchantments.power = { inv_tool_tab = false, } --- implemented in mcl_armor -mcl_enchanting.enchantments.projectile_protection = { - name = S("Projectile Protection"), - max_level = 4, - primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {blast_protection = true, fire_protection = true, protection = true}, - weight = 5, - description = S("Reduces projectile damage."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{1, 16}, {11, 26}, {21, 36}, {31, 46}, {41, 56}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - --- implemented in mcl_armor -mcl_enchanting.enchantments.protection = { - name = S("Protection"), - max_level = 4, - primary = {armor_head = true, armor_torso = true, armor_legs = true, armor_feet = true}, - secondary = {}, - disallow = {non_combat_armor = true}, - incompatible = {blast_protection = true, fire_protection = true, projectile_protection = true}, - weight = 10, - description = S("Reduces most types of damage by 4% for each level."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{1, 12}, {12, 23}, {23, 34}, {34, 45}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - -- implemented via minetest.calculate_knockback (together with the Knockback enchantment) and mcl_bows mcl_enchanting.enchantments.punch = { name = S("Punch"), @@ -739,25 +607,6 @@ mcl_enchanting.enchantments.soul_speed = { inv_tool_tab = false, }]]-- --- implemented in mcl_armor -mcl_enchanting.enchantments.thorns = { - name = S("Thorns"), - max_level = 3, - primary = {armor_head = true}, - secondary = {armor_torso = true, armor_legs = true, armor_feet = true}, - disallow = {non_combat_armor = true}, - incompatible = {}, - weight = 1, - description = S("Reflects some of the damage taken when hit, at the cost of reducing durability with each proc."), - curse = false, - on_enchant = function() end, - requires_tool = false, - treasure = false, - power_range_table = {{10, 61}, {30, 71}, {50, 81}}, - inv_combat_tab = true, - inv_tool_tab = false, -} - -- for tools & weapons implemented via on_enchant; for bows implemented in mcl_bows; for armor implemented in mcl_armor and mcl_tt; for fishing rods implemented in mcl_fishing mcl_enchanting.enchantments.unbreaking = { name = S("Unbreaking"), diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index 3243b78796..89fdc393dc 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -6,6 +6,9 @@ function mcl_enchanting.is_book(itemname) end function mcl_enchanting.get_enchantments(itemstack) + if not itemstack then + return({}) + end return minetest.deserialize(itemstack:get_meta():get_string("mcl_enchanting:enchantments")) or {} end @@ -267,7 +270,8 @@ function mcl_enchanting.initialize() new_def.groups.not_in_creative_inventory = 1 new_def.groups.not_in_craft_guide = 1 new_def.groups.enchanted = 1 - new_def.texture = itemdef.texture or itemname:gsub("%:", "_") + new_def._mcl_armor_texture = new_def._mcl_armor_texture and new_def._mcl_armor_texture .. mcl_enchanting.overlay + new_def._mcl_armor_preview = new_def._mcl_armor_preview and new_def._mcl_armor_preview .. mcl_enchanting.overlay new_def._mcl_enchanting_enchanted_tool = new_name new_def.after_use = get_after_use_callback(itemdef) local register_list = register_item_list diff --git a/mods/ITEMS/mcl_farming/pumpkin.lua b/mods/ITEMS/mcl_farming/pumpkin.lua index 72b4e54125..8d234d586d 100644 --- a/mods/ITEMS/mcl_farming/pumpkin.lua +++ b/mods/ITEMS/mcl_farming/pumpkin.lua @@ -111,12 +111,16 @@ pumpkin_face_base_def.description = S("Pumpkin") pumpkin_face_base_def._doc_items_longdesc = S("A pumpkin can be worn as a helmet. Pumpkins grow from pumpkin stems, which in turn grow from pumpkin seeds.") pumpkin_face_base_def._doc_items_usagehelp = nil pumpkin_face_base_def.tiles = {"farming_pumpkin_top.png", "farming_pumpkin_top.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_side.png", "farming_pumpkin_face.png"} +pumpkin_face_base_def.groups.armor=1 +pumpkin_face_base_def.groups.non_combat_armor=1 pumpkin_face_base_def.groups.armor_head=1 +pumpkin_face_base_def.groups.non_combat_armor_head=1 pumpkin_face_base_def._mcl_armor_mob_range_factor = 0 pumpkin_face_base_def._mcl_armor_mob_range_mob = "mobs_mc:enderman" +pumpkin_face_base_def._mcl_armor_entry = "head" pumpkin_face_base_def.groups.non_combat_armor=1 if minetest.get_modpath("mcl_armor") then - pumpkin_face_base_def.on_secondary_use = armor.on_armor_use + pumpkin_face_base_def.on_secondary_use = mcl_armor.equip_on_use end -- Register stem growth diff --git a/mods/ITEMS/mcl_heads/init.lua b/mods/ITEMS/mcl_heads/init.lua index 55b2bf616b..ec6a5638e2 100644 --- a/mods/ITEMS/mcl_heads/init.lua +++ b/mods/ITEMS/mcl_heads/init.lua @@ -5,7 +5,7 @@ local mod_screwdriver = minetest.get_modpath("screwdriver") local equip_armor if minetest.get_modpath("mcl_armor") then - equip_armor = armor.on_armor_use + equip_armor = mcl_armor.equip_on_use end -- Heads system @@ -42,7 +42,7 @@ local function addhead(name, texture, desc, longdesc, rangemob, rangefactor) { -0.25, -0.5, -0.25, 0.25, 0.0, 0.25, }, }, }, - groups = {handy=1, armor_head=1,non_combat_armor=1, head=1, deco_block=1, dig_by_piston=1 }, + groups = {handy = 1, armor = 1, armor_head = 1, non_combat_armor = 1, non_combat_armor_head = 1, head = 1, deco_block = 1, dig_by_piston = 1}, -- The head textures are based off the textures of an actual mob. tiles = { -- Note: bottom texture is overlaid over top texture to get rid of possible transparency. @@ -111,6 +111,7 @@ local function addhead(name, texture, desc, longdesc, rangemob, rangefactor) _mcl_armor_mob_range_mob = rangemob, _mcl_armor_mob_range_factor = rangefactor, + _mcl_armor_element = "head", _mcl_blast_resistance = 1, _mcl_hardness = 1, }) diff --git a/mods/ITEMS/mcl_nether/init.lua b/mods/ITEMS/mcl_nether/init.lua index 4670547675..0a0e2b183b 100644 --- a/mods/ITEMS/mcl_nether/init.lua +++ b/mods/ITEMS/mcl_nether/init.lua @@ -1,6 +1,5 @@ local S = minetest.get_translator("mcl_nether") -local mod_death_messages = minetest.get_modpath("mcl_death_messages") local mod_screwdriver = minetest.get_modpath("screwdriver") ~= nil local on_rotate if mod_screwdriver then @@ -111,10 +110,7 @@ minetest.register_node("mcl_nether:magma", { end -- Hurt players standing on top of this block if player:get_hp() > 0 then - if mod_death_messages then - mcl_death_messages.player_damage(player, S("@1 stood too long on a magma block.", player:get_player_name())) - end - player:set_hp(player:get_hp() - 1, { type = "punch", from = "mod" }) + mcl_util.deal_damage(player, 1, {type = "hot_floor"}) end end, _mcl_blast_resistance = 0.5, diff --git a/mods/ITEMS/mcl_nether/mod.conf b/mods/ITEMS/mcl_nether/mod.conf index 8bef6c6c97..f5ffa61ac1 100644 --- a/mods/ITEMS/mcl_nether/mod.conf +++ b/mods/ITEMS/mcl_nether/mod.conf @@ -1,3 +1,3 @@ name = mcl_nether depends = mcl_core, mcl_sounds, mcl_util, walkover, doc_items, mcl_colors -optional_depends = mcl_death_messages, doc, screwdriver +optional_depends = doc, screwdriver diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 211cf50b04..9a1e38d996 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -132,17 +132,10 @@ minetest.register_globalstep(function(dtime) if player:get_pos() then mcl_potions._add_spawner(player, "#225533") end if EF.poisoned[player].hit_timer >= EF.poisoned[player].step then - - if entity and entity._cmi_is_mob then - entity.health = math.max(entity.health - 1, 1) - EF.poisoned[player].hit_timer = 0 - elseif is_player then - player:set_hp( math.max(player:get_hp() - 1, 1), { type = "punch", other = "poison"}) - EF.poisoned[player].hit_timer = 0 - else -- if not player or mob then remove - EF.poisoned[player] = nil + if mcl_util.get_hp(player) - 1 > 0 then + mcl_util.deal_damage(player, 1, {type = "magic"}) end - + EF.poisoned[player].hit_timer = 0 end if EF.poisoned[player] and EF.poisoned[player].timer >= EF.poisoned[player].dur then @@ -351,37 +344,12 @@ minetest.register_globalstep(function(dtime) end) - -local is_fire_node = { ["mcl_core:lava_flowing"]=true, - ["mcl_core:lava_source"]=true, - ["mcl_fire:eternal_fire"]=true, - ["mcl_fire:fire"]=true, - ["mcl_nether:magma"]=true, - ["mcl_nether:nether_lava_source"]=true, - ["mcl_nether:nether_lava_flowing"]=true, - ["mcl_nether:nether_lava_source"]=true -} - -- Prevent damage to player with Fire Resistance enabled -minetest.register_on_player_hpchange(function(player, hp_change, reason) - - if EF.fire_proof[player] and hp_change < 0 then - -- This is a bit forced, but it assumes damage is taken by fire and avoids it - -- also assumes any change in hp happens between calls to this function - -- it's worth noting that you don't take damage from players in this case... - local player_info = mcl_playerinfo[player:get_player_name()] - - if is_fire_node[player_info.node_head] or is_fire_node[player_info.node_feet] or is_fire_node[player_info.node_stand] then - return 0 - else - return hp_change - end - - else - return hp_change +mcl_damage.register_modifier(function(obj, damage, reason) + if EF.fire_proof[obj] and not reason.flags.bypasses_magic and reason.flags.is_fire then + return 0 end - -end, true) +end, -50) @@ -603,21 +571,18 @@ function mcl_potions.make_invisible(player, toggle) return end - if minetest.get_modpath("mcl_armor") and player:is_player() then - armor.textures[playername].skin = skin_file - armor:update_player_visuals(player) - elseif not player:is_player() and minetest.get_modpath("mcl_armor") or not player:is_player() and not minetest.get_modpath("mcl_armor") then + if player:is_player() then + mcl_player.player_set_skin(player, "mobs_mc_empty.png") + elseif not player:is_player() then player:set_properties({visual_size = {x = 0, y = 0}}) end player:set_nametag_attributes({color = {a = 0}}) elseif EF.invisible[player] then -- show player - if minetest.get_modpath("mcl_armor") and player:is_player() then - skin_file = mcl_skins.skins[playername] .. ".png" - armor.textures[playername].skin = skin_file - armor:update_player_visuals(player) - elseif not player:is_player() and minetest.get_modpath("mcl_armor") or not player:is_player() and not minetest.get_modpath("mcl_armor") then + if player:is_player() then + mcl_skins.update_player_skin(player) + elseif not player:is_player() then player:set_properties({visual_size = EF.invisible[player].old_size}) end player:set_nametag_attributes({color = {r = 255, g = 255, b = 255, a = 255}}) @@ -724,12 +689,7 @@ function mcl_potions.healing_func(player, hp) hp = -1 end - if obj and obj._cmi_is_mob then - obj.health = obj.health + hp - elseif player:is_player() then - player:set_hp(player:get_hp() + hp, { type = "punch", other = "harming" }) - end - + mcl_util.deal_damage(obj, -hp, {type = "magic"}) end end diff --git a/mods/ITEMS/mcl_potions/locale/mcl_potions.de.tr b/mods/ITEMS/mcl_potions/locale/mcl_potions.de.tr index 36f5280b9e..34693d531a 100644 --- a/mods/ITEMS/mcl_potions/locale/mcl_potions.de.tr +++ b/mods/ITEMS/mcl_potions/locale/mcl_potions.de.tr @@ -112,18 +112,3 @@ No effect=Keine Wirkung A throwable potion that will shatter on impact, where it gives all nearby players and mobs a status effect.=Ein werfbarer Trank, der bei Kollision zerbrechen wird, wo er allen nahen Spielern und Mobs einen Statuseffekt geben wird. This particular arrow is tipped and will give an effect when it hits a player or mob.=Diese Pfeilspitze dieses Pfeils in einem Trank getränkt und gibt einen Effekt, wenn er einen Spieler oder einen Mob trifft. - - - -##### not used anymore ##### - -Lingering Weakness Potion=Schwächeverweiltrank -Lingering Weakness Potion +=Schwächeverweiltrank + -Lingering Strength Potion=Stärkeverweiltrank -Lingering Strength Potion II=Stärkeverweiltrank II -Lingering Strength Potion +=Stärkeverweiltrank + -Weakness Splash Potion=Schwächewurftrank -Weakness Splash Potion +=Schwächewurftrank + -Strength Splash Potion=Stärkewurftrank -Strength Splash Potion II=Stärkewurftrank II -Strength Splash Potion +=Stärkewurftrank + diff --git a/mods/ITEMS/mcl_sponges/init.lua b/mods/ITEMS/mcl_sponges/init.lua index 75a99b0f13..147db6cc53 100644 --- a/mods/ITEMS/mcl_sponges/init.lua +++ b/mods/ITEMS/mcl_sponges/init.lua @@ -114,6 +114,19 @@ function place_wet_sponge(itemstack, placer, pointed_thing) if mcl_worlds.pos_to_dimension(pointed_thing.above) == "nether" then minetest.item_place_node(ItemStack("mcl_sponges:sponge"), placer, pointed_thing) + local pos = pointed_thing.above + for n = 0, 25 do + minetest.add_particle({ + pos = {x = pos.x + math.random(-1, 1)*math.random()/2, y = pos.y + 0.6, z = pos.z + math.random(-1, 1)*math.random()/2}, + velocity = {x = 0, y = math.random(), z = 0}, + acceleration = {x=0, y=0, z=0}, + expirationtime = math.random(), + collisiondetection = false, + vertical = false, + size = math.random(2, 5), + texture = "mcl_particles_sponge"..math.random(1, 5)..".png", + }) + end if not minetest.is_creative_enabled(name) then itemstack:take_item() end diff --git a/mods/ITEMS/mcl_tnt/mod.conf b/mods/ITEMS/mcl_tnt/mod.conf index 9d75a788cb..2e90ddb80b 100644 --- a/mods/ITEMS/mcl_tnt/mod.conf +++ b/mods/ITEMS/mcl_tnt/mod.conf @@ -1,3 +1,3 @@ name = mcl_tnt depends = mcl_explosions, mcl_particles -optional_depends = mcl_sounds, mcl_mobitems, mcl_death_messages, doc_identifier, mesecons +optional_depends = mcl_sounds, mcl_mobitems, doc_identifier, mesecons diff --git a/mods/ITEMS/mcl_totems/init.lua b/mods/ITEMS/mcl_totems/init.lua index b4ec3eb8d5..499d7362df 100644 --- a/mods/ITEMS/mcl_totems/init.lua +++ b/mods/ITEMS/mcl_totems/init.lua @@ -1,5 +1,58 @@ --- Node is currently defined in mobs_mc. --- TODO: Add full item definition here when status effects become a thing. +local hud_totem = {} --- Add group for Creative Mode. -minetest.override_item("mobs_mc:totem", {groups = { combat_item=1}}) +minetest.register_on_leaveplayer(function(player) + hud_totem[player] = nil +end) + +-- Save the player from death when holding totem of undying in hand +mcl_damage.register_modifier(function(obj, damage, reason) + if obj:is_player() then + local hp = obj:get_hp() + if hp - damage <= 0 then + local wield = obj:get_wielded_item() + if wield:get_name() == "mobs_mc:totem" then + local ppos = obj:get_pos() + local pnname = minetest.get_node(ppos).name + -- Some exceptions when _not_ to save the player + for n=1, #mobs_mc.misc.totem_fail_nodes do + if pnname == mobs_mc.misc.totem_fail_nodes[n] then + return + end + end + -- Reset breath as well + if obj:get_breath() < 11 then + obj:set_breath(10) + end + + if not minetest.is_creative_enabled(obj:get_player_name()) then + wield:take_item() + obj:set_wielded_item(wield) + end + + -- Effects + minetest.sound_play({name = "mcl_totems_totem", gain=1}, {pos=ppos, max_hear_distance=16}, true) + + -- Big totem overlay + if not hud_totem[obj] then + hud_totem[obj] = obj:hud_add({ + hud_elem_type = "image", + text = "mcl_totems_totem.png", + position = { x=0.5, y=1 }, + scale = { x=17, y=17 }, + offset = { x=0, y=-178 }, + z_index = 100, + }) + minetest.after(3, function() + if obj:is_player() then + obj:hud_remove(hud_totem[obj]) + hud_totem[obj] = nil + end + end) + end + + -- Set HP to exactly 1 + return hp - 1 + end + end + end +end, 1000) diff --git a/mods/ITEMS/mcl_totems/mod.conf b/mods/ITEMS/mcl_totems/mod.conf index 70c5844c65..4ba94defc7 100644 --- a/mods/ITEMS/mcl_totems/mod.conf +++ b/mods/ITEMS/mcl_totems/mod.conf @@ -1,2 +1,2 @@ name = mcl_totems -depends = mobs_mc +depends = mobs_mc, mcl_damage diff --git a/mods/MISC/mcl_commands/kill.lua b/mods/MISC/mcl_commands/kill.lua index 2de69e6a0b..85754a0ec5 100644 --- a/mods/MISC/mcl_commands/kill.lua +++ b/mods/MISC/mcl_commands/kill.lua @@ -1,5 +1,4 @@ local S = minetest.get_translator("mcl_commands") -local mod_death_messages = minetest.get_modpath("mcl_death_messages") local function handle_kill_command(suspect, victim) if minetest.settings:get_bool("enable_damage") == false then @@ -21,17 +20,8 @@ local function handle_kill_command(suspect, victim) if wield:get_name() == "mobs_mc:totem" then victimref:set_wielded_item("") end - if mod_death_messages then - local msg - if suspect == victim then - msg = S("@1 committed suicide.", victim) - else - msg = S("@1 was killed by @2.", victim, suspect) - end - mcl_death_messages.player_damage(victimref, msg) - end -- DIE! - victimref:set_hp(0) + victimref:set_hp(0, {_mcl_type = "out_of_world"}) -- Log if not suspect == victim then minetest.log("action", string.format("%s killed %s using /kill", suspect, victim)) @@ -56,4 +46,4 @@ minetest.register_chatcommand("kill", { return handle_kill_command(name, param) end end, -}) \ No newline at end of file +}) diff --git a/mods/MISC/mcl_commands/mod.conf b/mods/MISC/mcl_commands/mod.conf index d651fad7b6..00d707098f 100644 --- a/mods/MISC/mcl_commands/mod.conf +++ b/mods/MISC/mcl_commands/mod.conf @@ -1,4 +1,3 @@ name = mcl_commands author = Wuzzy description = MCL2 commands -optional_depends = mcl_death_messages diff --git a/mods/PLAYER/mcl_criticals/init.lua b/mods/PLAYER/mcl_criticals/init.lua new file mode 100644 index 0000000000..27d09abb20 --- /dev/null +++ b/mods/PLAYER/mcl_criticals/init.lua @@ -0,0 +1,30 @@ +mcl_damage.register_modifier(function(obj, damage, reason) + if reason.type == "player" then + local hitter = reason.direct + if mcl_sprint.is_sprinting(hitter) then + obj:add_velocity(hitter:get_velocity()) + elseif (hitter:get_velocity() or hitter:get_player_velocity()).y < 0 then + local pos = mcl_util.get_object_center(obj) + minetest.add_particlespawner({ + amount = 15, + time = 0.1, + minpos = {x=pos.x-0.5, y=pos.y-0.5, z=pos.z-0.5}, + maxpos = {x=pos.x+0.5, y=pos.y+0.5, z=pos.z+0.5}, + minvel = {x=-0.1, y=-0.1, z=-0.1}, + maxvel = {x=0.1, y=0.1, z=0.1}, + minacc = {x=0, y=0, z=0}, + maxacc = {x=0, y=0, z=0}, + minexptime = 1, + maxexptime = 2, + minsize = 1.5, + maxsize = 1.5, + collisiondetection = false, + vertical = false, + texture = "mcl_particles_crit.png^[colorize:#bc7a57:127", + }) + minetest.sound_play("mcl_criticals_hit", {object = obj}) + -- the minecraft wiki is actually wrong about a crit dealing 150% damage, see minecraft source code + return damage + math.random(0, math.floor(damage * 1.5 + 2)) + end + end +end, -100) diff --git a/mods/PLAYER/mcl_criticals/mod.conf b/mods/PLAYER/mcl_criticals/mod.conf new file mode 100644 index 0000000000..5b0b91330f --- /dev/null +++ b/mods/PLAYER/mcl_criticals/mod.conf @@ -0,0 +1,2 @@ +name = mcl_criticals +depends = mcl_damage diff --git a/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.0.ogg b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.0.ogg new file mode 100644 index 0000000000..8184d10768 Binary files /dev/null and b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.0.ogg differ diff --git a/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.1.ogg b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.1.ogg new file mode 100644 index 0000000000..aed9981623 Binary files /dev/null and b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.1.ogg differ diff --git a/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.2.ogg b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.2.ogg new file mode 100644 index 0000000000..6d573b9f28 Binary files /dev/null and b/mods/PLAYER/mcl_criticals/sounds/mcl_criticals_hit.2.ogg differ diff --git a/mods/PLAYER/mcl_death_drop/init.lua b/mods/PLAYER/mcl_death_drop/init.lua index 90a2b0fbd1..fca566a377 100644 --- a/mods/PLAYER/mcl_death_drop/init.lua +++ b/mods/PLAYER/mcl_death_drop/init.lua @@ -11,7 +11,6 @@ end mcl_death_drop.register_dropped_list("PLAYER", "main", true) mcl_death_drop.register_dropped_list("PLAYER", "craft", true) mcl_death_drop.register_dropped_list("PLAYER", "armor", true) -mcl_death_drop.register_dropped_list(function(player) return select(3, armor:get_valid_player(player)) end , "armor", false) minetest.register_on_dieplayer(function(player) local keep = minetest.settings:get_bool("mcl_keepInventory", false) @@ -50,7 +49,6 @@ minetest.register_on_dieplayer(function(player) inv:set_list(listname, {}) end end - armor:set_player_armor(player) - armor:update_inventory(player) + mcl_armor.update(player) end end) diff --git a/mods/PLAYER/mcl_hunger/hunger.lua b/mods/PLAYER/mcl_hunger/hunger.lua index 30ad10ac2e..51d7fdaebe 100644 --- a/mods/PLAYER/mcl_hunger/hunger.lua +++ b/mods/PLAYER/mcl_hunger/hunger.lua @@ -1,5 +1,4 @@ local S = minetest.get_translator("mcl_hunger") -local mod_death_messages = minetest.get_modpath("mcl_death_messages") -- wrapper for minetest.item_eat (this way we make sure other mods can't break this one) minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, pointed_thing) @@ -110,10 +109,7 @@ local function poisonp(tick, time, time_left, damage, exhaustion, name) -- Deal damage and exhaust player -- TODO: Introduce fatal poison at higher difficulties if player:get_hp()-damage > 0 then - if mod_death_messages then - mcl_death_messages.player_damage(player, S("@1 succumbed to the poison.", name)) - end - player:set_hp(player:get_hp()-damage) + mcl_util.deal_damage(player, damage, {type = "hunger"}) end mcl_hunger.exhaust(name, exhaustion) diff --git a/mods/PLAYER/mcl_hunger/init.lua b/mods/PLAYER/mcl_hunger/init.lua index c65206599b..6b99985748 100644 --- a/mods/PLAYER/mcl_hunger/init.lua +++ b/mods/PLAYER/mcl_hunger/init.lua @@ -1,5 +1,4 @@ local S = minetest.get_translator("mcl_hunger") -local mod_death_messages = minetest.get_modpath("mcl_death_messages") mcl_hunger = {} @@ -159,10 +158,7 @@ minetest.register_globalstep(function(dtime) -- Damage hungry player down to 1 HP -- TODO: Allow starvation at higher difficulty levels if hp-1 > 0 then - if mod_death_messages then - mcl_death_messages.player_damage(player, S("@1 starved to death.", name)) - end - player:set_hp(hp-1) + mcl_util.deal_damage(player, 1, {type = "starve"}) end end end diff --git a/mods/PLAYER/mcl_hunger/mod.conf b/mods/PLAYER/mcl_hunger/mod.conf index 7795da7a25..99ab71ff33 100644 --- a/mods/PLAYER/mcl_hunger/mod.conf +++ b/mods/PLAYER/mcl_hunger/mod.conf @@ -2,4 +2,3 @@ name = mcl_hunger author = BlockMen description = Adds a simple hunger meachanic with satiation, food poisoning and different healing. depends = hudbars -optional_depends = mcl_death_messages diff --git a/mods/PLAYER/mcl_player/init.lua b/mods/PLAYER/mcl_player/init.lua index 9df852502e..6cf2f0014b 100644 --- a/mods/PLAYER/mcl_player/init.lua +++ b/mods/PLAYER/mcl_player/init.lua @@ -88,22 +88,41 @@ function mcl_player.player_set_model(player, model_name) player_model[name] = model_name end -function mcl_player.player_set_textures(player, textures, preview) - local name = player:get_player_name() - player_textures[name] = textures - player:set_properties({textures = textures,}) - if preview then - player:get_meta():set_string("mcl_player:preview", preview) - end +local function set_texture(player, index, texture) + local textures = player_textures[player:get_player_name()] + textures[index] = texture + player:set_properties({textures = textures}) +end + +local function set_preview(player, field, preview) + player:get_meta():set_string("mcl_player:" .. field .. "_preview", preview) +end + +function mcl_player.player_set_skin(player, texture, preview) + set_texture(player, 1, texture) + set_preview(player, "skin", preview) +end + +function mcl_player.player_set_armor(player, texture, preview) + set_texture(player, 2, texture) + set_preview(player, "armor", preview) +end + +function mcl_player.player_set_wielditem(player, texture) + set_texture(player, 3, texture) end function mcl_player.player_get_preview(player) - local preview = player:get_meta():get_string("mcl_player:preview") - if preview == nil or preview == "" then - return "player.png" - else - return preview + local preview = player:get_meta():get_string("mcl_player:skin_preview") + if preview == "" then + preview = "player.png" end + local armor_preview = player:get_meta():set_string("mcl_player:armor_preview") + if armor_preview ~= "" then + preview = preview .. "^" .. armor_preview + end + return preview + end function mcl_player.get_player_formspec_model(player, x, y, w, h, fsname) @@ -129,8 +148,10 @@ end -- Update appearance when the player joins minetest.register_on_joinplayer(function(player) - mcl_player.player_attached[player:get_player_name()] = false + local name = player:get_player_name() + mcl_player.player_attached[name] = false mcl_player.player_set_model(player, "character.b3d") + player_textures[name] = {"blank.png", "blank.png", "blank.png"} --player:set_local_animation({x=0, y=79}, {x=168, y=187}, {x=189, y=198}, {x=200, y=219}, 30) player:set_fov(86.1) -- see >>> end) @@ -222,62 +243,3 @@ minetest.register_globalstep(function(dtime) end end end) - --- Don't change HP if the player falls in the water or through End Portal: -minetest.register_on_player_hpchange(function(player, hp_change, reason) - if reason and reason.type == "fall" and player then - local pos = player:get_pos() - local node = minetest.get_node(pos) - local velocity = player:get_velocity() or player:get_player_velocity() or {x=0,y=-10,z=0} - local v_axis_max = math.max(math.abs(velocity.x), math.abs(velocity.y), math.abs(velocity.z)) - local step = {x = velocity.x / v_axis_max, y = velocity.y / v_axis_max, z = velocity.z / v_axis_max} - for i = 1, math.ceil(v_axis_max/5)+1 do -- trace at least 1/5 of the way per second - if not node or node.name == "ignore" then - minetest.get_voxel_manip():read_from_map(pos, pos) - node = minetest.get_node(pos) - end - if node then - if minetest.registered_nodes[node.name].walkable then - return hp_change - end - if minetest.get_item_group(node.name, "water") ~= 0 then - return 0 - end - if node.name == "mcl_portals:portal_end" then - if mcl_portals and mcl_portals.end_teleport then - mcl_portals.end_teleport(player) - end - return 0 - end - end - pos = vector.add(pos, step) - node = minetest.get_node(pos) - end - end - return hp_change -end, true) - -minetest.register_on_respawnplayer(function(player) - local pos = player:get_pos() - minetest.add_particlespawner({ - amount = 50, - time = 0.001, - minpos = vector.add(pos, 0), - maxpos = vector.add(pos, 0), - minvel = vector.new(-5,-5,-5), - maxvel = vector.new(5,5,5), - minexptime = 1.1, - maxexptime = 1.5, - minsize = 1, - maxsize = 2, - collisiondetection = false, - vertical = false, - texture = "mcl_particles_mob_death.png^[colorize:#000000:255", - }) - - minetest.sound_play("mcl_mobs_mob_poof", { - pos = pos, - gain = 1.0, - max_hear_distance = 8, - }, true) -end) diff --git a/mods/PLAYER/mcl_playerinfo/mod.conf b/mods/PLAYER/mcl_playerinfo/mod.conf index 9f2b0c4a57..25c05f03e0 100644 --- a/mods/PLAYER/mcl_playerinfo/mod.conf +++ b/mods/PLAYER/mcl_playerinfo/mod.conf @@ -1,4 +1,4 @@ name = mcl_playerinfo author = TenPlus1 description = This is a helper mod for other mod to query the nodes around the player. -depends = mcl_init, mcl_core, mcl_particles, mcl_death_messages +depends = mcl_init, mcl_core, mcl_particles diff --git a/mods/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index ee24267135..9436ae94da 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -114,37 +114,6 @@ end local node_stand, node_stand_below, node_head, node_feet - -minetest.register_on_punchplayer(function(player, hitter, damage) - if hitter:is_player() then - if hitter:get_player_control().aux1 then - player:add_velocity(hitter:get_velocity()) - end - if hitter:get_velocity().y < -6 then - player:set_hp(player:get_hp() - (damage * math.random(0.50 , 0.75))) - local pos = player:get_pos() - minetest.add_particlespawner({ - amount = 15, - time = 0.1, - minpos = {x=pos.x-0.5, y=pos.y-0.5, z=pos.z-0.5}, - maxpos = {x=pos.x+0.5, y=pos.y+0.5, z=pos.z+0.5}, - minvel = {x=-0.1, y=-0.1, z=-0.1}, - maxvel = {x=0.1, y=0.1, z=0.1}, - minacc = {x=0, y=0, z=0}, - maxacc = {x=0, y=0, z=0}, - minexptime = 1, - maxexptime = 2, - minsize = 1.5, - maxsize = 1.5, - collisiondetection = false, - vertical = false, - texture = "mcl_particles_crit.png^[colorize:#bc7a57:127", - }) - end - end -end) - - minetest.register_globalstep(function(dtime) time = time + dtime @@ -166,6 +135,7 @@ minetest.register_globalstep(function(dtime) local parent = player:get_attach() local wielded = player:get_wielded_item() local player_velocity = player:get_velocity() or player:get_player_velocity() + local wielded_def = wielded:get_definition() local c_x, c_y = unpack(player_collision(player)) @@ -196,11 +166,11 @@ minetest.register_globalstep(function(dtime) and (fly_node == "air" or fly_node == "ignore") if elytra.active then - if player_velocity.x < (player_velocity_old.x - 10) or player_velocity.x > (player_velocity_old.x + 10) then - player:set_hp(player:get_hp() - (math.abs(player_velocity_old.x) * 0.2)) + if player_velocity.x < (player_velocity_old.x - 10) or player_velocity.x > (player_velocity_old.x + 10) and fly_node ~= "ignore" then + mcl_util.deal_damage(player, math.abs(player_velocity_old.x) * 0.2, {type = "fly_into_wall"}) end - if player_velocity.z < (player_velocity_old.z - 10) or player_velocity.z > (player_velocity_old.z + 10) then - player:set_hp(player:get_hp() - (math.abs(player_velocity_old.z) * 0.2)) + if player_velocity.z < (player_velocity_old.z - 10) or player_velocity.z > (player_velocity_old.z + 10) and fly_node ~= "ignore" then + mcl_util.deal_damage(player, math.abs(player_velocity_old.z) * 0.2, {type = "fly_into_wall"}) end mcl_player.player_set_animation(player, "fly") if player_velocity.y < -1.5 then @@ -247,7 +217,16 @@ minetest.register_globalstep(function(dtime) playerphysics.remove_physics_factor(player, "gravity", "mcl_playerplus:elytra") end + if wielded_def and wielded_def._mcl_toollike_wield then + player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0)) + elseif string.find(wielded:get_name(), "mcl_bows:bow") then + player:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20)) + else + player:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90)) + end + player_velocity_old = player:get_velocity() or player:get_player_velocity() + -- controls right and left arms pitch when shooting a bow if string.find(wielded:get_name(), "mcl_bows:bow") and control.RMB and not control.LMB and not control.up and not control.down and not control.left and not control.right then player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-30,pitch * -1 * .35)) @@ -421,8 +400,7 @@ minetest.register_globalstep(function(dtime) -- Check privilege, too and (not check_player_privs(name, {noclip = true})) then if player:get_hp() > 0 then - mcl_death_messages.player_damage(player, S("@1 suffocated to death.", name)) - player:set_hp(player:get_hp() - 1) + mcl_util.deal_damage(player, 1, {type = "in_wall"}) end end @@ -437,8 +415,7 @@ minetest.register_globalstep(function(dtime) local dist_feet = vector.distance({x=pos.x, y=pos.y-1, z=pos.z}, near) if dist < 1.1 or dist_feet < 1.1 then if player:get_hp() > 0 then - mcl_death_messages.player_damage(player, S("@1 was prickled to death by a cactus.", name)) - player:set_hp(player:get_hp() - 1, { type = "punch", from = "mod" }) + mcl_util.deal_damage(player, 1, {type = "cactus"}) end end end @@ -545,3 +522,61 @@ minetest.register_on_leaveplayer(function(player) mcl_playerplus_internal[name] = nil mcl_playerplus.elytra[player] = nil end) + +-- Don't change HP if the player falls in the water or through End Portal: +mcl_damage.register_modifier(function(obj, damage, reason) + if reason.type == "fall" then + local pos = obj:get_pos() + local node = minetest.get_node(pos) + local velocity = obj:get_velocity() or obj:get_player_velocity() or {x=0,y=-10,z=0} + local v_axis_max = math.max(math.abs(velocity.x), math.abs(velocity.y), math.abs(velocity.z)) + local step = {x = velocity.x / v_axis_max, y = velocity.y / v_axis_max, z = velocity.z / v_axis_max} + for i = 1, math.ceil(v_axis_max/5)+1 do -- trace at least 1/5 of the way per second + if not node or node.name == "ignore" then + minetest.get_voxel_manip():read_from_map(pos, pos) + node = minetest.get_node(pos) + end + if node then + if minetest.registered_nodes[node.name].walkable then + return + end + if minetest.get_item_group(node.name, "water") ~= 0 then + return 0 + end + if node.name == "mcl_portals:portal_end" then + if mcl_portals and mcl_portals.end_teleport then + mcl_portals.end_teleport(obj) + end + return 0 + end + end + pos = vector.add(pos, step) + node = minetest.get_node(pos) + end + end +end, -200) + +minetest.register_on_respawnplayer(function(player) + local pos = player:get_pos() + minetest.add_particlespawner({ + amount = 50, + time = 0.001, + minpos = vector.add(pos, 0), + maxpos = vector.add(pos, 0), + minvel = vector.new(-5,-5,-5), + maxvel = vector.new(5,5,5), + minexptime = 1.1, + maxexptime = 1.5, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "mcl_particles_mob_death.png^[colorize:#000000:255", + }) + + minetest.sound_play("mcl_mobs_mob_poof", { + pos = pos, + gain = 1.0, + max_hear_distance = 8, + }, true) +end) diff --git a/mods/PLAYER/mcl_playerplus/mod.conf b/mods/PLAYER/mcl_playerplus/mod.conf index 95121f8ead..6989957d77 100644 --- a/mods/PLAYER/mcl_playerplus/mod.conf +++ b/mods/PLAYER/mcl_playerplus/mod.conf @@ -1,5 +1,5 @@ name = mcl_playerplus author = TenPlus1 description = Adds some simple player-related gameplay effects: Hurt by touching a cactus, suffocation and more. -depends = mcl_init, mcl_core, mcl_particles, mcl_hunger, mcl_death_messages, playerphysics, mcl_playerinfo, mcl_weather, mcl_spawn, mcl_enchanting +depends = mcl_init, mcl_core, mcl_particles, mcl_hunger, playerphysics, mcl_playerinfo, mcl_weather, mcl_spawn, mcl_enchanting, mcl_damage diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index 0b508adc69..84f147da6c 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -7,7 +7,6 @@ mcl_skins = { } local S = minetest.get_translator("mcl_skins") -local has_mcl_armor = minetest.get_modpath("mcl_armor") local has_mcl_inventory = minetest.get_modpath("mcl_inventory") -- load skin list and metadata @@ -115,10 +114,6 @@ mcl_skins.set_player_skin = function(player, skin_id) mcl_skins.previews[playername] = preview player:get_meta():set_string("mcl_skins:skin_id", tostring(skin_id)) mcl_skins.update_player_skin(player) - if has_mcl_armor then - armor.textures[playername].skin = skin_file - armor:update_player_visuals(player) - end if has_mcl_inventory then mcl_inventory.update_inventory_formspec(player) end @@ -134,7 +129,7 @@ mcl_skins.update_player_skin = function(player) return end local playername = player:get_player_name() - mcl_player.player_set_textures(player, { mcl_skins.skins[playername] .. ".png" }, mcl_skins.previews[playername] .. ".png" ) + mcl_player.player_set_skin(player, mcl_skins.skins[playername] .. ".png", mcl_skins.previews[playername] .. ".png") end -- load player skin on join diff --git a/mods/PLAYER/mcl_skins/mod.conf b/mods/PLAYER/mcl_skins/mod.conf index 6ccbe98f10..657d3cc0ea 100644 --- a/mods/PLAYER/mcl_skins/mod.conf +++ b/mods/PLAYER/mcl_skins/mod.conf @@ -2,4 +2,4 @@ name = mcl_skins author = TenPlus1 description = Mod that allows players to set their individual skins. depends = mcl_player -optional_depends = mcl_inventory, intllib, mcl_armor +optional_depends = mcl_inventory, intllib diff --git a/mods/PLAYER/wieldview/LICENSE.txt b/mods/PLAYER/mcl_wieldview/LICENSE.txt similarity index 100% rename from mods/PLAYER/wieldview/LICENSE.txt rename to mods/PLAYER/mcl_wieldview/LICENSE.txt diff --git a/mods/PLAYER/wieldview/README.txt b/mods/PLAYER/mcl_wieldview/README.txt similarity index 100% rename from mods/PLAYER/wieldview/README.txt rename to mods/PLAYER/mcl_wieldview/README.txt diff --git a/mods/PLAYER/mcl_wieldview/init.lua b/mods/PLAYER/mcl_wieldview/init.lua new file mode 100644 index 0000000000..fc9ebc074e --- /dev/null +++ b/mods/PLAYER/mcl_wieldview/init.lua @@ -0,0 +1,118 @@ +mcl_wieldview = { + players = {} +} + +function mcl_wieldview.get_item_texture(itemname) + if itemname == "" then + return + end + + local def = minetest.registered_items[itemname] + if not def then + return + end + + local inv_image = def.inventory_image + if inv_image == "" then + return + end + + local texture = inv_image + + local transform = minetest.get_item_group(itemname, "wieldview_transform") + if transform then + -- This actually works with groups ratings because transform1, transform2, etc. + -- have meaning and transform0 is used for identidy, so it can be ignored + texture = texture .. "^[transform" .. transform + end + + return texture +end + +function mcl_wieldview.update_wielded_item(player) + if not player then + return + end + local itemstack = player:get_wielded_item() + local itemname = itemstack:get_name() + + local def = mcl_wieldview.players[player] + + if def.item == itemname then + return + end + + def.item = itemname + def.texture = mcl_wieldview.get_item_texture(itemname) or "blank.png" + + mcl_player.player_set_wielditem(player, def.texture) +end + +minetest.register_on_joinplayer(function(player) + mcl_wieldview.players[player] = {item = "", texture = "blank.png"} + + minetest.after(0, function() + if not player:is_player() then + return + end + + mcl_wieldview.update_wielded_item(player) + + local itementity = minetest.add_entity(player:get_pos(), "mcl_wieldview:wieldnode") + itementity:set_attach(player, "Hand_Right", vector.new(0, 1, 0), vector.new(90, 0, 45)) + itementity:get_luaentity().wielder = player + end) +end) + +minetest.register_on_leaveplayer(function(player) + mcl_wieldview.players[player] = nil +end) + +minetest.register_globalstep(function() + for _, player in pairs(minetest.get_connected_players()) do + mcl_wieldview.update_wielded_item(player) + end +end) + +minetest.register_entity("mcl_wieldview:wieldnode", { + initial_properties = { + hp_max = 1, + visual = "wielditem", + physical = false, + textures = {""}, + automatic_rotate = 1.5, + is_visible = true, + pointable = false, + collide_with_objects = false, + static_save = false, + collisionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, + selectionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, + visual_size = {x = 0.21, y = 0.21}, + }, + + itemstring = "", + + on_step = function(self) + if self.wielder:is_player() then + local def = mcl_wieldview.players[self.wielder] + local itemstring = def.item + + if self.itemstring ~= itemstring then + local itemdef = minetest.registered_items[itemstring] + self.object:set_properties({glow = itemdef and itemdef.light_source or 0}) + + -- wield item as cubic + if def.texture == "blank.png" then + self.object:set_properties({textures = {itemstring}}) + -- wield item as flat + else + self.object:set_properties({textures = {""}}) + end + + self.itemstring = itemstring + end + else + self.object:remove() + end + end, +}) diff --git a/mods/PLAYER/wieldview/mod.conf b/mods/PLAYER/mcl_wieldview/mod.conf similarity index 66% rename from mods/PLAYER/wieldview/mod.conf rename to mods/PLAYER/mcl_wieldview/mod.conf index 4cd2a69359..4b30978768 100644 --- a/mods/PLAYER/wieldview/mod.conf +++ b/mods/PLAYER/mcl_wieldview/mod.conf @@ -1,5 +1,4 @@ -name = wieldview +name = mcl_wieldview author = stujones11 description = Makes hand wielded items visible to other players. -depends = mcl_armor - +depends = mcl_player diff --git a/mods/PLAYER/wieldview/init.lua b/mods/PLAYER/wieldview/init.lua deleted file mode 100644 index 91b2cd7215..0000000000 --- a/mods/PLAYER/wieldview/init.lua +++ /dev/null @@ -1,131 +0,0 @@ -local update_time = tonumber(minetest.settings:get("wieldview_update_time")) -if not update_time then - update_time = 2 - minetest.settings:set("wieldview_update_time", tostring(update_time)) -end -local node_tiles = minetest.settings:get_bool("wieldview_node_tiles") -if not node_tiles then - node_tiles = false - minetest.settings:set("wieldview_node_tiles", "false") -end - -wieldview = { - wielded_item = {}, - transform = {}, -} - -dofile(minetest.get_modpath(minetest.get_current_modname()).."/transform.lua") - -wieldview.get_item_texture = function(self, item) - local texture = "blank.png" - if item ~= "" then - if minetest.registered_items[item] then - if minetest.registered_items[item].inventory_image ~= "" then - texture = minetest.registered_items[item].inventory_image - elseif node_tiles == true and minetest.registered_items[item].tiles - and type(minetest.registered_items[item].tiles[1]) == "string" - and minetest.registered_items[item].tiles[1] ~= "" then - texture = minetest.inventorycube(minetest.registered_items[item].tiles[1]) - end - end - -- Get item image transformation, first from group, then from transform.lua - local transform = minetest.get_item_group(item, "wieldview_transform") - if transform == 0 then - transform = wieldview.transform[item] - end - if transform then - -- This actually works with groups ratings because transform1, transform2, etc. - -- have meaning and transform0 is used for identidy, so it can be ignored - texture = texture.."^[transform"..tostring(transform) - end - end - return texture -end - -wieldview.update_wielded_item = function(self, player) - if not player then - return - end - local name = player:get_player_name() - local stack = player:get_wielded_item() - local item = stack:get_name() - if not item then - return - end - if self.wielded_item[name] then - if self.wielded_item[name] == item then - return - end - if not armor.textures[name] then - return - end - armor.textures[name].wielditem = self:get_item_texture(item) - armor:update_player_visuals(player) - end - self.wielded_item[name] = item -end - -minetest.register_on_joinplayer(function(player) - local name = player:get_player_name() - wieldview.wielded_item[name] = "" - minetest.after(0, function(target) - -- if the player left :is_player() will return nil - if not target:is_player() then - return - end - wieldview:update_wielded_item(target) - local itementity = minetest.add_entity(target:get_pos(), "wieldview:wieldnode") - itementity:set_attach(target, "Hand_Right", vector.new(0, 1, 0), vector.new(90, 0, 45)) - itementity:get_luaentity().wielder = name - end, player) -end) - -minetest.register_globalstep(function() - for _,player in pairs(minetest.get_connected_players()) do - wieldview:update_wielded_item(player) - end -end) - -minetest.register_entity("wieldview:wieldnode", { - initial_properties = { - hp_max = 1, - visual = "wielditem", - physical = false, - textures = {""}, - automatic_rotate = 1.5, - is_visible = true, - pointable = false, - collide_with_objects = false, - static_save = false, - collisionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, - selectionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21}, - visual_size = {x = 0.21, y = 0.21}, - }, - - itemstring = "", - - on_step = function(self) - local player = minetest.get_player_by_name(self.wielder) - if player then - local wielded = player:get_wielded_item() - local itemstring = wielded:get_name() - - if self.itemstring ~= itemstring then - local def = minetest.registered_items[itemstring] - self.object:set_properties({glow = def and def.light_source or 0}) - - -- wield item as cubic - if armor.textures[self.wielder].wielditem == "blank.png" then - self.object:set_properties({textures = {itemstring}}) - -- wield item as flat - else - self.object:set_properties({textures = {""}}) - end - - self.itemstring = itemstring - end - else - self.object:remove() - end - end, -}) diff --git a/mods/PLAYER/wieldview/transform.lua b/mods/PLAYER/wieldview/transform.lua deleted file mode 100644 index a19956796f..0000000000 --- a/mods/PLAYER/wieldview/transform.lua +++ /dev/null @@ -1,10 +0,0 @@ --- Wielded Item Transformations - http://dev.minetest.net/texture - -wieldview.transform = { - ["screwdriver:screwdriver"]="R90", - ["screwdriver:screwdriver1"]="R90", - ["screwdriver:screwdriver2"]="R90", - ["screwdriver:screwdriver3"]="R90", - ["screwdriver:screwdriver4"]="R90", -} -