Make villager stand still if there is near player
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / creeper.lua
blobb131bf09e54b8bd92b5bdeb390abde62b748a6de
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 --dofile(minetest.get_modpath("mobs").."/api.lua")
10 --###################
11 --################### CREEPER
12 --###################
17 mobs:register_mob("mobs_mc:creeper", {
18 type = "monster",
19 hp_min = 20,
20 hp_max = 20,
21 collisionbox = {-0.3, -0.01, -0.3, 0.3, 1.69, 0.3},
22 pathfinding = 1,
23 visual = "mesh",
24 mesh = "mobs_mc_creeper.b3d",
25 textures = {
26 {"mobs_mc_creeper.png"},
28 visual_size = {x=3, y=3},
29 sounds = {
30 attack = "tnt_ignite",
31 --TODO: death = "",
32 --TODO: damage = "",
33 fuse = "tnt_ignite",
34 explode = "tnt_explode",
35 distance = 16,
37 makes_footstep_sound = true,
38 walk_velocity = 1.05,
39 run_velocity = 2.1,
40 runaway_from = { "mobs_mc:ocelot", "mobs_mc:cat" },
41 attack_type = "explode",
43 explosion_radius = 3,
44 reach = 4,
45 explosion_damage_radius = 7,
46 explosion_timer = 1.5,
47 allow_fuse_reset = true,
48 stop_to_explode = true,
50 -- Force-ignite creeper with flint and steel and explode after 1.5 seconds.
51 -- TODO: Make creeper flash after doing this as well.
52 -- TODO: Test and debug this code.
53 on_rightclick = function(self, clicker)
54 if self._forced_explosion_countdown_timer ~= nil then
55 return
56 end
57 local item = clicker:get_wielded_item()
58 if item:get_name() == mobs_mc.items.flint_and_steel then
59 if not minetest.settings:get_bool("creative_mode") then
60 -- Wear tool
61 local wdef = item:get_definition()
62 item:add_wear(1000)
63 -- Tool break sound
64 if item:get_count() == 0 and wdef.sound and wdef.sound.breaks then
65 minetest.sound_play(wdef.sound.breaks, {pos = clicker:getpos(), gain = 0.5})
66 end
67 clicker:set_wielded_item(item)
68 end
69 self._forced_explosion_countdown_timer = self.explosion_timer
70 minetest.sound_play(self.sounds.attack, {pos = self.object:getpos(), gain = 1, max_hear_distance = 16})
71 end
72 end,
73 do_custom = function(self, dtime)
74 if self._forced_explosion_countdown_timer ~= nil then
75 self._forced_explosion_countdown_timer = self._forced_explosion_countdown_timer - dtime
76 if self._forced_explosion_countdown_timer <= 0 then
77 mobs:explosion(self.object:getpos(), self.explosion_radius, 0, 1, self.sounds.explode)
78 self.object:remove()
79 end
80 end
81 end,
82 on_die = function(self, pos)
83 -- Drop a random music disc
84 -- TODO: Only do this if killed by skeleton
85 if math.random(1, 200) == 1 then
86 local r = math.random(1, #mobs_mc.items.music_discs)
87 minetest.add_item({x=pos.x, y=pos.y+1, z=pos.z}, mobs_mc.items.music_discs[r])
88 end
89 end,
90 maxdrops = 2,
91 drops = {
92 {name = mobs_mc.items.gunpowder,
93 chance = 1,
94 min = 0,
95 max = 2,},
97 -- Head
98 -- TODO: Only drop if killed by charged creeper
99 {name = mobs_mc.items.head_creeper,
100 chance = 200, -- 0.5%
101 min = 1,
102 max = 1,},
104 animation = {
105 speed_normal = 24,
106 speed_run = 48,
107 stand_start = 0,
108 stand_end = 23,
109 walk_start = 24,
110 walk_end = 49,
111 run_start = 24,
112 run_end = 49,
113 hurt_start = 110,
114 hurt_end = 139,
115 death_start = 140,
116 death_end = 189,
117 look_start = 50,
118 look_end = 108,
120 floats = 1,
121 fear_height = 4,
122 lava_damage = 4,
123 light_damage = 0,
124 view_range = 16,
125 blood_amount = 0,
129 mobs:spawn_specific("mobs_mc:creeper", mobs_mc.spawn.solid, {"air"}, 0, 7, 20, 16500, 2, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max)
131 -- compatibility
132 mobs:alias_mob("mobs:creeper", "mobs_mc:creeper")
134 -- spawn eggs
135 mobs:register_egg("mobs_mc:creeper", S("Creeper"), "mobs_mc_spawn_icon_creeper.png", 0)
137 if minetest.settings:get_bool("log_mods") then
138 minetest.log("action", "MC Creeper loaded")