Update 3.1 functions

This commit is contained in:
Echoes 2024-02-07 21:46:58 +00:00
parent bc1536223c
commit 440c620bf0
2 changed files with 27 additions and 26 deletions

View File

@ -1,15 +1,15 @@
-- Seems like defaults in settingtypes.txt are not taken by default
if minetest.settings:get("spears_throw_speed") == nil then
minetest.settings:set("spears_throw_speed", 13)
end
--if minetest.settings:get("spears_throw_speed") == nil then
-- minetest.settings:set("spears_throw_speed", 13)
--end
if minetest.settings:get("spears_drag_coeff") == nil then
minetest.settings:set("spears_drag_coeff", 0.1)
end
if minetest.settings:get("spears_node_cracky_limit") == nil then
minetest.settings:set("spears_node_cracky_limit", 3)
end
-- if minetest.settings:get("spears_node_cracky_limit") == nil then
-- minetest.settings:set("spears_node_cracky_limit", 3)
-- end
-- DISABLE_STONE_SPEAR = false
@ -23,8 +23,8 @@ end
-- SPEARS_THROW_SPEED = 13
SPEARS_V_ZERO = {x = 0, y = 0, z = 0}
-- SPEARS_DRAG_COEFF = 0.1
SPEARS_NODE_UNKNOWN = nil
SPEARS_NODE_THROUGH = 0
SPEARS_NODE_STICKY = 1
SPEARS_NODE_CRACKY = 2
-- SPEARS_NODE_CRACKY_LIMIT = 3
-- SPEARS_NODE_UNKNOWN = nil
-- SPEARS_NODE_THROUGH = 0
-- SPEARS_NODE_STICKY = 1
-- SPEARS_NODE_CRACKY = 2
-- SPEARS_NODE_CRACKY_LIMIT = 3

View File

@ -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