diff --git a/mods/CORE/mcl_damage/init.lua b/mods/CORE/mcl_damage/init.lua index 773e7a43e..8804b8561 100644 --- a/mods/CORE/mcl_damage/init.lua +++ b/mods/CORE/mcl_damage/init.lua @@ -155,7 +155,6 @@ end, true) minetest.register_on_player_hpchange(function(player, hp_change, mt_reason) if not damage_enabled then return 0 end if player:get_hp() > 0 then - mt_reason.approved = true if hp_change < 0 then mcl_damage.run_damage_callbacks(player, -hp_change, mcl_damage.from_mt(mt_reason)) end @@ -163,9 +162,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, mt_reason) end, false) minetest.register_on_dieplayer(function(player, mt_reason) - if mt_reason.approved then - mcl_damage.run_death_callbacks(player, mcl_damage.from_mt(mt_reason)) - end + mcl_damage.run_death_callbacks(player, mcl_damage.from_mt(mt_reason)) minetest.log("action","Player "..player:get_player_name().." died at "..minetest.pos_to_string(vector.round(player:get_pos()))) end) diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 05c6ed9c6..f5e50ba2a 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -335,24 +335,27 @@ function mob_class:on_step(dtime) if self:check_despawn(pos, dtime) then return true end - self:slow_mob() + if self:check_death_and_slow_mob() then + --minetest.log("action", "Mob is dying: ".. tostring(self.name)) + -- Do we abandon out of here now? + end + if self:falling(pos) then return end self:check_suspend() - self:check_water_flow() - - self:env_danger_movement_checks (dtime) - if not self.fire_resistant then mcl_burning.tick(self.object, dtime, self) -- mcl_burning.tick may remove object immediately if not self.object:get_pos() then return end end - if mobs_debug then self:update_tag() end - if self.state == "die" then return end + self:check_water_flow() + self:env_danger_movement_checks (dtime) + + if mobs_debug then self:update_tag() end + self:follow_flop() -- Mob following code. self:set_animation_speed() -- set animation speed relitive to velocity diff --git a/mods/ENTITIES/mcl_mobs/combat.lua b/mods/ENTITIES/mcl_mobs/combat.lua index 1886c7ccc..b7d176855 100644 --- a/mods/ENTITIES/mcl_mobs/combat.lua +++ b/mods/ENTITIES/mcl_mobs/combat.lua @@ -746,7 +746,7 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) local name = hitter:get_player_name() or "" - -- attack puncher and call other mobs for help + -- attack puncher if self.passive == false and self.state ~= "flop" and (self.child == false or self.type == "monster") @@ -758,37 +758,37 @@ function mob_class:on_punch(hitter, tflp, tool_capabilities, dir) self:do_attack(hitter) self._aggro= true end + end - -- alert others to the attack - local objs = minetest.get_objects_inside_radius(hitter:get_pos(), self.view_range) - local obj = nil + -- 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 + for n = 1, #objs do - obj = objs[n]:get_luaentity() + 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 - obj:do_attack(hitter) - elseif type(obj.group_attack) == "table" then - for i=1, #obj.group_attack do - if obj.name == obj.group_attack[i] then - obj._aggro = true - obj:do_attack(hitter) - break - end + 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 + obj:do_attack(hitter) + elseif type(obj.group_attack) == "table" then + for i=1, #obj.group_attack do + if obj.group_attack[i] == self.name then + obj._aggro = true + obj:do_attack(hitter) + break end end end + end - -- have owned mobs attack player threat - if obj.owner == name and obj.owner_loyal then - obj:do_attack(self.object) - end + -- have owned mobs attack player threat + if obj.owner == name and obj.owner_loyal then + obj:do_attack(self.object) end end end diff --git a/mods/ENTITIES/mcl_mobs/movement.lua b/mods/ENTITIES/mcl_mobs/movement.lua index df00a42a7..758e74467 100644 --- a/mods/ENTITIES/mcl_mobs/movement.lua +++ b/mods/ENTITIES/mcl_mobs/movement.lua @@ -279,6 +279,7 @@ function mob_class:env_danger_movement_checks(dtime) yaw = self:set_yaw( yaw, 8) end else + -- This code should probably be moved to movement code if self.move_in_group ~= false then self:check_herd(dtime) end diff --git a/mods/ENTITIES/mcl_mobs/physics.lua b/mods/ENTITIES/mcl_mobs/physics.lua index 0617fd1e8..c7ea98c57 100644 --- a/mods/ENTITIES/mcl_mobs/physics.lua +++ b/mods/ENTITIES/mcl_mobs/physics.lua @@ -47,7 +47,8 @@ end function mob_class:player_in_active_range() for _,p in pairs(minetest.get_connected_players()) do - if vector.distance(self.object:get_pos(),p:get_pos()) <= mob_active_range then return true end + local pos = self.object:get_pos() + if pos and vector.distance(pos, p:get_pos()) <= mob_active_range then return true end -- slightly larger than the mc 32 since mobs spawn on that circle and easily stand still immediately right after spawning. end end @@ -182,15 +183,17 @@ function mob_class:collision() return({x,z}) end -function mob_class:slow_mob() +function mob_class:check_death_and_slow_mob() local d = 0.85 - if self:check_dying() then d = 0.92 end + local dying = self:check_dying() + if dying then d = 0.92 end local v = self.object:get_velocity() if v then --diffuse object velocity self.object:set_velocity({x = v.x*d, y = v.y, z = v.z*d}) end + return dying end -- move mob in facing direction @@ -519,17 +522,16 @@ function mob_class:check_for_death(cause, cmi_cause) self:set_velocity(0) local acc = self.object:get_acceleration() - acc.x, acc.y, acc.z = 0, DEFAULT_FALL_SPEED, 0 - self.object:set_acceleration(acc) + if acc then + acc.x, acc.y, acc.z = 0, DEFAULT_FALL_SPEED, 0 + self.object:set_acceleration(acc) + end local length -- default death function and die animation (if defined) if self.instant_death then length = 0 - elseif self.animation - and self.animation.die_start - and self.animation.die_end then - + elseif self.animation and self.animation.die_start and self.animation.die_end then local frames = self.animation.die_end - self.animation.die_start local speed = self.animation.die_speed or 15 length = math.max(frames / speed, 0) + DEATH_DELAY @@ -545,7 +547,6 @@ function mob_class:check_for_death(cause, cmi_cause) if not self.object:get_luaentity() then return end - death_handle(self) local dpos = self.object:get_pos() local cbox = self.collisionbox @@ -554,6 +555,7 @@ function mob_class:check_for_death(cause, cmi_cause) self.object:remove() mcl_mobs.death_effect(dpos, yaw, cbox, not self.instant_death) end + if length <= 0 then kill(self) else @@ -870,33 +872,32 @@ function mob_class:falling(pos) -- floating in water (or falling) local v = self.object:get_velocity() + if v then + if v.y > 0 then + -- apply gravity when moving up + self.object:set_acceleration({ + x = 0, + y = DEFAULT_FALL_SPEED, + z = 0 + }) - if v.y > 0 then - - -- apply gravity when moving up - self.object:set_acceleration({ - x = 0, - y = DEFAULT_FALL_SPEED, - 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}) + 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 end + local acc = self.object:get_acceleration() + if minetest.registered_nodes[node_ok(pos).name].groups.lava then - - if self.floats_on_lava == 1 then - + if acc and self.floats_on_lava == 1 then self.object:set_acceleration({ x = 0, y = -self.fall_speed / (math.max(1, v.y) ^ 2), @@ -907,9 +908,7 @@ function mob_class:falling(pos) -- in water then float up if minetest.registered_nodes[node_ok(pos).name].groups.water then - - if self.floats == 1 then - + if acc and self.floats == 1 then self.object:set_acceleration({ x = 0, y = -self.fall_speed / (math.max(1, v.y) ^ 2), @@ -917,10 +916,8 @@ function mob_class:falling(pos) }) end else - -- fall damage onto solid ground - if self.fall_damage == 1 - and self.object:get_velocity().y == 0 then + if self.fall_damage == 1 and self.object:get_velocity().y == 0 then local n = node_ok(vector.offset(pos,0,-1,0)).name local d = (self.old_y or 0) - self.object:get_pos().y @@ -981,24 +978,31 @@ end function mob_class:check_dying() if ((self.state and self.state=="die") or self:check_for_death()) and not self.animation.die_end then local rot = self.object:get_rotation() - rot.z = ((math.pi/2-rot.z)*.2)+rot.z - self.object:set_rotation(rot) + if rot then + rot.z = ((math.pi/2-rot.z)*.2)+rot.z + self.object:set_rotation(rot) + end return true end end function mob_class:check_suspend() - if not self:player_in_active_range() then - local pos = self.object:get_pos() + local pos = self.object:get_pos() + + if pos and not self:player_in_active_range() then local node_under = node_ok(vector.offset(pos,0,-1,0)).name - local acc = self.object:get_acceleration() + self:set_animation( "stand", true) - if acc.y > 0 or node_under ~= "air" then - self.object:set_acceleration(vector.new(0,0,0)) - self.object:set_velocity(vector.new(0,0,0)) - end - if acc.y == 0 and node_under == "air" then - self:falling(pos) + + local acc = self.object:get_acceleration() + if acc then + if acc.y > 0 or node_under ~= "air" then + self.object:set_acceleration(vector.new(0,0,0)) + self.object:set_velocity(vector.new(0,0,0)) + end + if acc.y == 0 and node_under == "air" then + self:falling(pos) + end end return true end diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 7ca4dd88a..34a7a511c 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -15,7 +15,7 @@ mcl_mobs.register_mob("mobs_mc:iron_golem", { description = S("Iron Golem"), type = "npc", spawn_class = "passive", - passive = true, + passive = false, hp_min = 100, hp_max = 100, breath_max = -1, @@ -42,7 +42,7 @@ mcl_mobs.register_mob("mobs_mc:iron_golem", { damage = 14, knock_back = false, reach = 3, - group_attack = true, + group_attack = { "mobs_mc:villager" }, attacks_monsters = true, attack_type = "dogfight", _got_poppy = false, diff --git a/mods/HUD/mcl_base_textures/textures/crack_anylength.png b/mods/HUD/mcl_base_textures/textures/crack_anylength.png index 07e5df8fd..7ddede00d 100644 Binary files a/mods/HUD/mcl_base_textures/textures/crack_anylength.png and b/mods/HUD/mcl_base_textures/textures/crack_anylength.png differ diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 13ed23668..00de9228c 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -1,5 +1,7 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local ASSIST_TIMEOUT_SEC = 5 + mcl_death_messages = { assist = {}, messages = { @@ -181,8 +183,10 @@ local function get_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) + -- Avoid a timing issue if the assist passes its timeout. + local assist_details = mcl_death_messages.assist[obj] + if messages.assist and assist_details then + return messages._translator(messages.assist, mcl_util.get_object_name(obj), assist_details.name) end end @@ -232,20 +236,17 @@ mcl_damage.register_on_death(function(obj, reason) end) 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 + if (obj:get_hp() - damage > 0) and reason.source and + (reason.source:is_player() or obj:get_luaentity()) then + -- To avoid timing issues we cancel the previous job before adding a new one. + if mcl_death_messages.assist[obj] then + mcl_death_messages.assist[obj].job:cancel() end - end -end) -minetest.register_globalstep(function(dtime) - for obj, tbl in pairs(mcl_death_messages.assist) do - tbl.timeout = tbl.timeout - dtime - if not obj:is_player() and not obj:get_luaentity() or tbl.timeout > 0 then + -- Add a new assist object with a timeout job. + local new_job = minetest.after(ASSIST_TIMEOUT_SEC, function() mcl_death_messages.assist[obj] = nil - end + end) + mcl_death_messages.assist[obj] = {name = mcl_util.get_object_name(reason.source), job = new_job} end end) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index 6ef9a86f9..19c56b4d3 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -809,7 +809,7 @@ function mcl_core.get_grass_palette_index(pos) local biome_name = minetest.get_biome_name(biome) local reg_biome = minetest.registered_biomes[biome_name] if reg_biome then - index = reg_biome._mcl_palette_index + index = reg_biome._mcl_grass_palette_index end end return index @@ -939,7 +939,7 @@ minetest.register_lbm({ else node.name = "mcl_core:dirt_with_grass" end - node.param2 = reg_biome._mcl_palette_index + node.param2 = reg_biome._mcl_grass_palette_index -- Fall back to savanna palette index if not node.param2 then node.param2 = SAVANNA_INDEX diff --git a/mods/ITEMS/mcl_core/nodes_base.lua b/mods/ITEMS/mcl_core/nodes_base.lua index 476bdf9ce..8c7d19e9e 100644 --- a/mods/ITEMS/mcl_core/nodes_base.lua +++ b/mods/ITEMS/mcl_core/nodes_base.lua @@ -373,7 +373,7 @@ minetest.register_node("mcl_core:dirt_with_grass", { overlay_tiles = {"mcl_core_grass_block_top.png", "", {name="mcl_core_grass_block_side_overlay.png", tileable_vertical=false}}, palette = "mcl_core_palette_grass.png", palette_index = 0, - color = "#8EB971", + color = "#7CBD6B", is_ground_content = true, stack_max = 64, groups = { diff --git a/mods/ITEMS/mcl_core/nodes_trees.lua b/mods/ITEMS/mcl_core/nodes_trees.lua index 787faa6d7..0207b4ec1 100644 --- a/mods/ITEMS/mcl_core/nodes_trees.lua +++ b/mods/ITEMS/mcl_core/nodes_trees.lua @@ -35,7 +35,14 @@ function mcl_core.update_leaves(pos, oldnode) -- manually placed leaf nodes have param2 -- set and will never decay automatically if lnode.param2 == 0 then - minetest.swap_node(lpos, {name = lnode.name .. "_orphan"}) + local orphan_name = lnode.name .. "_orphan" + local def = minetest.registered_nodes[orphan_name] + if def then + --minetest.log("Registered: ".. orphan_name) + minetest.swap_node(lpos, {name = orphan_name}) + else + --minetest.log("Not registered: ".. orphan_name) + end end end end diff --git a/mods/ITEMS/mcl_farming/sweet_berry.lua b/mods/ITEMS/mcl_farming/sweet_berry.lua index 8a91c0e79..7dc6326a4 100644 --- a/mods/ITEMS/mcl_farming/sweet_berry.lua +++ b/mods/ITEMS/mcl_farming/sweet_berry.lua @@ -107,7 +107,7 @@ local function berry_damage_check(obj) if not p then return end if not minetest.find_node_near(p,0.4,{"group:sweet_berry_thorny"},true) then return end local v = obj:get_velocity() - if v.x < 0.1 and v.y < 0.1 and v.z < 0.1 then return end + if math.abs(v.x) < 0.1 and math.abs(v.y) < 0.1 and math.abs(v.z) < 0.1 then return end mcl_util.deal_damage(obj, 0.5, {type = "sweet_berry"}) end diff --git a/mods/ITEMS/mcl_flowers/init.lua b/mods/ITEMS/mcl_flowers/init.lua index d7b046cf5..0ea7f77ad 100644 --- a/mods/ITEMS/mcl_flowers/init.lua +++ b/mods/ITEMS/mcl_flowers/init.lua @@ -19,7 +19,7 @@ local get_palette_color_from_pos = function(pos) local biome_name = minetest.get_biome_name(biome) local reg_biome = minetest.registered_biomes[biome_name] if reg_biome then - index = reg_biome._mcl_palette_index + index = reg_biome._mcl_grass_palette_index end end return index diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 03c5aeb13..470f2a8c6 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -280,8 +280,8 @@ local function set_palette(minp,maxp,data2,area,biomemap,nodes) local bn = minetest.get_biome_name(biomemap[b_pos]) if bn then local biome = minetest.registered_biomes[bn] - if biome and biome._mcl_biome_type then - data2[p_pos] = biome._mcl_palette_index + if biome and biome._mcl_biome_type and biome._mcl_grass_palette_index then + data2[p_pos] = biome._mcl_grass_palette_index lvm_used = true end end @@ -349,8 +349,8 @@ local function block_fixes(vm, data, data2, emin, emax, area, minp, maxp, blocks local lvm_used = false local pr = PseudoRandom(blockseed) if minp.y <= mcl_vars.mg_overworld_max and maxp.y >= mcl_vars.mg_overworld_min then - -- Set param2 (=color) of sugar cane and grass - lvm_used = set_palette(minp,maxp,data2,area,biomemap,{"mcl_core:reeds","mcl_core:dirt_with_grass"}) + -- Set param2 (=color) of nodes which use the grass colour palette. + lvm_used = set_palette(minp,maxp,data2,area,biomemap,{"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"}) end return lvm_used end @@ -417,3 +417,20 @@ mcl_mapgen_core.register_generator("structures",nil, function(minp, maxp, blocks end return false, false, false end, 100, true) + +minetest.register_lbm({ + label = "Fix grass palette indexes", + name = "mcl_mapgen_core:fix_grass_palette_indexes", + nodenames = {"mcl_core:dirt_with_grass", "mcl_flowers:tallgrass", "mcl_flowers:double_grass", "mcl_flowers:double_grass_top", "mcl_flowers:fern", "mcl_flowers:double_fern", "mcl_flowers:double_fern_top", "mcl_core:reeds", "mcl_core:dirt_with_grass_snow"}, + run_at_every_load = true, + action = function(pos, node) + local biome_data = minetest.get_biome_data(pos) + local biome = biome_data.biome + local biome_name = minetest.get_biome_name(biome) + local reg_biome = minetest.registered_biomes[biome_name] + if node.param2 ~= reg_biome._mcl_grass_palette_index then + node.param2 = reg_biome._mcl_grass_palette_index + minetest.set_node(pos, node) + end + end, +})