Replace getpos() with get_pos()
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / cow+mooshroom.lua
blobbf1f9c1d6fe1b96229eec76bf2c2e8f283b362fd
1 --License for code WTFPL and otherwise stated in readmes
3 -- intllib
4 local MP = minetest.get_modpath(minetest.get_current_modname())
5 local S, NS = dofile(MP.."/intllib.lua")
7 local cow_def = {
8 type = "animal",
9 hp_min = 10,
10 hp_max = 10,
11 collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.39, 0.45},
12 visual = "mesh",
13 mesh = "mobs_mc_cow.b3d",
14 textures = { {
15 "mobs_mc_cow.png",
16 "blank.png",
17 }, },
18 visual_size = {x=2.8, y=2.8},
19 makes_footstep_sound = true,
20 walk_velocity = 1,
21 drops = {
22 {name = mobs_mc.items.beef_raw,
23 chance = 1,
24 min = 1,
25 max = 3,},
26 {name = mobs_mc.items.leather,
27 chance = 1,
28 min = 0,
29 max = 2,},
31 water_damage = 1,
32 lava_damage = 5,
33 light_damage = 0,
34 runaway = true,
35 sounds = {
36 random = "mobs_mc_cow",
37 damage = "mobs_mc_cow_hurt",
38 death = "mobs_mc_cow_hurt",
39 distance = 16,
41 animation = {
42 stand_speed = 25, walk_speed = 25, run_speed = 50,
43 stand_start = 0, stand_end = 0,
44 walk_start = 0, walk_end = 40,
45 run_start = 0, run_end = 40,
47 follow = mobs_mc.follow.cow,
48 on_rightclick = function(self, clicker)
49 if mobs:feed_tame(self, clicker, 1, true, true) then return end
50 if mobs:protect(self, clicker) then return end
52 if self.child then
53 return
54 end
56 local item = clicker:get_wielded_item()
57 if item:get_name() == mobs_mc.items.bucket and clicker:get_inventory() then
58 local inv = clicker:get_inventory()
59 inv:remove_item("main", mobs_mc.items.bucket)
60 -- if room add bucket of milk to inventory, otherwise drop as item
61 if inv:room_for_item("main", {name=mobs_mc.items.milk}) then
62 clicker:get_inventory():add_item("main", mobs_mc.items.milk)
63 else
64 local pos = self.object:get_pos()
65 pos.y = pos.y + 0.5
66 minetest.add_item(pos, {name = mobs_mc.items.milk})
67 end
68 return
69 end
70 mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
71 end,
72 follow = mobs_mc.items.wheat,
73 view_range = 10,
74 fear_height = 4,
77 mobs:register_mob("mobs_mc:cow", cow_def)
79 -- Mooshroom
80 local mooshroom_def = table.copy(cow_def)
82 mooshroom_def.mesh = "mobs_mc_cow.b3d"
83 mooshroom_def.textures = { {"mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png"}, }
84 mooshroom_def.on_rightclick = function(self, clicker)
85 if mobs:feed_tame(self, clicker, 1, true, true) then return end
86 if mobs:protect(self, clicker) then return end
88 if self.child then
89 return
90 end
91 local item = clicker:get_wielded_item()
92 -- Use shears to get mushrooms and turn mooshroom into cow
93 if item:get_name() == mobs_mc.items.shears then
94 local pos = self.object:get_pos()
95 minetest.sound_play("shears", {pos = pos})
96 minetest.add_item({x=pos.x, y=pos.y+1.4, z=pos.z}, mobs_mc.items.mushroom_red .. " 5")
98 local oldyaw = self.object:getyaw()
99 self.object:remove()
100 local cow = minetest.add_entity(pos, "mobs_mc:cow")
101 cow:setyaw(oldyaw)
103 if not minetest.settings:get_bool("creative_mode") then
104 item:add_wear(mobs_mc.misc.shears_wear)
105 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
107 -- Use bucket to milk
108 elseif item:get_name() == mobs_mc.items.bucket and clicker:get_inventory() then
109 local inv = clicker:get_inventory()
110 inv:remove_item("main", mobs_mc.items.bucket)
111 -- If room, add milk to inventory, otherwise drop as item
112 if inv:room_for_item("main", {name=mobs_mc.items.milk}) then
113 clicker:get_inventory():add_item("main", mobs_mc.items.milk)
114 else
115 local pos = self.object:get_pos()
116 pos.y = pos.y + 0.5
117 minetest.add_item(pos, {name = mobs_mc.items.milk})
119 -- Use bowl to get mushroom stew
120 elseif item:get_name() == mobs_mc.items.bowl and clicker:get_inventory() then
121 local inv = clicker:get_inventory()
122 inv:remove_item("main", mobs_mc.items.bowl)
123 -- If room, add mushroom stew to inventory, otherwise drop as item
124 if inv:room_for_item("main", {name=mobs_mc.items.mushroom_stew}) then
125 clicker:get_inventory():add_item("main", mobs_mc.items.mushroom_stew)
126 else
127 local pos = self.object:get_pos()
128 pos.y = pos.y + 0.5
129 minetest.add_item(pos, {name = mobs_mc.items.mushroom_stew})
132 mobs:capture_mob(self, clicker, 0, 5, 60, false, nil)
134 mobs:register_mob("mobs_mc:mooshroom", mooshroom_def)
137 -- Spawning
138 mobs:spawn_specific("mobs_mc:cow", mobs_mc.spawn.grassland, {"air"}, 9, minetest.LIGHT_MAX+1, 30, 17000, 20, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max)
139 mobs:spawn_specific("mobs_mc:mooshroom", mobs_mc.spawn.mushroom_island, {"air"}, 9, minetest.LIGHT_MAX+1, 30, 17000, 10, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max)
141 -- compatibility
142 mobs:alias_mob("mobs_animal:cow", "mobs_mc:cow")
144 -- spawn egg
145 mobs:register_egg("mobs_mc:cow", S("Cow"), "mobs_mc_spawn_icon_cow.png", 0)
146 mobs:register_egg("mobs_mc:mooshroom", S("Mooshroom"), "mobs_mc_spawn_icon_mooshroom.png", 0)
148 if minetest.settings:get_bool("log_mods") then
149 minetest.log("action", "MC Cow loaded")