diff --git a/README.md b/README.md index 7c3cecece..ca4d01959 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# (Currently in feature freeze) + # MineClone 2 An unofficial Minecraft-like game for Minetest. Forked from MineClone by davedevils. Developed by many people. Not developed or endorsed by Mojang AB. 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 000000000..e8099a41a 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 000000000..0004ce4db 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 000000000..62ae83a86 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 000000000..7ee00cbf5 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 000000000..5278caff3 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 f619b5465..f976457c0 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -532,6 +532,10 @@ function mcl_util.get_object_name(object) 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_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index eda74aeb4..2d8cef5b0 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 000000000..d413bae72 --- /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 000000000..eda7e8871 --- /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 000000000..c26d33089 --- /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 000000000..c973f3d1b --- /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 bc4d3067d..76c062a40 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,630 +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 - 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 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) @@ -776,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 @@ -819,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 @@ -885,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) @@ -912,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) @@ -951,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 @@ -986,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 @@ -1005,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 @@ -1015,25 +1514,10 @@ 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 - return lightfunc(pos, tod) + local ok, light = pcall(minetest.get_natural_light or minetest.get_node_light, pos, tod) + if ok then + return light else return 0 end @@ -1121,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 @@ -1162,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", @@ -1178,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", @@ -1203,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 @@ -1211,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 @@ -1229,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 @@ -1295,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({ @@ -1319,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 @@ -1329,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() @@ -1344,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 @@ -1391,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 @@ -1401,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 @@ -1481,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 @@ -1496,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 @@ -1535,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 @@ -1556,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 @@ -1573,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 @@ -1596,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) @@ -1604,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 @@ -1612,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 "" @@ -1625,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} @@ -1639,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 @@ -1663,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 @@ -2324,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) @@ -2343,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) @@ -2362,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 @@ -2388,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 @@ -2403,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) @@ -2419,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 @@ -2428,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 @@ -2441,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" @@ -2516,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) @@ -2584,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 @@ -2612,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 @@ -2675,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 @@ -2689,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) @@ -2741,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") @@ -2794,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) @@ -2807,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") @@ -2817,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 @@ -2854,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) @@ -3736,643 +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, - description = def.description, - 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 000000000..5dc0b8884 --- /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 000000000..44f43f20f --- /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 000000000..fd95b60ef --- /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 000000000..7c709c09e --- /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 000000000..0fc94ffe6 --- /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 000000000..6b23d2fe7 --- /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 000000000..847315ff1 --- /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 000000000..9a5fd9ea1 --- /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 000000000..e7ae6ffbe --- /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 000000000..dfef98ee8 --- /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 000000000..98d2644e8 --- /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 9383ee067..8ee45f299 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 210c6b9c6..ca4dc1e4f 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 69246b470..b0daba2c4 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 ea90de74a..000000000 --- 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 000000000..1228dd9d7 --- /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 000000000..4d7ba8015 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 000000000..c022d94f8 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 000000000..4c5e3f9b3 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 28a500bf5..000000000 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 000000000..7598b14ed --- /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 c92ccbba5..3476bee4c 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/bat.lua b/mods/ENTITIES/mobs_mc/bat.lua index e9e1c1a16..70e084ee2 100644 --- a/mods/ENTITIES/mobs_mc/bat.lua +++ b/mods/ENTITIES/mobs_mc/bat.lua @@ -8,6 +8,9 @@ mobs:register_mob("mobs_mc:bat", { 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}, @@ -45,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 5340b804e..146e8da70 100644 --- a/mods/ENTITIES/mobs_mc/blaze.lua +++ b/mods/ENTITIES/mobs_mc/blaze.lua @@ -18,6 +18,9 @@ mobs:register_mob("mobs_mc:blaze", { 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", @@ -36,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, @@ -64,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, @@ -76,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({ @@ -148,6 +160,11 @@ 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 @@ -155,7 +172,7 @@ mobs:register_arrow("mobs_mc:blaze_fireball", { 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, @@ -163,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, @@ -178,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 615ec86e7..9146a012f 100644 --- a/mods/ENTITIES/mobs_mc/chicken.lua +++ b/mods/ENTITIES/mobs_mc/chicken.lua @@ -18,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", @@ -26,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, @@ -64,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) @@ -98,6 +111,21 @@ mobs:register_mob("mobs_mc:chicken", { }, true) 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 @@ -106,22 +134,53 @@ 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", }, 9, minetest.LIGHT_MAX+1, diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index 62e124463..0d6d31ffe 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -10,6 +10,7 @@ local cow_def = { 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", @@ -20,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, @@ -32,7 +34,7 @@ local cow_def = { max = 2, looting = "common",}, }, - runaway = true, + skittish = true, sounds = { random = "mobs_mc_cow", damage = "mobs_mc_cow_hurt", @@ -47,12 +49,17 @@ local cow_def = { 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 @@ -71,11 +78,28 @@ 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) @@ -86,12 +110,17 @@ 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 @@ -139,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) @@ -151,22 +179,53 @@ 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", }, 9, minetest.LIGHT_MAX+1, diff --git a/mods/ENTITIES/mobs_mc/creeper.lua b/mods/ENTITIES/mobs_mc/creeper.lua index 827d08aab..4552d79d1 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. @@ -149,6 +167,7 @@ mobs:register_mob("mobs_mc:creeper_charged", { "mobs_mc_creeper_charge.png"}, }, visual_size = {x=3, y=3}, + rotate = 270, sounds = { attack = "tnt_ignite", death = "mobs_mc_creeper_death", @@ -157,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, diff --git a/mods/ENTITIES/mobs_mc/ender_dragon.lua b/mods/ENTITIES/mobs_mc/ender_dragon.lua index 8b0b1977b..2111105d3 100644 --- a/mods/ENTITIES/mobs_mc/ender_dragon.lua +++ b/mods/ENTITIES/mobs_mc/ender_dragon.lua @@ -8,14 +8,22 @@ 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", @@ -24,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, @@ -47,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, @@ -133,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 7c55b34d6..9ebc3d6fa 100644 --- a/mods/ENTITIES/mobs_mc/enderman.lua +++ b/mods/ENTITIES/mobs_mc/enderman.lua @@ -193,18 +193,19 @@ 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", @@ -213,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 = { @@ -224,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) @@ -282,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 @@ -360,11 +377,16 @@ mobs:register_mob("mobs_mc:enderman", { --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" + self.hostile = true + self.state = "attack" + self.attacking = obj end end @@ -430,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 @@ -453,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 @@ -557,7 +579,7 @@ mobs:register_mob("mobs_mc:enderman", { water_damage = 8, view_range = 64, fear_height = 4, - attack_type = "dogfight", + attack_type = "punch", }) diff --git a/mods/ENTITIES/mobs_mc/endermite.lua b/mods/ENTITIES/mobs_mc/endermite.lua index 2bffa8304..712086828 100644 --- a/mods/ENTITIES/mobs_mc/endermite.lua +++ b/mods/ENTITIES/mobs_mc/endermite.lua @@ -9,12 +9,15 @@ mobs:register_mob("mobs_mc: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 1d7179162..609110bdb 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -14,13 +14,17 @@ 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 = { @@ -36,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}, @@ -48,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"} @@ -73,6 +80,7 @@ mobs:register_mob("mobs_mc:ghast", { self.object:set_properties({textures=self.base_texture}) end end, + ]]-- }) @@ -92,32 +100,40 @@ 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) + --[[ 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 06a2ba2e2..241ac3444 100644 --- a/mods/ENTITIES/mobs_mc/guardian.lua +++ b/mods/ENTITIES/mobs_mc/guardian.lua @@ -14,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 5b8150dd4..4fb989e2f 100644 --- a/mods/ENTITIES/mobs_mc/guardian_elder.lua +++ b/mods/ENTITIES/mobs_mc/guardian_elder.lua @@ -16,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 ac631f205..461c60efd 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -88,6 +88,10 @@ local horse = { 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 = { @@ -97,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, }, @@ -114,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, @@ -182,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 @@ -214,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)) @@ -239,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 @@ -253,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 @@ -282,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 @@ -357,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, @@ -520,22 +542,53 @@ 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, diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 0d3e74645..48e573e13 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -16,8 +16,11 @@ mobs:register_mob("mobs_mc: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", @@ -40,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 655cddfb6..58f565ec1 100644 --- a/mods/ENTITIES/mobs_mc/llama.lua +++ b/mods/ENTITIES/mobs_mc/llama.lua @@ -28,6 +28,15 @@ 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, @@ -50,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, @@ -83,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) @@ -126,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({ @@ -170,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, @@ -240,3 +292,38 @@ 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 000000000..ec59e0f70 --- /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 cebc037c0..ab34f334f 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/ocelot.lua b/mods/ENTITIES/mobs_mc/ocelot.lua index 5a3f135a1..e36abec77 100644 --- a/mods/ENTITIES/mobs_mc/ocelot.lua +++ b/mods/ENTITIES/mobs_mc/ocelot.lua @@ -31,6 +31,8 @@ local ocelot = { type = "animal", spawn_class = "passive", can_despawn = true, + rotate = 270, + skittish = true, hp_min = 10, hp_max = 10, xp_min = 1, @@ -43,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, @@ -57,7 +59,7 @@ local ocelot = { }, animation = { speed_normal = 25, - run_speed = 50, + run_speed = 150, stand_start = 0, stand_end = 0, walk_start = 0, @@ -123,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 diff --git a/mods/ENTITIES/mobs_mc/parrot.lua b/mods/ENTITIES/mobs_mc/parrot.lua index c04ea77c6..de52c6252 100644 --- a/mods/ENTITIES/mobs_mc/parrot.lua +++ b/mods/ENTITIES/mobs_mc/parrot.lua @@ -20,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 = { @@ -85,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, }) diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index b7d919cff..d7433a092 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -6,7 +6,8 @@ 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, @@ -19,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, @@ -50,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) @@ -91,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 @@ -104,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 @@ -164,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, @@ -188,22 +211,53 @@ 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", }, 9, minetest.LIGHT_MAX+1, diff --git a/mods/ENTITIES/mobs_mc/polar_bear.lua b/mods/ENTITIES/mobs_mc/polar_bear.lua index 98268961b..0476229b5 100644 --- a/mods/ENTITIES/mobs_mc/polar_bear.lua +++ b/mods/ENTITIES/mobs_mc/polar_bear.lua @@ -31,7 +31,7 @@ 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, diff --git a/mods/ENTITIES/mobs_mc/rabbit.lua b/mods/ENTITIES/mobs_mc/rabbit.lua index 6b47fec70..90d5c27bf 100644 --- a/mods/ENTITIES/mobs_mc/rabbit.lua +++ b/mods/ENTITIES/mobs_mc/rabbit.lua @@ -8,7 +8,7 @@ local rabbit = { spawn_class = "passive", passive = true, reach = 1, - + rotate = 270, hp_min = 3, hp_max = 3, xp_min = 1, @@ -62,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” @@ -116,22 +114,53 @@ 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", }, 9, minetest.LIGHT_MAX+1, diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index 9ddc0adee..1527fd6da 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -63,8 +63,13 @@ mobs:register_mob("mobs_mc:sheep", { 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", @@ -73,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, @@ -99,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 @@ -195,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 @@ -252,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. @@ -309,22 +337,53 @@ 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, @@ -336,3 +395,4 @@ 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 0d5ad880a..9932c5add 100644 --- a/mods/ENTITIES/mobs_mc/shulker.lua +++ b/mods/ENTITIES/mobs_mc/shulker.lua @@ -15,7 +15,7 @@ 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, diff --git a/mods/ENTITIES/mobs_mc/silverfish.lua b/mods/ENTITIES/mobs_mc/silverfish.lua index 5af3c8aa0..148c4c722 100644 --- a/mods/ENTITIES/mobs_mc/silverfish.lua +++ b/mods/ENTITIES/mobs_mc/silverfish.lua @@ -44,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 61e1c6eb2..37b1fc6dd 100644 --- a/mods/ENTITIES/mobs_mc/skeleton+stray.lua +++ b/mods/ENTITIES/mobs_mc/skeleton+stray.lua @@ -16,11 +16,15 @@ 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, @@ -31,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 = { @@ -43,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, @@ -75,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, @@ -86,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, diff --git a/mods/ENTITIES/mobs_mc/skeleton_wither.lua b/mods/ENTITIES/mobs_mc/skeleton_wither.lua index 1c0bdbea1..279a1d8cb 100644 --- a/mods/ENTITIES/mobs_mc/skeleton_wither.lua +++ b/mods/ENTITIES/mobs_mc/skeleton_wither.lua @@ -87,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 28621ee6f..0cae6757d 100644 --- a/mods/ENTITIES/mobs_mc/slime+magma_cube.lua +++ b/mods/ENTITIES/mobs_mc/slime+magma_cube.lua @@ -59,15 +59,15 @@ 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, @@ -84,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, @@ -301,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, @@ -313,6 +311,7 @@ local magma_cube_big = { }, walk_velocity = 4, run_velocity = 4, + rotate = 270, damage = 6, reach = 3, armor = 53, @@ -324,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, 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 5c9ee492b..acb236445 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 acb236445..1ef7a5227 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 1ef7a5227..c2743fbcc 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 c2743fbcc..000000000 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 000000000..5c9ee492b 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 c1cb5be4b..6ade915ab 100644 --- a/mods/ENTITIES/mobs_mc/spider.lua +++ b/mods/ENTITIES/mobs_mc/spider.lua @@ -17,17 +17,22 @@ local 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 = { @@ -44,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, diff --git a/mods/ENTITIES/mobs_mc/squid.lua b/mods/ENTITIES/mobs_mc/squid.lua index 0c425bb51..55d4b05c3 100644 --- a/mods/ENTITIES/mobs_mc/squid.lua +++ b/mods/ENTITIES/mobs_mc/squid.lua @@ -17,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", @@ -48,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 000000000..e0715af9f 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 000000000..40c39648f 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 000000000..b02c41b26 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 000000000..2c7c71c2f 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 000000000..83f7a8faa 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 000000000..a4bd9cb1f 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 000000000..c3297ce94 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 000000000..71eabea53 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 000000000..929a60950 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 000000000..1507d6d79 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 000000000..809e645fb 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 000000000..ff17ff67c 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 000000000..7009e6efc 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 000000000..1de65a407 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 000000000..645df4977 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 000000000..c6ae669dd 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 000000000..6318e163d 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_spit.png b/mods/ENTITIES/mobs_mc/textures/mobs_mc_spit.png new file mode 100644 index 000000000..6cdb3e0b3 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 a72827d5d..c23643cda 100644 --- a/mods/ENTITIES/mobs_mc/vex.lua +++ b/mods/ENTITIES/mobs_mc/vex.lua @@ -15,7 +15,7 @@ mobs:register_mob("mobs_mc:vex", { 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 db9cf3b19..154e9411f 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -962,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 04c95b88f..f87483e2b 100644 --- a/mods/ENTITIES/mobs_mc/villager_evoker.lua +++ b/mods/ENTITIES/mobs_mc/villager_evoker.lua @@ -35,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 496f08fc6..46b8760a1 100644 --- a/mods/ENTITIES/mobs_mc/villager_illusioner.lua +++ b/mods/ENTITIES/mobs_mc/villager_illusioner.lua @@ -10,7 +10,7 @@ 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", @@ -18,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 276f80011..7df54ef58 100644 --- a/mods/ENTITIES/mobs_mc/villager_vindicator.lua +++ b/mods/ENTITIES/mobs_mc/villager_vindicator.lua @@ -37,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 1948b693d..450710c49 100644 --- a/mods/ENTITIES/mobs_mc/villager_zombie.lua +++ b/mods/ENTITIES/mobs_mc/villager_zombie.lua @@ -29,6 +29,9 @@ 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, @@ -51,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 8ebe71fc0..0c72d0018 100644 --- a/mods/ENTITIES/mobs_mc/witch.lua +++ b/mods/ENTITIES/mobs_mc/witch.lua @@ -34,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 72459a354..7c9072f43 100644 --- a/mods/ENTITIES/mobs_mc/wither.lua +++ b/mods/ENTITIES/mobs_mc/wither.lua @@ -53,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 7f14ac6b0..89a4b4629 100644 --- a/mods/ENTITIES/mobs_mc/wolf.lua +++ b/mods/ENTITIES/mobs_mc/wolf.lua @@ -23,13 +23,31 @@ local 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 = { @@ -53,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) @@ -75,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 @@ -142,17 +161,29 @@ dog.owner_loyal = true 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 diff --git a/mods/ENTITIES/mobs_mc/zombie.lua b/mods/ENTITIES/mobs_mc/zombie.lua index 4ae5796b3..7d0fb1491 100644 --- a/mods/ENTITIES/mobs_mc/zombie.lua +++ b/mods/ENTITIES/mobs_mc/zombie.lua @@ -49,6 +49,8 @@ local zombie = { description = S("Zombie"), type = "monster", spawn_class = "hostile", + hostile = true, + rotate = 270, hp_min = 20, hp_max = 20, xp_min = 5, @@ -74,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, @@ -93,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, } diff --git a/mods/ENTITIES/mobs_mc/zombiepig.lua b/mods/ENTITIES/mobs_mc/zombiepig.lua index 1ea4197c1..72a19f413 100644 --- a/mods/ENTITIES/mobs_mc/zombiepig.lua +++ b/mods/ENTITIES/mobs_mc/zombiepig.lua @@ -15,13 +15,16 @@ local 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, @@ -41,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, 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 90747c38a..f14c99314 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 484e40ec1..77f107863 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 2fb04c4ca..489a19683 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 a1505b349..ac6a1d752 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 e5a400e95..8e94dcc6b 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_experience/init.lua b/mods/HUD/mcl_experience/init.lua index 47db77bca..fd78534fc 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -263,7 +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 = mcl_util.calculate_durability(itemstack) + local uses = mcl_util.calculate_durability(stack) local multiplier = 2 * 65535 / uses local repair = experience * multiplier local new_wear = wear - repair diff --git a/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua b/mods/ITEMS/REDSTONE/mesecons_walllever/init.lua index a0ecf354d..92c809785 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 index 4d6686807..d58b5e666 100644 --- a/mods/ITEMS/mcl_armor/api.lua +++ b/mods/ITEMS/mcl_armor/api.lua @@ -90,6 +90,14 @@ function mcl_armor.register_set(def) 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 @@ -101,9 +109,13 @@ function mcl_armor.register_set(def) groups.combat_armor = 1 groups.mcl_armor_points = def.points[name] groups.mcl_armor_toughness = def.toughness - groups.mcl_armor_uses = math.floor(def.durability * element.durability) + 1 + 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, @@ -117,11 +129,12 @@ function mcl_armor.register_set(def) }, on_place = mcl_armor.equip_on_use, on_secondary_use = mcl_armor.equip_on_use, - _on_equip = def.on_equip, - _on_unequip = def.on_unequip, + _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 = modname .. "_" .. itemname .. ".png", - _mcl_armor_preview = modname .. "_" .. itemname .. "_preview.png", + _mcl_armor_texture = textures[name] or modname .. "_" .. itemname .. ".png", + _mcl_armor_preview = previews[name] or modname .. "_" .. itemname .. "_preview.png", }) if def.craft_material then @@ -197,12 +210,26 @@ function mcl_armor.update(obj) if not itemstack:is_empty() then local def = itemstack:get_definition() - if def._mcl_armor_texture then - info.texture = "(" .. def._mcl_armor_texture .. ")" .. (info.texture and "^" .. info.texture or "") + 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 - if obj:is_player() and def._mcl_armor_preview then - info.preview = "(player.png^[opacity:0^" .. def._mcl_armor_preview .. ")" .. (info.preview and "^" .. info.preview or "" ) + 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") diff --git a/mods/ITEMS/mcl_armor/damage.lua b/mods/ITEMS/mcl_armor/damage.lua index c5023deb5..f17033495 100644 --- a/mods/ITEMS/mcl_armor/damage.lua +++ b/mods/ITEMS/mcl_armor/damage.lua @@ -1,3 +1,12 @@ +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 @@ -28,8 +37,7 @@ mcl_damage.register_modifier(function(obj, damage, reason) points = points + minetest.get_item_group(itemname, "mcl_armor_points") toughness = toughness + minetest.get_item_group(itemname, "mcl_armor_toughness") - mcl_util.use_item_durability(itemstack, uses) - inv:set_stack("armor", element.index, itemstack) + use_durability(obj, inv, element.index, itemstack, uses) end if not flags.bypasses_magic then @@ -81,11 +89,11 @@ mcl_damage.register_modifier(function(obj, damage, reason) 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, {type = "thorns", direct = obj}) + mcl_util.deal_damage(reason.source, thorns_damage, {type = "thorns", direct = obj}) local thorns_item = thorns_pieces[math.random(#thorns_pieces)] - mcl_util.use_item_durability(thorns_item.itemstack, 2) - inv:set_stack("armor", thorns_item.index, thorns_item.itemstack) + + use_durability(obj, inv, thorns_item.index, thorns_item.itemstack, 2) end mcl_armor.update(obj) diff --git a/mods/ITEMS/mcl_beds/functions.lua b/mods/ITEMS/mcl_beds/functions.lua index b1ce06b96..ecd749603 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_chests/locale/template.txt b/mods/ITEMS/mcl_chests/locale/template.txt index d680c24c9..1d947184b 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 8fbd79722..3d90dd5ae 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_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index e5b61d328..89fdc393d 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 diff --git a/mods/ITEMS/mcl_potions/functions.lua b/mods/ITEMS/mcl_potions/functions.lua index 9a1e38d99..55a98ba9d 100644 --- a/mods/ITEMS/mcl_potions/functions.lua +++ b/mods/ITEMS/mcl_potions/functions.lua @@ -689,7 +689,7 @@ function mcl_potions.healing_func(player, hp) hp = -1 end - mcl_util.deal_damage(obj, -hp, {type = "magic"}) + mcl_util.deal_damage(player, -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 36f5280b9..34693d531 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 75a99b0f1..147db6cc5 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/PLAYER/mcl_playerplus/init.lua b/mods/PLAYER/mcl_playerplus/init.lua index 08cecd615..9436ae94d 100644 --- a/mods/PLAYER/mcl_playerplus/init.lua +++ b/mods/PLAYER/mcl_playerplus/init.lua @@ -166,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