-- Descended from maikerumine "snowball" code -- License for code WTFPL local snowball_GRAVITY = 9 local snowball_VELOCITY = 19 mobs:register_arrow (":mobs:snowball_entity", { visual = "sprite", visual_size = {x=.5, y=.5}, textures = {"default_snowball.png"}, velocity = snowball_VELOCITY, hit_player = function(self, player) player:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {}, }, nil) end, hit_mob = function(self, mob) mob:punch(self.object, 1.0, { full_punch_interval = 1.0, damage_groups = {}, }, nil) end , }) local mobs_shoot_snowball = function (item, player, pointed_thing) local playerpos = player:get_pos() local obj = minetest.add_entity ( { x = playerpos.x, y = playerpos.y +1.5, z = playerpos.z } , "mobs:snowball_entity") local ent = obj:get_luaentity() local dir = player:get_look_dir() ent.velocity = snowball_VELOCITY -- needed for api internal timing ent.switch = 1 -- needed so that item doesn't despawn straight away obj:set_velocity({ x = dir.x * snowball_VELOCITY, y = dir.y * snowball_VELOCITY, z = dir.z * snowball_VELOCITY, }) obj:set_acceleration ({ x = dir.x * -3, y = -snowball_GRAVITY, z = dir.z * -3 }) -- pass player name to item for chick ownership local ent2 = obj:get_luaentity() ent2.playername = player:get_player_name() if not minetest.settings:get_bool ("creative_mode") then item:take_item() end return item end -- Snowball minetest.register_craftitem (":mobs:snowball", { description = "Snowball" , inventory_image = "default_snowball.png" , on_use = mobs_shoot_snowball , })