]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/mob/chatcommands.lua
Fix insanely loud jump sound
[Crafter.git] / mods / mob / chatcommands.lua
index 7985c11e4750a6870d5f960aad0649f116067a25..e2e387cc12477a1566fcd86a8c721123e7c27611 100644 (file)
@@ -27,19 +27,31 @@ minetest.register_chatcommand("spawn", {
                
                --add amount of entities if registered
                if minetest.registered_entities[str] ~= nil then
-                       local pos = minetest.get_player_by_name(name):get_pos()
-                       pos.y = pos.y + 1
+                       local player = minetest.get_player_by_name(name)
+                       local pos = player:get_pos()
+                       pos.y = pos.y + 1.625
+                       local pos2 = vector.add(pos,vector.multiply(player:get_look_dir(),80))
+                       local ray = minetest.raycast(pos,pos2,false,false)
+                       local casted_pos = table.copy(pos)
+                       if ray then
+                               local intersection = ray:next()
+                               if intersection and intersection.above then
+                                       casted_pos = intersection.above
+                               end
+                       end
+
+
                        --add in amount through loop
                        if amount > 1 then
                                for i = 1,amount do 
-                                       minetest.add_entity(pos,str)
+                                       minetest.add_entity(casted_pos,str)
                                end
                        else --add single
-                               minetest.add_entity(pos,str)
+                               minetest.add_entity(casted_pos,str)
                        end
                else --tell player the mob doesn't exist if not a registered entity
                        minetest.chat_send_player(name, str:match("^.-:(.*)"):gsub("^%l", string.upper).." is not a mob.")
                end
                
        end,
-})
+})
\ No newline at end of file