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",
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},
52 makes_footstep_sound
= true,
53 attack_type
= "shoot",
54 arrow
= "mobs_mc:snowball_entity",
73 do_custom
= function(self
, dtime
)
74 if not mobs_griefing
then
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
84 self
._snowtimer
= self
._snowtimer
+ dtime
85 if self
.health
> 0 and self
._snowtimer
> snow_trail_frequency
then
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
97 minetest
.set_node(pos
, {name
= mobs_mc
.items
.top_snow
})
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
108 self
.object
:set_properties({
109 textures
= gotten_texture
,
112 local pos
= self
.object
:getpos()
113 minetest
.sound_play("shears", {pos
= pos
})
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
)
126 -- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
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
)
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} },
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")
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")