diff --git a/API.txt b/API.txt index d16d8e3..3bf8bb8 100644 --- a/API.txt +++ b/API.txt @@ -4,6 +4,14 @@ Creatures MOB-Engine API creatures.register_mob(#Creature definition) -registers a mob at MOB-Engine; returns true when sucessfull +creatures.register_alias(old_mob, new_mob) -- returns true if sucessfull + -registers an alias for other mob, e.g. from other mods or removed ones. + existent entities (MOBs), Spawners and Spawn Eggs are converted; + returns true when sucessfull + ^ old_mob: name as string, e.g. "creatures:oerrki" + ^ new_mob: name as string, e.g. "creatures:oerkki" + ^ example: creatures.register_alias("creatures:oerrki", "creatures:oerkki") + creatures.rnd(chance_table) -returns a weighted random table element; chance_sum of table must be 1 ^ example: creatures.rnd({elem1 = {chance = 0.7}, {elem2 = {chance = 0.3}}) diff --git a/chicken/README.txt b/chicken/README.txt index 5c45ab7..25fb1f2 100644 --- a/chicken/README.txt +++ b/chicken/README.txt @@ -2,13 +2,14 @@ Chicken for Creatures MOB-Engine ================================ Copyright (c) 2015-2016 BlockMen -Version: 2.2 +Version: 2.3 Adds chicken to Minetest (requires Creatures MOB-Engine). Chicken spawn on dirt and grass blocks, have 5 HP and are friendly. When killed or dying they drop meat, which can be eaten or cooked and probably some feathers. Also they drop -randomly eggs, which can be thrown to spawn new chicken or fried and eaten. +randomly eggs, which can be thrown to spawn new chicken or fried and eaten. They appear +with white or brown feathers. License: diff --git a/chicken/init.lua b/chicken/init.lua index 5e00e90..5874001 100644 --- a/chicken/init.lua +++ b/chicken/init.lua @@ -55,6 +55,12 @@ core.register_craftitem(":creatures:feather", { inventory_image = "creatures_feather.png", }) + +local colors = { + white = {chance = 0.7}, + brown = {chance = 0.3} +} + local def = { -- general name = "creatures:chicken", @@ -74,14 +80,14 @@ local def = { idle2 = {chance = 0.69, duration = 0.8}, pick = {chance = 0.2, duration = 2}, walk = {chance = 0.2, duration = 5.5, moving_speed = 0.7, update_yaw = 2}, - panic = {moving_speed = 2.1}, + panic = {moving_speed = 3.1, update_yaw = 0.8}, lay_egg = {chance = 0.01, duration = 1}, }, model = { mesh = "creatures_chicken.b3d", - textures = {"creatures_chicken.png"}, - collisionbox = {-0.25, -0.01, -0.3, 0.25, 0.45, 0.3}, + textures = {"creatures_chicken_white.png"}, + collisionbox = {-0.19, -0.01, -0.19, 0.19, 0.52, 0.19}, rotation = 90.0, collide_with_objects = false, animations = { @@ -126,6 +132,20 @@ local def = { {"creatures:feather", {min = 1, max = 2}, chance = 0.45}, }, + get_staticdata = function(self) + return { + feather_color = self.feather_color, + } + end, + + on_activate = function(self, staticdata) + if not self.feather_color then + self.feather_color = creatures.rnd(colors) or "white" + end + -- update feather color + self.object:set_properties({textures = {"creatures_chicken_" .. self.feather_color .. ".png"}}) + end, + on_step = function(self, dtime) if self.mode == "lay_egg" then dropEgg(self.object) diff --git a/chicken/textures/creatures_chicken_brown.png b/chicken/textures/creatures_chicken_brown.png new file mode 100644 index 0000000..529a4fd Binary files /dev/null and b/chicken/textures/creatures_chicken_brown.png differ diff --git a/chicken/textures/creatures_chicken_white.png b/chicken/textures/creatures_chicken_white.png new file mode 100644 index 0000000..8301537 Binary files /dev/null and b/chicken/textures/creatures_chicken_white.png differ diff --git a/creatures/common.lua b/creatures/common.lua index 8c9983d..110e334 100644 --- a/creatures/common.lua +++ b/creatures/common.lua @@ -25,17 +25,25 @@ nullVec = {x = 0, y = 0, z = 0} DEGTORAD = math.pi / 180.0 -- common functions -function creatures.rnd(table, errval) +function creatures.sumChances(tab) + local psum = 0 + for s,w in pairs(tab) do + psum = psum + ((tonumber(w) or w.chance or 0)) + end + return psum +end + +function creatures.rnd(tab, errval) if not errval then errval = false end local res = 1000000000 local rn = math.random(0, res - 1) - local retval = nil + local retval = nil local psum = 0 - for s,w in pairs(table) do + for s,w in pairs(tab) do psum = psum + ((tonumber(w) or w.chance or 0) * res) if psum > rn then retval = s @@ -50,6 +58,10 @@ function throw_error(msg) core.log("error", "#Creatures: ERROR: " .. msg) end +function throw_warning(msg) + core.log("warning", "#Creatures: WARNING: " .. msg) +end + function creatures.compare_pos(pos1, pos2) if not pos1 or not pos2 then return @@ -64,8 +76,8 @@ function creatures.findTarget(search_obj, pos, radius, search_type, ignore_mob, local player_near = false local mobs = {} for _,obj in ipairs(core.get_objects_inside_radius(pos, radius)) do - if obj ~= search_obj then - if xray or core.line_of_sight(pos, obj:getpos()) == true then + if obj ~= search_obj then + if xray or core.line_of_sight(pos, obj:getpos()) == true then local is_player = obj:is_player() if is_player then player_near = true @@ -73,33 +85,33 @@ function creatures.findTarget(search_obj, pos, radius, search_type, ignore_mob, return {}, true end end - local entity = obj:get_luaentity() - local isItem = (entity and entity.name == "__builtin:item") or false - local ignore = (entity and entity.mob_name == ignore_mob and search_type ~= "mates") or false + local entity = obj:get_luaentity() + local isItem = (entity and entity.name == "__builtin:item") or false + local ignore = (entity and entity.mob_name == ignore_mob and search_type ~= "mates") or false - if search_type == "all" then - if not isItem and not ignore then - table.insert(mobs, obj) - end - elseif search_type == "hostile" then - if not ignore and (entity and entity.hostile == true) or is_player then - table.insert(mobs, obj) - end - elseif search_type == "nonhostile" then - if entity and not entity.hostile and not isItem and not ignore then - table.insert(mobs, obj) - end - elseif search_type == "player" then - if is_player then - table.insert(mobs, obj) - end - elseif search_type == "mate" then - if not isItem and (entity and entity.mob_name == ignore_mob) then - table.insert(mobs, obj) - end - end - end - end --for + if search_type == "all" then + if not isItem and not ignore then + table.insert(mobs, obj) + end + elseif search_type == "hostile" then + if not ignore and (entity and entity.hostile == true) or is_player then + table.insert(mobs, obj) + end + elseif search_type == "nonhostile" then + if entity and not entity.hostile and not isItem and not ignore then + table.insert(mobs, obj) + end + elseif search_type == "player" then + if is_player then + table.insert(mobs, obj) + end + elseif search_type == "mate" then + if not isItem and (entity and entity.mob_name == ignore_mob) then + table.insert(mobs, obj) + end + end + end + end --for end return mobs,player_near diff --git a/creatures/register.lua b/creatures/register.lua index 212c65c..922e9dc 100644 --- a/creatures/register.lua +++ b/creatures/register.lua @@ -53,6 +53,18 @@ local function translate_def(def) --if name == "attack" then new_def.modes[name].chance = 0 end end end + + -- Check if the modes have correct sum + local mode_chance_sum = creatures.sumChances(new_def.modes) + if mode_chance_sum > 1 then + throw_warning("Chance of modes too high for MOB: " .. def.name .. + ". Mode chances will be incorrect.") + elseif mode_chance_sum < 1 then + throw_warning("Chance of modes too low for MOB: " .. def.name .. + ". Filling up to correct mode chances.") + new_def.modes["_empty"] = {chance = 1 - mode_chance_sum, duration = 0} + end + -- insert special mode "_run" which is used when in panic if def.stats.can_panic then if def.modes.walk then @@ -578,3 +590,46 @@ function creatures.register_spawner(spawner_def) return true end + +local function register_alias_entity(old_mob, new_mob) + core.register_entity(":" .. old_mob, { + physical = false, + collisionbox = {0, 0, 0, 0, 0, 0}, + visual = "sprite", + visual_size = {x = 0, y = 0}, + textures = {"creatures_spawner.png"}, -- dummy texture + makes_footstep_sound = false, + + on_activate = function(self) + local pos = self.object:getpos() + if pos then + core.add_entity(pos, new_mob) + end + if self.object then + self.object:remove() + end + end, + }) +end + + +function creatures.register_alias(old_mob, new_mob) -- returns true if sucessfull + local def = core.registered_entities[new_mob] + if not def then + throw_error("No valid definition for given.") + return false + end + + register_alias_entity(old_mob, new_mob) + + if core.registered_nodes[new_mob .. "_spawner"] then + register_alias_entity(old_mob .. "_spawner_dummy", new_mob .. "_spawner_dummy") + core.register_alias(old_mob .. "_spawner", new_mob .. "_spawner") + end + + if core.registered_items[new_mob .. "_spawn_egg"] then + core.register_alias(old_mob .. "_spawn_egg", new_mob .. "_spawn_egg") + end + + return true +end diff --git a/ghost/init.lua b/ghost/init.lua index c3ef546..9a1c3ba 100644 --- a/ghost/init.lua +++ b/ghost/init.lua @@ -45,7 +45,7 @@ local def = { model = { mesh = "creatures_ghost.b3d", textures = {"creatures_ghost.png"}, - collisionbox = {-0.25, 0, -0.3, 0.25, 1.3, 0.3}, + collisionbox = {-0.22, 0, -0.22, 0.22, 1.2, 0.22}, rotation = -90.0, animations = { idle = {start = 0, stop = 80, speed = 15}, diff --git a/oerrki/LICENSE.txt b/oerkki/LICENSE.txt similarity index 100% rename from oerrki/LICENSE.txt rename to oerkki/LICENSE.txt diff --git a/oerrki/README.txt b/oerkki/README.txt similarity index 76% rename from oerrki/README.txt rename to oerkki/README.txt index 97c8147..648b7e1 100644 --- a/oerrki/README.txt +++ b/oerkki/README.txt @@ -1,12 +1,12 @@ -Oerrki for Creatures MOB-Engine +Oerkki for Creatures MOB-Engine =============================== Copyright (c) 2016 BlockMen Version: 1.0 Beta -Adds classic Minetest Ghost called "Oerrki". (requires Creatures MOB-Engine). -Oerrki spawn only at night or in dark places and remain around 5 minutes in the world. +Adds classic Minetest Ghost called "Oerkki". (requires Creatures MOB-Engine). +Oerkki spawn only at night or in dark places and remain around 5 minutes in the world. Other than Ghosts or Zombies they don't die by sunlight. diff --git a/oerrki/depends.txt b/oerkki/depends.txt similarity index 69% rename from oerrki/depends.txt rename to oerkki/depends.txt index acd6e5b..864a01d 100644 --- a/oerrki/depends.txt +++ b/oerkki/depends.txt @@ -1,3 +1,3 @@ default creatures - +oerrki? diff --git a/oerrki/init.lua b/oerkki/init.lua similarity index 79% rename from oerrki/init.lua rename to oerkki/init.lua index 1d62e24..293a9e0 100644 --- a/oerrki/init.lua +++ b/oerkki/init.lua @@ -1,4 +1,4 @@ ---= Oerrki for Creatures MOB-Engine (cme) =-- +--= Oerkki for Creatures MOB-Engine (cme) =-- -- Copyright (c) 2016 BlockMen -- -- init.lua @@ -21,7 +21,7 @@ local def = { - name = "creatures:oerrki", + name = "creatures:oerkki", stats = { hp = 13, lifetime = 540, -- 9 Minutes @@ -36,9 +36,9 @@ local def = { }, model = { - mesh = "creatures_oerrki.b3d", - textures = {"creatures_oerrki.png"}, - collisionbox = {-0.25, -0.01, -0.3, 0.25, 1.75, 0.3}, + mesh = "creatures_oerkki.b3d", + textures = {"creatures_oerkki.png"}, + collisionbox = {-0.22, -0.01, -0.22, 0.22, 1.65, 0.22}, rotation = -90.0, animations = { idle = {start = 1, stop = 23, speed = 15}, @@ -50,12 +50,12 @@ local def = { }, sounds = { - on_damage = {name = "creatures_oerrki_hit", gain = 1.0, distance = 10}, - on_death = {name = "creatures_oerrki_hit", gain = 1.0, distance = 10}, + on_damage = {name = "creatures_oerkki_hit", gain = 1.0, distance = 10}, + on_death = {name = "creatures_oerkki_hit", gain = 1.0, distance = 10}, swim = {name = "creatures_splash", gain = 1.0, distance = 10}, random = { - idle = {name = "creatures_oerrki_idle", gain = 1.0, distance = 25}, - attack = {name = "creatures_oerrki_attack", gain = 1.0, distance = 20}, + idle = {name = "creatures_oerkki_idle", gain = 1.0, distance = 25}, + attack = {name = "creatures_oerkki_attack", gain = 1.0, distance = 20}, }, }, @@ -93,12 +93,12 @@ local def = { height_limit = {min = -200, max = 50}, spawn_egg = { - description = "Oerrki Spawn-Egg", - texture = "creatures_egg_oerrki.png", + description = "Oerkki Spawn-Egg", + texture = "creatures_egg_oerkki.png", }, spawner = { - description = "Oerrki Spawner", + description = "Oerkki Spawner", range = 8, player_range = 20, number = 6, @@ -108,3 +108,6 @@ local def = { } creatures.register_mob(def) + +-- Convert "Oerrki's" (caused by typo) +creatures.register_alias("creatures:oerrki", "creatures:oerkki") diff --git a/oerrki/models/creatures_oerrki.b3d b/oerkki/models/creatures_oerkki.b3d similarity index 100% rename from oerrki/models/creatures_oerrki.b3d rename to oerkki/models/creatures_oerkki.b3d diff --git a/oerrki/sounds/creatures_oerrki_attack.ogg b/oerkki/sounds/creatures_oerkki_attack.ogg similarity index 100% rename from oerrki/sounds/creatures_oerrki_attack.ogg rename to oerkki/sounds/creatures_oerkki_attack.ogg diff --git a/oerrki/sounds/creatures_oerrki_hit.1.ogg b/oerkki/sounds/creatures_oerkki_hit.1.ogg similarity index 100% rename from oerrki/sounds/creatures_oerrki_hit.1.ogg rename to oerkki/sounds/creatures_oerkki_hit.1.ogg diff --git a/oerrki/sounds/creatures_oerrki_hit.2.ogg b/oerkki/sounds/creatures_oerkki_hit.2.ogg similarity index 100% rename from oerrki/sounds/creatures_oerrki_hit.2.ogg rename to oerkki/sounds/creatures_oerkki_hit.2.ogg diff --git a/oerrki/sounds/creatures_oerrki_idle.1.ogg b/oerkki/sounds/creatures_oerkki_idle.1.ogg similarity index 100% rename from oerrki/sounds/creatures_oerrki_idle.1.ogg rename to oerkki/sounds/creatures_oerkki_idle.1.ogg diff --git a/oerrki/sounds/creatures_oerrki_idle.2.ogg b/oerkki/sounds/creatures_oerkki_idle.2.ogg similarity index 100% rename from oerrki/sounds/creatures_oerrki_idle.2.ogg rename to oerkki/sounds/creatures_oerkki_idle.2.ogg diff --git a/oerrki/textures/creatures_egg_oerrki.png b/oerkki/textures/creatures_egg_oerkki.png similarity index 100% rename from oerrki/textures/creatures_egg_oerrki.png rename to oerkki/textures/creatures_egg_oerkki.png diff --git a/oerrki/textures/creatures_oerrki.png b/oerkki/textures/creatures_oerkki.png similarity index 100% rename from oerrki/textures/creatures_oerrki.png rename to oerkki/textures/creatures_oerkki.png diff --git a/sheep/init.lua b/sheep/init.lua index 2872b32..f692de9 100644 --- a/sheep/init.lua +++ b/sheep/init.lua @@ -60,7 +60,12 @@ end -- white, grey, brown, black (see wool colors as reference) -local colors = {"white", "grey", "brown", "black"} +local colors = { + white = {chance = 0.7}, + grey = {chance = 0.1}, + brown = {chance = 0.1}, + black = {chance = 0.1} +} local def = { name = "creatures:sheep", @@ -78,7 +83,7 @@ local def = { model = { mesh = "creatures_sheep.b3d", textures = {"creatures_sheep.png^creatures_sheep_white.png"}, - collisionbox = {-0.5, -0.01, -0.55, 0.5, 1.1, 0.55}, + collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.06, 0.45}, rotation = -90.0, animations = { idle = {start = 1, stop = 60, speed = 15}, @@ -164,7 +169,7 @@ local def = { end if not self.wool_color then - self.wool_color = colors[math.random(1, #colors)] + self.wool_color = creatures.rnd(colors) or "white" end -- update fur setColor(self) diff --git a/zombie/init.lua b/zombie/init.lua index 98a16ed..a9b462b 100644 --- a/zombie/init.lua +++ b/zombie/init.lua @@ -51,7 +51,7 @@ local def = { model = { mesh = "creatures_zombie.b3d", textures = {"creatures_zombie.png"}, - collisionbox = {-0.25, -0.01, -0.3, 0.25, 1.75, 0.3}, + collisionbox = {-0.25, -0.01, -0.25, 0.25, 1.65, 0.25}, rotation = -90.0, animations = { idle = {start = 0, stop = 80, speed = 15},