Compare commits

...

31 Commits

Author SHA1 Message Date
6bc97332e6 Merge remote-tracking branch 'upstream/master' 2024-09-15 12:53:31 +02:00
Echoes
32d0ee567a Update 3.1.1 2024-03-03 10:08:29 +00:00
Echoes
5c7ef471ca Update file CHANGELOG 2024-03-03 10:07:58 +00:00
Echoes
dd5c92c0bc Deprecate completely defaults.lua 2024-03-03 09:55:16 +00:00
Echoes
ee21ce3826 Italian translations 2024-02-10 14:39:07 +00:00
Echoes
e1459d04cf Update 2 files
- /defaults.lua
- /CHANGELOG
2024-02-07 21:55:56 +00:00
Echoes
60c0656cd1 Update file functions.lua 2024-02-07 21:52:24 +00:00
Echoes
57c840451c Update file functions.lua 2024-02-07 21:49:31 +00:00
Echoes
440c620bf0 Update 3.1 functions 2024-02-07 21:46:58 +00:00
Echoes
bc1536223c 3.1 Changelog 2024-02-07 21:12:48 +00:00
Echoes
81e2c5c343 Replace spears_throw.ogg with mono 2024-02-07 21:09:57 +00:00
Echoes
299a3134ff Replace spears_hit.ogg 2024-02-07 21:09:29 +00:00
Echoes
3f3210d172 Update tools.lua with l18n support 2024-02-04 18:05:01 +00:00
Echoes
e9e7afd6c5 Merge branch 'master' into 'master'
Translation i18n support

See merge request echoes91/spears!3
2024-02-04 18:01:45 +00:00
Echoes
67b13d723b Merge branch 'master' into 'master'
# Conflicts:
#   tools.lua

Merging S('Text elements') with minetest.settings usage
2024-02-04 17:58:49 +00:00
Echoes
fa9601a6de Update mod.conf to fix release 3.0 2024-02-03 10:33:17 +00:00
echoes91
d5adec41d2 Version 3.0 2024-02-03 10:57:32 +01:00
echoes91
534e7ecc8f Version 3.0 2024-02-03 10:56:25 +01:00
Jaidyn Ann
152e649fb4 Add Esperanto translation 2024-01-03 15:16:09 -06:00
Jaidyn Ann
f9e839435c Add translation support 2024-01-03 15:15:57 -06:00
4514a8d0a1 Merge remote-tracking branch 'upstream/master' 2023-06-07 22:47:09 +02:00
Echoes
5ac99ff835 Version 2.4 2022-10-12 21:58:41 +00:00
echoes91
dca8c3ea26 Version 2.4 - Add pigiron 2022-10-12 23:52:34 +02:00
echoes91
4083fd6181 Version 2.4 - Add pigiron 2022-10-12 23:51:07 +02:00
echoes91
8dad57e2a6 Version 2.4 2022-10-12 23:20:51 +02:00
Echoes
f2e49d11cb Update mod.conf 2022-09-29 12:10:04 +00:00
Echoes
5b5e6a2774 Update mod.conf 2022-09-29 12:06:36 +00:00
echoes91
2cfbd68b48 Update 2.3 2022-09-28 23:50:27 +02:00
echoes91
a523aff826 Update 2.3 2022-09-28 23:44:35 +02:00
2100c74a21 Merge branch 'crabman77-fix' 2022-08-20 20:30:24 +02:00
b888cda310 fix itemframes issue nalc/nalc-server-mods#103
fix deployer issue nalc/nalc-server-mods#104
fix deprecated function
fix bad/Nonexistent collision detection on mobs/players, use collision box for very good detection
add translation client side
2022-07-21 17:35:07 +02:00
16 changed files with 328 additions and 112 deletions

View File

@ -1,3 +1,25 @@
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
Version 2.3:
- Updated to Minetest 5.6.0 API
- Changed receipts to avoid being confused with arrows
- Various cleansing and fixes
Version 2.2: Version 2.2:
- "Hit detection" based on spearhead position - "Hit detection" based on spearhead position
- Spears go through buildable_to nodes (snow) - Spears go through buildable_to nodes (snow)

View File

@ -3,23 +3,28 @@
This mod adds spears to Minetest. This mod adds spears to Minetest.
How to download: 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: Forum topic:
https://forum.minetest.net/viewtopic.php?f=11&t=13367 https://forum.minetest.net/viewtopic.php?f=11&t=13367
How to install: How to install:
Minetest content DB is the way!
http://wiki.minetest.com/wiki/Installing_Mods http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod: How to use the mod:
Craft a spear with | stick | stick | (material) |, works also mirrored. Craft a spear with | | | (material) |
| | stick | |
| stick | | |,
works also mirrored.
Spears can be thrown using right mouse button, they either hurt someone or stick where they land on; damage depends on speed and material, flight trajectory is ballistic with (unrealistic) drag. Spears can be thrown using right mouse button, they either hurt someone or stick where they land on; damage depends on speed and material, flight trajectory is ballistic with (unrealistic) drag.
Spears can be used to fight, but are slower and weaker than swords. Spears can be used to fight, but are slower and weaker than swords.
Spears can be used to dig, but are slower and weaker and pickaxes. Spears can be used to dig, but are slower and weaker and pickaxes.
If you miss the target it's your fault, the spear is fine. If you miss the target it's your fault, the spear is fine.
You can grab a spear on the fly (or maybe wait until it falls?). You can grab a spear on the fly (or maybe wait until it falls?).
You can stick a spear into a block, but if you remove the block then the spear falls (obviously). You can stick a spear into a block, but if you remove the block then the spear falls (obviously).
This mod contains the word "spear" more than 100 times, if you want the exact number count them yourself. This mod contains the word "spear" more than 100 times, if you want the exact number you can count them.
If you feel clever, throw a spear right above you and look at it to see what happens. If you feel clever, throw a spear right above you and look at it to see what happens.
You can even throw a spear from above down to your foes, it's even easier to hit. You can even throw a spear from above down to your foes, it's even easier to hit.
Someone once reported to have hit its own foot but it takes practice to do that. Someone once reported to have hit its own foot but it takes practice to do that.

View File

@ -1,7 +1,30 @@
DISABLE_STONE_SPEAR = false -- Seems like defaults in settingtypes.txt are not taken by default
DISABLE_STEEL_SPEAR = false --if minetest.settings:get("spears_throw_speed") == nil then
DISABLE_COPPER_SPEAR = false -- minetest.settings:set("spears_throw_speed", 13)
DISABLE_BRONZE_SPEAR = false --end
DISABLE_DIAMOND_SPEAR = false
DISABLE_OBSIDIAN_SPEAR = false --[[ if minetest.settings:get("spears_drag_coeff") == nil then
DISABLE_GOLD_SPEAR = false 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

View File

@ -7,30 +7,40 @@ function spears_throw (itemstack, player, pointed_thing)
local pitch = player:get_look_vertical() local pitch = player:get_look_vertical()
local yaw = player:get_look_horizontal() local yaw = player:get_look_horizontal()
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6) local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
-- Plant into node local wear = itemstack:get_wear()
if pointed_thing.type == "node" then local pointed_a = pointed_thing.above
local node = minetest.get_node(pointed_thing.under) local pointed_b = pointed_thing.under
if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then if pointed_thing.type == "node" and vector.distance(pointed_a, throw_pos) < 1 then -- Stick into node
local spear_object = minetest.add_entity(vector.divide(vector.add(vector.multiply(pointed_thing.above, 2), pointed_thing.under), 3), spear) local node = minetest.get_node(pointed_b)
local check_node = spears_check_node(node.name)
if check_node == nil then
return false
elseif check_node == 'cracky' then
minetest.sound_play("default_metal_footstep", {pos = pointed_a}, true)
return false
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:set_rotation(rotation)
spear_object:get_luaentity()._wear = itemstack:get_wear() spear_object:get_luaentity()._wear = wear
spear_object:get_luaentity()._stickpos = pointed_thing.under spear_object:get_luaentity()._stickpos = pointed_b
return minetest.sound_play("default_place_node", {pos = pointed_a}, true)
return false
end end
end else -- Throw
-- Avoid hitting yourself and throw local throw_speed = tonumber(minetest.settings:get("spears_throw_speed") or 13)
local throw_speed = 12 --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_player_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)))
spear_object:set_rotation(rotation) spear_object:set_rotation(rotation)
minetest.sound_play("spears_throw", {pos = player_pos}, true) minetest.sound_play("spears_throw", {pos = player_pos}, true)
spear_object:get_luaentity()._wear = itemstack:get_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
function spears_set_entity(spear_type, base_damage, toughness) function spears_set_entity(spear_type, base_damage, toughness)
@ -41,6 +51,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
visual_size = {x = 0.3, y = 0.3, z = 0.3}, visual_size = {x = 0.3, y = 0.3, z = 0.3},
wield_item = "spears:spear_" .. spear_type, wield_item = "spears:spear_" .. spear_type,
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3}, collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
lastpos={},
}, },
on_activate = function (self, staticdata, dtime_s) on_activate = function (self, staticdata, dtime_s)
@ -59,66 +70,70 @@ function spears_set_entity(spear_type, base_damage, toughness)
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
if not self._wear then local wear = self._wear
if wear == nil then
self.object:remove() self.object:remove()
return return false
end end
local pos = self.object:get_pos()
local velocity = self.object:get_velocity() local velocity = self.object:get_velocity()
local speed = vector.length(velocity) local speed = vector.length(velocity)
-- Spear is stuck ? if self._stickpos ~= nil then -- Spear is stuck
if self._stickpos then
local node = minetest.get_node(self._stickpos) local node = minetest.get_node(self._stickpos)
local node_cracky = minetest.registered_nodes[node.name].groups.cracky local check_node = spears_check_node(node.name)
local pos = self.object:get_pos() if check_node ~= 'sticky' then -- Fall when node is removed
if node_cracky and node_cracky < 3 then
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 = self._wear}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
elseif not self._node_walkable then return false
minetest.sound_play("default_place_node", {pos = throw_pos}, true)
end
self._node_walkable = minetest.registered_nodes[node.name].walkable
if not node or not self._node_walkable then -- Fall when node is removed
self.object:remove()
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear})
return
end end
else -- Spear is flying else -- Spear is flying
local direction = vector.normalize(velocity) local direction = vector.normalize(velocity)
local yaw = minetest.dir_to_yaw(direction) local yaw = minetest.dir_to_yaw(direction)
local pitch = math.acos(velocity.y/speed) - math.pi/3 local pitch = math.acos(velocity.y/speed) - math.pi/3
local pos = self.object:get_pos()
local spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5)) local spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5))
local node = minetest.get_node(spearhead_pos)
self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch}) self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
-- Hit someone? -- Hit a target?
local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 0.6) local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 1)
for _,object in ipairs(objects_in_radius) do 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 local damage = (speed + base_damage)^1.15 - 20
object:punch(self.object, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy=damage},}, direction) object:punch(self.object, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy=damage},}, direction)
self.object:remove() self.object:remove()
minetest.sound_play("spears_hit", {pos = pos}, true) minetest.sound_play("spears_hit", {pos = pos}, true)
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear + 65535/toughness}) wear = spears_wear(wear, toughness)
return minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
return true
end end
end end
-- Hit a node? -- Hit a node?
if node and minetest.registered_nodes[node.name].walkable local node = minetest.get_node(spearhead_pos)
and not minetest.registered_nodes[node.name].buildable_to local check_node = spears_check_node(node.name)
and not (minetest.registered_nodes[node.name].groups.slab and spearhead_pos.y % 1 < 0.5) if check_node == nil then
then -- Stick self.object:remove()
self.object:set_acceleration({x = 0, y = 0, z = 0}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
self.object:set_velocity({x = 0, y = 0, z = 0}) elseif check_node ~= 'through' then
self._wear = self._wear + 65535/toughness wear = spears_wear(wear, toughness)
if self._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()
return minetest.add_item(pos, {name='defaut:stick'})
end return false
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 == '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._stickpos = spearhead_pos
self._wear = wear
end
else -- Get drag else -- Get drag
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1) local viscosity = minetest.registered_nodes[node.name].liquid_viscosity
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) local acceleration = vector.multiply(velocity, -drag)
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7) acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
self.object:set_acceleration(acceleration) self.object:set_acceleration(acceleration)
@ -128,3 +143,83 @@ function spears_set_entity(spear_type, base_damage, toughness)
} }
return SPEAR_ENTITY return SPEAR_ENTITY
end 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 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 'through'
end
end
function spears_wear(initial_wear, toughness)
if not minetest.settings:get_bool("creative_mode") then
local wear = initial_wear + 65535/toughness
return wear
else
local wear = initial_wear
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

View File

@ -1,15 +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") -- local input = io.open(minetest.get_modpath("spears").."/spears.conf", "r")
if input then -- if input then
dofile(minetest.get_modpath("spears").."/spears.conf") -- dofile(minetest.get_modpath("spears").."/spears.conf")
input:close() -- input:close()
input = nil -- input = nil
end -- end
dofile(minetest.get_modpath("spears").."/functions.lua") dofile(minetest.get_modpath("spears").."/functions.lua")
dofile(minetest.get_modpath("spears").."/tools.lua") dofile(minetest.get_modpath("spears").."/tools.lua")
minetest.log("action", "[MOD] Spears loaded with throwing speed " .. minetest.settings:get("spears_throw_speed") .. " and drag coeff. " .. minetest.settings:get("spears_drag_coeff"))
minetest.log("action", "[spears] loaded.")

9
locale/spears.eo.tr Normal file
View File

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

9
locale/spears.fr.tr Normal file
View File

@ -0,0 +1,9 @@
# textdomain: spears
Stone spear=Lance en pierre
Steel spear=Lance en acier
Copper spear=Lance en cuivre
Bronze spear=Lance en bronze
Obsidian spear=Lance en obsidienne
Diamond spear=Lance en diamant
Golden spear=Lance en or

9
locale/spears.it.tr Normal file
View File

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

9
locale/template.txt Normal file
View File

@ -0,0 +1,9 @@
# textdomain: spears
Stone Spear=
Iron Spear=
Steel Spear=
Copper Spear=
Bronze Spear=
Obsidian Spear=
Diamond Spear=
Golden Spear=

View File

@ -1,4 +1,7 @@
name = spears name = spears
title = Separs
description = Add spears to Minetest
depends = default depends = default
optional_depends = pigiron
description = Add spears to Minetest, versatile weapons that can be thrown
author = Echoes91
title = Spears
min_minetest_version = 5.4

17
settingtypes.txt Normal file
View File

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

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +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

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

View File

@ -1,20 +1,29 @@
local S = minetest.get_translator("spears")
function spears_register_spear(spear_type, desc, base_damage, toughness, material) function spears_register_spear(spear_type, desc, base_damage, toughness, material)
minetest.register_tool("spears:spear_" .. spear_type, { minetest.register_tool("spears:spear_" .. spear_type, {
description = desc .. " spear", description = desc,
wield_image = "spears_spear_" .. spear_type .. ".png^[transform4", wield_image = "spears_spear_" .. spear_type .. ".png^[transform4",
inventory_image = "spears_spear_" .. spear_type .. ".png", inventory_image = "spears_spear_" .. spear_type .. ".png",
wield_scale= {x = 1.5, y = 1.5, z = 1.5}, wield_scale= {x = 1.5, y = 1.5, z = 1.5},
on_secondary_use = function(itemstack, user, pointed_thing) on_secondary_use = function(itemstack, user, pointed_thing)
spears_throw(itemstack, user, pointed_thing) spears_throw(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
end, end,
on_place = function(itemstack, user, pointed_thing) on_place = function(itemstack, user, pointed_thing)
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
if minetest.registered_nodes[node.name] and (node.name == "itemframes:pedestal" or node.name == "itemframes:frame") then
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack)
return itemstack
end
end
spears_throw(itemstack, user, pointed_thing) spears_throw(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
@ -38,46 +47,59 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
minetest.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{'', '', material}, {"", "", material},
{'', 'group:stick', ''}, {"", "group:stick", ""},
{'group:stick', '', ''}, {"group:stick", "", ""}
} }
}) })
minetest.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{material, '', ''}, {material, "", ""},
{'', 'group:stick', ''}, {"", "group:stick", ""},
{'', '', 'group:stick'}, {"", "", "group:stick"}
} }
}) })
end end
if not DISABLE_STONE_SPEAR then if minetest.settings:get_bool('spears_enable_stone_spear') then
spears_register_spear('stone', 'Stone', 4, 20, 'group:stone') spears_register_spear('stone', S('Stone Spear'), 4, 20, 'group:stone')
end end
if not DISABLE_STEEL_SPEAR then if minetest.get_modpath("pigiron") then
spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_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 minetest.settings:get_bool('spears_enable_steel_spear') then
spears_register_spear('steel', S('Steel Spear'), 6, 35, 'default:steel_ingot')
end
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 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 minetest.settings:get_bool('spears_enable_steel_spear') then
spears_register_spear('steel', S('Steel Spear'), 6, 30, 'default:steel_ingot')
end
if minetest.settings:get_bool('spears_enable_copper_spear') then
spears_register_spear('copper', S('Copper Spear'), 5, 30, 'default:copper_ingot')
end
if minetest.settings:get_bool('spears_enable_bronze_spear') then
spears_register_spear('bronze', S('Bronze Spear'), 6, 35, 'default:bronze_ingot')
end
end end
if not DISABLE_COPPER_SPEAR then if minetest.settings:get_bool('spears_enable_obsidian_spear') then
spears_register_spear('copper', 'Copper', 5, 35, 'default:copper_ingot') spears_register_spear('obsidian', S('Obsidian Spear'), 8, 30, 'default:obsidian')
end end
if not DISABLE_BRONZE_SPEAR then if minetest.settings:get_bool('spears_enable_diamond_spear') then
spears_register_spear('bronze', 'Bronze', 6, 35, 'default:bronze_ingot') spears_register_spear('diamond', S('Diamond Spear'), 8, 40, 'default:diamond')
end end
if not DISABLE_OBSIDIAN_SPEAR then if minetest.settings:get_bool('spears_enable_gold_spear') then
spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian') spears_register_spear('gold', S('Golden Spear'), 5, 40, 'default:gold_ingot')
end
if not DISABLE_DIAMOND_SPEAR then
spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond')
end
if not DISABLE_GOLD_SPEAR then
spears_register_spear('gold', 'Golden', 5, 40, 'default:gold_ingot')
end end