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
35 collisionbox
= {-0.3, -0.01, -0.3, 0.3, 0.69, 0.3},
37 mesh
= "mobs_mc_cat.b3d",
38 textures
= {"mobs_mc_cat_ocelot.png"},
39 visual_size
= {x
=2.0, y
=2.0},
40 makes_footstep_sound
= true,
41 walk_chance
= default_walk_chance
,
52 random = "mobs_kitten",
56 speed_normal
= 25, speed_run
= 50,
57 stand_start
= 0, stand_end
= 0,
58 walk_start
= 0, walk_end
= 40,
59 run_start
= 0, run_end
= 40,
61 follow
= mobs_mc
.follow
.ocelot
,
64 attack_type
= "dogfight",
68 attack_animals
= true,
69 specific_attack
= { "mobs_mc:chicken" },
70 on_rightclick
= function(self
, clicker
)
71 if self
.child
then return end
72 -- Try to tame ocelot (mobs:feed_tame is intentionally NOT used)
73 local item
= clicker
:get_wielded_item()
74 if is_food(item
:get_name()) then
75 if not minetest
.settings
:get_bool("creative_mode") then
77 clicker
:set_wielded_item(item
)
79 -- 1/3 chance of getting tamed
80 if pr
:next(1, 3) == 1 then
81 local yaw
= self
.object
:get_yaw()
82 local cat
= minetest
.add_entity(self
.object
:getpos(), "mobs_mc:cat")
84 local ent
= cat
:get_luaentity()
85 ent
.owner
= clicker
:get_player_name()
95 mobs
:register_mob("mobs_mc:ocelot", ocelot
)
98 local cat
= table.copy(ocelot
)
99 cat
.textures
= {{"mobs_mc_cat_black.png"}, {"mobs_mc_cat_red.png"}, {"mobs_mc_cat_siamese.png"}}
101 cat
.order
= "roam" -- "sit" or "roam"
102 cat
.owner_loyal
= true
105 -- Automatically teleport cat to owner
106 cat
.do_custom
= mobs_mc
.make_owner_teleport_function(12)
107 cat
.on_rightclick
= function(self
, clicker
)
108 if mobs
:feed_tame(self
, clicker
, 1, true, false) then return end
109 if mobs
:capture_mob(self
, clicker
, 0, 60, 5, false, nil) then return end
110 if mobs
:protect(self
, clicker
) then return end
112 if self
.child
then return end
114 -- Toggle sitting order
116 if not self
.owner
or self
.owner
== "" then
117 -- Huh? This cat has no owner? Let's fix this! This should never happen.
118 self
.owner
= clicker
:get_player_name()
121 if not self
.order
or self
.order
== "" or self
.order
== "sit" then
123 self
.walk_chance
= default_walk_chance
127 -- TODO: Add sitting model
135 mobs
:register_mob("mobs_mc:cat", cat
)
137 local base_spawn_chance
= 5000
141 name
= "mobs_mc:ocelot",
142 nodes
= mobs_mc
.spawn
.jungle
,
144 light_max
= minetest
.LIGHT_MAX
+1,
146 chance
= math
.ceil(base_spawn_chance
* 1.5), -- emulates 1/3 spawn failure rate
147 active_object_count
= 12,
148 min_height
= mobs_mc
.spawn_height
.water
+1, -- Right above ocean level
149 max_height
= mobs_mc
.spawn_height
.overworld_max
,
150 on_spawn
= function(self
, pos
)
151 --[[ Note: Minecraft has a 1/3 spawn failure rate.
152 In this mod it is emulated by reducing the spawn rate accordingly (see above). ]]
154 -- 1/7 chance to spawn 2 ocelot kittens
155 if pr
:next(1,7) == 1 then
156 -- Turn object into a child
157 local make_child
= function(object
)
158 local ent
= object
:get_luaentity()
159 object
:set_properties({
160 visual_size
= { x
= ent
.base_size
.x
/2, y
= ent
.base_size
.y
/2 },
162 ent
.base_colbox
[1]/2,
163 ent
.base_colbox
[2]/2,
164 ent
.base_colbox
[3]/2,
165 ent
.base_colbox
[4]/2,
166 ent
.base_colbox
[5]/2,
167 ent
.base_colbox
[6]/2,
173 -- Possible spawn offsets, two of these will get selected
186 local o
= pr
:next(1, #offsets
)
187 local offset
= offsets
[o
]
188 local child_pos
= vector
.add(pos
, offsets
[o
])
189 table.remove(offsets
, o
)
190 make_child(minetest
.add_entity(child_pos
, "mobs_mc:ocelot"))
197 mobs
:alias_mob("mobs:kitten", "mobs_mc:ocelot")
200 -- FIXME: The spawn icon shows a cat texture, not an ocelot texture
201 mobs
:register_egg("mobs_mc:ocelot", S("Ocelot"), "mobs_mc_spawn_icon_cat.png", 0)
203 if minetest
.settings
:get_bool("log_mods") then
204 minetest
.log("action", "MC Ocelot loaded")