From 440c620bf029270e76ddec1cb12650391dd1d476 Mon Sep 17 00:00:00 2001 From: Echoes Date: Wed, 7 Feb 2024 21:46:58 +0000 Subject: [PATCH] Update 3.1 functions --- defaults.lua | 22 +++++++++++----------- functions.lua | 31 ++++++++++++++++--------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/defaults.lua b/defaults.lua index f7ed7bb..5d6fe44 100644 --- a/defaults.lua +++ b/defaults.lua @@ -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 \ No newline at end of file diff --git a/functions.lua b/functions.lua index 4f01621..f8e6752 100644 --- a/functions.lua +++ b/functions.lua @@ -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