Fix ocelots being aggressive to players
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / ocelot.lua
bloba590029fd68fe241794e05160814680476b11567
1 --MCmobs v0.4
2 --maikerumine
3 --made for MC like Survival game
4 --License for code WTFPL and otherwise stated in readmes
6 -- intllib
7 local MP = minetest.get_modpath(minetest.get_current_modname())
8 local S, NS = dofile(MP.."/intllib.lua")
10 --###################
11 --################### OCELOT AND CAT
12 --###################
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
22 return true
23 elseif string.sub(itemstring, 1, 6) == "group:" and minetest.get_item_group(itemstring, string.sub(itemstring, 7, -1)) ~= 0 then
24 return true
25 end
26 end
27 return false
28 end
30 -- Ocelot
31 local ocelot = {
32 type = "animal",
33 hp_min = 10,
34 hp_max = 10,
35 collisionbox = {-0.3, -0.01, -0.3, 0.3, 0.69, 0.3},
36 visual = "mesh",
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,
42 walk_velocity = 1,
43 run_velocity = 3,
44 floats = 1,
45 runaway = true,
46 water_damage = 0,
47 lava_damage = 4,
48 light_damage = 0,
49 fall_damage = 0,
50 fear_height = 4,
51 sounds = {
52 random = "mobs_kitten",
53 distance = 16,
55 animation = {
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,
62 view_range = 12,
63 passive = true,
64 attack_type = "dogfight",
65 pathfinding = 1,
66 damage = 2,
67 reach = 1,
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
76 item:take_item()
77 clicker:set_wielded_item(item)
78 end
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")
83 cat:set_yaw(yaw)
84 local ent = cat:get_luaentity()
85 ent.owner = clicker:get_player_name()
86 ent.tamed = true
87 self.object:remove()
88 return
89 end
90 end
92 end,
95 mobs:register_mob("mobs_mc:ocelot", ocelot)
97 -- Cat
98 local cat = table.copy(ocelot)
99 cat.textures = {{"mobs_mc_cat_black.png"}, {"mobs_mc_cat_red.png"}, {"mobs_mc_cat_siamese.png"}}
100 cat.owner = ""
101 cat.order = "roam" -- "sit" or "roam"
102 cat.owner_loyal = true
103 cat.tamed = true
104 cat.runaway = false
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
122 self.order = "roam"
123 self.walk_chance = default_walk_chance
124 self.jump = true
125 else
126 -- “Sit!”
127 -- TODO: Add sitting model
128 self.order = "sit"
129 self.walk_chance = 0
130 self.jump = false
135 mobs:register_mob("mobs_mc:cat", cat)
137 local base_spawn_chance = 5000
139 -- Spawn ocelot
140 mobs:spawn({
141 name = "mobs_mc:ocelot",
142 nodes = mobs_mc.spawn.jungle,
143 neighbors = {"air"},
144 light_max = minetest.LIGHT_MAX+1,
145 light_min = 0,
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 },
161 collisionbox = {
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,
170 ent.child = true
173 -- Possible spawn offsets, two of these will get selected
174 local k = 0.7
175 local offsets = {
176 { x=k, y=0, z=0 },
177 { x=-k, y=0, z=0 },
178 { x=0, y=0, z=k },
179 { x=0, y=0, z=-k },
180 { x=k, y=0, z=k },
181 { x=k, y=0, z=-k },
182 { x=-k, y=0, z=k },
183 { x=-k, y=0, z=-k },
185 for i=1, 2 do
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"))
193 end,
196 -- compatibility
197 mobs:alias_mob("mobs:kitten", "mobs_mc:ocelot")
199 -- spawn eggs
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")