3 --made for MC like Survival game
4 --License for code WTFPL and otherwise stated in readmes
7 local MP
= minetest
.get_modpath(minetest
.get_current_modname())
8 local S
, NS
= dofile(MP
.."/intllib.lua")
11 --################### OCELOT AND CAT
14 local pr
= PseudoRandom(os
.time()*12)
16 local default_walk_chance
= 70
18 -- Returns true if the item is food (taming) for the cat/ocelot
19 local is_food
= function(itemstring
)
20 for f
=1, #mobs_mc
.follow
.ocelot
do
21 if itemstring
== mobs_mc
.follow
.ocelot
[f
] then
23 elseif string.sub(itemstring
, 1, 6) == "group:" and minetest
.get_item_group(itemstring
, string.sub(itemstring
, 7, -1)) ~= 0 then
36 collisionbox
= {-0.3, -0.01, -0.3, 0.3, 0.69, 0.3},
38 mesh
= "mobs_mc_cat.b3d",
39 textures
= {"mobs_mc_cat_ocelot.png"},
40 visual_size
= {x
=2.0, y
=2.0},
41 makes_footstep_sound
= true,
42 walk_chance
= default_walk_chance
,
53 random = "mobs_kitten",
57 speed_normal
= 25, speed_run
= 50,
58 stand_start
= 0, stand_end
= 0,
59 walk_start
= 0, walk_end
= 40,
60 run_start
= 0, run_end
= 40,
62 follow
= mobs_mc
.follow
.ocelot
,
65 attack_type
= "dogfight",
69 attack_animals
= true,
70 specific_attack
= { "mobs_mc:chicken" },
71 on_rightclick
= function(self
, clicker
)
72 if self
.child
then return end
73 -- Try to tame ocelot (mobs:feed_tame is intentionally NOT used)
74 local item
= clicker
:get_wielded_item()
75 if is_food(item
:get_name()) then
76 if not minetest
.settings
:get_bool("creative_mode") then
78 clicker
:set_wielded_item(item
)
80 -- 1/3 chance of getting tamed
81 if pr
:next(1, 3) == 1 then
82 local yaw
= self
.object
:get_yaw()
83 local cat
= minetest
.add_entity(self
.object
:getpos(), "mobs_mc:cat")
85 local ent
= cat
:get_luaentity()
86 ent
.owner
= clicker
:get_player_name()
96 mobs
:register_mob("mobs_mc:ocelot", ocelot
)
99 local cat
= table.copy(ocelot
)
100 cat
.textures
= {{"mobs_mc_cat_black.png"}, {"mobs_mc_cat_red.png"}, {"mobs_mc_cat_siamese.png"}}
101 cat
.can_despawn
= false
103 cat
.order
= "roam" -- "sit" or "roam"
104 cat
.owner_loyal
= true
107 -- Automatically teleport cat to owner
108 cat
.do_custom
= mobs_mc
.make_owner_teleport_function(12)
109 cat
.on_rightclick
= function(self
, clicker
)
110 if mobs
:feed_tame(self
, clicker
, 1, true, false) then return end
111 if mobs
:capture_mob(self
, clicker
, 0, 60, 5, false, nil) then return end
112 if mobs
:protect(self
, clicker
) then return end
114 if self
.child
then return end
116 -- Toggle sitting order
118 if not self
.owner
or self
.owner
== "" then
119 -- Huh? This cat has no owner? Let's fix this! This should never happen.
120 self
.owner
= clicker
:get_player_name()
123 if not self
.order
or self
.order
== "" or self
.order
== "sit" then
125 self
.walk_chance
= default_walk_chance
129 -- TODO: Add sitting model
137 mobs
:register_mob("mobs_mc:cat", cat
)
139 local base_spawn_chance
= 5000
143 name
= "mobs_mc:ocelot",
144 nodes
= mobs_mc
.spawn
.jungle
,
146 light_max
= minetest
.LIGHT_MAX
+1,
148 chance
= math
.ceil(base_spawn_chance
* 1.5), -- emulates 1/3 spawn failure rate
149 active_object_count
= 12,
150 min_height
= mobs_mc
.spawn_height
.water
+1, -- Right above ocean level
151 max_height
= mobs_mc
.spawn_height
.overworld_max
,
152 on_spawn
= function(self
, pos
)
153 --[[ Note: Minecraft has a 1/3 spawn failure rate.
154 In this mod it is emulated by reducing the spawn rate accordingly (see above). ]]
156 -- 1/7 chance to spawn 2 ocelot kittens
157 if pr
:next(1,7) == 1 then
158 -- Turn object into a child
159 local make_child
= function(object
)
160 local ent
= object
:get_luaentity()
161 object
:set_properties({
162 visual_size
= { x
= ent
.base_size
.x
/2, y
= ent
.base_size
.y
/2 },
164 ent
.base_colbox
[1]/2,
165 ent
.base_colbox
[2]/2,
166 ent
.base_colbox
[3]/2,
167 ent
.base_colbox
[4]/2,
168 ent
.base_colbox
[5]/2,
169 ent
.base_colbox
[6]/2,
175 -- Possible spawn offsets, two of these will get selected
188 local o
= pr
:next(1, #offsets
)
189 local offset
= offsets
[o
]
190 local child_pos
= vector
.add(pos
, offsets
[o
])
191 table.remove(offsets
, o
)
192 make_child(minetest
.add_entity(child_pos
, "mobs_mc:ocelot"))
199 mobs
:alias_mob("mobs:kitten", "mobs_mc:ocelot")
202 -- FIXME: The spawn icon shows a cat texture, not an ocelot texture
203 mobs
:register_egg("mobs_mc:ocelot", S("Ocelot"), "mobs_mc_spawn_icon_cat.png", 0)
205 if minetest
.settings
:get_bool("log_mods") then
206 minetest
.log("action", "MC Ocelot loaded")