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")
10 --maikerumines throwing code
13 local c
= mobs_mc
.is_item_variable_overridden
15 minetest
.register_node("mobs_mc:arrow_box", {
21 {-6.5/17, -1.5/17, -1.5/17, 6.5/17, 1.5/17, 1.5/17},
23 {-4.5/17, 2.5/17, 2.5/17, -3.5/17, -2.5/17, -2.5/17},
24 {-8.5/17, 0.5/17, 0.5/17, -6.5/17, -0.5/17, -0.5/17},
26 {6.5/17, 1.5/17, 1.5/17, 7.5/17, 2.5/17, 2.5/17},
27 {7.5/17, -2.5/17, 2.5/17, 6.5/17, -1.5/17, 1.5/17},
28 {7.5/17, 2.5/17, -2.5/17, 6.5/17, 1.5/17, -1.5/17},
29 {6.5/17, -1.5/17, -1.5/17, 7.5/17, -2.5/17, -2.5/17},
31 {7.5/17, 2.5/17, 2.5/17, 8.5/17, 3.5/17, 3.5/17},
32 {8.5/17, -3.5/17, 3.5/17, 7.5/17, -2.5/17, 2.5/17},
33 {8.5/17, 3.5/17, -3.5/17, 7.5/17, 2.5/17, -2.5/17},
34 {7.5/17, -2.5/17, -2.5/17, 8.5/17, -3.5/17, -3.5/17},
37 tiles
= {"mcl_bows_arrow.png^[transformFX", "mcl_bows_arrow.png^[transformFX", "mcl_bows_arrow_back.png", "mcl_bows_arrow_front.png", "mcl_bows_arrow.png", "mcl_bows_arrow.png^[transformFX"},
38 groups
= {not_in_creative_inventory
=1},
41 local THROWING_ARROW_ENTITY
={
45 visual_size
= {x
=0.1, y
=0.1},
46 textures
= {"mobs_mc:arrow_box"},
49 collisionbox
= {0,0,0,0,0,0},
53 THROWING_ARROW_ENTITY
.on_step
= function(self
, dtime
)
54 self
.timer
=self
.timer
+dtime
55 local pos
= self
.object
:get_pos()
56 local node
= minetest
.get_node(pos
)
58 minetest
.add_particle({
60 velocity
= {x
=0, y
=0, z
=0},
61 acceleration
= {x
=0, y
=0, z
=0},
64 collisiondetection
= false,
66 texture
= "mobs_mc_arrow_particle.png",
69 if self
.timer
>0.2 then
70 local objs
= minetest
.get_objects_inside_radius({x
=pos
.x
,y
=pos
.y
,z
=pos
.z
}, 1.5)
71 for k
, obj
in pairs(objs
) do
72 if obj
:get_luaentity() ~= nil then
73 if obj
:get_luaentity().name
~= "mobs_mc:arrow_entity" and obj
:get_luaentity().name
~= "__builtin:item" then
75 minetest
.sound_play("damage", {pos
= pos
})
76 obj
:punch(self
.object
, 1.0, {
77 full_punch_interval
=1.0,
78 damage_groups
={fleshy
=damage
},
84 minetest
.sound_play("damage", {pos
= pos
})
85 obj
:punch(self
.object
, 1.0, {
86 full_punch_interval
=1.0,
87 damage_groups
={fleshy
=damage
},
94 if self
.lastpos
.x
~=nil then
95 if node
.name
~= "air" then
96 minetest
.sound_play("bowhit1", {pos
= pos
})
97 minetest
.add_item(self
.lastpos
, 'mobs_mc:arrow')
101 self
.lastpos
={x
=pos
.x
, y
=pos
.y
, z
=pos
.z
}
104 minetest
.register_entity("mobs_mc:arrow_entity", THROWING_ARROW_ENTITY
)
107 {"mobs_mc:arrow", "mobs_mc:arrow_entity" },
110 local throwing_shoot_arrow
= function(itemstack
, player
)
111 for _
,arrow
in ipairs(arrows
) do
112 if player
:get_inventory():get_stack("main", player
:get_wield_index()+1):get_name() == arrow
[1] then
113 if not minetest
.settings
:get_bool("creative_mode") then
114 player
:get_inventory():remove_item("main", arrow
[1])
116 local playerpos
= player
:get_pos()
117 local obj
= minetest
.add_entity({x
=playerpos
.x
,y
=playerpos
.y
+1.5,z
=playerpos
.z
}, arrow
[2]) --mc
118 local dir
= player
:get_look_dir()
119 obj
:setvelocity({x
=dir
.x
*22, y
=dir
.y
*22, z
=dir
.z
*22})
120 obj
:setacceleration({x
=dir
.x
*-3, y
=-10, z
=dir
.z
*-3})
121 obj
:setyaw(player
:get_look_yaw()+math
.pi
)
122 minetest
.sound_play("throwing_sound", {pos
=playerpos
})
123 if obj
:get_luaentity().player
== "" then
124 obj
:get_luaentity().player
= player
126 obj
:get_luaentity().node
= player
:get_inventory():get_stack("main", 1):get_name()
134 minetest
.register_craftitem("mobs_mc:arrow", {
135 description
= S("Arrow"),
136 _doc_items_longdesc
= S("Arrows are ammunition for bows."),
137 _doc_items_usagehelp
= S("To use arrows as ammunition for a bow, put them in the inventory slot following the bow. Slots are counted left to right, top to bottom."),
138 inventory_image
= "mcl_bows_arrow_inv.png",
142 if c("arrow") and c("flint") and c("feather") and c("stick") then
143 minetest
.register_craft({
144 output
= 'mobs_mc:arrow 4',
146 {mobs_mc
.items
.flint
},
147 {mobs_mc
.items
.stick
},
148 {mobs_mc
.items
.feather
},
154 minetest
.register_tool("mobs_mc:bow_wood", {
155 description
= S("Bow"),
156 _doc_items_longdesc
= S("Bows are ranged weapons to shoot arrows at your foes."),
157 _doc_items_usagehelp
= S("To use the bow, you first need to have at least one arrow in slot following the bow. Leftclick to shoot. Each hit deals 3 damage."),
158 inventory_image
= "mcl_bows_bow.png",
159 on_use
= function(itemstack
, user
, pointed_thing
)
160 if throwing_shoot_arrow(itemstack
, user
, pointed_thing
) then
161 if not minetest
.settings
:get_bool("creative_mode") then
162 itemstack
:add_wear(65535/50)
169 minetest
.register_craft({
170 output
= 'mobs_mc:bow_wood',
172 {mobs_mc
.items
.string, mobs_mc
.items
.stick
, ''},
173 {mobs_mc
.items
.string, '', mobs_mc
.items
.stick
},
174 {mobs_mc
.items
.string, mobs_mc
.items
.stick
, ''},
179 local how_to_throw
= "Hold it in your and and leftclick to throw."
184 local egg_GRAVITY
= 9
185 local egg_VELOCITY
= 19
187 mobs
:register_arrow("mobs_mc:egg_entity", {
189 visual_size
= {x
=.5, y
=.5},
190 textures
= {"mobs_chicken_egg.png"},
191 velocity
= egg_VELOCITY
,
193 hit_player
= function(self
, player
)
194 player
:punch(minetest
.get_player_by_name(self
.playername
) or self
.object
, 1.0, {
195 full_punch_interval
= 1.0,
200 hit_mob
= function(self
, player
)
201 player
:punch(minetest
.get_player_by_name(self
.playername
) or self
.object
, 1.0, {
202 full_punch_interval
= 1.0,
207 hit_node
= function(self
, pos
, node
)
209 if math
.random(1, 10) > 1 then
215 local nod
= minetest
.get_node_or_nil(pos
)
218 or not minetest
.registered_nodes
[nod
.name
]
219 or minetest
.registered_nodes
[nod
.name
].walkable
== true then
223 local mob
= minetest
.add_entity(pos
, "mobs_mc:chicken")
224 local ent2
= mob
:get_luaentity()
228 x
= ent2
.base_size
.x
/ 2,
229 y
= ent2
.base_size
.y
/ 2
232 ent2
.base_colbox
[1] / 2,
233 ent2
.base_colbox
[2] / 2,
234 ent2
.base_colbox
[3] / 2,
235 ent2
.base_colbox
[4] / 2,
236 ent2
.base_colbox
[5] / 2,
237 ent2
.base_colbox
[6] / 2
243 ent2
.owner
= self
.playername
248 local mobs_shoot_egg
= function (item
, player
, pointed_thing
)
250 local playerpos
= player
:get_pos()
252 minetest
.sound_play("default_place_node_hard", {
255 max_hear_distance
= 5,
258 local obj
= minetest
.add_entity({
260 y
= playerpos
.y
+1.5,
262 }, "mobs_mc:egg_entity")
264 local ent
= obj
:get_luaentity()
265 local dir
= player
:get_look_dir()
267 ent
.velocity
= egg_VELOCITY
-- needed for api internal timing
268 ent
.switch
= 1 -- needed so that egg doesn't despawn straight away
271 x
= dir
.x
* egg_VELOCITY
,
272 y
= dir
.y
* egg_VELOCITY
,
273 z
= dir
.z
* egg_VELOCITY
276 obj
:setacceleration({
282 -- pass player name to egg for chick ownership
283 local ent2
= obj
:get_luaentity()
284 ent2
.playername
= player
:get_player_name()
286 if not minetest
.settings
:get_bool("creative_mode") then
293 minetest
.register_craftitem("mobs_mc:egg", {
294 description
= S("Egg"),
295 _doc_items_longdesc
= S("Eggs can be thrown and break on impact. There is a small chance that 1 or even 4 chicks will pop out"),
296 _doc_items_usagehelp
= how_to_throw
,
297 inventory_image
= "mobs_chicken_egg.png",
298 on_use
= mobs_shoot_egg
,
304 local snowball_GRAVITY
= 9
305 local snowball_VELOCITY
= 19
307 mobs
:register_arrow("mobs_mc:snowball_entity", {
309 visual_size
= {x
=.5, y
=.5},
310 textures
= {"mcl_throwing_snowball.png"},
311 velocity
= snowball_VELOCITY
,
313 hit_player
= function(self
, player
)
314 -- FIXME: No knockback
315 player
:punch(self
.object
, 1.0, {
316 full_punch_interval
= 1.0,
321 hit_mob
= function(self
, mob
)
322 -- Hurt blazes, but not damage to anything else
324 if mob
:get_luaentity().name
== "mobs_mc:blaze" then
327 -- FIXME: No knockback
328 mob
:punch(self
.object
, 1.0, {
329 full_punch_interval
= 1.0,
336 if c("snowball") then
338 local mobs_shoot_snowball
= function (item
, player
, pointed_thing
)
340 local playerpos
= player
:get_pos()
342 local obj
= minetest
.add_entity({
344 y
= playerpos
.y
+1.5,
346 }, "mobs_mc:snowball_entity")
348 local ent
= obj
:get_luaentity()
349 local dir
= player
:get_look_dir()
351 ent
.velocity
= snowball_VELOCITY
-- needed for api internal timing
352 ent
.switch
= 1 -- needed so that egg doesn't despawn straight away
355 x
= dir
.x
* snowball_VELOCITY
,
356 y
= dir
.y
* snowball_VELOCITY
,
357 z
= dir
.z
* snowball_VELOCITY
360 obj
:setacceleration({
362 y
= -snowball_GRAVITY
,
366 -- pass player name to egg for chick ownership
367 local ent2
= obj
:get_luaentity()
368 ent2
.playername
= player
:get_player_name()
370 if not minetest
.settings
:get_bool("creative_mode") then
379 minetest
.register_craftitem("mobs_mc:snowball", {
380 description
= S("Snowball"),
381 _doc_items_longdesc
= S("Snowballs can be thrown at your enemies. A snowball deals 3 damage to blazes, but is harmless to anything else."),
382 _doc_items_usagehelp
= how_to_throw
,
383 inventory_image
= "mcl_throwing_snowball.png",
384 on_use
= mobs_shoot_snowball
,
388 --end maikerumine code
390 if minetest
.settings
:get_bool("log_mods") then
391 minetest
.log("action", "MC mobs loaded")