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 -- Seems like defaults in settingtypes.txt are not taken by default
if minetest.settings:get("spears_throw_speed") == nil then --if minetest.settings:get("spears_throw_speed") == nil then
minetest.settings:set("spears_throw_speed", 13) -- minetest.settings:set("spears_throw_speed", 13)
end --end
if minetest.settings:get("spears_drag_coeff") == nil then if minetest.settings:get("spears_drag_coeff") == nil then
minetest.settings:set("spears_drag_coeff", 0.1) minetest.settings:set("spears_drag_coeff", 0.1)
end end
if minetest.settings:get("spears_node_cracky_limit") == nil then -- if minetest.settings:get("spears_node_cracky_limit") == nil then
minetest.settings:set("spears_node_cracky_limit", 3) -- minetest.settings:set("spears_node_cracky_limit", 3)
end -- end
-- DISABLE_STONE_SPEAR = false -- DISABLE_STONE_SPEAR = false
@ -23,8 +23,8 @@ end
-- SPEARS_THROW_SPEED = 13 -- SPEARS_THROW_SPEED = 13
SPEARS_V_ZERO = {x = 0, y = 0, z = 0} SPEARS_V_ZERO = {x = 0, y = 0, z = 0}
-- SPEARS_DRAG_COEFF = 0.1 -- SPEARS_DRAG_COEFF = 0.1
SPEARS_NODE_UNKNOWN = nil -- SPEARS_NODE_UNKNOWN = nil
SPEARS_NODE_THROUGH = 0 -- SPEARS_NODE_THROUGH = 0
SPEARS_NODE_STICKY = 1 -- SPEARS_NODE_STICKY = 1
SPEARS_NODE_CRACKY = 2 -- SPEARS_NODE_CRACKY = 2
-- SPEARS_NODE_CRACKY_LIMIT = 3 -- 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 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 node = minetest.get_node(pointed_b)
local check_node = spears_check_node(node.name) local check_node = spears_check_node(node.name)
if check_node == SPEARS_NODE_UNKNOWN then if check_node == nil then
return false return false
elseif check_node == SPEARS_NODE_CRACKY then elseif check_node == SPEARS_NODE_CRACKY then
minetest.sound_play("default_metal_footstep", {pos = pointed_a}, true) 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) minetest.sound_play("default_place_node", {pos = pointed_a}, true)
return false return false
end end
else -- Avoid hitting yourself and throw else -- Throw
local throw_speed = tonumber(minetest.settings:get("spears_throw_speed")) local throw_speed = tonumber(minetest.settings:get("spears_throw_speed") or 13)
while vector.distance(player_pos, throw_pos) < 1.2 do --while vector.distance(player_pos, throw_pos) < 1.2 do
throw_pos = vector.add(throw_pos, vector.multiply(direction, 0.1)) -- throw_pos = vector.add(throw_pos, vector.multiply(direction, 0.1))
end --end
local player_vel = player:get_velocity() local player_vel = player:get_velocity()
local spear_object = minetest.add_entity(throw_pos, spear) local spear_object = minetest.add_entity(throw_pos, spear)
spear_object:set_velocity(vector.add(player_vel, vector.multiply(direction, throw_speed))) 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) minetest.sound_play("spears_throw", {pos = player_pos}, true)
spear_object:get_luaentity()._wear = wear spear_object:get_luaentity()._wear = wear
spear_object:get_luaentity()._stickpos = nil spear_object:get_luaentity()._stickpos = nil
spear_object:get_luaentity()._owner = player:get_luaentity()
return true return true
end end
end end
@ -109,20 +110,20 @@ function spears_set_entity(spear_type, base_damage, toughness)
if check_node == SPEARS_NODE_UNKNOWN then if check_node == SPEARS_NODE_UNKNOWN then
self.object:remove() self.object:remove()
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear}) 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) wear = spears_wear(wear, toughness)
if wear >= 65535 then if wear >= 65535 then
minetest.sound_play("default_tool_breaks", {pos = pos}, true) minetest.sound_play("default_tool_breaks", {pos = pos}, true)
self.object:remove() self.object:remove()
minetest.add_item(pos, {name='defaut:stick'}) minetest.add_item(pos, {name='defaut:stick'})
return false return false
elseif check_node == SPEARS_NODE_CRACKY then elseif check_node == 'cracky' then
minetest.sound_play("default_metal_footstep", {pos = pos}, true) minetest.sound_play("default_metal_footstep", {pos = pos}, true)
self.object:remove() self.object:remove()
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
return false return false
elseif check_node == SPEARS_NODE_STICKY then elseif check_node == 'sticky' then
self.object:set_acceleration(SPEARS_V_ZERO) self.object:set_acceleration(vector3(0, 0, 0):Unpack())
self.object:set_velocity(SPEARS_V_ZERO) self.object:set_velocity(SPEARS_V_ZERO)
minetest.sound_play("default_place_node", {pos = pos}, true) minetest.sound_play("default_place_node", {pos = pos}, true)
self._stickpos = spearhead_pos self._stickpos = spearhead_pos
@ -144,15 +145,15 @@ end
function spears_check_node(node_name) function spears_check_node(node_name)
local node = minetest.registered_nodes[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 if node == nil then
return SPEARS_NODE_UNKNOWN return nil
elseif node.groups.cracky ~= nil and node.groups.cracky < cracky_limit then 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 elseif node.walkable and not node.buildable_to then
return SPEARS_NODE_STICKY return 'sticky'
else else
return SPEARS_NODE_THROUGH return 'through'
end end
end end