Make villager stand still if there is near player
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / snowman.lua
blobb73dd763fcc811aaf99eb401c88905b93f29a554
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")
9 local snow_trail_frequency = 0.5 -- Time in seconds for checking to add a new snow trail
11 local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
13 local gotten_texture = {
14 "mobs_mc_snowman.png",
15 "blank.png",
16 "blank.png",
17 "blank.png",
18 "blank.png",
19 "blank.png",
20 "blank.png",
23 mobs:register_mob("mobs_mc:snowman", {
24 type = "npc",
25 passive = true,
26 hp_min = 4,
27 hp_max = 4,
28 pathfinding = 1,
29 view_range = 10,
30 fall_damage = 0,
31 water_damage = 4,
32 lava_damage = 20,
33 attacks_monsters = true,
34 collisionbox = {-0.35, -0.01, -0.35, 0.35, 1.89, 0.35},
35 visual = "mesh",
36 mesh = "mobs_mc_snowman.b3d",
37 textures = {
38 "mobs_mc_snowman.png", --snowman texture
39 "farming_pumpkin_top.png", --top
40 "farming_pumpkin_top.png", --down
41 "farming_pumpkin_face.png", --front
42 "farming_pumpkin_side.png", --left
43 "farming_pumpkin_side.png", --right
44 "farming_pumpkin_side.png", --left
46 gotten_texture = gotten_texture,
47 drops = {{ name = mobs_mc.items.snowball, chance = 1, min = 0, max = 15 }},
48 visual_size = {x=3, y=3},
49 walk_velocity = 0.6,
50 run_velocity = 2,
51 jump = true,
52 makes_footstep_sound = true,
53 attack_type = "shoot",
54 arrow = "mobs_mc:snowball_entity",
55 shoot_interval = 1,
56 shoot_offset = 1,
57 animation = {
58 stand_speed = 25,
59 walk_speed = 25,
60 run_speed = 50,
61 stand_start = 20,
62 stand_end = 40,
63 walk_start = 0,
64 walk_end = 20,
65 run_start = 0,
66 run_end = 20,
67 die_start = 40,
68 die_end = 50,
69 die_speed = 25,
70 die_loop = false,
72 blood_amount = 0,
73 do_custom = function(self, dtime)
74 if not mobs_griefing then
75 return
76 end
77 -- Leave a trail of top snow behind.
78 -- This is done in do_custom instead of just using replace_what because with replace_what,
79 -- the top snop may end up floating in the air.
80 if not self._snowtimer then
81 self._snowtimer = 0
82 return
83 end
84 self._snowtimer = self._snowtimer + dtime
85 if self.health > 0 and self._snowtimer > snow_trail_frequency then
86 self._snowtimer = 0
87 local pos = self.object:getpos()
88 local below = {x=pos.x, y=pos.y-1, z=pos.z}
89 local def = minetest.registered_nodes[minetest.get_node(pos).name]
90 -- Node at snow golem's position must be replacable
91 if def and def.buildable_to then
92 -- Node below must be walkable
93 -- and a full cube (this prevents oddities like top snow on top snow, lower slabs, etc.)
94 local belowdef = minetest.registered_nodes[minetest.get_node(below).name]
95 if belowdef and belowdef.walkable and (belowdef.node_box == nil or belowdef.node_box.type == "regular") then
96 -- Place top snow
97 minetest.set_node(pos, {name = mobs_mc.items.top_snow})
98 end
99 end
101 end,
102 -- Remove pumpkin if using shears
103 on_rightclick = function(self, clicker)
104 local item = clicker:get_wielded_item()
105 if self.gotten ~= true and item:get_name() == mobs_mc.items.shears then
106 -- Remove pumpkin
107 self.gotten = true
108 self.object:set_properties({
109 textures = gotten_texture,
112 local pos = self.object:getpos()
113 minetest.sound_play("shears", {pos = pos})
115 -- Wear out
116 if not minetest.settings:get_bool("creative_mode") then
117 item:add_wear(mobs_mc.misc.shears_wear)
118 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
121 end,
123 rain_damage = 4,
126 -- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
127 -- of the node.
128 -- This summons a snow golen when pos is next to a row of two snow blocks.
129 mobs_mc.tools.check_snow_golem_summon = function(pos)
130 local checks = {
131 -- These are the possible placement patterns
132 -- { snow block pos. 1, snow block pos. 2, snow golem spawn position }
133 { {x=pos.x, y=pos.y-1, z=pos.z}, {x=pos.x, y=pos.y-2, z=pos.z}, {x=pos.x, y=pos.y-2.5, z=pos.z} },
134 { {x=pos.x, y=pos.y+1, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y-0.5, z=pos.z} },
135 { {x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y-0.5, z=pos.z} },
136 { {x=pos.x+1, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y-0.5, z=pos.z} },
137 { {x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z-2}, {x=pos.x, y=pos.y-0.5, z=pos.z-2} },
138 { {x=pos.x, y=pos.y, z=pos.z+1}, {x=pos.x, y=pos.y, z=pos.z+2}, {x=pos.x, y=pos.y-0.5, z=pos.z+2} },
141 for c=1, #checks do
142 local b1 = checks[c][1]
143 local b2 = checks[c][2]
144 local place = checks[c][3]
145 local b1n = minetest.get_node(b1)
146 local b2n = minetest.get_node(b2)
147 if b1n.name == mobs_mc.items.snow_block and b2n.name == mobs_mc.items.snow_block then
148 -- Remove the pumpkin and both snow blocks and summon the snow golem
149 minetest.remove_node(pos)
150 minetest.remove_node(b1)
151 minetest.remove_node(b2)
152 core.check_for_falling(pos)
153 core.check_for_falling(b1)
154 core.check_for_falling(b2)
155 minetest.add_entity(place, "mobs_mc:snowman")
156 break
161 -- Spawn egg
162 mobs:register_egg("mobs_mc:snowman", S("Snow Golem"), "mobs_mc_spawn_icon_snowman.png", 0)
164 if minetest.settings:get_bool("log_mods") then
165 minetest.log("action", "MC Snow Golem loaded")