Replace getpos() with get_pos()
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / snowman.lua
blob1c1ad6860a17955f458b514096d19dc7dbdee163
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 -- TODO: sounds: damage, death
38 textures = {
39 "mobs_mc_snowman.png", --snowman texture
40 "farming_pumpkin_side.png", --top
41 "farming_pumpkin_top.png", --down
42 "farming_pumpkin_face.png", --front
43 "farming_pumpkin_side.png", --left
44 "farming_pumpkin_side.png", --right
45 "farming_pumpkin_top.png", --left
47 gotten_texture = gotten_texture,
48 drops = {{ name = mobs_mc.items.snowball, chance = 1, min = 0, max = 15 }},
49 visual_size = {x=3, y=3},
50 walk_velocity = 0.6,
51 run_velocity = 2,
52 jump = true,
53 makes_footstep_sound = true,
54 attack_type = "shoot",
55 arrow = "mobs_mc:snowball_entity",
56 shoot_interval = 1,
57 shoot_offset = 1,
58 animation = {
59 stand_speed = 25,
60 walk_speed = 25,
61 run_speed = 50,
62 stand_start = 20,
63 stand_end = 40,
64 walk_start = 0,
65 walk_end = 20,
66 run_start = 0,
67 run_end = 20,
68 die_start = 40,
69 die_end = 50,
70 die_speed = 25,
71 die_loop = false,
73 blood_amount = 0,
74 do_custom = function(self, dtime)
75 if not mobs_griefing then
76 return
77 end
78 -- Leave a trail of top snow behind.
79 -- This is done in do_custom instead of just using replace_what because with replace_what,
80 -- the top snop may end up floating in the air.
81 if not self._snowtimer then
82 self._snowtimer = 0
83 return
84 end
85 self._snowtimer = self._snowtimer + dtime
86 if self.health > 0 and self._snowtimer > snow_trail_frequency then
87 self._snowtimer = 0
88 local pos = self.object:get_pos()
89 local below = {x=pos.x, y=pos.y-1, z=pos.z}
90 local def = minetest.registered_nodes[minetest.get_node(pos).name]
91 -- Node at snow golem's position must be replacable
92 if def and def.buildable_to then
93 -- Node below must be walkable
94 -- and a full cube (this prevents oddities like top snow on top snow, lower slabs, etc.)
95 local belowdef = minetest.registered_nodes[minetest.get_node(below).name]
96 if belowdef and belowdef.walkable and (belowdef.node_box == nil or belowdef.node_box.type == "regular") then
97 -- Place top snow
98 minetest.set_node(pos, {name = mobs_mc.items.top_snow})
99 end
102 end,
103 -- Remove pumpkin if using shears
104 on_rightclick = function(self, clicker)
105 local item = clicker:get_wielded_item()
106 if self.gotten ~= true and item:get_name() == mobs_mc.items.shears then
107 -- Remove pumpkin
108 self.gotten = true
109 self.object:set_properties({
110 textures = gotten_texture,
113 local pos = self.object:get_pos()
114 minetest.sound_play("shears", {pos = pos})
116 -- Wear out
117 if not minetest.settings:get_bool("creative_mode") then
118 item:add_wear(mobs_mc.misc.shears_wear)
119 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
122 end,
124 rain_damage = 4,
127 -- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
128 -- of the node.
129 -- This summons a snow golen when pos is next to a row of two snow blocks.
130 mobs_mc.tools.check_snow_golem_summon = function(pos)
131 local checks = {
132 -- These are the possible placement patterns
133 -- { snow block pos. 1, snow block pos. 2, snow golem spawn position }
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-2.5, z=pos.z} },
135 { {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} },
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+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} },
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} },
139 { {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} },
142 for c=1, #checks do
143 local b1 = checks[c][1]
144 local b2 = checks[c][2]
145 local place = checks[c][3]
146 local b1n = minetest.get_node(b1)
147 local b2n = minetest.get_node(b2)
148 if b1n.name == mobs_mc.items.snow_block and b2n.name == mobs_mc.items.snow_block then
149 -- Remove the pumpkin and both snow blocks and summon the snow golem
150 minetest.remove_node(pos)
151 minetest.remove_node(b1)
152 minetest.remove_node(b2)
153 core.check_for_falling(pos)
154 core.check_for_falling(b1)
155 core.check_for_falling(b2)
156 minetest.add_entity(place, "mobs_mc:snowman")
157 break
162 -- Spawn egg
163 mobs:register_egg("mobs_mc:snowman", S("Snow Golem"), "mobs_mc_spawn_icon_snowman.png", 0)
165 if minetest.settings:get_bool("log_mods") then
166 minetest.log("action", "MC Snow Golem loaded")