1
0
mirror of https://gitlab.com/echoes91/spears.git synced 2025-07-27 10:20:17 +02:00

9 Commits

Author SHA1 Message Date
4514a8d0a1 Merge remote-tracking branch 'upstream/master' 2023-06-07 22:47:09 +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
e2182ca004 Delete depends.txt, add mod.conf 2022-07-02 21:36:09 +02:00
a5b33a6e9a Fix crash 2020-08-09 00:58:12 +02:00
8770387fbc Change craft recipes that conflict with throwing mod 2020-08-08 23:46:38 +02:00
66c69c5265 Fix undeclared global variable warning at startup
DISABLE_GOLD_SPEAR
2020-06-20 16:31:26 +02:00
662e637595 Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev 2020-06-14 22:16:47 +02:00
63d339a686 Corrige avertissement sur variable globale 2018-12-24 01:14:12 +01:00
15 changed files with 159 additions and 275 deletions

View File

@ -1,24 +1,3 @@
Version 3.2.0
- Moving from minetest. to core. API calls for future-proof newcomers-friendly maintenance.
- Properly manage default settings values in defaults.lua
- Addied full_punch_interval parameter to settings
Update 3.1.2
- Fix initial loading with fallback values for logging and Esperanto translations tweaks.
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: Version 2.4:
- Functions rewrite, fixed many vector/variable declarations and unknown node handling - Functions rewrite, fixed many vector/variable declarations and unknown node handling
- Added pigiron support - Added pigiron support

24
README
View File

@ -1,32 +1,28 @@
=== SPEARS for LUANTI by Echoes91 === === SPEARS for MINETEST by Echoes91 ===
This mod adds spears to Luanti (formerly to Minetest). This mod adds spears to Minetest.
How to download: How to download:
If you have this file, you probably know. If you have this file, you already know
If you're reading from gitlab.com, you already know.
But in doubt, https://gitlab.com/echoes91/spears/-/archive/master/spears-master.zip
Forum topic: Forum topic:
https://forum.luanti.org/viewtopic.php?t=13367 https://forum.minetest.net/viewtopic.php?f=11&t=13367
How to install: How to install:
Content DB is the way! http://wiki.minetest.com/wiki/Installing_Mods
https://wiki.luanti.org/Mods#Installation
How to use the mod: How to use the mod:
Craft a spear with | | | material | Craft a spear with | | | (material) |
| | stick | | | | stick | |
| stick | | | | stick | | |,
works also mirrored. 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 to know the exact number there must be a sed script for that. 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 down to your foes from above, 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,52 +1,16 @@
-- Seems like defaults in settingtypes.txt are not taken by default, let's default them DISABLE_STONE_SPEAR = false
if core.settings:get("spears_throw_speed") == nil then DISABLE_STEEL_SPEAR = false
core.settings:set("spears_throw_speed", 13) DISABLE_COPPER_SPEAR = false
end DISABLE_BRONZE_SPEAR = false
DISABLE_DIAMOND_SPEAR = false
if core.settings:get("spears_drag_coeff") == nil then DISABLE_OBSIDIAN_SPEAR = false
core.settings:set("spears_drag_coeff", 0.1) DISABLE_GOLD_SPEAR = false
end DISABLE_IRON_SPEAR = false
SPEARS_THROW_SPEED = 13
if core.settings:get("spears_node_cracky_limit") == nil then SPEARS_V_ZERO = {x = 0, y = 0, z = 0}
core.settings:set("spears_node_cracky_limit", 3) SPEARS_DRAG_COEFF = 0.1
end SPEARS_NODE_UNKNOWN = nil
SPEARS_NODE_THROUGH = 0
if core.settings:get("spears_full_punch_interval") == nil then SPEARS_NODE_STICKY = 1
core.settings:set("spears_full_punch_interval", 1.5) SPEARS_NODE_CRACKY = 2
end SPEARS_NODE_CRACKY_LIMIT = 3
if core.settings:get("spears_enable_stone_spear") == nil then
core.settings:set_bool("spears_enable_stone_spear", true)
end
if core.get_modpath("pigiron") then
if core.settings:get("spears_enable_iron_spear") == nil then
core.settings:set_bool("spears_enable_iron_spear", true)
end
else
core.settings:set_bool("spears_enable_iron_spear", false)
end
if core.settings:get("spears_enable_steel_spear") == nil then
core.settings:set_bool("spears_enable_steel_spear", true)
end
if core.settings:get("spears_enable_copper_spear") == nil then
core.settings:set_bool("spears_enable_copper_spear", true)
end
if core.settings:get("spears_enable_bronze_spear") == nil then
core.settings:set_bool("spears_enable_bronze_spear", true)
end
if core.settings:get("spears_enable_obsidian_spear") == nil then
core.settings:set_bool("spears_enable_obsidian_spear", true)
end
if core.settings:get("spears_enable_diamond_spear") == nil then
core.settings:set_bool("spears_enable_diamond_spear", true)
end
if core.settings:get("spears_enable_gold_spear") == nil then
core.settings:set_bool("spears_enable_gold_spear", true)
end

View File

@ -11,31 +11,33 @@ function spears_throw (itemstack, player, pointed_thing)
local pointed_a = pointed_thing.above local pointed_a = pointed_thing.above
local pointed_b = pointed_thing.under local pointed_b = pointed_thing.under
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 = core.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 == nil then if check_node == SPEARS_NODE_UNKNOWN then
return false return false
elseif check_node == 'cracky' then elseif check_node == SPEARS_NODE_CRACKY then
core.sound_play("default_metal_footstep", {pos = pointed_a}, true) minetest.sound_play("default_metal_footstep", {pos = pointed_a}, true)
return false return false
elseif check_node == 'sticky' then elseif check_node == SPEARS_NODE_STICKY then
local spear_object = core.add_entity(vector.divide(vector.add(vector.multiply(pointed_a, 2), pointed_b), 3), spear) 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 = wear spear_object:get_luaentity()._wear = wear
spear_object:get_luaentity()._stickpos = pointed_b spear_object:get_luaentity()._stickpos = pointed_b
core.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 -- Throw else -- Avoid hitting yourself and throw
local throw_speed = tonumber(core.settings:get("spears_throw_speed")) 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
local player_vel = player:get_velocity() local player_vel = player:get_velocity()
local spear_object = core.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)
core.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
@ -48,6 +50,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)
@ -75,61 +78,60 @@ function spears_set_entity(spear_type, base_damage, toughness)
local velocity = self.object:get_velocity() local velocity = self.object:get_velocity()
local speed = vector.length(velocity) local speed = vector.length(velocity)
if self._stickpos ~= nil then -- Spear is stuck if self._stickpos ~= nil then -- Spear is stuck
local node = core.get_node(self._stickpos) local node = minetest.get_node(self._stickpos)
local check_node = spears_check_node(node.name) local check_node = spears_check_node(node.name)
if check_node ~= 'sticky' then -- Fall when node is removed if check_node ~= SPEARS_NODE_STICKY then -- Fall when node is removed
self.object:remove() self.object:remove()
core.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
end end
else -- Spear is flying else -- Spear is flying
local direction = vector.normalize(velocity) local direction = vector.normalize(velocity)
local yaw = core.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 spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5)) local spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5))
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 a target? -- Hit someone?
local objects_in_radius = core.get_objects_inside_radius(spearhead_pos, 1) local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 0.6)
for _,object in ipairs(objects_in_radius) do for _,object in ipairs(objects_in_radius) do
if spears_check_target(self, object, spearhead_pos) and object:get_armor_groups().fleshy then if object:get_luaentity() ~= self 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()
core.sound_play("spears_hit", {pos = pos}, true) minetest.sound_play("spears_hit", {pos = pos}, true)
wear = spears_wear(wear, toughness) wear = spears_wear(wear, toughness)
core.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
return true return true
end end
end end
-- Hit a node? -- Hit a node?
local node = core.get_node(spearhead_pos) local node = minetest.get_node(spearhead_pos)
local check_node = spears_check_node(node.name) local check_node = spears_check_node(node.name)
if check_node == nil then if check_node == SPEARS_NODE_UNKNOWN then
self.object:remove() self.object:remove()
core.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = wear})
elseif check_node ~= 'through' then elseif check_node ~= SPEARS_NODE_THROUGH then
wear = spears_wear(wear, toughness) wear = spears_wear(wear, toughness)
if wear >= 65535 then if wear >= 65535 then
core.sound_play("default_tool_breaks", {pos = pos}, true) minetest.sound_play("default_tool_breaks", {pos = pos}, true)
self.object:remove() self.object:remove()
core.add_item(pos, {name='defaut:stick'}) minetest.add_item(pos, {name='defaut:stick'})
return false return false
elseif check_node == 'cracky' then elseif check_node == SPEARS_NODE_CRACKY then
core.sound_play("default_metal_footstep", {pos = pos}, true) minetest.sound_play("default_metal_footstep", {pos = pos}, true)
self.object:remove() self.object:remove()
core.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 == 'sticky' then elseif check_node == SPEARS_NODE_STICKY then
self.object:set_acceleration({x = 0, y = 0, z = 0}) self.object:set_acceleration(SPEARS_V_ZERO)
self.object:set_velocity({x = 0, y = 0, z = 0}) self.object:set_velocity(SPEARS_V_ZERO)
core.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
self._wear = wear self._wear = wear
end end
else -- Get drag else -- Get drag
local viscosity = core.registered_nodes[node.name].liquid_viscosity local viscosity = minetest.registered_nodes[node.name].liquid_viscosity
local drag_coeff = tonumber(core.settings:get("spears_drag_coeff")) local drag = math.max(viscosity, SPEARS_DRAG_COEFF)
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)
@ -141,21 +143,20 @@ function spears_set_entity(spear_type, base_damage, toughness)
end end
function spears_check_node(node_name) function spears_check_node(node_name)
local node = core.registered_nodes[node_name] local node = minetest.registered_nodes[node_name]
local cracky_limit = tonumber(core.settings:get("spears_node_cracky_limit"))
if node == nil then if node == nil then
return nil return SPEARS_NODE_UNKNOWN
elseif node.groups.cracky ~= nil and node.groups.cracky < cracky_limit then elseif node.groups.cracky ~= nil and node.groups.cracky < SPEARS_NODE_CRACKY_LIMIT then
return 'cracky' return SPEARS_NODE_CRACKY
elseif node.walkable and not node.buildable_to then elseif node.walkable and not node.buildable then
return 'sticky' return SPEARS_NODE_STICKY
else else
return 'through' return SPEARS_NODE_THROUGH
end end
end end
function spears_wear(initial_wear, toughness) function spears_wear(initial_wear, toughness)
if not core.settings:get_bool("creative_mode") then if not minetest.settings:get_bool("creative_mode") then
local wear = initial_wear + 65535/toughness local wear = initial_wear + 65535/toughness
return wear return wear
else else
@ -163,59 +164,3 @@ function spears_wear(initial_wear, toughness)
return wear return wear
end end
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,7 +1,18 @@
-- Welcome to spears mod dofile(minetest.get_modpath("spears").."/defaults.lua")
dofile(core.get_modpath("spears").."/defaults.lua") local input = io.open(minetest.get_modpath("spears").."/spears.conf", "r")
dofile(core.get_modpath("spears").."/functions.lua") if input then
dofile(core.get_modpath("spears").."/tools.lua") dofile(minetest.get_modpath("spears").."/spears.conf")
input:close()
input = nil
end
core.log("action", "[MOD] Spears loaded with throwing speed " .. (core.settings:get("spears_throw_speed")) .. " and drag coeff. " .. (core.settings:get("spears_drag_coeff"))) 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

View File

@ -1,9 +0,0 @@
# 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

View File

@ -1,9 +0,0 @@
# 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

View File

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

View File

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

View File

@ -1,20 +0,0 @@
# 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
# When used as melee weapon, the spear will do full damage if this time is spent between punches.
spears_full_punch_interval (When used as melee weapon, the spear will do full damage if this time is spent between punches.) float 1.5
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.

8
spears.conf.example Normal file
View File

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

View File

@ -1,28 +1,36 @@
local S = core.get_translator("spears")
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)
core.register_tool("spears:spear_" .. spear_type, { minetest.register_tool("spears:spear_" .. spear_type, {
description = desc, description = S(desc .. " spear"),
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 core.settings:get_bool("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 core.settings:get_bool("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,
tool_capabilities = { tool_capabilities = {
full_punch_interval = core.settings:get("spears_full_punch_interval"), full_punch_interval = 1.5,
max_drop_level=1, max_drop_level=1,
groupcaps={ groupcaps={
cracky = {times={[3]=2}, uses=toughness, maxlevel=1}, cracky = {times={[3]=2}, uses=toughness, maxlevel=1},
@ -35,9 +43,9 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
local SPEAR_ENTITY = spears_set_entity(spear_type, base_damage, toughness) local SPEAR_ENTITY = spears_set_entity(spear_type, base_damage, toughness)
core.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY) minetest.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY)
core.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{"", "", material}, {"", "", material},
@ -46,7 +54,7 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
} }
}) })
core.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{material, "", ""}, {material, "", ""},
@ -56,43 +64,44 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
}) })
end end
if core.settings:get_bool('spears_enable_stone_spear') then if not DISABLE_STONE_SPEAR then
spears_register_spear('stone', S('Stone Spear'), 4, 20, 'group:stone') spears_register_spear('stone', 'Stone', 4, 20, 'group:stone')
end end
if core.get_modpath("pigiron") then if minetest.get_modpath("pigiron") then
if core.settings:get_bool('spears_enable_iron_spear') then if not DISABLE_IRON_SPEAR then
spears_register_spear('iron', S('Iron Spear'), 5.5, 30, 'pigiron:iron_ingot') spears_register_spear('iron', 'Iron', 5.5, 30, 'pigiron:iron_ingot')
end end
if core.settings:get_bool('spears_enable_steel_spear') then if not DISABLE_STEEL_SPEAR then
spears_register_spear('steel', S('Steel Spear'), 6, 35, 'default:steel_ingot') spears_register_spear('steel', 'Steel', 6, 35, 'default:steel_ingot')
end end
if core.settings:get_bool('spears_enable_copper_spear') then if not DISABLE_COPPER_SPEAR then
spears_register_spear('copper', S('Copper Spear'), 4.8, 30, 'default:copper_ingot') spears_register_spear('copper', 'Copper', 4.8, 30, 'default:copper_ingot')
end end
if core.settings:get_bool('spears_enable_bronze_spear') then if not DISABLE_BRONZE_SPEAR then
spears_register_spear('bronze', S('Bronze Spear'), 5.5, 35, 'default:bronze_ingot') spears_register_spear('bronze', 'Bronze', 5.5, 35, 'default:bronze_ingot')
end end
else else
if core.settings:get_bool('spears_enable_steel_spear') then if not DISABLE_STEEL_SPEAR then
spears_register_spear('steel', S('Steel Spear'), 6, 30, 'default:steel_ingot') spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot')
end end
if core.settings:get_bool('spears_enable_copper_spear') then if not DISABLE_COPPER_SPEAR then
spears_register_spear('copper', S('Copper Spear'), 5, 30, 'default:copper_ingot') spears_register_spear('copper', 'Copper', 5, 30, 'default:copper_ingot')
end end
if core.settings:get_bool('spears_enable_bronze_spear') then if not DISABLE_BRONZE_SPEAR then
spears_register_spear('bronze', S('Bronze Spear'), 6, 35, 'default:bronze_ingot') spears_register_spear('bronze', 'Bronze', 6, 35, 'default:bronze_ingot')
end end
end end
if core.settings:get_bool('spears_enable_obsidian_spear') then
spears_register_spear('obsidian', S('Obsidian Spear'), 8, 30, 'default:obsidian') if not DISABLE_OBSIDIAN_SPEAR then
spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian')
end end
if core.settings:get_bool('spears_enable_diamond_spear') then if not DISABLE_DIAMOND_SPEAR then
spears_register_spear('diamond', S('Diamond Spear'), 8, 40, 'default:diamond') spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond')
end end
if core.settings:get_bool('spears_enable_gold_spear') then if not DISABLE_GOLD_SPEAR then
spears_register_spear('gold', S('Golden Spear'), 5, 40, 'default:gold_ingot') spears_register_spear('gold', 'Golden', 5, 40, 'default:gold_ingot')
end end