3 --made for MC like Survival game
4 --License for code WTFPL and otherwise stated in readmes
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",
23 mobs
:register_mob("mobs_mc:snowman", {
33 attacks_monsters
= true,
34 collisionbox
= {-0.35, -0.01, -0.35, 0.35, 1.89, 0.35},
36 mesh
= "mobs_mc_snowman.b3d",
37 -- TODO: sounds: damage, death
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},
53 makes_footstep_sound
= true,
54 attack_type
= "shoot",
55 arrow
= "mobs_mc:snowball_entity",
74 do_custom
= function(self
, dtime
)
75 if not mobs_griefing
then
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
85 self
._snowtimer
= self
._snowtimer
+ dtime
86 if self
.health
> 0 and self
._snowtimer
> snow_trail_frequency
then
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
98 minetest
.set_node(pos
, {name
= mobs_mc
.items
.top_snow
})
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
109 self
.object
:set_properties({
110 textures
= gotten_texture
,
113 local pos
= self
.object
:get_pos()
114 minetest
.sound_play("shears", {pos
= pos
})
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
)
127 -- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
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
)
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} },
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")
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")