1
0
mirror of https://gitlab.com/echoes91/spears.git synced 2025-06-30 22:50:21 +02:00

6 Commits
2.3 ... master

Author SHA1 Message Date
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
7 changed files with 19 additions and 33 deletions

View File

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

7
README
View File

@ -12,17 +12,14 @@ How to install:
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 | | | (material) | Craft a spear with | stick | stick | (material) |, works also mirrored.
| | 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 you can count them. This mod contains the word "spear" more than 100 times, if you want the exact number count them yourself.
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

@ -7,7 +7,7 @@ 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)
-- Stick into node -- Plant into node
if pointed_thing.type == "node" then if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)
if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then
@ -23,7 +23,7 @@ function spears_throw (itemstack, player, pointed_thing)
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)
@ -63,19 +63,19 @@ function spears_set_entity(spear_type, base_damage, toughness)
self.object:remove() self.object:remove()
return return
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 ? -- Spear is stuck ?
if self._stickpos then 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 node_cracky = minetest.registered_nodes[node.name].groups.cracky
local pos = self.object:get_pos()
if node_cracky and node_cracky < 3 then if node_cracky and node_cracky < 3 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 = self._wear}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear})
elseif not self._node_walkable then elseif not self._node_walkable then
minetest.sound_play("default_place_node", {pos = pos}, true) minetest.sound_play("default_place_node", {pos = throw_pos}, true)
end end
self._node_walkable = minetest.registered_nodes[node.name].walkable self._node_walkable = minetest.registered_nodes[node.name].walkable
if not node or not self._node_walkable then -- Fall when node is removed if not node or not self._node_walkable then -- Fall when node is removed
@ -87,6 +87,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
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) 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})

View File

@ -11,8 +11,5 @@ dofile(minetest.get_modpath("spears").."/functions.lua")
dofile(minetest.get_modpath("spears").."/tools.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", "[spears] loaded.")
minetest.log("action", "[MOD] Spears loaded")
end

View File

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

View File

@ -4,4 +4,3 @@ DISABLE_COPPER_SPEAR = true
DISABLE_BRONZE_SPEAR = true DISABLE_BRONZE_SPEAR = true
DISABLE_DIAMOND_SPEAR = true DISABLE_DIAMOND_SPEAR = true
DISABLE_OBSIDIAN_SPEAR = true DISABLE_OBSIDIAN_SPEAR = true
DISABLE_GOLD_SPEAR = true

View File

@ -7,14 +7,14 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
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.settings:get_bool("creative_mode") then if not minetest.setting_getbool("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)
spears_throw(itemstack, user, pointed_thing) spears_throw(itemstack, user, pointed_thing)
if not minetest.settings:get_bool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
return itemstack return itemstack
@ -38,18 +38,18 @@ 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