forked from mtcontrib/spears
Update 3.1 functions
This commit is contained in:
@ -13,7 +13,7 @@ function spears_throw (itemstack, player, pointed_thing)
|
||||
if pointed_thing.type == "node" and vector.distance(pointed_a, throw_pos) < 1 then -- Stick into node
|
||||
local node = minetest.get_node(pointed_b)
|
||||
local check_node = spears_check_node(node.name)
|
||||
if check_node == SPEARS_NODE_UNKNOWN then
|
||||
if check_node == nil then
|
||||
return false
|
||||
elseif check_node == SPEARS_NODE_CRACKY then
|
||||
minetest.sound_play("default_metal_footstep", {pos = pointed_a}, true)
|
||||
@ -26,11 +26,11 @@ function spears_throw (itemstack, player, pointed_thing)
|
||||
minetest.sound_play("default_place_node", {pos = pointed_a}, true)
|
||||
return false
|
||||
end
|
||||
else -- Avoid hitting yourself and throw
|
||||
local throw_speed = tonumber(minetest.settings:get("spears_throw_speed"))
|
||||
while vector.distance(player_pos, throw_pos) < 1.2 do
|
||||
throw_pos = vector.add(throw_pos, vector.multiply(direction, 0.1))
|
||||
end
|
||||
else -- Throw
|
||||
local throw_speed = tonumber(minetest.settings:get("spears_throw_speed") or 13)
|
||||
--while vector.distance(player_pos, throw_pos) < 1.2 do
|
||||
-- throw_pos = vector.add(throw_pos, vector.multiply(direction, 0.1))
|
||||
--end
|
||||
local player_vel = player:get_velocity()
|
||||
local spear_object = minetest.add_entity(throw_pos, spear)
|
||||
spear_object:set_velocity(vector.add(player_vel, vector.multiply(direction, throw_speed)))
|
||||
@ -38,6 +38,7 @@ function spears_throw (itemstack, player, pointed_thing)
|
||||
minetest.sound_play("spears_throw", {pos = player_pos}, true)
|
||||
spear_object:get_luaentity()._wear = wear
|
||||
spear_object:get_luaentity()._stickpos = nil
|
||||
spear_object:get_luaentity()._owner = player:get_luaentity()
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -109,20 +110,20 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
||||
if check_node == SPEARS_NODE_UNKNOWN then
|
||||
self.object:remove()
|
||||
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
|
||||
elseif check_node ~= SPEARS_NODE_THROUGH then
|
||||
elseif check_node ~= 'through' then
|
||||
wear = spears_wear(wear, toughness)
|
||||
if wear >= 65535 then
|
||||
minetest.sound_play("default_tool_breaks", {pos = pos}, true)
|
||||
self.object:remove()
|
||||
minetest.add_item(pos, {name='defaut:stick'})
|
||||
return false
|
||||
elseif check_node == SPEARS_NODE_CRACKY then
|
||||
elseif check_node == 'cracky' then
|
||||
minetest.sound_play("default_metal_footstep", {pos = pos}, true)
|
||||
self.object:remove()
|
||||
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
|
||||
return false
|
||||
elseif check_node == SPEARS_NODE_STICKY then
|
||||
self.object:set_acceleration(SPEARS_V_ZERO)
|
||||
elseif check_node == 'sticky' then
|
||||
self.object:set_acceleration(vector3(0, 0, 0):Unpack())
|
||||
self.object:set_velocity(SPEARS_V_ZERO)
|
||||
minetest.sound_play("default_place_node", {pos = pos}, true)
|
||||
self._stickpos = spearhead_pos
|
||||
@ -144,15 +145,15 @@ end
|
||||
|
||||
function spears_check_node(node_name)
|
||||
local node = minetest.registered_nodes[node_name]
|
||||
local cracky_limit = tonumber(minetest.settings:get("spears_node_cracky_limit"))
|
||||
local cracky_limit = tonumber(minetest.settings:get("spears_node_cracky_limit") or 3)
|
||||
if node == nil then
|
||||
return SPEARS_NODE_UNKNOWN
|
||||
return nil
|
||||
elseif node.groups.cracky ~= nil and node.groups.cracky < cracky_limit then
|
||||
return SPEARS_NODE_CRACKY
|
||||
return 'cracky'
|
||||
elseif node.walkable and not node.buildable_to then
|
||||
return SPEARS_NODE_STICKY
|
||||
return 'sticky'
|
||||
else
|
||||
return SPEARS_NODE_THROUGH
|
||||
return 'through'
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user