diff --git a/CHANGELOG b/CHANGELOG index 1a53d7c..508938a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,16 @@ +Update 3.1.1 +- Fix all initial settings values and completely deprecate defaults.lua + +Version 3.1: +- Initial l18n translations support +- Replace stereo sounds with mono +- Fix behaviour with initial settings +- Clean reduntant variables and deprecate defaults.lua + +Version 3.0: +- First attempt to detect collisionboxes +- Implemented settings through settingtypes.txt, deprecating "spears.conf" + Version 2.4: - Functions rewrite, fixed many vector/variable declarations and unknown node handling - Added pigiron support diff --git a/README b/README.md similarity index 90% rename from README rename to README.md index 1f42b23..b6dfc9e 100644 --- a/README +++ b/README.md @@ -3,12 +3,14 @@ This mod adds spears to Minetest. How to download: -If you have this file, you already know +If you have this file, you probably know. +If you're reading from gitlab.com, you already know. Forum topic: https://forum.minetest.net/viewtopic.php?f=11&t=13367 How to install: +Minetest content DB is the way! http://wiki.minetest.com/wiki/Installing_Mods How to use the mod: diff --git a/defaults.lua b/defaults.lua index 7b9edaa..2942843 100644 --- a/defaults.lua +++ b/defaults.lua @@ -1,16 +1,30 @@ -DISABLE_STONE_SPEAR = false -DISABLE_STEEL_SPEAR = false -DISABLE_COPPER_SPEAR = false -DISABLE_BRONZE_SPEAR = false -DISABLE_DIAMOND_SPEAR = false -DISABLE_OBSIDIAN_SPEAR = false -DISABLE_GOLD_SPEAR = false -DISABLE_IRON_SPEAR = false -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 +-- 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_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 + + +-- DISABLE_STONE_SPEAR = false +-- DISABLE_STEEL_SPEAR = false +-- DISABLE_COPPER_SPEAR = false +-- DISABLE_BRONZE_SPEAR = false +-- DISABLE_DIAMOND_SPEAR = false +-- DISABLE_OBSIDIAN_SPEAR = false +-- DISABLE_GOLD_SPEAR = false +-- DISABLE_IRON_SPEAR = false +-- 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 \ No newline at end of file diff --git a/functions.lua b/functions.lua index abc4a11..e2e444c 100644 --- a/functions.lua +++ b/functions.lua @@ -13,12 +13,12 @@ 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 + elseif check_node == 'cracky' then minetest.sound_play("default_metal_footstep", {pos = pointed_a}, true) return false - elseif check_node == SPEARS_NODE_STICKY then + elseif check_node == 'sticky' then local spear_object = minetest.add_entity(vector.divide(vector.add(vector.multiply(pointed_a, 2), pointed_b), 3), spear) spear_object:set_rotation(rotation) spear_object:get_luaentity()._wear = wear @@ -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 = 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 @@ -80,7 +81,7 @@ function spears_set_entity(spear_type, base_damage, toughness) if self._stickpos ~= nil then -- Spear is stuck local node = minetest.get_node(self._stickpos) local check_node = spears_check_node(node.name) - if check_node ~= SPEARS_NODE_STICKY then -- Fall when node is removed + if check_node ~= 'sticky' then -- Fall when node is removed self.object:remove() minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear}) return false @@ -91,10 +92,10 @@ function spears_set_entity(spear_type, base_damage, toughness) local pitch = math.acos(velocity.y/speed) - math.pi/3 local spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5)) self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch}) - -- Hit someone? - local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 0.6) + -- Hit a target? + local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 1) for _,object in ipairs(objects_in_radius) do - if object:get_luaentity() ~= self and object:get_armor_groups().fleshy then + if spears_check_target(self, object, spearhead_pos) and object:get_armor_groups().fleshy then local damage = (speed + base_damage)^1.15 - 20 object:punch(self.object, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy=damage},}, direction) self.object:remove() @@ -107,31 +108,32 @@ function spears_set_entity(spear_type, base_damage, toughness) -- Hit a node? local node = minetest.get_node(spearhead_pos) local check_node = spears_check_node(node.name) - if check_node == SPEARS_NODE_UNKNOWN then + if check_node == nil 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) - self.object:set_velocity(SPEARS_V_ZERO) + elseif check_node == 'sticky' then + self.object:set_acceleration({x = 0, y = 0, z = 0}) + self.object:set_velocity({x = 0, y = 0, z = 0}) minetest.sound_play("default_place_node", {pos = pos}, true) self._stickpos = spearhead_pos self._wear = wear end else -- Get drag local viscosity = minetest.registered_nodes[node.name].liquid_viscosity - local drag = math.max(viscosity, SPEARS_DRAG_COEFF) + local drag_coeff = tonumber(minetest.settings:get("spears_drag_coeff") or 0.1) + local drag = math.max(viscosity, drag_coeff) local acceleration = vector.multiply(velocity, -drag) acceleration.y = acceleration.y - 10 * ((7 - drag) / 7) self.object:set_acceleration(acceleration) @@ -144,14 +146,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") or 3) if node == nil then - return SPEARS_NODE_UNKNOWN - elseif node.groups.cracky ~= nil and node.groups.cracky < SPEARS_NODE_CRACKY_LIMIT then - return SPEARS_NODE_CRACKY - elseif node.walkable and not node.buildable then - return SPEARS_NODE_STICKY + return nil + elseif node.groups.cracky ~= nil and node.groups.cracky < cracky_limit then + return 'cracky' + elseif node.walkable and not node.buildable_to then + return 'sticky' else - return SPEARS_NODE_THROUGH + return 'through' end end @@ -164,3 +167,59 @@ function spears_wear(initial_wear, toughness) return wear end end + +function spears_check_target(self, object, spearhead_pos) + if object:get_luaentity() == self then + return false + elseif isPointInsideEntity(object, spearhead_pos) then + -- print(self.name .. " hit " .. object:get_luaentity().name) + return true + else + -- print(self.name .. " missed " .. object:get_luaentity().name) + return false + end +end + +-- Function to check if a point is inside an entity +function isPointInsideEntity(object, point) + local pos = object:get_pos() + local collisionbox = object:get_properties().collisionbox + local yaw = object:get_yaw() + + -- Adjust position for the center of the collision box + local center = { + x = pos.x + (collisionbox[1] + collisionbox[4]) / 2, + y = pos.y + (collisionbox[2] + collisionbox[5]) / 2, + z = pos.z + (collisionbox[3] + collisionbox[6]) / 2 + } + + -- Rotate the point around the entity's center + local rotatedPoint = rotatePoint(point, center, yaw) + + -- Check if the rotated point is inside the collision box + return rotatedPoint.x >= pos.x + collisionbox[1] and + rotatedPoint.x <= pos.x + collisionbox[4] and + rotatedPoint.y >= pos.y + collisionbox[2] and + rotatedPoint.y <= pos.y + collisionbox[5] and + rotatedPoint.z >= pos.z + collisionbox[3] and + rotatedPoint.z <= pos.z + collisionbox[6] +end + +-- Function to rotate a point around a center and yaw angle +function rotatePoint(point, center, yaw) + local cosYaw = math.cos(yaw) + local sinYaw = math.sin(yaw) + + local translatedX = point.x - center.x + local translatedZ = point.z - center.z + + local rotatedX = translatedX * cosYaw - translatedZ * sinYaw + local rotatedZ = translatedX * sinYaw + translatedZ * cosYaw + + return { + x = rotatedX + center.x, + y = point.y, + z = rotatedZ + center.z + } +end + diff --git a/init.lua b/init.lua index eca9a05..1747f20 100644 --- a/init.lua +++ b/init.lua @@ -1,18 +1,14 @@ -dofile(minetest.get_modpath("spears").."/defaults.lua") +-- dofile(minetest.get_modpath("spears").."/defaults.lua") -local input = io.open(minetest.get_modpath("spears").."/spears.conf", "r") -if input then - dofile(minetest.get_modpath("spears").."/spears.conf") - input:close() - input = nil -end +-- local input = io.open(minetest.get_modpath("spears").."/spears.conf", "r") +-- if input then +-- dofile(minetest.get_modpath("spears").."/spears.conf") +-- input:close() +-- input = nil +-- end dofile(minetest.get_modpath("spears").."/functions.lua") dofile(minetest.get_modpath("spears").."/tools.lua") -local log_mods = minetest.settings:get_bool("log_mods") - -if minetest.settings:get_bool("log_mods") then - minetest.log("action", "[MOD] Spears loaded") -end +minetest.log("action", "[MOD] Spears loaded with throwing speed " .. minetest.settings:get("spears_throw_speed") .. " and drag coeff. " .. minetest.settings:get("spears_drag_coeff")) diff --git a/locale/spears.eo.tr b/locale/spears.eo.tr new file mode 100644 index 0000000..1e636ad --- /dev/null +++ b/locale/spears.eo.tr @@ -0,0 +1,9 @@ +# textdomain: spears +Stone Spear=Ŝtona Ponardego +Iron Spear=Fera Ponardego +Steel Spear=Ŝtala Ponardego +Copper Spear=Kupra Ponardego +Bronze Spear=Bronza Ponardego +Obsidian Spear=Obsidiana Ponardego +Diamond Spear=Diamanta Ponardego +Golden Spear=Ora Ponardego diff --git a/locale/spears.it.tr b/locale/spears.it.tr new file mode 100644 index 0000000..099345a --- /dev/null +++ b/locale/spears.it.tr @@ -0,0 +1,9 @@ +# textdomain: spears +Stone Spear=Lancia di Pietra +Iron Spear=Lancia di Ferro +Steel Spear=Lancia di Acciaio +Copper Spear=Lancia di Rame +Bronze Spear=Lancia di Bronzo +Obsidian Spear=Lancia di Ossidiana +Diamond Spear=Lancia di Diamante +Golden Spear=Lancia Dorata diff --git a/locale/template.txt b/locale/template.txt index 1571f7b..d11246b 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -1,11 +1,9 @@ # textdomain: spears - -Stone spear= -Steel spear= -Copper spear= -Bronze spear= -Obsidian spear= -Diamond spear= -Golden spear= - - +Stone Spear= +Iron Spear= +Steel Spear= +Copper Spear= +Bronze Spear= +Obsidian Spear= +Diamond Spear= +Golden Spear= diff --git a/mod.conf b/mod.conf index 29dd3d4..9a13ec3 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,6 @@ name = spears depends = default +optional_depends = pigiron description = Add spears to Minetest, versatile weapons that can be thrown author = Echoes91 title = Spears diff --git a/settingtypes.txt b/settingtypes.txt new file mode 100644 index 0000000..b7c42c5 --- /dev/null +++ b/settingtypes.txt @@ -0,0 +1,17 @@ +# Initial speed +spears_throw_speed (Spear's speed when throwing) float 13 + +# Drag and fluid viscosity slows down the spear +spears_drag_coeff (Drag coefficient for spears in air) float 0.1 + +# Crackyness limit to stick a spear into a node instead of bouncing +spears_node_cracky_limit (Cracky node level limit to stick a spear) int 3 + +spears_enable_stone_spear (Stone spear enabled) bool true +spears_enable_iron_spear (Iron spear enabled, requires pigiron mod) bool false +spears_enable_steel_spear (Steel spear enabled) bool true +spears_enable_copper_spear (Copper spear enabled) bool true +spears_enable_bronze_spear (Bronze spear enabled) bool true +spears_enable_obsidian_spear (Obsidian spear enabled) bool true +spears_enable_diamond_spear (Diamond spear enabled) bool true +spears_enable_gold_spear (Gold spear enabled) bool true diff --git a/sounds/spears_hit.ogg b/sounds/spears_hit.ogg index d5b681c..ccde4c9 100644 Binary files a/sounds/spears_hit.ogg and b/sounds/spears_hit.ogg differ diff --git a/sounds/spears_throw.ogg b/sounds/spears_throw.ogg index ed1d993..dbf6e1e 100644 Binary files a/sounds/spears_throw.ogg and b/sounds/spears_throw.ogg differ diff --git a/spears.conf.example b/spears.conf.example deleted file mode 100644 index a92a86d..0000000 --- a/spears.conf.example +++ /dev/null @@ -1,8 +0,0 @@ -DISABLE_STONE_SPEAR = true -DISABLE_STEEL_SPEAR = true -DISABLE_COPPER_SPEAR = true -DISABLE_BRONZE_SPEAR = true -DISABLE_DIAMOND_SPEAR = true -DISABLE_OBSIDIAN_SPEAR = true -DISABLE_GOLD_SPEAR = true -SPEARS_THROW_SPEED = 13 diff --git a/tools.lua b/tools.lua index a17b12d..b8f5abf 100644 --- a/tools.lua +++ b/tools.lua @@ -1,10 +1,9 @@ - local S = minetest.get_translator("spears") function spears_register_spear(spear_type, desc, base_damage, toughness, material) minetest.register_tool("spears:spear_" .. spear_type, { - description = S(desc .. " spear"), + description = desc, wield_image = "spears_spear_" .. spear_type .. ".png^[transform4", inventory_image = "spears_spear_" .. spear_type .. ".png", wield_scale= {x = 1.5, y = 1.5, z = 1.5}, @@ -64,44 +63,43 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia }) end -if not DISABLE_STONE_SPEAR then - spears_register_spear('stone', 'Stone', 4, 20, 'group:stone') +if minetest.settings:get_bool('spears_enable_stone_spear') then + spears_register_spear('stone', S('Stone Spear'), 4, 20, 'group:stone') end if minetest.get_modpath("pigiron") then - if not DISABLE_IRON_SPEAR then - spears_register_spear('iron', 'Iron', 5.5, 30, 'pigiron:iron_ingot') + if minetest.settings:get_bool('spears_enable_iron_spear') then + spears_register_spear('iron', S('Iron Spear'), 5.5, 30, 'pigiron:iron_ingot') end - if not DISABLE_STEEL_SPEAR then - spears_register_spear('steel', 'Steel', 6, 35, 'default:steel_ingot') + if minetest.settings:get_bool('spears_enable_steel_spear') then + spears_register_spear('steel', S('Steel Spear'), 6, 35, 'default:steel_ingot') end - if not DISABLE_COPPER_SPEAR then - spears_register_spear('copper', 'Copper', 4.8, 30, 'default:copper_ingot') + if minetest.settings:get_bool('spears_enable_copper_spear') then + spears_register_spear('copper', S('Copper Spear'), 4.8, 30, 'default:copper_ingot') end - if not DISABLE_BRONZE_SPEAR then - spears_register_spear('bronze', 'Bronze', 5.5, 35, 'default:bronze_ingot') + if minetest.settings:get_bool('spears_enable_bronze_spear') then + spears_register_spear('bronze', S('Bronze Spear'), 5.5, 35, 'default:bronze_ingot') end else - if not DISABLE_STEEL_SPEAR then - spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot') + if minetest.settings:get_bool('spears_enable_steel_spear') then + spears_register_spear('steel', S('Steel Spear'), 6, 30, 'default:steel_ingot') end - if not DISABLE_COPPER_SPEAR then - spears_register_spear('copper', 'Copper', 5, 30, 'default:copper_ingot') + if minetest.settings:get_bool('spears_enable_copper_spear') then + spears_register_spear('copper', S('Copper Spear'), 5, 30, 'default:copper_ingot') end - if not DISABLE_BRONZE_SPEAR then - spears_register_spear('bronze', 'Bronze', 6, 35, 'default:bronze_ingot') + if minetest.settings:get_bool('spears_enable_bronze_spear') then + spears_register_spear('bronze', S('Bronze Spear'), 6, 35, 'default:bronze_ingot') end end - -if not DISABLE_OBSIDIAN_SPEAR then - spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian') +if minetest.settings:get_bool('spears_enable_obsidian_spear') then + spears_register_spear('obsidian', S('Obsidian Spear'), 8, 30, 'default:obsidian') end -if not DISABLE_DIAMOND_SPEAR then - spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond') +if minetest.settings:get_bool('spears_enable_diamond_spear') then + spears_register_spear('diamond', S('Diamond Spear'), 8, 40, 'default:diamond') end -if not DISABLE_GOLD_SPEAR then - spears_register_spear('gold', 'Golden', 5, 40, 'default:gold_ingot') +if minetest.settings:get_bool('spears_enable_gold_spear') then + spears_register_spear('gold', S('Golden Spear'), 5, 40, 'default:gold_ingot') end